@copilotkit/vue 1.69.2 → 1.69.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PARITY.md +1 -1
- package/README.md +7 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +14 -14
- package/dist/use-render-activity-message-DMY6Krn-.cjs +85 -0
- package/dist/use-render-activity-message-DMY6Krn-.cjs.map +1 -0
- package/dist/{use-render-activity-message-Db2rOZkW.js → use-render-activity-message-W2lbqLZH.js} +2844 -2828
- package/dist/use-render-activity-message-W2lbqLZH.js.map +1 -0
- package/dist/v2/components/CopilotKitInspector.vue.d.ts +2 -0
- package/dist/v2/components/CopilotKitInspector.vue.d.ts.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/providers/CopilotKitProvider.types.d.ts +10 -9
- package/dist/v2/providers/CopilotKitProvider.types.d.ts.map +1 -1
- package/dist/v2/providers/CopilotKitProvider.vue.d.ts +1 -1
- package/dist/v2/providers/CopilotKitProvider.vue.d.ts.map +1 -1
- package/dist/v2/providers/keys.d.ts +10 -0
- package/dist/v2/providers/keys.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/v2/__tests__/mocks/web-inspector.ts +32 -1
- package/src/v2/components/CopilotKitInspector.vue +41 -3
- package/src/v2/components/__tests__/CopilotKitInspector.test.ts +31 -6
- package/src/v2/providers/CopilotKitProvider.types.ts +10 -9
- package/src/v2/providers/CopilotKitProvider.vue +25 -23
- package/src/v2/providers/__tests__/CopilotKitProvider.test.ts +148 -37
- package/src/v2/providers/keys.ts +15 -0
- package/dist/use-render-activity-message-CIlNtfvE.cjs +0 -85
- package/dist/use-render-activity-message-CIlNtfvE.cjs.map +0 -1
- package/dist/use-render-activity-message-Db2rOZkW.js.map +0 -1
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";var Zn=Object.create;var Pt=Object.defineProperty;var eo=Object.getOwnPropertyDescriptor;var to=Object.getOwnPropertyNames;var no=Object.getPrototypeOf,oo=Object.prototype.hasOwnProperty;var ao=(t,o,n,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of to(o))!oo.call(t,r)&&r!==n&&Pt(t,r,{get:()=>o[r],enumerable:!(a=eo(o,r))||a.enumerable});return t};var vt=(t,o,n)=>(n=t!=null?Zn(no(t)):{},ao(o||!t||!t.__esModule?Pt(n,"default",{value:t,enumerable:!0}):n,t));const e=require("vue"),Y=require("zod"),j=require("@copilotkit/shared"),Tt=require("zod-to-json-schema"),oe=require("@copilotkit/core"),dt=require("@a2ui/web_core/v0_9"),ye=require("@a2ui/web_core/v0_9/basic_catalog"),qe=require("@ag-ui/client"),se=require("lucide-vue-next"),an=require("streamdown-vue"),sn=e.defineComponent({inheritAttrs:!1,__name:"CopilotKitInspector",props:{core:{}},setup(t){const o=t,n=e.useAttrs(),a=e.shallowRef(null);let r=!0;return e.onMounted(()=>{import("@copilotkit/web-inspector").then(s=>{s.defineWebInspector?.(),r&&(a.value=s.WEB_INSPECTOR_TAG)}).catch(s=>{console.error("Failed to load CopilotKit inspector:",s)})}),e.onUnmounted(()=>{r=!1}),(s,i)=>a.value?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(a.value),e.mergeProps({key:0},e.unref(n),{".core":o.core??null}),null,48,[".core"])):e.createCommentVNode("",!0)}}),rn=Symbol("CopilotKit"),wt=Symbol("CopilotChatConfiguration"),ln=Symbol("SandboxFunctions");function xe(){const t=e.inject(rn);if(!t)throw new Error("useCopilotKit must be used within CopilotKitProvider");return t}const so="2025-06-18";function ro(t){const o="'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*",n="* blob: data: http://localhost:* https://localhost:*",a=t?.length?` ${t.join(" ")}`:"",r=`${o}${a}`,s=`${n}${a}`;return`<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src * data: blob: 'unsafe-inline'; media-src * blob: data:; font-src * blob: data:; script-src ${r}; style-src * blob: data: 'unsafe-inline'; connect-src *; frame-src ${s}; base-uri 'self';" />
|
|
6
|
-
<style>html,body{margin:0;padding:0;height:100%;width:100%;overflow:hidden}*{box-sizing:border-box}iframe{background-color:transparent;border:none;padding:0;overflow:hidden;width:100%;height:100%}</style>
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
<script>
|
|
10
|
-
if(window.self===window.top){throw new Error("This file must be used in an iframe.")}
|
|
11
|
-
const inner=document.createElement("iframe");
|
|
12
|
-
inner.style="width:100%;height:100%;border:none;";
|
|
13
|
-
inner.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms");
|
|
14
|
-
document.body.appendChild(inner);
|
|
15
|
-
window.addEventListener("message",async(event)=>{
|
|
16
|
-
if(event.source===window.parent){
|
|
17
|
-
if(event.data&&event.data.method==="ui/notifications/sandbox-resource-ready"){
|
|
18
|
-
const{html,sandbox}=event.data.params;
|
|
19
|
-
if(typeof sandbox==="string")inner.setAttribute("sandbox",sandbox);
|
|
20
|
-
if(typeof html==="string")inner.srcdoc=html;
|
|
21
|
-
}else if(inner&&inner.contentWindow){
|
|
22
|
-
inner.contentWindow.postMessage(event.data,"*");
|
|
23
|
-
}
|
|
24
|
-
}else if(event.source===inner.contentWindow){
|
|
25
|
-
window.parent.postMessage(event.data,"*");
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-ready",params:{}},"*");
|
|
29
|
-
<\/script>
|
|
30
|
-
</body>
|
|
31
|
-
</html>`}class io{queues=new Map;processing=new Map;async enqueue(o,n){const a=o.threadId||"default";return new Promise((r,s)=>{let i=this.queues.get(a);i||(i=[],this.queues.set(a,i)),i.push({execute:n,resolve:r,reject:s}),this.processQueue(a,o)})}async processQueue(o,n){if(!this.processing.get(o)){this.processing.set(o,!0);try{const a=this.queues.get(o);if(!a)return;for(;a.length>0;){const r=a[0];try{await this.waitForAgentIdle(n);const s=await r.execute();r.resolve(s)}catch(s){r.reject(s instanceof Error?s:new Error(String(s)))}a.shift()}}finally{this.processing.set(o,!1)}}}cancel(o){const n=this.queues.get(o);if(n){for(const a of n)a.reject(new Error("MCPAppsRequestQueue cancelled on unmount"));n.length=0}this.queues.delete(o),this.processing.delete(o)}waitForAgentIdle(o){return new Promise((n,a)=>{if(!o.isRunning){n();return}let r=!1;const s=setTimeout(()=>{r||(r=!0,clearInterval(c),l.unsubscribe(),a(new Error("[CopilotKit] Timed out waiting for agent to become idle")))},3e4),i=()=>{r||(r=!0,clearTimeout(s),clearInterval(c),l.unsubscribe(),n())},l=o.subscribe({onRunFinalized:i,onRunFailed:i}),c=setInterval(()=>{o.isRunning||i()},500)})}}const rt=new io,cn="mcp-apps",un=Y.z.object({result:Y.z.object({content:Y.z.array(Y.z.any()).optional(),structuredContent:Y.z.any().optional(),isError:Y.z.boolean().optional()}),resourceUri:Y.z.string(),serverHash:Y.z.string(),serverId:Y.z.string().optional(),toolInput:Y.z.record(Y.z.string(),Y.z.unknown()).optional()});function lo(t){return"id"in t&&"method"in t}function co(t){return!("id"in t)&&"method"in t}const dn=e.defineComponent({name:"MCPAppsActivityRenderer",props:{activityType:{type:String,required:!0},content:{type:Object,required:!0},message:{type:Object,required:!0},agent:{type:Object,required:!1,default:void 0}},setup(t){const{copilotkit:o}=xe(),n=e.ref(null),a=e.ref(null),r=e.ref(!1),s=e.ref(null),i=e.ref(!0),l=e.ref({}),c=e.ref(null),d=e.ref({inProgress:!1,promise:null,resourceUri:null}),x=b=>{a.value?.contentWindow&&a.value.contentWindow.postMessage(b,"*")},p=(b,h)=>{x({jsonrpc:"2.0",id:b,result:h})},v=(b,h,C)=>{x({jsonrpc:"2.0",id:b,error:{code:h,message:C}})},u=(b,h)=>{x({jsonrpc:"2.0",method:b,params:h||{}})};e.watch([()=>t.agent,()=>t.content],([b,h])=>{i.value=!0,s.value=null,r.value=!1,l.value={},c.value=null;const{resourceUri:C,serverHash:f,serverId:g}=h;if(d.value.inProgress&&d.value.resourceUri===C){d.value.promise?.then(y=>{y&&(c.value=y,i.value=!1)}).catch(y=>{s.value=y instanceof Error?y:new Error(String(y)),i.value=!1});return}if(!b){s.value=new Error("No agent available to fetch resource"),i.value=!1;return}d.value.inProgress=!0,d.value.resourceUri=C;const m=(async()=>{try{const M=(await rt.enqueue(b,()=>b.runAgent({forwardedProps:{__proxiedMCPRequest:{serverHash:f,serverId:g,method:"resources/read",params:{uri:C}}}}))).result?.contents?.[0];if(!M)throw new Error("No resource content in response");return M}finally{d.value.inProgress=!1}})();d.value.promise=m,m.then(y=>{y&&(c.value=y,i.value=!1)}).catch(y=>{s.value=y instanceof Error?y:new Error(String(y)),i.value=!1})},{immediate:!0}),e.watch([i,c],([b,h],C,f)=>{if(b||!h)return;const g=n.value;if(!g)return;let m=!0,y=null,S=null,M=null;(async()=>{try{const I=document.createElement("iframe");M=I,I.style.width="100%",I.style.height="100px",I.style.border="none",I.style.backgroundColor="transparent",I.style.display="block",I.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms"),I.setAttribute("data-testid","mcp-app-iframe"),I.setAttribute("title","Interactive MCP application");const A=new Promise(z=>{S=$=>{$.source===I.contentWindow&&$.data?.method==="ui/notifications/sandbox-proxy-ready"&&(S&&(window.removeEventListener("message",S),S=null),z())},window.addEventListener("message",S)});if(!m){S&&(window.removeEventListener("message",S),S=null);return}const N=c.value?._meta?.ui?.csp?.resourceDomains;if(I.srcdoc=ro(N),a.value=I,g.appendChild(I),await A,!m)return;y=async z=>{if(z.source!==I.contentWindow)return;const $=z.data;if(!(!$||typeof $!="object"||$.jsonrpc!=="2.0")){if(lo($))switch($.method){case"ui/initialize":{p($.id,{protocolVersion:so,hostInfo:{name:"CopilotKit MCP Apps Host",version:"1.0.0"},hostCapabilities:{openLinks:{},logging:{}},hostContext:{theme:"light",platform:"web"}});break}case"ui/message":{const U=t.agent;if(!U){p($.id,{isError:!1});break}try{const G=$.params,B=G?.role||"user",w=G?.content?.filter(F=>F.type==="text"&&F.text).map(F=>F.text).join(`
|
|
32
|
-
`)||"";w&&U.addMessage({id:j.randomUUID(),role:B,content:w}),p($.id,{isError:!1}),(G?.followUp??B==="user")&&w&&rt.enqueue(U,()=>o.value.runAgent({agent:U})).catch(F=>{console.error("[MCPAppsRenderer] ui/message agent run failed:",F)})}catch(G){console.error("[CopilotKit] MCPApps ui/message handler error:",G),p($.id,{isError:!0})}break}case"ui/open-link":{const U=$.params?.url;if(!U){v($.id,-32602,"Missing url parameter");break}window.open(U,"_blank","noopener,noreferrer"),p($.id,{isError:!1});break}case"tools/call":{const{serverHash:U,serverId:G}=t.content,B=t.agent;if(!U){v($.id,-32603,"No server hash available for proxying");break}if(!B){v($.id,-32603,"No agent available for proxying");break}try{const w=await rt.enqueue(B,()=>B.runAgent({forwardedProps:{__proxiedMCPRequest:{serverHash:U,serverId:G,method:"tools/call",params:$.params}}}));p($.id,w.result||{})}catch(w){v($.id,-32603,String(w))}break}default:v($.id,-32601,`Method not found: ${$.method}`)}if(co($))switch($.method){case"ui/notifications/initialized":m&&(r.value=!0);break;case"ui/notifications/size-changed":{const{width:U,height:G}=$.params||{};m&&(l.value={width:typeof U=="number"?U:void 0,height:typeof G=="number"?G:void 0});break}}}},window.addEventListener("message",y);const _=h.text?h.text:h.blob?atob(h.blob):null;if(!_)throw new Error("Resource has no text or blob content");u("ui/notifications/sandbox-resource-ready",{html:_})}catch(I){m&&(s.value=I instanceof Error?I:new Error(String(I)))}})(),f(()=>{m=!1,S&&(window.removeEventListener("message",S),S=null),y&&window.removeEventListener("message",y),M&&(M.remove(),M=null),a.value=null})},{flush:"post"}),e.watch(l,b=>{a.value&&(b.width!==void 0&&(a.value.style.minWidth=`min(${b.width}px, 100%)`,a.value.style.width="100%"),b.height!==void 0&&(a.value.style.height=`${b.height}px`))},{deep:!0}),e.watch([r,()=>t.content.toolInput],([b,h])=>{b&&h&&u("ui/notifications/tool-input",{arguments:h})},{deep:!0}),e.watch([r,()=>t.content.result],([b,h])=>{b&&h&&u("ui/notifications/tool-result",h)},{deep:!0});const k=e.computed(()=>c.value?._meta?.ui?.prefersBorder!==!0?{}:{borderRadius:"8px",backgroundColor:"#f9f9f9",border:"1px solid #e0e0e0"});return e.onBeforeUnmount(()=>{const b=t.agent?.threadId||"default";rt.cancel(b)}),()=>e.h("div",{ref:n,style:{width:"100%",height:l.value.height!==void 0?`${l.value.height}px`:"auto",minHeight:"100px",overflow:"hidden",position:"relative",...k.value}},[i.value?e.h("div",{style:{padding:"1rem",color:"#666"}},"Loading..."):null,s.value?e.h("div",{style:{color:"red",padding:"1rem"}},`Error: ${s.value.message}`):null])}}),uo="a2ui-surface",po=Y.z.object({operations:Y.z.array(Y.z.record(Y.z.string(),Y.z.unknown()))});function Ct(t){return t.surfaceId??t.beginRendering?.surfaceId??t.surfaceUpdate?.surfaceId??t.dataModelUpdate?.surfaceId??t.deleteSurface?.surfaceId??t.createSurface?.surfaceId??t.updateComponents?.surfaceId??t.updateDataModel?.surfaceId??"default"}class pn extends oe.CopilotKitCore{_renderToolCalls=[];_hookRenderToolCalls=new Map;_cachedMergedRenderToolCalls=null;_renderCustomMessages=[];_renderActivityMessages=[];_interruptState=null;constructor(o){super(o),this._renderToolCalls=o.renderToolCalls??[],this._renderCustomMessages=o.renderCustomMessages??[],this._renderActivityMessages=o.renderActivityMessages??[]}get renderCustomMessages(){return this._renderCustomMessages}get renderActivityMessages(){return this._renderActivityMessages}setRenderActivityMessages(o){this._renderActivityMessages=[...o]}setRenderCustomMessages(o){this._renderCustomMessages=[...o],this.notifySubscribers(n=>{n.onRenderCustomMessagesChanged?.({copilotkit:this,renderCustomMessages:[...this.renderCustomMessages]})},"Subscriber onRenderCustomMessagesChanged error:")}get propRenderToolCalls(){return this._renderToolCalls}get renderToolCalls(){if(this._hookRenderToolCalls.size===0)return this._renderToolCalls;if(this._cachedMergedRenderToolCalls)return this._cachedMergedRenderToolCalls;const o=new Map;for(const n of this._renderToolCalls)o.set(`${n.agentId??""}:${n.name}`,n);for(const[n,a]of this._hookRenderToolCalls)o.set(n,a);return this._cachedMergedRenderToolCalls=Array.from(o.values()),this._cachedMergedRenderToolCalls}get interruptState(){return this._interruptState}setRenderToolCalls(o){this._renderToolCalls=[...o],this._cachedMergedRenderToolCalls=null,this._notifyRenderToolCallsChanged()}addHookRenderToolCall(o){const n=`${o.agentId??""}:${o.name}`;this._hookRenderToolCalls.set(n,o),this._cachedMergedRenderToolCalls=null,this._notifyRenderToolCallsChanged()}removeHookRenderToolCall(o,n){const a=`${n??""}:${o}`;this._hookRenderToolCalls.delete(a)&&(this._cachedMergedRenderToolCalls=null,this._notifyRenderToolCallsChanged())}_notifyRenderToolCallsChanged(){this.notifySubscribers(o=>{const n=o;n.onRenderToolCallsChanged&&n.onRenderToolCallsChanged({copilotkit:this,renderToolCalls:[...this.renderToolCalls]})},"Subscriber onRenderToolCallsChanged error:")}setInterruptState(o){this._interruptState=o,this.notifySubscribers(n=>{n.onInterruptStateChanged?.({copilotkit:this,interruptState:this._interruptState})},"Subscriber onInterruptStateChanged error:")}subscribe(o){return super.subscribe(o)}async waitForPendingFrameworkUpdates(){await e.nextTick()}}const Ut="a2ui_operations",mo=e.defineComponent({name:"DefaultA2UILoading",setup(){const t=[.8,.6,.4];return()=>e.h("div",{class:"cpk:flex cpk:flex-col cpk:gap-3 cpk:rounded-xl cpk:border cpk:border-gray-100 cpk:bg-gray-50/50 cpk:p-5",style:{minHeight:"120px"},"data-testid":"a2ui-loading"},[e.h("div",{class:"cpk:flex cpk:items-center cpk:gap-2"},[e.h("div",{class:"cpk:h-3 cpk:w-3 cpk:rounded-full cpk:bg-gray-200",style:{animation:"cpk-a2ui-pulse 1.5s ease-in-out infinite"},"data-testid":"a2ui-loading-dot"}),e.h("span",{class:"cpk:text-xs cpk:font-medium cpk:text-gray-400"},"Generating UI...")]),e.h("div",{class:"cpk:flex cpk:flex-col cpk:gap-2"},t.map((o,n)=>e.h("div",{key:n,class:"cpk:h-3 cpk:rounded cpk:bg-gray-200/70",style:{width:`${o*100}%`,animation:`cpk-a2ui-pulse 1.5s ease-in-out ${n*.15}s infinite`},"data-testid":"a2ui-loading-bar"}))),e.h("style",{},`@keyframes cpk-a2ui-pulse {
|
|
33
|
-
0%, 100% { opacity: 0.4; }
|
|
34
|
-
50% { opacity: 1; }
|
|
35
|
-
}`)])}});function mn(t){return{activityType:"a2ui-surface",content:Y.z.any(),render:e.defineComponent({name:"A2UIMessageRendererHost",props:{activityType:{type:String,required:!0},content:{type:Object,required:!0},message:{type:Object,required:!0},agent:{type:Object,required:!1,default:void 0}},setup(o){const n=e.computed(()=>Array.isArray(o.content?.[Ut])?o.content[Ut]:[]);return()=>n.value.length===0?t.loadingComponent?e.h(t.loadingComponent):e.h(mo):e.h(Rn,{activityType:"a2ui-surface",content:{operations:n.value},message:o.message,agent:o.agent,theme:t.theme,catalog:t.catalog})}})}}function ut(t){const o=t.name==="*"&&!t.args?Y.z.any():t.args;return{name:t.name,args:o,render:t.render,...t.agentId?{agentId:t.agentId}:{}}}const kt="render_a2ui";function fo(t,o){e.watch([()=>t.value,o],([n,a],r,s)=>{if(!a)return;const i=ut({name:kt,args:Y.z.any(),render:({status:c,args:d})=>{if(c==="complete")return null;const x=d,p=x?.items;if(Array.isArray(p)&&p.length>0)return null;const v=x?.components;return Array.isArray(v)&&v.length>2?null:go(d)}}),l=n.propRenderToolCalls;n.setRenderToolCalls([...l.filter(c=>c.name!==kt),i]),s(()=>{const c=n.propRenderToolCalls;n.setRenderToolCalls(c.filter(d=>d.name!==kt)),xt.clear()})},{immediate:!0})}const xt=new Map;function go(t){const o=t,n=typeof o?.name=="string"?o.name:"__default__";let a=xt.get(n);a||(a={lastTime:0,lastTokens:0},xt.set(n,a));const r=Date.now();let s=a.lastTokens;if(r-a.lastTime>200){const p=JSON.stringify(t??{}).length;s=Math.round(p/4),a.lastTime=r,a.lastTokens=s}const i=s<50?0:s<200?1:s<400?2:3,l=()=>e.h("div",{style:{width:"7px",height:"7px",borderRadius:"50%",backgroundColor:"#d4d4d8",flexShrink:0}}),c=()=>e.h("div",{style:{width:"12px"}}),d=(p,v,u,k,b,h)=>e.h("div",{style:{width:`${p}px`,height:`${v}px`,borderRadius:"9999px",backgroundColor:u,...k!==void 0?{animation:`cpk-a2ui-fade 2.4s ease-in-out ${k}s infinite`}:{},...b!==void 0?{opacity:b}:{},...h?{transition:h}:{}}}),x=(p,v,u)=>e.h("div",{style:{display:"flex",alignItems:"center",gap:"6px",opacity:p?1:0,transition:`opacity 0.4s ${v}s`}},u);return e.h("div",{style:{margin:"12px 0",maxWidth:"320px"}},[e.h("div",{style:{position:"relative",overflow:"hidden",borderRadius:"12px",border:"1px solid rgba(228,228,231,0.8)",backgroundColor:"#fff",boxShadow:"0 1px 2px rgba(0,0,0,0.04)",padding:"16px 18px 14px"}},[e.h("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"12px"}},[e.h("div",{style:{display:"flex",gap:"4px"}},[l(),l(),l()]),d(64,6,"#e4e4e7",void 0,i>=1?1:.4,"opacity 0.5s")]),e.h("div",{style:{display:"grid",gap:"7px"}},[x(i>=0,0,[d(36,7,"rgba(147,197,253,0.7)",0),d(80,7,"rgba(219,234,254,0.8)",.2)]),x(i>=0,.1,[c(),l(),d(100,7,"rgba(24,24,27,0.2)",.3)]),x(i>=1,.15,[c(),d(48,7,"rgba(24,24,27,0.15)",.1),d(40,7,"rgba(153,246,228,0.6)",.5),d(56,7,"rgba(147,197,253,0.6)",.3)]),x(i>=1,.2,[c(),l(),d(60,7,"rgba(24,24,27,0.15)",.4)]),x(i>=2,.25,[d(40,7,"rgba(153,246,228,0.5)",.2),l(),d(48,7,"rgba(24,24,27,0.15)",.6),d(64,7,"rgba(147,197,253,0.5)",.1)]),x(i>=2,.3,[d(36,7,"rgba(147,197,253,0.6)",.5),d(36,7,"rgba(24,24,27,0.12)",.7)]),x(i>=3,.35,[l(),d(44,7,"rgba(24,24,27,0.18)",.3),l(),d(56,7,"rgba(153,246,228,0.5)",.8),d(48,7,"rgba(147,197,253,0.5)",.4)])]),e.h("div",{style:{pointerEvents:"none",position:"absolute",inset:"0",background:"linear-gradient(105deg, transparent 0%, transparent 40%, rgba(255,255,255,0.6) 50%, transparent 60%, transparent 100%)",backgroundSize:"250% 100%",animation:"cpk-a2ui-sweep 3s ease-in-out infinite"}})]),e.h("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",marginTop:"8px"}},[e.h("span",{style:{fontSize:"12px",color:"#a1a1aa",letterSpacing:"0.025em"}},"Building interface"),...s>0?[e.h("span",{style:{fontSize:"11px",color:"#d4d4d8",fontVariantNumeric:"tabular-nums"}},`~${s.toLocaleString()} tokens`)]:[]]),e.h("style",`
|
|
36
|
-
@keyframes cpk-a2ui-fade {
|
|
37
|
-
0%, 100% { opacity: 1; }
|
|
38
|
-
50% { opacity: 0.5; }
|
|
39
|
-
}
|
|
40
|
-
@keyframes cpk-a2ui-sweep {
|
|
41
|
-
0% { background-position: 250% 0; }
|
|
42
|
-
100% { background-position: -250% 0; }
|
|
43
|
-
}
|
|
44
|
-
`)])}function we(t,o,n){const a=e.defineComponent({name:`A2UI_${t.name}`,props:{context:{type:Object,required:!0},buildChild:{type:Function,required:!0}},setup(r){const s=e.ref({});let i=null;const l=n?n():void 0;function c(d){i&&i.dispose(),i=new dt.GenericBinder(d,t.schema),s.value=i.snapshot,i.subscribe(x=>{s.value=x})}return c(r.context),e.watch(()=>r.context,d=>{c(d)}),e.onUnmounted(()=>{i&&(i.dispose(),i=null)}),()=>o({props:s.value,buildChild:r.buildChild,context:r.context,state:l})}});return{name:t.name,schema:t.schema,render:a}}const Fe="8px",ho="16px",Ze="1px solid #ccc",pt="8px",fn=t=>{switch(t){case"center":return"center";case"end":return"flex-end";case"spaceAround":return"space-around";case"spaceBetween":return"space-between";case"spaceEvenly":return"space-evenly";case"start":return"flex-start";case"stretch":return"stretch";default:return"flex-start"}},It=t=>{switch(t){case"start":return"flex-start";case"center":return"center";case"end":return"flex-end";case"stretch":return"stretch";default:return"stretch"}},nt=()=>({margin:Fe,boxSizing:"border-box"}),vo=()=>({margin:Fe,padding:ho,border:Ze,borderRadius:pt,boxSizing:"border-box"});function At(t,o){return Array.isArray(t)?t.map(n=>{if(n&&typeof n=="object"&&"id"in n){const a=n;return o(a.id,a.basePath)}return typeof n=="string"?o(n):null}).filter(n=>n!==null):[]}let ko=0;function mt(){return`a2ui-vue-${++ko}`}const bo=we(ye.TextApi,({props:t})=>{const o=t.text??"",n={...nt(),display:"inline-block"};switch(t.variant){case"h1":return e.h("h1",{style:n},o);case"h2":return e.h("h2",{style:n},o);case"h3":return e.h("h3",{style:n},o);case"h4":return e.h("h4",{style:n},o);case"h5":return e.h("h5",{style:n},o);case"caption":return e.h("small",{style:{...n,color:"#666",textAlign:"left"}},o);default:return e.h("span",{style:n},o)}}),yo=we(ye.ImageApi,({props:t})=>{const o=a=>a==="scaleDown"?"scale-down":a||"fill",n={...nt(),objectFit:o(t.fit),width:"100%",height:"auto",display:"block"};return t.variant==="icon"?(n.width="24px",n.height="24px"):t.variant==="avatar"?(n.width="40px",n.height="40px",n.borderRadius="50%"):t.variant==="smallFeature"?n.maxWidth="100px":t.variant==="largeFeature"?n.maxHeight="400px":t.variant==="header"&&(n.height="200px",n.objectFit="cover"),e.h("img",{src:t.url,alt:t.description||"",style:n})}),wo=we(ye.IconApi,({props:t})=>{const o=typeof t.name=="string"?t.name:t.name?.path,n={...nt(),fontSize:"24px",width:"24px",height:"24px",display:"inline-flex",alignItems:"center",justifyContent:"center"};return e.h("span",{class:"material-symbols-outlined",style:n},o)}),Co=we(ye.VideoApi,({props:t})=>{const o={...nt(),width:"100%",aspectRatio:"16/9"};return e.h("video",{src:t.url,controls:!0,style:o})}),xo=we(ye.AudioPlayerApi,({props:t})=>{const o={...nt(),width:"100%"};return e.h("div",{style:{display:"flex",flexDirection:"column",gap:"4px",width:"100%"}},[t.description?e.h("span",{style:{fontSize:"12px",color:"#666"}},t.description):null,e.h("audio",{src:t.url,controls:!0,style:o})])}),So=we(ye.RowApi,({props:t,buildChild:o})=>e.h("div",{style:{display:"flex",flexDirection:"row",justifyContent:fn(t.justify),alignItems:It(t.align),width:"100%",margin:"0",padding:"0"}},At(t.children,o))),To=we(ye.ColumnApi,({props:t,buildChild:o})=>e.h("div",{style:{display:"flex",flexDirection:"column",justifyContent:fn(t.justify),alignItems:It(t.align),width:"100%",margin:"0",padding:"0"}},At(t.children,o))),Io=we(ye.ListApi,({props:t,buildChild:o})=>{const n=t.direction==="horizontal",a={display:"flex",flexDirection:n?"row":"column",alignItems:It(t.align),overflowX:n?"auto":"hidden",overflowY:n?"hidden":"auto",width:"100%",margin:"0",padding:"0"};return e.h("div",{style:a},At(t.children,o))}),Ao=we(ye.CardApi,({props:t,buildChild:o})=>{const n={...vo(),backgroundColor:"#fff",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",width:"100%"};return e.h("div",{style:n},[t.child?o(t.child):null])}),Ro=we(ye.TabsApi,({props:t,buildChild:o,state:n})=>{const a=t.tabs||[];return e.h("div",{style:{display:"flex",flexDirection:"column",width:"100%",margin:Fe}},[e.h("div",{style:{display:"flex",borderBottom:"1px solid #ccc",marginBottom:"8px"}},a.map((r,s)=>{const i=typeof r.title=="string"?r.title:String(r.title??"");return e.h("button",{key:s,onClick:()=>{n.selectedIndex.value=s},style:{padding:"8px 16px",border:"none",background:"none",borderBottom:n.selectedIndex.value===s?"2px solid var(--a2ui-primary-color, #007bff)":"none",fontWeight:n.selectedIndex.value===s?"bold":"normal",cursor:"pointer",color:n.selectedIndex.value===s?"var(--a2ui-primary-color, #007bff)":"inherit"}},i)})),e.h("div",{style:{flex:"1"}},[a[n.selectedIndex.value]?.child?o(a[n.selectedIndex.value].child):null])])},()=>({selectedIndex:e.ref(0)})),Eo=we(ye.DividerApi,({props:t})=>{const o=t.axis==="vertical",n={margin:Fe,border:"none",backgroundColor:"#ccc"};return o?(n.width="1px",n.height="100%"):(n.width="100%",n.height="1px"),e.h("div",{style:n})}),Mo=we(ye.ModalApi,({props:t,buildChild:o,state:n})=>e.h("div",{},[e.h("div",{onClick:()=>{n.isOpen.value=!0},style:{display:"inline-block"}},[t.trigger?o(t.trigger):null]),n.isOpen.value?e.h("div",{style:{position:"fixed",top:"0",left:"0",right:"0",bottom:"0",backgroundColor:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"1000"},onClick:()=>{n.isOpen.value=!1}},[e.h("div",{style:{backgroundColor:"#fff",padding:"24px",borderRadius:"8px",maxWidth:"90%",maxHeight:"90%",overflow:"auto",display:"flex",flexDirection:"column"},onClick:a=>a.stopPropagation()},[e.h("div",{style:{display:"flex",justifyContent:"flex-end"}},[e.h("button",{onClick:()=>{n.isOpen.value=!1},style:{border:"none",background:"none",fontSize:"20px",cursor:"pointer",padding:"4px"}},"×")]),e.h("div",{style:{flex:"1"}},[t.content?o(t.content):null])])]):null]),()=>({isOpen:e.ref(!1)})),$o=we(ye.ButtonApi,({props:t,buildChild:o})=>{const n={margin:Fe,padding:"8px 16px",cursor:"pointer",border:t.variant==="borderless"?"none":"1px solid #ccc",backgroundColor:t.variant==="primary"?"var(--a2ui-primary-color, #007bff)":t.variant==="borderless"?"transparent":"#fff",color:t.variant==="primary"?"#fff":"inherit",borderRadius:"4px",display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box"};return e.h("button",{style:n,onClick:t.action,disabled:t.isValid===!1},[t.child?o(t.child):null])}),Bo=we(ye.TextFieldApi,({props:t,state:o})=>{const n=o.id,a=t.variant==="longText",r=t.variant==="number"?"number":t.variant==="obscured"?"password":"text",s={padding:"8px",width:"100%",border:t.validationErrors&&t.validationErrors.length>0?"1px solid red":Ze,borderRadius:pt,boxSizing:"border-box"},i=t.validationErrors&&t.validationErrors.length>0;return e.h("div",{style:{display:"flex",flexDirection:"column",gap:"4px",width:"100%",margin:Fe}},[t.label?e.h("label",{for:n,style:{fontSize:"14px",fontWeight:"bold"}},t.label):null,a?e.h("textarea",{id:n,style:s,value:t.value||"",onInput:l=>t.setValue(l.target.value)}):e.h("input",{id:n,type:r,style:s,value:t.value||"",onInput:l=>t.setValue(l.target.value)}),i?e.h("span",{style:{fontSize:"12px",color:"red"}},t.validationErrors[0]):null])},()=>({id:mt()})),No=we(ye.CheckBoxApi,({props:t,state:o})=>{const n=o.id,a=t.validationErrors&&t.validationErrors.length>0;return e.h("div",{style:{display:"flex",flexDirection:"column",margin:Fe}},[e.h("div",{style:{display:"flex",alignItems:"center",gap:"8px"}},[e.h("input",{id:n,type:"checkbox",checked:!!t.value,onChange:r=>t.setValue(r.target.checked),style:{cursor:"pointer",outline:a?"1px solid red":"none"}}),t.label?e.h("label",{for:n,style:{cursor:"pointer",color:a?"red":"inherit"}},t.label):null]),a?e.h("span",{style:{fontSize:"12px",color:"red",marginTop:"4px"}},t.validationErrors?.[0]):null])},()=>({id:mt()})),Vo=we(ye.ChoicePickerApi,({props:t,context:o,state:n})=>{const a=Array.isArray(t.value)?t.value:[],r=t.variant==="mutuallyExclusive",s=l=>{if(r)t.setValue([l]);else{const c=a.includes(l)?a.filter(d=>d!==l):[...a,l];t.setValue(c)}},i=(t.options||[]).filter(l=>!t.filterable||n.filter.value===""||String(typeof l.label=="string"?l.label:"").toLowerCase().includes(n.filter.value.toLowerCase()));return e.h("div",{style:{display:"flex",flexDirection:"column",gap:"8px",margin:Fe,width:"100%"}},[t.label?e.h("strong",{style:{fontSize:"14px"}},t.label):null,t.filterable?e.h("input",{type:"text",placeholder:"Filter options...",value:n.filter.value,onInput:l=>{n.filter.value=l.target.value},style:{padding:"4px 8px",border:Ze,borderRadius:pt}}):null,e.h("div",{style:{display:"flex",flexDirection:t.displayStyle==="chips"?"row":"column",flexWrap:t.displayStyle==="chips"?"wrap":"nowrap",gap:"8px"}},i.map((l,c)=>{const d=a.includes(l.value),x=typeof l.label=="string"?l.label:String(l.label??l.value);return t.displayStyle==="chips"?e.h("button",{key:c,onClick:()=>s(l.value),style:{padding:"4px 12px",borderRadius:"16px",border:d?"1px solid var(--a2ui-primary-color, #007bff)":Ze,backgroundColor:d?"var(--a2ui-primary-color, #007bff)":"#fff",color:d?"#fff":"inherit",cursor:"pointer",fontSize:"12px"}},x):e.h("label",{key:c,style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer"}},[e.h("input",{type:r?"radio":"checkbox",checked:d,onChange:()=>s(l.value),name:r?`choice-${o.componentModel.id}`:void 0}),e.h("span",{style:{fontSize:"14px"}},x)])}))])},()=>({filter:e.ref("")})),Fo=we(ye.SliderApi,({props:t,state:o})=>{const n=o.id;return e.h("div",{style:{display:"flex",flexDirection:"column",gap:"4px",margin:Fe,width:"100%"}},[e.h("div",{style:{display:"flex",justifyContent:"space-between"}},[t.label?e.h("label",{for:n,style:{fontSize:"14px",fontWeight:"bold"}},t.label):null,e.h("span",{style:{fontSize:"12px",color:"#666"}},String(t.value))]),e.h("input",{id:n,type:"range",min:t.min??0,max:t.max,value:t.value??0,onInput:a=>t.setValue(Number(a.target.value)),style:{width:"100%",cursor:"pointer"}})])},()=>({id:mt()})),Do=we(ye.DateTimeInputApi,({props:t,state:o})=>{const n=o.id;let a="datetime-local";t.enableDate&&!t.enableTime&&(a="date"),!t.enableDate&&t.enableTime&&(a="time");const r={padding:"8px",width:"100%",border:Ze,borderRadius:pt,boxSizing:"border-box"};return e.h("div",{style:{display:"flex",flexDirection:"column",gap:"4px",width:"100%",margin:Fe}},[t.label?e.h("label",{for:n,style:{fontSize:"14px",fontWeight:"bold"}},t.label):null,e.h("input",{id:n,type:a,style:r,value:t.value||"",onInput:s=>t.setValue(s.target.value),min:typeof t.min=="string"?t.min:void 0,max:typeof t.max=="string"?t.max:void 0})])},()=>({id:mt()})),Oo=[bo,yo,wo,Co,xo,So,To,Io,Ao,Ro,Eo,Mo,$o,Bo,No,Vo,Fo,Do],Ke=new dt.Catalog("https://a2ui.org/specification/v0_9/basic_catalog.json",Oo,ye.BASIC_FUNCTIONS),Lo="A2UI Component Schema — available components for generating UI surfaces. Use these component names and properties when creating A2UI operations.";function Po(t){const o=t??Ke,n="https://a2ui.org/specification/v0_9/basic_catalog.json",a=[];if(a.push("Available A2UI catalog:"),o.id===n)return a.push(`- ${o.id} (basic catalog)`),a.join(`
|
|
45
|
-
`);let r=!0;for(const i of Ke.components.keys())if(!o.components.has(i)){r=!1;break}const s=[];for(const i of o.components.keys())Ke.components.has(i)||s.push(i);a.push(`- ${o.id}`),r?a.push(" Extends the basic catalog with all standard components plus:"):(a.push(" Custom catalog (does NOT include all basic components)."),a.push(" Custom components:"));for(const i of s){const l=o.components.get(i);if(!l)continue;const c=Tt.zodToJsonSchema(l.schema);a.push(` - ${i}:`),a.push(` ${JSON.stringify(c,null,2).split(`
|
|
46
|
-
`).join(`
|
|
47
|
-
`)}`)}return a.join(`
|
|
48
|
-
`)}function Uo(t){const o=t??Ke,n={};for(const[a,r]of o.components){const s=Tt.zodToJsonSchema(r.schema,{target:"jsonSchema2019-09"});n[a]={allOf:[{$ref:"common_types.json#/$defs/ComponentCommon"},{properties:{component:{const:a},...s.properties},required:["component",...s.required??[]]}]}}return{catalogId:o.id,components:n}}function zo(t,o){const n=e.computed(()=>Po(o.catalog()));e.watch([()=>t.value,o.enabled,n],([r,s,i],l,c)=>{if(!s)return;const d=r.a2uiAgents,x=r.addContext({description:"A2UI catalog capabilities: available catalog IDs and custom component definitions the client can render.",value:i,...d?{agentIds:d}:{}});c(()=>r.removeContext(x))},{immediate:!0});const a=e.computed(()=>o.includeSchema()?JSON.stringify(Uo(o.catalog())):null);e.watch([()=>t.value,o.enabled,a],([r,s,i],l,c)=>{if(!s||!i)return;const d=r.a2uiAgents,x=d?{agentIds:d}:{},p=[];p.push(r.addContext({description:Lo,value:i,...x})),p.push(r.addContext({description:"A2UI generation guidelines — protocol rules, tool arguments, path rules, data model format, and form/two-way-binding instructions.",value:j.A2UI_DEFAULT_GENERATION_GUIDELINES,...x})),p.push(r.addContext({description:"A2UI design guidelines — visual design rules, component hierarchy tips, and action handler patterns.",value:j.A2UI_DEFAULT_DESIGN_GUIDELINES,...x})),c(()=>{for(const v of p)r.removeContext(v)})},{immediate:!0})}function gn(t){const o=t.match(/<style\b[^>]*>[\s\S]*?<\/style>/gi);return o?o.join(""):""}function hn(t){let o=t;o=o.replace(/<[^>]*$/,""),o=o.replace(/<(style|script|head)\b[^>]*>[\s\S]*?<\/\1>/gi,""),o=o.replace(/<(style|script|head)\b[^>]*>[\s\S]*$/gi,""),o=o.replace(/&[a-zA-Z0-9#]*$/,"");const n=o.match(/<body[^>]*>([\s\S]*)/i);return n&&(o=n[1],o=o.replace(/<\/body>[\s\S]*/i,"")),o}function vn(){const t=e.inject(ln,e.computed(()=>[]));return e.computed(()=>t.value)}const kn="open-generative-ui",bn=Y.z.object({initialHeight:Y.z.number().optional(),generating:Y.z.boolean().optional(),css:Y.z.string().optional(),cssComplete:Y.z.boolean().optional(),html:Y.z.array(Y.z.string()).optional(),htmlComplete:Y.z.boolean().optional(),jsFunctions:Y.z.string().optional(),jsFunctionsComplete:Y.z.boolean().optional(),jsExpressions:Y.z.array(Y.z.string()).optional(),jsExpressionsComplete:Y.z.boolean().optional()}),yn=Y.z.object({initialHeight:Y.z.number().optional(),placeholderMessages:Y.z.array(Y.z.string()).optional(),css:Y.z.string().optional(),html:Y.z.string().optional(),jsFunctions:Y.z.string().optional(),jsExpressions:Y.z.array(Y.z.string()).optional()});function jo(t,o){return!!(o.cssComplete&&(!t||!t.cssComplete)||o.htmlComplete||o.generating===!1||o.jsFunctions&&(!t||!t.jsFunctions)||(o.jsExpressions?.length??0)>(t?.jsExpressions?.length??0)||o.html?.length&&(!t||!t.html?.length))}function _o(t){return/<head[\s>]/i.test(t)?t:`<head></head>${t}`}function Ho(t,o){const n=t.indexOf("</head>");return n!==-1?t.slice(0,n)+`<style>${o}</style>`+t.slice(n):`<head><style>${o}</style></head>${t}`}async function zt(){const t=await import("@jetbrains/websandbox");return t.default?.default??t.default}const wn=e.defineComponent({name:"OpenGenerativeUIRenderer",props:{content:{type:Object,required:!0}},setup(t){const o=vn(),n=e.ref(null),a=e.ref(t.content),r=e.ref(t.content),s=e.ref(null),i=e.ref(null),l=e.ref(null),c=e.ref(!1),d=e.ref(!1),x=e.ref(0),p=e.ref(!1),v=e.ref([]),u=e.computed(()=>{const I={};for(const A of o.value)I[A.name]=A.handler;return I});e.watch(()=>t.content,I=>{if(r.value=I,jo(a.value,I)){s.value!==null&&(window.clearTimeout(s.value),s.value=null),a.value=I;return}s.value===null&&(s.value=window.setTimeout(()=>{a.value=r.value,s.value=null},1e3))},{immediate:!0}),e.onBeforeUnmount(()=>{s.value!==null&&window.clearTimeout(s.value)});const k=e.computed(()=>{if(!a.value.htmlComplete&&a.value.html?.length)return a.value.html.join("")}),b=e.computed(()=>k.value?hn(k.value):void 0),h=e.computed(()=>k.value?gn(k.value):""),C=e.computed(()=>a.value.htmlComplete&&a.value.html?.length?a.value.html.join(""):void 0),f=e.computed(()=>a.value.cssComplete?a.value.css:void 0),g=e.computed(()=>!!a.value.cssComplete&&!!b.value&&b.value.trim().length>0),m=e.computed(()=>!!C.value||g.value),y=e.computed(()=>`${a.value.initialHeight??200}px`),S=()=>{l.value&&(l.value.destroy(),l.value=null),d.value=!1},M=()=>{i.value&&(i.value.destroy(),i.value=null),c.value=!1,v.value=[],x.value=0,p.value=!1};e.watch([g,C,f,b,h,()=>n.value],async([I,A],N,_)=>{if(!I||A||!n.value||l.value)return;let z=!1;try{const $=await zt();if(z||!n.value)return;const U=$.create({},{frameContainer:n.value,frameContent:"<head></head><body></body>",allowAdditionalAttributes:""});l.value=U,U.iframe.setAttribute("data-testid","open-generative-ui-preview-sandbox"),U.iframe.style.width="100%",U.iframe.style.height="100%",U.iframe.style.border="none",U.iframe.style.backgroundColor="transparent",U.promise.then(()=>{z||!l.value||(d.value=!0,U.run("var s=document.createElement('style');s.textContent='html, body { overflow: hidden !important; }';document.head.appendChild(s);"))})}catch($){console.error("[OpenGenerativeUI] Failed to load sandbox module:",$)}_(()=>{z=!0})},{immediate:!0}),e.watch([b,h,f,d],([I,A,N,_])=>{if(!l.value||!_)return;const z=[];N&&z.push(`<style>${N}</style>`),A&&z.push(A),z.length&&l.value.run(`document.head.innerHTML = ${JSON.stringify(z.join(""))}`),I&&l.value.run(`document.body.innerHTML = ${JSON.stringify(I)}`)},{immediate:!0}),e.watch([C,f,u,()=>n.value],async([I,A,N],_,z)=>{if(M(),!I||!n.value)return;S();let $=!1;try{const U=await zt();if($||!n.value)return;const G=_o(I),B=A?Ho(G,A):G,w=U.create(N,{frameContainer:n.value,frameContent:B,allowAdditionalAttributes:""});i.value=w,w.iframe.setAttribute("data-testid","open-generative-ui-final-sandbox"),w.iframe.style.width="100%",w.iframe.style.height="100%",w.iframe.style.border="none",w.iframe.style.backgroundColor="transparent",w.promise.then(()=>{if($||!i.value)return;c.value=!0,w.run("var s=document.createElement('style');s.textContent='html, body { overflow: hidden !important; }';document.head.appendChild(s);");const R=a.value.jsFunctions;R&&!p.value&&(p.value=!0,v.value.unshift(R));const F=a.value.jsExpressions;if(F?.length){const ae=x.value;ae<F.length&&(v.value.push(...F.slice(ae)),x.value=F.length)}const W=[...v.value];v.value=[];for(const ae of W)w.run(ae)})}catch(U){console.error("[OpenGenerativeUI] Failed to load sandbox module:",U)}z(()=>{$=!0})},{immediate:!0}),e.watch(()=>a.value.jsFunctions,I=>{!I||p.value||(p.value=!0,c.value&&i.value?i.value.run(I):v.value.push(I))}),e.watch(()=>a.value.jsExpressions,I=>{if(!I?.length)return;const A=x.value;if(A>=I.length)return;const N=I.slice(A);if(x.value=I.length,c.value&&i.value)for(const _ of N)i.value.run(_);else v.value.push(...N)},{deep:!0});const E=e.computed(()=>a.value.generating!==!1);return e.watch([g,C],([I,A])=>{A&&S(),I||S()},{immediate:!0}),e.onBeforeUnmount(()=>{s.value!==null&&window.clearTimeout(s.value),S(),M()}),()=>e.h("div",{ref:n,"data-testid":"open-generative-ui-renderer",style:{position:"relative",width:"100%",height:y.value,borderRadius:"8px",backgroundColor:m.value?"transparent":"#f5f5f5",border:m.value?"none":"1px solid #e0e0e0",overflow:"hidden",display:m.value?"block":"flex",alignItems:m.value?void 0:"center",justifyContent:m.value?void 0:"center"}},[m.value?null:e.h("div",{"data-testid":"open-generative-ui-placeholder"},[e.h("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",style:{animation:"ck-spin 1s linear infinite"}},[e.h("circle",{cx:"12",cy:"12",r:"10",stroke:"#e0e0e0","stroke-width":"3"}),e.h("path",{d:"M12 2a10 10 0 0 1 10 10",stroke:"#999","stroke-width":"3","stroke-linecap":"round"})]),e.h("style","@keyframes ck-spin { to { transform: rotate(360deg) } }")]),E.value?e.h("div",{"data-testid":"open-generative-ui-progress-overlay",style:{position:"absolute",inset:0,backgroundColor:"rgba(255,255,255,0.45)"}}):null])}}),Cn=e.defineComponent({name:"OpenGenerativeUIActivityRenderer",props:{activityType:{type:String,required:!0},content:{type:Object,required:!0},message:{type:Object,required:!0},agent:{type:Object,required:!1,default:void 0}},setup(t){return()=>e.h(wn,{content:t.content})}}),xn=e.defineComponent({name:"OpenGenerativeUIToolRenderer",props:{name:{type:String,required:!0},args:{type:Object,required:!0},status:{type:String,required:!0},result:{type:String,required:!1}},setup(t){const o=e.ref(0);return e.watch(()=>t.args.placeholderMessages,(n,a,r)=>{if(!n?.length||t.status===oe.ToolCallStatus.Complete)return;o.value=Math.max(n.length-1,0);const s=window.setInterval(()=>{o.value=(o.value+1)%Math.max(n.length,1)},5e3);r(()=>window.clearInterval(s))},{immediate:!0}),()=>{if(t.status===oe.ToolCallStatus.Complete)return null;const n=t.args.placeholderMessages;if(!n?.length)return null;const a=n[o.value]??n[0];return e.h("div",{style:{padding:"8px 12px",color:"#999",fontSize:"14px"},"data-testid":"open-generative-ui-tool-placeholder"},a)}}}),Rt=Symbol("LicenseContext");function Sn(){return e.ref(j.createLicenseContextValue(null))}const Wo={style:{display:"flex",gap:"8px",alignItems:"center"}},qo=["href"],Ko=52,jt="--copilotkit-license-banner-offset",it=e.defineComponent({__name:"LicenseWarningBanner",props:{type:{},featureName:{default:void 0},expiryDate:{default:void 0},graceRemaining:{default:void 0}},emits:["dismiss"],setup(t,{emit:o}){const n=t,a=o,r=e.computed(()=>{switch(n.type){case"no_license":return{severity:"info",message:"Powered by CopilotKit",actionLabel:"Get a license",actionUrl:"https://copilotkit.ai/pricing"};case"feature_unlicensed":return{severity:"warning",message:`⚠ The "${n.featureName??""}" feature requires a CopilotKit license.`,actionLabel:"Get a license",actionUrl:"https://copilotkit.ai/pricing"};case"expiring":{const p=n.graceRemaining;return{severity:"warning",message:`Your CopilotKit license expires in ${p} ${p===1?"day":"days"}. Please renew.`,actionLabel:"Renew",actionUrl:"https://dashboard.operations.copilotkit.ai"}}case"expired":return{severity:"critical",message:`Your CopilotKit license expired${n.expiryDate?` on ${n.expiryDate}`:""}. Please renew at copilotkit.ai/pricing`,actionLabel:"Renew now",actionUrl:"https://copilotkit.ai/pricing"};case"invalid":return{severity:"critical",message:"Invalid CopilotKit license token. Please check your configuration.",actionLabel:"Get a license",actionUrl:"https://copilotkit.ai/pricing"};default:return null}}),s={position:"fixed",bottom:"8px",left:"50%",transform:"translateX(-50%)",zIndex:99999,display:"inline-flex",alignItems:"center",gap:"12px",whiteSpace:"nowrap",padding:"8px 16px",fontSize:"13px",fontFamily:"-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",borderRadius:"6px",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.15)"},i=e.computed(()=>{switch(r.value?.severity){case"warning":return{backgroundColor:"#fffbeb",border:"1px solid #fbbf24",color:"#92400e"};case"critical":return{backgroundColor:"#fef2f2",border:"1px solid #fca5a5",color:"#991b1b"};default:return{backgroundColor:"#eff6ff",border:"1px solid #93c5fd",color:"#1e40af"}}}),l=e.computed(()=>({...s,...i.value})),c=e.getCurrentInstance(),d=e.computed(()=>typeof(c?.vnode.props??{}).onDismiss=="function");function x(){a("dismiss")}return e.onMounted(()=>{typeof document>"u"||document.documentElement.style.setProperty(jt,`${Ko}px`)}),e.onBeforeUnmount(()=>{typeof document>"u"||document.documentElement.style.removeProperty(jt)}),(p,v)=>r.value?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle(l.value),"data-testid":"copilot-license-banner"},[e.createElementVNode("span",null,e.toDisplayString(r.value.message),1),e.createElementVNode("div",Wo,[e.createElementVNode("a",{href:r.value.actionUrl,target:"_blank",rel:"noopener noreferrer",style:{fontWeight:600,textDecoration:"underline",color:"inherit"}},e.toDisplayString(r.value.actionLabel),9,qo),d.value?(e.openBlock(),e.createElementBlock("button",{key:0,style:{background:"none",border:"none",cursor:"pointer",color:"inherit",fontSize:"16px"},onClick:x}," × ")):e.createCommentVNode("",!0)])],4)):e.createCommentVNode("",!0)}}),_t="X-CopilotCloud-Public-Api-Key",Go="https://api.cloud.copilotkit.ai/copilotkit/v1",Jo="frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.",Qo="humanInTheLoop must be a stable array. If you want to dynamically add or remove human-in-the-loop tools, use `useHumanInTheLoop` instead.",Xo="renderCustomMessages must be a stable array.",Yo="renderActivityMessages must be a stable array.",Zo="openGenerativeUI.sandboxFunctions must be a stable array.",ea=`When generating UI with generateSandboxedUi, follow these design principles inspired by shadcn/ui:
|
|
49
|
-
|
|
50
|
-
- Use a minimal, flat aesthetic. Avoid drop shadows and gradients — rely on subtle borders (1px solid, light gray like #e5e7eb) to define surfaces.
|
|
51
|
-
- Neutral base palette: white backgrounds, zinc/slate gray text (#09090b for headings, #71717a for secondary text). One accent color for interactive elements.
|
|
52
|
-
- Use system font stacks (system-ui, -apple-system, sans-serif) at readable sizes (14px body, 600 weight for headings). Tight line-heights.
|
|
53
|
-
- Small, consistent border-radius (6–8px). Cards and containers use border, not shadow, for separation.
|
|
54
|
-
- Buttons: solid fill for primary (dark bg, white text), outline for secondary (border + transparent bg). Subtle hover state (slight opacity or background shift).
|
|
55
|
-
- Use CSS Grid or Flexbox for layout. Ensure the UI looks good at any width.
|
|
56
|
-
- Minimal transitions (150ms) for hover/focus states only. No decorative animations.
|
|
57
|
-
- Keep the UI focused and dense — avoid excessive padding. Use compact spacing (8–12px gaps, 10–14px padding in controls).`,ta=`Generate sandboxed UI. IMPORTANT: The generated code runs in a sandboxed iframe WITHOUT same-origin access. Do NOT use localStorage, sessionStorage, document.cookie, IndexedDB, or fetch/XMLHttpRequest to same-origin URLs. To communicate with the host application, use Websandbox.connection.remote.<functionName>(args) which returns a Promise.
|
|
58
|
-
|
|
59
|
-
You CAN use external libraries from CDNs by including <script> or <link> tags in the HTML <head> (e.g., Chart.js, D3, Three.js, x-data-spreadsheet, etc.). CDN resources load normally inside the sandbox.
|
|
60
|
-
|
|
61
|
-
PARAMETER ORDER IS CRITICAL — generate parameters in exactly this order:
|
|
62
|
-
1. initialHeight + placeholderMessages (shown to user while generating)
|
|
63
|
-
2. css (all styles FIRST — the user sees a placeholder until CSS is complete)
|
|
64
|
-
3. html (streams in live — the user watches the UI build as HTML is generated)
|
|
65
|
-
4. jsFunctions (reusable helper functions)
|
|
66
|
-
5. jsExpressions (applied one-by-one — the user sees each expression take effect)`,na=e.defineComponent({__name:"CopilotKitProvider",props:{runtimeUrl:{},headers:{type:[Object,Function],default:()=>({})},credentials:{},defaultThrottleMs:{},publicApiKey:{},publicLicenseKey:{},licenseToken:{},properties:{default:()=>({})},useSingleEndpoint:{type:Boolean,default:void 0},agents__unsafe_dev_only:{default:()=>({})},selfManagedAgents:{default:()=>({})},renderToolCalls:{},renderActivityMessages:{default:()=>[]},renderCustomMessages:{default:()=>[]},frontendTools:{default:()=>[]},humanInTheLoop:{default:()=>[]},openGenerativeUI:{default:void 0},showDevConsole:{type:[Boolean,String],default:!1},onError:{},a2ui:{default:void 0},inspectorDefaultAnchor:{},debug:{type:[Boolean,Object]}},setup(t){const o={},n=t,a=e.ref(!1),r=()=>{if(n.showDevConsole===!0){a.value=!0;return}if(n.showDevConsole==="auto"){if(typeof window>"u"){a.value=!1;return}const O=new Set(["localhost","127.0.0.1"]);a.value=O.has(window.location.hostname);return}a.value=!1};e.watch(()=>n.showDevConsole,r,{immediate:!0});const s=n.frontendTools,i=n.humanInTheLoop,l=n.renderCustomMessages,c=n.renderActivityMessages,d=n.openGenerativeUI?.sandboxFunctions;e.watch(()=>n.frontendTools,O=>{O!==s&&console.error(Jo)}),e.watch(()=>n.humanInTheLoop,O=>{O!==i&&console.error(Qo)}),e.watch(()=>n.renderCustomMessages,O=>{O!==l&&console.error(Xo)}),e.watch(()=>n.renderActivityMessages,O=>{O!==c&&console.error(Yo)}),e.watch(()=>n.openGenerativeUI?.sandboxFunctions,O=>{O!==d&&console.error(Zo)});const x=e.computed(()=>n.publicApiKey??n.publicLicenseKey),p=e.computed(()=>({...n.agents__unsafe_dev_only,...n.selfManagedAgents})),v=e.computed(()=>Object.keys(p.value).length>0),u=e.computed(()=>typeof n.headers=="function"?n.headers():n.headers),k=e.computed(()=>{const O=u.value;return!x.value||O[_t]?O:{...O,[_t]:x.value}}),b=e.computed(()=>n.runtimeUrl??(x.value?Go:void 0));e.watch([b,x,v],([O,te,ee])=>{if(O||te||ee)return;const Se="Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'";if(process.env.NODE_ENV==="production")throw new Error(Se);console.warn(Se)},{immediate:!0});const h=e.computed(()=>{const O=[],te=[];for(const ee of n.humanInTheLoop)O.push({name:ee.name,description:ee.description,parameters:ee.parameters,followUp:ee.followUp,...ee.agentId&&{agentId:ee.agentId},handler:async()=>{console.warn(`Human-in-the-loop tool '${ee.name}' called but no interactive handler is set up.`)}}),ee.render&&te.push({name:ee.name,args:ee.parameters??Y.z.any(),render:ee.render,...ee.agentId&&{agentId:ee.agentId}});return{tools:O,renderToolCalls:te}}),C=e.computed(()=>{const O=[];for(const te of n.frontendTools)O.push(te);for(const te of z.value)O.push(te);return O.push(...h.value.tools),O}),f=e.computed(()=>{const O=[...n.renderToolCalls??[]];for(const te of[...n.frontendTools,...z.value])if(te.render){const ee=te.parameters??(te.name==="*"?Y.z.any():void 0);ee&&O.push({name:te.name,args:ee,render:te.render})}return O.push(...h.value.renderToolCalls),O}),g=e.computed(()=>n.renderCustomMessages??[]),m=e.ref(!1),y=e.ref(!1),S=e.ref(void 0),M=e.computed(()=>y.value||!!n.openGenerativeUI),E=e.computed(()=>!!n.a2ui?.catalog),I=e.computed(()=>m.value||E.value),A=e.computed(()=>E.value?{...n.properties,a2uiCatalogAvailable:!0}:n.properties),N=e.computed(()=>n.openGenerativeUI?.sandboxFunctions??[]),_=(O,te)=>Tt.zodToJsonSchema(O,te),z=e.computed(()=>M.value?[{name:"generateSandboxedUi",description:ta,parameters:yn,handler:async()=>"UI generated",followUp:!0,render:xn}]:[]),$=e.computed(()=>{const O=[{activityType:cn,content:un,render:dn}];return M.value&&O.push({activityType:kn,content:bn,render:Cn}),I.value&&O.unshift(mn({theme:n.a2ui?.theme??o,catalog:n.a2ui?.catalog,loadingComponent:n.a2ui?.loadingComponent})),O}),U=e.computed(()=>[...n.renderActivityMessages??[],...$.value]),G=O=>{n.defaultThrottleMs!==void 0&&(!Number.isFinite(n.defaultThrottleMs)||n.defaultThrottleMs<0)&&console.error(`CopilotKitProvider: defaultThrottleMs must be a non-negative finite number, got ${n.defaultThrottleMs}. useAgent hooks without an explicit throttleMs will fall back to unthrottled.`),O.setDefaultThrottleMs(n.defaultThrottleMs)},B=()=>{const O=new pn({runtimeUrl:b.value,runtimeTransport:n.useSingleEndpoint===!0?"single":n.useSingleEndpoint===!1?"rest":"auto",headers:k.value,credentials:n.credentials,properties:A.value,agents__unsafe_dev_only:p.value,tools:C.value,renderToolCalls:f.value,renderActivityMessages:U.value,renderCustomMessages:g.value,debug:n.debug});return G(O),O},w=e.shallowRef(B()),R=e.ref(!1),F=e.ref(new Set);e.watch(w,(O,te,ee)=>{const Se=O.subscribe({onToolExecutionStart:({toolCallId:de})=>{F.value=new Set(F.value).add(de)},onToolExecutionEnd:({toolCallId:de})=>{setTimeout(()=>{const Me=new Set(F.value);Me.delete(de),F.value=Me,e.triggerRef(w)},0)}}),Re=O.subscribe({onRenderToolCallsChanged:()=>{e.triggerRef(w)}}),me=O.subscribe({onRenderCustomMessagesChanged:()=>{e.triggerRef(w)}}),ie=O.subscribe({onRuntimeConnectionStatusChanged:()=>{m.value=O.a2uiEnabled,y.value=O.openGenerativeUIEnabled,S.value=O.licenseStatus,e.triggerRef(w)}}),ue=O.subscribe({onError:de=>{n.onError?.({error:de.error,code:de.code,context:de.context})}});ee(()=>{Se.unsubscribe(),Re.unsubscribe(),me.unsubscribe(),ie.unsubscribe(),ue.unsubscribe()})},{immediate:!0}),e.watch([C],([O])=>{R.value&&w.value.setTools(O)}),e.watch([f],([O])=>{R.value&&w.value.setRenderToolCalls(O)}),e.watch([g],([O])=>{R.value&&(w.value.setRenderCustomMessages(O),e.triggerRef(w))}),e.watch([U],([O])=>{R.value&&(w.value.setRenderActivityMessages(O),e.triggerRef(w))});function W(){w.value.setRuntimeUrl(b.value),w.value.setRuntimeTransport(n.useSingleEndpoint===!0?"single":n.useSingleEndpoint===!1?"rest":"auto"),w.value.setHeaders(k.value),w.value.setCredentials(n.credentials),w.value.setProperties(A.value),w.value.setAgents__unsafe_dev_only(p.value),w.value.setDebug(n.debug),G(w.value)}e.watch([()=>b.value,()=>k.value,()=>n.credentials,()=>A.value,()=>p.value,()=>n.useSingleEndpoint,()=>n.debug],()=>{R.value&&W()}),e.watch(()=>n.defaultThrottleMs,()=>{R.value&&(G(w.value),e.triggerRef(w))}),e.onMounted(()=>{W(),m.value=w.value.a2uiEnabled,y.value=w.value.openGenerativeUIEnabled,S.value=w.value.licenseStatus,R.value=!0});const ae=e.computed(()=>n.a2ui?.theme),D=e.computed(()=>n.a2ui?.catalog),H=e.computed(()=>n.a2ui?.loadingComponent),q=e.computed(()=>n.a2ui?.includeSchema??!0);fo(w,()=>I.value),zo(w,{enabled:()=>I.value,catalog:()=>n.a2ui?.catalog,includeSchema:()=>n.a2ui?.includeSchema??!0});const K=e.ref([]);e.watch([M,N,()=>n.openGenerativeUI?.designSkill],([O,te,ee],Se,Re)=>{if(!O)return;const me=[];if(me.push(w.value.addContext({description:"Design guidelines for the generateSandboxedUi tool. Follow these when building UI.",value:ee??ea})),te.length>0){const ie=JSON.stringify(te.map(ue=>({name:ue.name,description:ue.description,parameters:j.schemaToJsonSchema(ue.parameters,{zodToJsonSchema:_})})));me.push(w.value.addContext({description:"Sandbox functions available in generated sandboxed UI code. Call via Websandbox.connection.remote.<functionName>(args).",value:ie}))}K.value=me,Re(()=>{for(const ie of me)w.value.removeContext(ie)})},{immediate:!0}),e.provide(rn,{copilotkit:w,executingToolCallIds:F,a2uiTheme:ae,a2uiCatalog:D,a2uiLoadingComponent:H,a2uiIncludeSchema:q}),e.provide(ln,N);const re=e.computed(()=>j.createLicenseContextValue(S.value));e.provide(Rt,re);const pe=e.computed(()=>S.value==="none"&&!x.value),he=e.computed(()=>S.value==="expired"),ve=e.computed(()=>S.value==="invalid"),Ae=e.computed(()=>S.value==="expiring");return(O,te)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.renderSlot(O.$slots,"default"),a.value?(e.openBlock(),e.createBlock(sn,{key:0,core:w.value,"default-anchor":n.inspectorDefaultAnchor},null,8,["core","default-anchor"])):e.createCommentVNode("",!0),pe.value?(e.openBlock(),e.createBlock(it,{key:1,type:"no_license"})):e.createCommentVNode("",!0),he.value?(e.openBlock(),e.createBlock(it,{key:2,type:"expired"})):e.createCommentVNode("",!0),ve.value?(e.openBlock(),e.createBlock(it,{key:3,type:"invalid"})):e.createCommentVNode("",!0),Ae.value?(e.openBlock(),e.createBlock(it,{key:4,type:"expiring"})):e.createCommentVNode("",!0)],64))}}),Be={chatInputPlaceholder:"Type a message...",chatInputToolbarStartTranscribeButtonLabel:"Transcribe",chatInputToolbarCancelTranscribeButtonLabel:"Cancel",chatInputToolbarFinishTranscribeButtonLabel:"Finish",chatInputToolbarAddButtonLabel:"Add photos or files",chatInputToolbarToolsButtonLabel:"Tools",assistantMessageToolbarCopyCodeLabel:"Copy",assistantMessageToolbarCopyCodeCopiedLabel:"Copied",assistantMessageToolbarCopyMessageLabel:"Copy",assistantMessageToolbarThumbsUpLabel:"Good response",assistantMessageToolbarThumbsDownLabel:"Bad response",assistantMessageToolbarReadAloudLabel:"Read aloud",assistantMessageToolbarRegenerateLabel:"Regenerate",userMessageToolbarCopyMessageLabel:"Copy",userMessageToolbarEditMessageLabel:"Edit",chatDisclaimerText:"AI can make mistakes. Please verify important information.",chatToggleOpenLabel:"Open chat",chatToggleCloseLabel:"Close chat",modalHeaderTitle:"CopilotKit Chat",welcomeMessageText:"How can I help you today?"};function oa(t,o){const n=Object.keys(t),a=Object.keys(o);if(n.length!==a.length)return!1;for(const r of n)if(t[r]!==o[r])return!1;return!0}function Ht(t){return t!==null&&typeof t=="object"&&Object.prototype.toString.call(t)==="[object Object]"}function Tn(t){const o=e.shallowRef(e.toValue(t));return e.watch(()=>e.toValue(t),n=>{const a=o.value;a!==n&&(Ht(a)&&Ht(n)&&oa(a,n)||(o.value=n))},{immediate:!0}),o}const In="(max-width: 767px)";function Wt(){return typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(In).matches}const ft=e.defineComponent({__name:"CopilotChatConfigurationProvider",props:{labels:{},agentId:{},threadId:{},hasExplicitThreadId:{type:Boolean,default:void 0},isModalDefaultOpen:{type:Boolean,default:void 0}},setup(t){const o=t,n=e.inject(wt,null),a=e.computed(()=>n?.value??null),r=e.computed(()=>o.threadId!==void 0&&o.hasExplicitThreadId!==!1),s=e.ref(null),i=Tn(e.computed(()=>o.labels)),l=e.computed(()=>({...Be,...a.value?.labels,...i.value})),c=e.computed(()=>o.agentId??a.value?.agentId??j.DEFAULT_AGENT_ID),d=j.randomUUID(),x=e.computed(()=>r.value?o.threadId:s.value?s.value.threadId:o.threadId?o.threadId:a.value?.threadId?a.value.threadId:d),p=e.computed(()=>r.value?!0:(s.value?s.value.explicit:o.hasExplicitThreadId!==void 0?o.hasExplicitThreadId:!!o.threadId)||!!a.value?.hasExplicitThreadId),v=e.computed(()=>o.isModalDefaultOpen!==void 0),u=e.computed(()=>o.isModalDefaultOpen??!0),k=e.ref(a.value?.isModalOpen??u.value);function b($){k.value=$}const h=e.computed(()=>v.value?k.value:a.value?.isModalOpen),C=e.computed(()=>v.value?b:a.value?.setModalOpen);function f($,U){if(r.value){console.warn("[CopilotKit] Ignoring setActiveThreadId(): threadId is controlled via the `threadId` prop on CopilotChatConfigurationProvider.");return}s.value={threadId:$,explicit:U?.explicit??!0}}function g(){if(r.value){console.warn("[CopilotKit] Ignoring startNewThread(): threadId is controlled via the `threadId` prop on CopilotChatConfigurationProvider.");return}s.value={threadId:j.randomUUID(),explicit:!1}}const m=e.ref(!1),y=e.ref(0);function S($){m.value=$,$&&Wt()&&C.value?.(!1)}function M(){return y.value+=1,()=>{y.value=Math.max(0,y.value-1)}}const E=e.computed(()=>a.value?a.value.drawerOpen:m.value),I=e.computed(()=>a.value?a.value.setDrawerOpen:S),A=e.computed(()=>a.value?a.value.drawerRegistered:y.value>0),N=e.computed(()=>a.value?a.value.registerDrawer:M),_=e.computed(()=>{const $=C.value;if($)return U=>{U&&Wt()&&I.value?.(!1),$(U)}}),z=e.computed(()=>({labels:l.value,agentId:c.value,threadId:x.value,hasExplicitThreadId:p.value,isModalOpen:h.value,setModalOpen:_.value,drawerOpen:E.value,setDrawerOpen:I.value,drawerRegistered:A.value,registerDrawer:N.value,setActiveThreadId:f,startNewThread:g}));return e.provide(wt,z),($,U)=>e.renderSlot($.$slots,"default")}});function ot(){const t=e.inject(Rt,Sn(),!0);return e.computed(()=>t.value)}function be(){const t=e.inject(wt,void 0);return e.computed(()=>t?.value??null)}const An=e.defineComponent({name:"A2UIDeferredChild",props:{surface:{type:Object,required:!0},id:{type:String,required:!0},basePath:{type:String,required:!0}},setup(t){const o=e.ref(0),n=t.surface.componentsModel.onCreated.subscribe(s=>{s.id===t.id&&o.value++}),a=t.surface.componentsModel.onDeleted.subscribe(s=>{s===t.id&&o.value++});e.onUnmounted(()=>{n.unsubscribe(),a.unsubscribe()});function r(s,i){const l=i||t.basePath;return e.h(An,{key:`${s}-${l}`,surface:t.surface,id:s,basePath:l})}return()=>{o.value;const s=t.surface.componentsModel.get(t.id);if(!s)return e.h("div",{style:{padding:"12px 16px",borderRadius:"8px",background:"linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%)",backgroundSize:"200% 100%",animation:"a2ui-shimmer 1.5s ease-in-out infinite",minHeight:"2rem"},innerHTML:"<style>@keyframes a2ui-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }</style>"});const i=t.surface.catalog.components.get(s.type);if(!i)return e.h("div",{style:{color:"red"}},`Unknown component: ${s.type}`);const l=new dt.ComponentContext(t.surface,t.id,t.basePath);return e.h(i.render,{context:l,buildChild:r})}}}),aa=e.defineComponent({name:"A2uiSurface",props:{surface:{type:Object,required:!0}},setup(t){return()=>e.h(An,{surface:t.surface,id:"root",basePath:"/"})}}),sa=["data-activity-type","data-message-id"],ra={key:0,class:"cpk:rounded-lg cpk:border cpk:border-red-200 cpk:bg-red-50 cpk:p-3 cpk:text-sm cpk:text-red-700"},ia={key:1,class:"cpk:flex cpk:min-h-0 cpk:flex-1 cpk:flex-col cpk:gap-6 cpk:overflow-auto cpk:py-6","data-testid":"a2ui-activity-renderer"},la=["data-surface-id"],ca={class:"a2ui-surface cpk:flex cpk:flex-1"},qt="default",Rn=e.defineComponent({__name:"A2UISurfaceActivityRenderer",props:{activityType:{},content:{},message:{},agent:{},theme:{},catalog:{}},setup(t){const o=t,{copilotkit:n}=xe(),a=e.shallowRef(null),r=e.ref(0),s=e.ref(null);let i="";function l(){if(!a.value){const v=o.catalog??Ke;a.value=new dt.MessageProcessor([v],u=>{c(u)})}return a.value}async function c(v){if(o.agent)try{n.value.setProperties({...n.value.properties??{},a2uiAction:v}),await n.value.runAgent({agent:o.agent})}finally{const{a2uiAction:u,...k}=n.value.properties??{};n.value.setProperties(k)}}function d(v){if(!v?.length)return;const u=JSON.stringify(v);if(u===i)return;i=u;const k=l();try{const b=new Map;for(const h of v){const C=Ct(h)??qt;b.has(C)||b.set(C,[]),b.get(C).push(h)}for(const[h,C]of b){const g=k.model.getSurface(h)?C.filter(m=>!m?.createSurface):C;k.processMessages(g)}s.value=null}catch(b){console.warn("[A2UI Vue] processMessages error:",b),s.value=b instanceof Error?b.message:String(b)}r.value++}e.watch(()=>[o.content.operations,o.theme,o.catalog,o.agent],()=>{d(o.content.operations)},{deep:!0,immediate:!0}),e.onBeforeUnmount(()=>{a.value=null,i=""});const x=e.computed(()=>(o.content.operations??[]).length>0),p=e.computed(()=>{if(r.value,!a.value)return[];const v=[],u=new Map;for(const k of o.content.operations??[]){const b=Ct(k)??qt;u.has(b)||u.set(b,[]),u.get(b).push(k)}for(const[k]of u){const b=a.value.model.getSurface(k);b&&v.push({surfaceId:k,surface:b})}return v});return(v,u)=>x.value?(e.openBlock(),e.createElementBlock("div",{key:0,"data-copilotkit":"","data-activity-type":t.activityType,"data-message-id":t.message.id},[s.value?(e.openBlock(),e.createElementBlock("div",ra," A2UI render error: "+e.toDisplayString(s.value),1)):(e.openBlock(),e.createElementBlock("div",ia,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.value,k=>(e.openBlock(),e.createElementBlock("div",{key:k.surfaceId,class:"cpk:flex cpk:w-full cpk:flex-none cpk:flex-col cpk:gap-4","data-surface-id":k.surfaceId},[e.createElementVNode("div",ca,[e.createVNode(e.unref(aa),{surface:k.surface},null,8,["surface"])])],8,la))),128))]))],8,sa)):e.createCommentVNode("",!0)}});function Et(t,o){return t.find(n=>n.role==="tool"&&n.toolCallId===o)}function ua(t){return`tool-call-${t}`}function En(t,o,n){const a=o.filter(r=>r.name===t.function.name);return a.find(r=>r.agentId===n)??a.find(r=>!r.agentId)??a[0]??o.find(r=>r.name==="*")}function da(t,o,n){const a=Et(o,t.id),r=j.partialJSONParse(t.function.arguments);if(a)return{name:t.function.name,args:r,status:oe.ToolCallStatus.Complete,result:a.content,toolCall:t,toolMessage:a};const s=n.has(t.id);return{name:t.function.name,args:r,status:s?oe.ToolCallStatus.Executing:oe.ToolCallStatus.InProgress,result:void 0,toolCall:t,toolMessage:void 0}}function pa(t,o,n){const a=Et(o,t.id),r=j.partialJSONParse(t.function.arguments);return a?{name:t.function.name,toolCallId:t.id,args:r,status:oe.ToolCallStatus.Complete,result:a.content}:n.has(t.id)?{name:t.function.name,toolCallId:t.id,args:r,status:oe.ToolCallStatus.Executing,result:void 0}:{name:t.function.name,toolCallId:t.id,args:r&&typeof r=="object"?r:{},status:oe.ToolCallStatus.InProgress,result:void 0}}function ma(t,o,n,a,r=j.DEFAULT_AGENT_ID){return[t.id,t.function.name,t.function.arguments,Et(o,t.id)?.content,n.has(t.id),En(t,a,r)?.render]}const fa=e.defineComponent({__name:"CopilotChatToolCallItem",props:{toolCall:{},messages:{default:()=>[]}},setup(t){const o=t,{copilotkit:n,executingToolCallIds:a}=xe(),r=be();function s(){return da(o.toolCall,o.messages,a.value)}function i(){return pa(o.toolCall,o.messages,a.value)}function l(){const d=r.value?.agentId??j.DEFAULT_AGENT_ID;return En(o.toolCall,n.value.renderToolCalls,d)}function c(){const d=r.value?.agentId??j.DEFAULT_AGENT_ID;return ma(o.toolCall,o.messages,a.value,n.value.renderToolCalls,d)}return(d,x)=>e.renderSlot(d.$slots,e.unref(ua)(t.toolCall.function.name),e.normalizeProps(e.guardReactiveProps(s())),()=>[e.renderSlot(d.$slots,"tool-call",e.normalizeProps(e.guardReactiveProps(s())),()=>[l()?e.withMemo(c(),()=>(e.openBlock(),e.createBlock(e.resolveDynamicComponent(l()?.render),e.normalizeProps(e.mergeProps({key:0},i())),null,16)),x,0):e.createCommentVNode("",!0)])])}}),Mn=e.defineComponent({__name:"CopilotChatToolCallsView",props:{message:{},messages:{default:()=>[]}},setup(t){const o=e.useSlots();function n(){return Object.keys(o)}return(a,r)=>(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.message.toolCalls??[],s=>(e.openBlock(),e.createBlock(fa,{key:s.id,"tool-call":s,messages:t.messages},e.createSlots({_:2},[e.renderList(n(),i=>({name:i,fn:e.withCtx(l=>[e.renderSlot(a.$slots,i,e.mergeProps({ref_for:!0},l??{}))])}))]),1032,["tool-call","messages"]))),128))}});let Kt=!1;function $n(){e.onMounted(()=>{if(Kt||typeof document>"u")return;Kt=!0,import("katex/dist/katex.min.css").catch(()=>{console.warn("[CopilotKit] Failed to load katex styles — math content may render without formatting")})})}const ga=["data-message-id"],ha={class:"cpk:w-full cpk:bg-transparent cpk:flex cpk:items-center cpk:-ml-[5px] cpk:-mt-[0px]"},va={class:"cpk:flex cpk:items-center cpk:gap-1"},ka=["aria-label","title"],ba=["aria-label","title"],ya=["aria-label","title"],wa=["aria-label","title"],Ca=["aria-label","title"],Gt="cpk:cursor-pointer cpk:p-1 cpk:text-muted-foreground cpk:transition-all cpk:hover:text-foreground cpk:disabled:cursor-not-allowed cpk:disabled:opacity-50",Jt="cpk:absolute cpk:top-full cpk:right-0 cpk:z-10 cpk:mt-1 cpk:min-w-[120px] cpk:overflow-hidden cpk:rounded-md cpk:border cpk:border-border cpk:bg-background cpk:shadow-lg",lt="cpk:w-full cpk:px-3 cpk:py-2 cpk:text-left cpk:text-sm cpk:transition-colors cpk:hover:bg-muted/40",Qt="cpk:cursor-pointer cpk:p-1 cpk:text-muted-foreground cpk:transition-all cpk:hover:text-foreground cpk:disabled:cursor-not-allowed cpk:disabled:opacity-50",Bn=e.defineComponent({__name:"CopilotChatAssistantMessage",props:{message:{},messages:{default:()=>[]},isRunning:{type:Boolean,default:!1},toolbarVisible:{type:Boolean,default:!0}},emits:["thumbs-up","thumbs-down","read-aloud","regenerate"],setup(t,{emit:o}){$n();const n=t,a=o,r=be(),s=e.computed(()=>r.value?.labels??Be),i=e.getCurrentInstance(),l=e.ref(!1);let c=null;const d=e.computed(()=>i?.vnode.props??{}),x=["cpk:inline-flex cpk:h-8 cpk:w-8 cpk:items-center cpk:justify-center cpk:rounded-md cpk:p-0","cpk:cursor-pointer cpk:text-[rgb(93,93,93)] cpk:transition-colors cpk:hover:bg-[#E8E8E8]","cpk:hover:text-[rgb(93,93,93)] cpk:dark:text-[rgb(243,243,243)] cpk:dark:hover:bg-[#303030]","cpk:dark:hover:text-[rgb(243,243,243)] cpk:disabled:pointer-events-none cpk:disabled:opacity-50"].join(" ");function p(D,H){try{const K=new URL(D,"https://copilotkit.local").pathname.split("/").filter(Boolean).pop();if(K)return decodeURIComponent(K)}catch{return H}return H}function v(D,H){if(typeof document>"u")return;const q=document.createElement("a");q.href=D,q.download=H,q.rel="noopener noreferrer",document.body.appendChild(q),q.click(),document.body.removeChild(q)}function u(D){const H=Array.from(D.querySelectorAll("thead th")).map(K=>(K.textContent??"").trim()),q=Array.from(D.querySelectorAll("tbody tr")).map(K=>Array.from(K.querySelectorAll("td")).map(re=>(re.textContent??"").trim()));return{headers:H,rows:q}}function k(D,H){const q=re=>{const pe=re.includes(H)||re.includes('"')||re.includes(`
|
|
67
|
-
`),he=re.replace(/"/g,'""');return pe?`"${he}"`:he},K=[];D.headers.length>0&&K.push(D.headers.map(q).join(H));for(const re of D.rows)K.push(re.map(q).join(H));return K.join(`
|
|
68
|
-
`)}function b(D){if(D.headers.length===0)return D.rows.map(K=>`| ${K.join(" | ")} |`).join(`
|
|
69
|
-
`);const H=`| ${D.headers.map(()=>"---").join(" | ")} |`,q=D.rows.map(K=>`| ${K.join(" | ")} |`);return[`| ${D.headers.join(" | ")} |`,H,...q].join(`
|
|
70
|
-
`)}function h(D,H,q){if(typeof document>"u")return;const K=new Blob([D],{type:q}),re=URL.createObjectURL(K);v(re,H),URL.revokeObjectURL(re)}const C=e.defineComponent({name:"CopilotMarkdownImage",inheritAttrs:!1,props:{src:{type:String,default:""},alt:{type:String,default:""}},setup(D,{attrs:H}){async function q(){if(!D.src)return;const K=p(D.src,"image");try{const re=await fetch(D.src);if(!re.ok)throw new Error("Failed to fetch image");const pe=await re.blob(),he=URL.createObjectURL(pe);v(he,K),URL.revokeObjectURL(he)}catch{v(D.src,K)}}return()=>{const K={...H,src:D.src,alt:D.alt,class:["cpk:max-w-full cpk:rounded-lg",H.class].filter(Boolean).join(" "),"data-streamdown":"image"};return delete K.className,e.h("div",{class:"cpk:group cpk:relative cpk:my-4 cpk:inline-block","data-streamdown":"image-wrapper"},[e.h("img",K),e.h("div",{class:"cpk:pointer-events-none cpk:absolute cpk:inset-0 cpk:hidden cpk:rounded-lg cpk:bg-black/10 cpk:group-hover:block"}),e.h("button",{type:"button",class:"cpk:absolute cpk:right-2 cpk:bottom-2 cpk:flex cpk:h-8 cpk:w-8 cpk:cursor-pointer cpk:items-center cpk:justify-center cpk:rounded-md cpk:border cpk:border-border cpk:bg-background/90 cpk:shadow-sm cpk:backdrop-blur-sm cpk:transition-all cpk:duration-200 cpk:hover:bg-background cpk:opacity-0 cpk:group-hover:opacity-100",title:"Download image",onClick:q},[e.h(se.Download,{class:"cpk:size-[14px]"})])])}}}),f=e.defineComponent({name:"CopilotMarkdownTable",inheritAttrs:!1,setup(D,{attrs:H,slots:q}){const K=e.ref(null),re=e.ref(!1),pe=e.ref(!1),he=e.ref(!1);let ve=null;const Ae=()=>{re.value=!1,pe.value=!1},O=()=>{ve&&clearTimeout(ve),he.value=!0,ve=setTimeout(()=>{he.value=!1,ve=null},2e3)},te=()=>K.value?K.value.querySelector("table"):null,ee=()=>{const ie=te();return ie?u(ie):null},Se=async ie=>{const ue=ee();if(!ue)return;const Me=k(ue,ie==="csv"?",":" ");if(typeof navigator<"u"&&navigator.clipboard?.writeText)try{await navigator.clipboard.writeText(Me)}catch{return}Ae(),O()},Re=ie=>{const ue=ee();ue&&(ie==="csv"?h(k(ue,","),"table.csv","text/csv"):h(b(ue),"table.md","text/markdown"),Ae())},me=ie=>{if(!K.value)return;const ue=ie.target;ue&&!K.value.contains(ue)&&Ae()};return e.onMounted(()=>{typeof document<"u"&&document.addEventListener("mousedown",me)}),e.onBeforeUnmount(()=>{ve&&clearTimeout(ve),typeof document<"u"&&document.removeEventListener("mousedown",me)}),()=>{const ie={...H,class:["cpk:w-full cpk:border-collapse cpk:border cpk:border-border",H.class].filter(Boolean).join(" "),"data-streamdown":"table"};return delete ie.className,e.h("div",{ref:K,class:"cpk:my-4 cpk:flex cpk:flex-col cpk:space-y-2","data-streamdown":"table-wrapper"},[e.h("div",{class:"cpk:flex cpk:items-center cpk:justify-end cpk:gap-1"},[e.h("div",{class:"cpk:relative"},[e.h("button",{type:"button",class:Gt,title:"Copy table",onClick:()=>{re.value=!re.value,pe.value=!1}},[he.value?e.h(se.Check,{class:"cpk:size-[14px]"}):e.h(se.Copy,{class:"cpk:size-[14px]"})]),re.value?e.h("div",{class:Jt},[e.h("button",{type:"button",class:lt,title:"Copy table as CSV",onClick:()=>Se("csv")},"CSV"),e.h("button",{type:"button",class:lt,title:"Copy table as TSV",onClick:()=>Se("tsv")},"TSV")]):null]),e.h("div",{class:"cpk:relative"},[e.h("button",{type:"button",class:Gt,title:"Download table",onClick:()=>{pe.value=!pe.value,re.value=!1}},[e.h(se.Download,{class:"cpk:size-[14px]"})]),pe.value?e.h("div",{class:Jt},[e.h("button",{type:"button",class:lt,title:"Download table as CSV",onClick:()=>Re("csv")},"CSV"),e.h("button",{type:"button",class:lt,title:"Download table as Markdown",onClick:()=>Re("markdown")},"Markdown")]):null])]),e.h("div",{class:"cpk:overflow-x-auto"},[e.h("table",ie,q.default?q.default():[])])])}}}),g={javascript:"js",js:"js",typescript:"ts",ts:"ts",json:"json",vue:"vue",html:"html",css:"css",md:"md",markdown:"md",sh:"sh",bash:"sh",py:"py",python:"py",go:"go",rust:"rs",rs:"rs"},m=e.defineComponent({name:"CopilotCodeBlockCopyAction",props:{code:{type:String,default:""}},setup(D){const H=e.ref(!1);let q=null;const K=async()=>{if(D.code){if(typeof navigator<"u"&&navigator.clipboard?.writeText)try{await navigator.clipboard.writeText(D.code)}catch{return}q&&clearTimeout(q),H.value=!0,q=setTimeout(()=>{H.value=!1,q=null},2e3)}};return e.onBeforeUnmount(()=>{q&&clearTimeout(q)}),()=>e.h("button",{type:"button",class:Qt,title:"Copy Code","data-streamdown":"code-block-copy-button",onClick:K},[H.value?e.h(se.Check,{class:"cpk:size-[14px]"}):e.h(se.Copy,{class:"cpk:size-[14px]"})])}}),y=e.defineComponent({name:"CopilotCodeBlockDownloadAction",props:{code:{type:String,default:""},language:{type:String,default:""}},setup(D){const H=()=>{if(!D.code)return;const q=g[D.language.toLowerCase()]??"txt";h(D.code,`file.${q}`,"text/plain")};return()=>e.h("button",{type:"button",class:Qt,title:"Download file","data-streamdown":"code-block-download-button",onClick:H},[e.h(se.Download,{class:"cpk:size-[14px]"})])}}),S={img:C,table:f};function M(D){return D?typeof D=="string"?D:Array.isArray(D)?D.map(q=>q&&typeof q=="object"&&"type"in q&&q.type==="text"&&typeof q.text=="string"?q.text:"").filter(q=>q.length>0).join(`
|
|
71
|
-
`):"":""}const E=e.computed(()=>M(n.message.content)),I=e.computed(()=>E.value.trim().length>0);function A(D){const H=d.value[D];return Array.isArray(H)?H.length>0:!!H}const N=e.computed(()=>A("onThumbsUp")),_=e.computed(()=>A("onThumbsDown")),z=e.computed(()=>A("onReadAloud")),$=e.computed(()=>A("onRegenerate")),U=e.computed(()=>n.messages[n.messages.length-1]?.id===n.message.id),G=e.computed(()=>n.toolbarVisible&&I.value&&!(n.isRunning&&U.value));function B(){c&&clearTimeout(c),l.value=!0,c=setTimeout(()=>{l.value=!1,c=null},2e3)}async function w(){const D=E.value;if(D&&!(typeof navigator>"u"||typeof navigator.clipboard?.writeText!="function"))try{await navigator.clipboard.writeText(D),B()}catch(H){console.error("Failed to copy to clipboard:",H)}}function R(){a("thumbs-up",n.message)}function F(){a("thumbs-down",n.message)}function W(){a("read-aloud",n.message)}function ae(){a("regenerate",n.message)}return e.onBeforeUnmount(()=>{c&&clearTimeout(c)}),(D,H)=>e.renderSlot(D.$slots,"layout",{message:t.message,content:E.value,isRunning:t.isRunning,toolbarVisible:t.toolbarVisible,shouldShowToolbar:G.value,messageRenderer:D.$slots["message-renderer"]??(()=>null),toolbar:D.$slots.toolbar??(()=>null),copyButton:D.$slots["copy-button"]??(()=>null),thumbsUpButton:D.$slots["thumbs-up-button"]??(()=>null),thumbsDownButton:D.$slots["thumbs-down-button"]??(()=>null),readAloudButton:D.$slots["read-aloud-button"]??(()=>null),regenerateButton:D.$slots["regenerate-button"]??(()=>null),toolCallsView:D.$slots["tool-calls-view"]??(()=>null),onCopy:w,onThumbsUp:R,onThumbsDown:F,onReadAloud:W,onRegenerate:ae},()=>[e.createElementVNode("div",e.mergeProps({"data-copilotkit":"","data-testid":"copilot-assistant-message",class:"cpk:prose cpk:max-w-full cpk:break-words cpk:dark:prose-invert","data-message-id":t.message.id},D.$attrs),[e.renderSlot(D.$slots,"message-renderer",{message:t.message,content:E.value},()=>[I.value?(e.openBlock(),e.createBlock(e.unref(an.StreamMarkdown),{key:0,class:"copilot-chat-assistant-markdown",content:E.value,components:S,"code-block-actions":[e.unref(y),e.unref(m)],"code-block-show-line-numbers":!1,"code-block-hide-copy":!0,"code-block-hide-download":!0,"allowed-link-prefixes":["https://","http://","#","/","./","../"],"shiki-theme":{light:"github-light",dark:"github-dark"}},null,8,["content","code-block-actions"])):e.createCommentVNode("",!0)]),e.renderSlot(D.$slots,"tool-calls-view",{message:t.message,messages:t.messages},()=>[e.createVNode(Mn,{message:t.message,messages:t.messages},e.createSlots({_:2},[e.renderList(D.$slots,(q,K)=>({name:K,fn:e.withCtx(re=>[e.renderSlot(D.$slots,K,e.normalizeProps(e.guardReactiveProps(re)))])}))]),1032,["message","messages"])]),G.value?e.renderSlot(D.$slots,"toolbar",{key:0,message:t.message,shouldShowToolbar:G.value},()=>[e.createElementVNode("div",ha,[e.createElementVNode("div",va,[e.renderSlot(D.$slots,"copy-button",{onCopy:w,copied:l.value,label:s.value.assistantMessageToolbarCopyMessageLabel},()=>[e.createElementVNode("button",{"data-testid":"copilot-copy-button",type:"button",class:e.normalizeClass(e.unref(x)),"aria-label":s.value.assistantMessageToolbarCopyMessageLabel,title:s.value.assistantMessageToolbarCopyMessageLabel,onClick:w},[l.value?(e.openBlock(),e.createBlock(e.unref(se.Check),{key:0,class:"cpk:size-[18px]"})):(e.openBlock(),e.createBlock(e.unref(se.Copy),{key:1,class:"cpk:size-[18px]"}))],10,ka)]),N.value?e.renderSlot(D.$slots,"thumbs-up-button",{key:0,onThumbsUp:R,label:s.value.assistantMessageToolbarThumbsUpLabel},()=>[e.createElementVNode("button",{type:"button",class:e.normalizeClass(e.unref(x)),"aria-label":s.value.assistantMessageToolbarThumbsUpLabel,title:s.value.assistantMessageToolbarThumbsUpLabel,onClick:R},[e.createVNode(e.unref(se.ThumbsUp),{class:"cpk:size-[18px]"})],10,ba)]):e.createCommentVNode("",!0),_.value?e.renderSlot(D.$slots,"thumbs-down-button",{key:1,onThumbsDown:F,label:s.value.assistantMessageToolbarThumbsDownLabel},()=>[e.createElementVNode("button",{type:"button",class:e.normalizeClass(e.unref(x)),"aria-label":s.value.assistantMessageToolbarThumbsDownLabel,title:s.value.assistantMessageToolbarThumbsDownLabel,onClick:F},[e.createVNode(e.unref(se.ThumbsDown),{class:"cpk:size-[18px]"})],10,ya)]):e.createCommentVNode("",!0),z.value?e.renderSlot(D.$slots,"read-aloud-button",{key:2,onReadAloud:W,label:s.value.assistantMessageToolbarReadAloudLabel},()=>[e.createElementVNode("button",{type:"button",class:e.normalizeClass(e.unref(x)),"aria-label":s.value.assistantMessageToolbarReadAloudLabel,title:s.value.assistantMessageToolbarReadAloudLabel,onClick:W},[e.createVNode(e.unref(se.Volume2),{class:"cpk:size-[20px]"})],10,wa)]):e.createCommentVNode("",!0),$.value?e.renderSlot(D.$slots,"regenerate-button",{key:3,onRegenerate:ae,label:s.value.assistantMessageToolbarRegenerateLabel},()=>[e.createElementVNode("button",{type:"button",class:e.normalizeClass(e.unref(x)),"aria-label":s.value.assistantMessageToolbarRegenerateLabel,title:s.value.assistantMessageToolbarRegenerateLabel,onClick:ae},[e.createVNode(e.unref(se.RefreshCw),{class:"cpk:size-[18px]"})],10,Ca)]):e.createCommentVNode("",!0),e.renderSlot(D.$slots,"toolbar-items")])])]):e.createCommentVNode("",!0)],16,ga)])}});class He extends Error{constructor(o){super(o),this.name="AudioRecorderError"}}const Nn=e.defineComponent({inheritAttrs:!1,__name:"CopilotChatAudioRecorder",setup(t,{expose:o}){const n=e.useAttrs(),a=e.ref(null),r=e.ref("idle"),s=e.ref(null),i=e.ref(null),l=e.ref(null),c=e.ref(null),d=e.ref(null),x=e.ref([]),p=e.ref([]),v=e.ref(0),u=e.ref(0),k=e.ref(0);function b(){d.value!==null&&(cancelAnimationFrame(d.value),d.value=null);const m=s.value;if(m&&m.state!=="inactive")try{m.stop()}catch{}i.value&&(i.value.getTracks().forEach(S=>S.stop()),i.value=null);const y=c.value;y&&y.state!=="closed"&&y.close().catch(()=>{}),s.value=null,l.value=null,c.value=null,x.value=[],p.value=[],v.value=0,u.value=0,k.value=0}async function h(){if(r.value!=="idle")throw new He("Recorder is already active");try{const m=await navigator.mediaDevices.getUserMedia({audio:!0});i.value=m;const y=new AudioContext;c.value=y;const S=y.createMediaStreamSource(m),M=y.createAnalyser();M.fftSize=2048,S.connect(M),l.value=M;const E=MediaRecorder.isTypeSupported("audio/webm;codecs=opus")?"audio/webm;codecs=opus":MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":MediaRecorder.isTypeSupported("audio/mp4")?"audio/mp4":"",I=E?{mimeType:E}:{},A=new MediaRecorder(m,I);s.value=A,x.value=[],A.ondataavailable=N=>{N.data.size>0&&x.value.push(N.data)},A.start(100),r.value="recording"}catch(m){throw b(),m instanceof Error&&m.name==="NotAllowedError"?new He("Microphone permission denied"):m instanceof Error&&m.name==="NotFoundError"?new He("No microphone found"):new He(m instanceof Error?m.message:"Failed to start recording")}}function C(){return new Promise((m,y)=>{const S=s.value;if(!S||r.value!=="recording"){y(new He("No active recording"));return}r.value="processing",S.onstop=()=>{const M=new Blob(x.value,{type:S.mimeType||"audio/webm"});b(),r.value="idle",m(M)},S.onerror=()=>{b(),r.value="idle",y(new He("Recording failed"))},S.stop()})}function f(m){let y=0;for(let S=0;S<m.length;S+=1){const M=(m[S]??128)/128-1;y+=M*M}return Math.sqrt(y/m.length)}function g(){const m=a.value;if(!m)return;const y=m.getContext("2d");if(!y)return;const S=m.getBoundingClientRect(),M=window.devicePixelRatio||1;(m.width!==S.width*M||m.height!==S.height*M)&&(m.width=S.width*M,m.height=S.height*M,y.scale(M,M));const E=2,A=E+1,N=Math.floor(S.width/A)+2;if(l.value&&r.value==="recording"){p.value.length===0&&(p.value=Array.from({length:N},()=>0)),k.value<1&&(k.value=Math.min(1,k.value+.03)),v.value+=1/3;const G=l.value.fftSize,B=new Uint8Array(G);l.value.getByteTimeDomainData(B);const w=f(B),W=w>u.value?.12:.08;u.value+=(w-u.value)*W,v.value>=A&&(v.value-=A,p.value.push(u.value),p.value.length>N&&(p.value=p.value.slice(-N)))}y.clearRect(0,0,S.width,S.height);const _=window.getComputedStyle(m);y.fillStyle=_.color,y.globalAlpha=k.value;const z=S.height/2,$=S.height/2-2,U=12;for(let G=0;G<p.value.length;G+=1){const B=p.value[G]??0,w=Math.min(B*4,1),R=Math.max(2,w*$*2),F=S.width-(p.value.length-G)*A-v.value,W=z-R/2;if(F+E<=0||F>=S.width)continue;let ae=1;F<U?ae=Math.max(0,F/U):F>S.width-U&&(ae=Math.max(0,(S.width-F)/U)),y.globalAlpha=k.value*ae,y.fillRect(F,W,E,R)}d.value=requestAnimationFrame(g)}return e.watch(r,()=>{d.value!==null&&(cancelAnimationFrame(d.value),d.value=null),d.value=requestAnimationFrame(g)},{immediate:!0}),e.onBeforeUnmount(()=>{b()}),o({get state(){return r.value},start:h,stop:C,dispose:b}),(m,y)=>(e.openBlock(),e.createElementBlock("div",e.mergeProps({"data-copilotkit":"",class:"cpk:w-full cpk:px-5 cpk:py-3"},e.unref(n)),[e.createElementVNode("canvas",{ref_key:"canvasRef",ref:a,class:"cpk:block cpk:h-[26px] cpk:w-full"},null,512)],16))}}),Mt=e.defineComponent({__name:"InlineFeatureWarning",props:{featureName:{}},setup(t){const o={padding:"8px 12px",backgroundColor:"#fffbeb",border:"1px solid #fbbf24",borderRadius:"6px",fontSize:"13px",color:"#92400e",fontFamily:"-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif"},n={color:"#b45309",textDecoration:"underline"};return(a,r)=>(e.openBlock(),e.createElementBlock("div",{style:o,"data-testid":"copilot-inline-feature-warning"},[e.createTextVNode(' ⚠ The "'+e.toDisplayString(t.featureName)+'" feature requires a CopilotKit license. ',1),e.createElementVNode("a",{href:"https://copilotkit.ai/pricing",target:"_blank",rel:"noopener noreferrer",style:n}," Get one at copilotkit.ai/pricing ")]))}});var Vn=(t=>(t.OnMessagesChanged="OnMessagesChanged",t.OnStateChanged="OnStateChanged",t.OnRunStatusChanged="OnRunStatusChanged",t))(Vn||{});const xa=["OnMessagesChanged","OnStateChanged","OnRunStatusChanged"];function gt(t={}){const o=t.threadId!==void 0,n=t.runtimeAgentId!==void 0,a=t.agentId!==void 0;if(o&&!n)throw new Error('useAgent: `threadId` requires `runtimeAgentId`. A threadId is written onto a single agent, but an agent resolved by agentId alone is shared, so scoping a thread to it would clobber other useAgent callers. Pass a distinct local `agentId` and the runtime agent to route to, e.g. useAgent({ agentId: "chat-1", runtimeAgentId: "assistant", threadId }).');if(n&&!o)throw new Error("useAgent: `runtimeAgentId` requires `threadId`. A proxied agent exists to scope a thread to a private instance; without a threadId it behaves like the shared agent while adding a registration and a local agentId to keep unique. Either pass the thread, or bind to the agent directly with useAgent({ agentId }).");if(n&&!a)throw new Error(`useAgent: \`runtimeAgentId\` requires an explicit \`agentId\`. The proxied agent is registered under \`agentId\`, and the usual fallbacks (chat configuration, then "${j.DEFAULT_AGENT_ID}") name agents that already exist — registering over one throws or shadows it. Pick a local id for this hook, e.g. useAgent({ agentId: "chat-1", runtimeAgentId: "assistant", threadId }).`);const r=n,s=be(),i=e.computed(()=>e.toValue(t.agentId)??s.value?.agentId??j.DEFAULT_AGENT_ID),l=e.computed(()=>r?e.toValue(t.runtimeAgentId):void 0),c=e.computed(()=>e.toValue(t.threadId)??(s.value?.hasExplicitThreadId?s.value.threadId:void 0)),{copilotkit:d}=xe(),x=e.computed(()=>t.updates??xa),p=e.computed(()=>d.value.defaultThrottleMs),v=e.computed(()=>e.toValue(t.throttleMs)),u=e.shallowRef(null),k=e.shallowRef(null),b=new Map,h=(g,m,y,S)=>{const M=new oe.ProxiedCopilotRuntimeAgent({runtimeUrl:m,agentId:g,transport:y,runtimeMode:"pending"});return M.headers={...S},M},C=e.shallowRef(null);r&&e.watch([i,l,()=>d.value],([g,m],y,S)=>{const{agent:M,unregister:E}=d.value.registerProxiedAgent({agentId:g,runtimeAgentId:m});b.delete(g),C.value=M,S(()=>{E(),C.value=null})},{immediate:!0});const f=()=>{const g=i.value,m=d.value;if(r){const A=C.value;if(A){b.delete(g);const z=u.value===A;u.value=A,k.value=A,z&&e.triggerRef(u);return}const N=b.get(g);if(N){N.headers={...m.headers},u.value=N,k.value=N;return}const _=new oe.ProxiedCopilotRuntimeAgent({runtimeUrl:m.runtimeUrl,agentId:g,runtimeAgentId:l.value,transport:m.runtimeTransport,runtimeMode:"pending"});_.headers={...m.headers},b.set(g,_),u.value=_,k.value=_;return}const y=m.getAgent(g);if(y){b.delete(g);const A=u.value===y;u.value=y,k.value=y,A&&e.triggerRef(u);return}const S=m.runtimeUrl!==void 0,M=m.runtimeConnectionStatus;if(S&&(M===oe.CopilotKitCoreRuntimeConnectionStatus.Disconnected||M===oe.CopilotKitCoreRuntimeConnectionStatus.Connecting||M===oe.CopilotKitCoreRuntimeConnectionStatus.Error)){const A=b.get(g);if(A){A.headers={...m.headers},u.value=A,k.value=A;return}const N=h(g,m.runtimeUrl,m.runtimeTransport,m.headers);b.set(g,N),u.value=N,k.value=N;return}const E=Object.keys(m.agents??{}),I=S?`runtimeUrl=${m.runtimeUrl}`:"no runtimeUrl";throw new Error(`useAgent: Agent '${g}' not found after runtime sync (${I}). `+(E.length?`Known agents: [${E.join(", ")}]`:"No agents registered.")+" Verify your runtime /info and/or agents__unsafe_dev_only.")};return e.watch([i,C,()=>d.value.agents,()=>d.value.runtimeConnectionStatus,()=>d.value.runtimeUrl,()=>d.value.runtimeTransport,()=>JSON.stringify(Object.entries(d.value.headers??{}).sort(([g],[m])=>g.localeCompare(m)))],f,{immediate:!0}),e.watch([()=>u.value,c],([g,m])=>{!g||!m||(g.threadId=m)},{immediate:!0}),e.watch([k,()=>JSON.stringify(Object.entries(d.value.headers??{}).sort(([g],[m])=>g.localeCompare(m)))],([g])=>{g instanceof qe.HttpAgent&&(g.headers={...d.value.headers})},{immediate:!0}),e.watch([k,x,v,p],([g,m],y,S)=>{const M=m;if(!g||M.length===0)return;let E=!0,I=!1;const A=()=>{E&&(I||(I=!0,queueMicrotask(()=>{I=!1,E&&e.triggerRef(u)})))},N={};M.includes("OnMessagesChanged")&&(N.onMessagesChanged=()=>{E&&e.triggerRef(u)}),M.includes("OnStateChanged")&&(N.onStateChanged=A),M.includes("OnRunStatusChanged")&&(N.onRunInitialized=A,N.onRunFinalized=A,N.onRunFailed=A,N.onRunErrorEvent=A);const _=d.value.subscribeToAgentWithOptions(g,N,{throttleMs:e.toValue(t.throttleMs)});S(()=>{E=!1,_.unsubscribe()})},{immediate:!0}),{agent:u}}function Fn(t={}){const{copilotkit:o}=xe(),n=be(),a=e.computed(()=>e.toValue(t.agentId)??n.value?.agentId??j.DEFAULT_AGENT_ID),r=e.ref([]),s=e.ref(!1),i=()=>{const d=o.value.getSuggestions(a.value);r.value=d.suggestions,s.value=d.isLoading};return e.watch([()=>o.value,a],()=>i(),{immediate:!0}),e.watch([()=>o.value,a],(d,x,p)=>{const v=o.value,u=a.value,k=v.subscribe({onSuggestionsChanged:({agentId:b,suggestions:h})=>{if(b!==u)return;r.value=h;const C=v.getSuggestions(u);s.value=C.isLoading},onSuggestionsStartedLoading:({agentId:b})=>{b===u&&(s.value=!0)},onSuggestionsFinishedLoading:({agentId:b})=>{b===u&&(s.value=!1)},onSuggestionsConfigChanged:()=>{const b=v.getSuggestions(u);r.value=b.suggestions,s.value=b.isLoading}});p(()=>k.unsubscribe())},{immediate:!0}),{suggestions:r,isLoading:s,reloadSuggestions:()=>{o.value.reloadSuggestions(a.value)},clearSuggestions:()=>{o.value.clearSuggestions(a.value)}}}function Dn(t){const o=e.shallowRef([]),n=e.ref(!1),a=e.ref(null),r=e.ref(null),s=e.ref(e.toValue(t.config)),i=e.shallowRef(o.value),l=e.computed(()=>s.value?.enabled??!1);e.watch(()=>e.toValue(t.config),f=>{s.value=f},{immediate:!0});const c=f=>{o.value=f,i.value=f},d=f=>{c(f(i.value))};async function x(f){const g=s.value,m=g?.accept??"*/*",y=g?.maxSize??20*1024*1024,S=f.filter(E=>!j.matchesAcceptFilter(E,m));for(const E of S)g?.onUploadFailed?.({reason:"invalid-type",file:E,message:`File "${E.name}" is not accepted. Supported types: ${m}`});const M=f.filter(E=>j.matchesAcceptFilter(E,m));for(const E of M){if(j.exceedsMaxSize(E,y)){g?.onUploadFailed?.({reason:"file-too-large",file:E,message:`File "${E.name}" exceeds the maximum size of ${j.formatFileSize(y)}`});continue}const I=j.getModalityFromMimeType(E.type),A=j.randomUUID();d(N=>[...N,{id:A,type:I,source:{type:"data",value:"",mimeType:E.type},filename:E.name,size:E.size,status:"uploading"}]);try{let N,_;if(g?.onUpload){const $=await g.onUpload(E),{metadata:U,...G}=$;N=G,_=U}else N={type:"data",value:await j.readFileAsBase64(E),mimeType:E.type};let z;I==="video"&&(z=await j.generateVideoThumbnail(E)),d($=>$.map(U=>U.id===A?{...U,source:N,status:"ready",thumbnail:z,metadata:_}:U))}catch(N){d(_=>_.filter(z=>z.id!==A)),console.error(`[CopilotKit] Failed to upload "${E.name}":`,N),g?.onUploadFailed?.({reason:"upload-failed",file:E,message:N instanceof Error?N.message:`Failed to upload "${E.name}"`})}}}async function p(f){const g=f.target;g?.files?.length&&(await x(Array.from(g.files)),g&&(g.value=""))}function v(f){l.value&&(f.preventDefault(),f.stopPropagation(),n.value=!0)}function u(f){f.preventDefault(),f.stopPropagation(),n.value=!1}async function k(f){if(f.preventDefault(),f.stopPropagation(),n.value=!1,!l.value)return;const g=Array.from(f.dataTransfer?.files??[]);g.length>0&&await x(g)}function b(f){d(g=>g.filter(m=>m.id!==f))}function h(){const f=i.value.filter(g=>g.status==="ready");return f.length===0||(d(g=>g.filter(m=>m.status!=="ready")),a.value&&(a.value.value="")),f}async function C(f){if(!l.value)return;const g=f.target;if(!g||!r.value?.contains(g))return;const m=s.value?.accept??"*/*",S=Array.from(f.clipboardData?.items??[]).filter(E=>{if(E.kind!=="file")return!1;const I=E.getAsFile();return I!==null&&j.matchesAcceptFilter(I,m)});if(S.length===0)return;f.preventDefault();const M=S.map(E=>E.getAsFile()).filter(E=>E!==null);await x(M)}return e.onMounted(()=>{typeof document<"u"&&document.addEventListener("paste",C)}),e.onBeforeUnmount(()=>{typeof document<"u"&&document.removeEventListener("paste",C)}),{attachments:o,enabled:l,dragOver:n,fileInputRef:a,containerRef:r,processFiles:x,handleFileUpload:p,handleDragOver:v,handleDragLeave:u,handleDrop:k,removeAttachment:b,consumeAttachments:h}}async function Sa(t){return await new Promise((o,n)=>{const a=new FileReader;a.onloadend=()=>{const r=a.result;o(r.split(",")[1]??"")},a.addEventListener("error",()=>n(new Error("Failed to read audio data"))),a.readAsDataURL(t)})}function Ta(t){return typeof t=="object"&&t!==null&&"error"in t&&"message"in t&&typeof t.error=="string"&&typeof t.message=="string"}function Ia(t){return{code:t.error,message:t.message,retryable:t.retryable??!1}}class We extends Error{info;constructor(o){super(o.message),this.name="TranscriptionError",this.info=o}}async function Aa(t,o,n="recording.webm"){const a=t.runtimeUrl;if(!a)throw new We({code:j.TranscriptionErrorCode.INVALID_REQUEST,message:"Runtime URL is not configured",retryable:!1});const r={...t.headers};let s;try{if(t.runtimeTransport==="single"){const i=await Sa(o);r["Content-Type"]="application/json",s=await fetch(a,{method:"POST",headers:r,body:JSON.stringify({method:"transcribe",body:{audio:i,mimeType:o.type||"audio/webm",filename:n}})})}else{delete r["Content-Type"];const i=new FormData;i.append("audio",o,n),s=await fetch(`${a}/transcribe`,{method:"POST",headers:r,body:i})}}catch(i){throw new We({code:j.TranscriptionErrorCode.NETWORK_ERROR,message:i instanceof Error?i.message:"Network request failed",retryable:!0})}if(!s.ok){let i;try{i=await s.json()}catch{throw new We({code:j.TranscriptionErrorCode.PROVIDER_ERROR,message:`HTTP ${s.status}: ${s.statusText}`,retryable:s.status>=500})}throw Ta(i)?new We(Ia(i)):new We({code:j.TranscriptionErrorCode.PROVIDER_ERROR,message:typeof i=="object"&&i!==null&&"message"in i?String(i.message):"Transcription failed",retryable:s.status>=500})}return await s.json()}function On(){const t=typeof window<"u"?window.innerHeight:0,o=e.ref(!1),n=e.ref(0),a=e.ref(t),r=e.ref(t),s=()=>{if(typeof window>"u")return;const l=window.visualViewport;if(!l)return;const c=window.innerHeight,d=l.height,x=Math.max(0,c-d),p=x>150;n.value=x,o.value=p,a.value=d,r.value=c};let i=null;return e.onMounted(()=>{typeof window>"u"||(i=window.visualViewport??null,i&&(s(),i.addEventListener("resize",s),i.addEventListener("scroll",s)))}),e.onBeforeUnmount(()=>{i&&(i.removeEventListener("resize",s),i.removeEventListener("scroll",s),i=null)}),{isKeyboardOpen:e.readonly(o),keyboardHeight:e.readonly(n),availableHeight:e.readonly(a),viewportHeight:e.readonly(r)}}const Ra={id:null,sendNonce:0},Ln=Symbol("LastUserMessage");function Ea(){return e.ref({...Ra})}function Ma({scrollRef:t,contentRef:o,spacerRef:n,topOffset:a=16}){const r=e.inject(Ln,Ea(),!0);let s=-1,i=null,l=null;function c(){i!==null&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(i),i=null,l?.disconnect(),l=null}e.watch([()=>r.value.id,()=>r.value.sendNonce,t,o,n,()=>a],([d,x,p,v,u],k,b)=>{if(b(c),x===s||(s=x,!d)||!p||!v||!u)return;const h=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(d):d.replace(/[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g,"\\$&"),C=v.querySelector(`[data-message-id="${h}"]`);if(!C)return;const f=p.clientHeight,g=C.getBoundingClientRect().height,m=parseFloat(getComputedStyle(C).paddingTop)||0,y=Math.max(0,g-m),S=Math.max(0,f-y-a);u.style.height=`${S}px`,typeof requestAnimationFrame=="function"&&(i=requestAnimationFrame(()=>{const M=Xt(C,p)+m-a;p.scrollTo({top:Math.max(0,M),behavior:"smooth"})})),typeof ResizeObserver<"u"&&(l=new ResizeObserver(()=>{if(!v||!u||!p)return;const M=v.getBoundingClientRect().height,E=Xt(C,v),I=M-E-g,A=Math.max(0,S-I);u.style.height=`${A}px`}),l.observe(v))},{immediate:!0,flush:"post"})}function Xt(t,o){const n=t.getBoundingClientRect(),a=o.getBoundingClientRect();return n.top-a.top+o.scrollTop}const $a={class:"cpk:pointer-events-auto cpk:mx-auto cpk:max-w-3xl cpk:px-4 cpk:py-0 cpk:@3xl:px-0 cpk:[div[data-sidebar-chat]_&]:px-8 cpk:[div[data-popup-chat]_&]:px-4"},Ba=["data-layout"],Na=["data-layout"],Va=["aria-label","disabled"],Fa={key:0,class:"cpk:my-1 cpk:h-px cpk:bg-border cpk:dark:bg-[#333333]"},Da=["onClick"],Oa={key:1,class:"cpk:flex cpk:w-full cpk:items-center cpk:justify-center cpk:px-5 cpk:py-3"},La=["value","placeholder","disabled"],Pa={key:0,class:"cpk:px-3 cpk:py-2 cpk:text-sm cpk:text-muted-foreground"},Ua=["data-slash-index","aria-selected","data-active","onMouseenter","onMousedown"],za=["aria-label","disabled"],ja=["aria-label","disabled"],_a=["aria-label","disabled"],Ha={class:"cpk:mr-[10px]"},Wa=["disabled"],qa={"data-testid":"copilot-chat-input-disclaimer",class:"cpk:mx-auto cpk:max-w-3xl cpk:px-4 cpk:py-3 cpk:text-center cpk:text-xs cpk:text-muted-foreground"},et=e.defineComponent({inheritAttrs:!1,__name:"CopilotChatInput",props:{modelValue:{},disabled:{type:Boolean,default:!1},placeholder:{},autoFocus:{type:Boolean,default:!0},clearOnSubmit:{type:Boolean,default:!0},mode:{default:"input"},toolsMenu:{default:()=>[]},isRunning:{type:Boolean,default:!1},positioning:{default:"static"},keyboardHeight:{default:0},showDisclaimer:{type:Boolean,default:void 0},maxRows:{default:5},bottomAnchored:{type:Boolean,default:!1}},emits:["update:modelValue","submit-message","stop","add-file","start-transcribe","cancel-transcribe","finish-transcribe","finish-transcribe-with-audio"],setup(t,{emit:o}){const n=t,a=o,r=e.useAttrs(),s=be(),i=e.getCurrentInstance(),l=e.ref(null),c=e.ref(null),d=e.ref(null),x=e.ref(null),p=e.ref(null),v=e.ref(null),u=e.ref(null),k=e.ref(null),b=e.ref(n.modelValue??""),h=e.ref(!1),C=e.ref("compact"),f=e.ref(null),g=e.ref(0),m=e.ref(null),y=e.ref(!1),S=e.ref({singleLineHeight:0,maxHeight:0,paddingLeft:0,paddingRight:0}),M=e.ref(null),E=e.ref(!1),I=e.ref(null),A=e.ref(null),N=e.ref(!1),_=e.ref(!1);let z=null,$=null;const U=e.computed(()=>i?.vnode.props??{}),G=e.computed(()=>n.modelValue!==void 0),B=e.computed(()=>G.value?n.modelValue??"":b.value),w=e.computed(()=>s.value?.labels??Be),R=e.computed(()=>n.placeholder??w.value.chatInputPlaceholder),F=e.computed(()=>n.mode==="input"&&C.value==="expanded"),W=e.computed(()=>n.mode!=="transcribe"&&n.isRunning),ae=e.computed(()=>n.showDisclaimer??n.positioning==="absolute"),D=e.computed(()=>ee("onSubmitMessage")),H=e.computed(()=>ee("onStop")),q=e.computed(()=>ee("onAddFile")),K=e.computed(()=>ee("onStartTranscribe")),re=e.computed(()=>ee("onCancelTranscribe")),pe=e.computed(()=>ee("onFinishTranscribe")),he=e.computed(()=>n.mode==="input"&&!n.disabled&&D.value&&B.value.trim().length>0),ve=e.computed(()=>W.value?!H.value:!he.value),Ae=e.computed(()=>[n.positioning==="absolute"&&"cpk:absolute cpk:bottom-0 cpk:left-0 cpk:right-0 cpk:z-20 cpk:pointer-events-none",r.class]),O=e.computed(()=>{const T={...r};return delete T.class,T});function te(T){return Array.isArray(T.items)}function ee(T){const V=U.value[T];return Array.isArray(V)?V.length>0:!!V}function Se(){return q.value?{label:w.value.chatInputToolbarAddButtonLabel,action:()=>a("add-file")}:null}function Re(){const T=[],V=Se();if(V&&T.push(V),n.toolsMenu.length>0){T.length>0&&T.push("-");for(const J of n.toolsMenu){if(J==="-"){if(T.length===0||T[T.length-1]==="-")continue;T.push("-");continue}T.push(J)}}for(;T.length>0&&T[T.length-1]==="-";)T.pop();return T}const me=e.computed(()=>Re()),ie=e.computed(()=>me.value.length>0);function ue(T){const V=new Set,J=[],ne=fe=>{for(const ce of fe)if(ce!=="-"){if(te(ce)&&ce.items.length>0){ne(ce.items);continue}!ce.action||V.has(ce.label)||(V.add(ce.label),J.push(ce))}};return ne(T),J}const de=e.computed(()=>ue(me.value));function Me(T,V=0,J="root"){const ne=[];for(const[fe,ce]of T.entries()){const ge=`${J}-${fe}`;if(ce==="-"){ne.push({type:"separator",key:`sep-${ge}`});continue}if(te(ce)&&ce.items.length>0){ne.push({type:"label",key:`label-${ge}`,label:ce.label,depth:V}),ne.push(...Me(ce.items,V+1,ge));continue}ce.action&&ne.push({type:"item",key:`item-${ge}`,label:ce.label,depth:V,action:ce.action})}return ne}const L=e.computed(()=>Me(me.value)),Q=e.computed(()=>{if(f.value===null||de.value.length===0)return[];const T=f.value.trim().toLowerCase();if(T.length===0)return de.value;const V=[],J=[];for(const ne of de.value){const fe=ne.label.toLowerCase();if(fe.startsWith(T)){V.push(ne);continue}fe.includes(T)&&J.push(ne)}return[...V,...J]}),Te=e.computed(()=>f.value!==null&&de.value.length>0);function Ne(T){G.value||(b.value=T),a("update:modelValue",T)}function Ge(){Ne("")}function Je(T){if(de.value.length===0){f.value=null;return}if(T.startsWith("/")){const V=T.split(/\r?\n/,1)[0]??"";f.value=V.slice(1);return}f.value=null}function Qe(T){Ge(),T.action?.(),f.value=null,g.value=0,requestAnimationFrame(()=>{c.value?.focus()})}function ze(){if(n.mode!=="input"||n.disabled||!D.value)return;const V=(c.value?.value??B.value).trim();V&&(a("submit-message",V),n.clearOnSubmit&&Ge(),c.value?.focus())}function Xe(T){const V=T.target.value;Ne(V),Je(V)}function je(){if(W.value){H.value&&a("stop");return}ze()}function Ye(T){if(!n.disabled&&!(h.value||T.isComposing||T.keyCode===229)){if(f.value!==null&&n.mode==="input"){if(T.key==="ArrowDown"){Q.value.length>0&&(T.preventDefault(),g.value=g.value<0?0:(g.value+1)%Q.value.length);return}if(T.key==="ArrowUp"){Q.value.length>0&&(T.preventDefault(),g.value<0?g.value=Q.value.length-1:g.value=g.value<=0?Q.value.length-1:g.value-1);return}if(T.key==="Enter"){const V=g.value>=0?Q.value[g.value]:void 0;if(V){T.preventDefault(),Qe(V);return}}if(T.key==="Escape"){T.preventDefault(),f.value=null;return}}if(T.key==="Enter"&&!T.shiftKey&&n.mode==="input"){if(T.preventDefault(),W.value){H.value&&a("stop");return}ze()}}}function Ce(){!ie.value||n.mode==="transcribe"||n.disabled||(y.value=!y.value)}function _e(){y.value=!1}function P(T){T(),_e(),e.nextTick(()=>{c.value?.focus()})}async function X(){const T=k.value;if(T&&T.state==="recording")try{const V=await T.stop();a("finish-transcribe-with-audio",V)}catch(V){console.error("Failed to stop recording:",V)}a("finish-transcribe")}function Z(T){const V=T.target;!V||n.mode!=="input"||V.tagName==="BUTTON"||V.closest("button")||c.value?.focus()}function le(){const T=c.value;if(!T||h.value)return;const V=T.value,J=T.style.height;T.style.height="auto";const ne=window.getComputedStyle(T),fe=parseFloat(ne.paddingLeft)||0,ce=parseFloat(ne.paddingRight)||0,ge=parseFloat(ne.paddingTop)||0,ke=parseFloat(ne.paddingBottom)||0;T.value="";const $e=T.scrollHeight;T.value=V;const Le=($e-ge-ke)*n.maxRows+ge+ke;S.value={singleLineHeight:$e,maxHeight:Le,paddingLeft:fe,paddingRight:ce},T.style.height=J,T.style.maxHeight=`${Le}px`}function Ie(){const T=c.value;if(!T)return 0;S.value.singleLineHeight===0&&le();const{maxHeight:V}=S.value;V&&(T.style.maxHeight=`${V}px`),T.style.height="auto";const J=T.scrollHeight;return T.style.height=`${V?Math.min(J,V):J}px`,J}function Ee(T){C.value!==T&&(E.value=!0,C.value=T)}function Ve(T){const V=window.getComputedStyle(T);if(V.font?.trim())return V.font;if(V.fontSize&&V.fontFamily){const J=`${V.fontStyle} ${V.fontVariant} ${V.fontWeight} ${V.fontSize}/${V.lineHeight} ${V.fontFamily}`;if(J.trim())return J}return process.env.NODE_ENV!=="production"&&!N.value&&(N.value=!0,console.warn("[CopilotChatInput] Could not resolve textarea font for layout measurement. Text-width-based expansion will be skipped until the next container resize.")),null}function Pe(){const T=d.value,V=x.value,J=p.value;if(!T||!V||!J)return A.value=null,null;const ne=window.getComputedStyle(T),fe=parseFloat(ne.paddingLeft)||0,ce=parseFloat(ne.paddingRight)||0,ge=parseFloat(ne.columnGap)||0,ke=T.clientWidth-fe-ce;if(ke<=0)return A.value=null,null;const $e=V.getBoundingClientRect().width,Oe=J.getBoundingClientRect().width,Le=Math.max(ke-$e-Oe-ge*2,0);if(Le<=0)return A.value=null,null;const st={compactWidth:Le};return A.value=st,st}function De(){if(n.mode!=="input"){Ee("compact");return}if(typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 767px)").matches){le(),Ie(),Ee("expanded");return}const T=c.value;if(!T||!d.value||!x.value||!p.value)return;S.value.singleLineHeight===0&&le();const V=Ie(),J=S.value.singleLineHeight,ne=B.value.includes(`
|
|
72
|
-
`),fe=J>0?V>J+1:!1;let ce=ne||fe;if(!ce){const ge=A.value??Pe();if(ge&&ge.compactWidth>0){const ke=Math.max(ge.compactWidth-S.value.paddingLeft-S.value.paddingRight,0);if(ke>0){const $e=I.value??document.createElement("canvas");I.value||(I.value=$e);const Oe=$e.getContext("2d");if(Oe){const Le=Ve(T);if(Le){Oe.font=Le;const st=B.value.length>0?B.value.split(`
|
|
73
|
-
`):[""];let ht=0;for(const Yn of st){const Lt=Oe.measureText(Yn||" ").width;Lt>ht&&(ht=Lt)}ht>ke&&(ce=!0)}}else process.env.NODE_ENV!=="production"&&!_.value&&(_.value=!0,console.warn("[CopilotChatInput] canvas.getContext('2d') returned null. Text-width-based expansion will be skipped."))}}}Ee(ce?"expanded":"compact")}function Ot(T){if(E.value){E.value=!1;return}T&&(A.value=null,N.value=!1,_.value=!1),M.value!==null&&cancelAnimationFrame(M.value),M.value=requestAnimationFrame(()=>{M.value=null,De()})}return e.watch(()=>n.modelValue,T=>{G.value&&(b.value=T??"")}),e.watch(B,T=>{Je(T),De()}),e.watch(de,()=>{de.value.length===0&&(f.value=null)}),e.watch([f,()=>Q.value.length],([T,V])=>{T!==null&&T!==m.value&&V>0&&(g.value=0),m.value=T},{immediate:!0}),e.watch([f,Q],()=>{if(f.value===null){g.value=0;return}if(Q.value.length===0){g.value=-1;return}(g.value<0||g.value>=Q.value.length)&&(g.value=0)},{immediate:!0}),e.watch(()=>n.mode,async T=>{T!=="input"&&(C.value="compact",f.value=null,_e());const V=k.value;if(V){if(T==="transcribe"){try{await V.start()}catch(J){console.error(J)}return}if(V.state==="recording")try{await V.stop()}catch{}}},{immediate:!0}),e.watch(k,async T=>{if(!(!T||n.mode!=="transcribe")&&T.state==="idle")try{await T.start()}catch(V){console.error(V)}},{immediate:!0}),e.watch(g,async T=>{if(!Te.value||T<0)return;await e.nextTick(),v.value?.querySelector(`[data-slash-index="${T}"]`)?.scrollIntoView?.({block:"nearest"})}),e.watch(()=>n.disabled,T=>{T&&_e()}),e.onMounted(()=>{if(n.autoFocus&&n.mode==="input"&&c.value?.focus(),De(),typeof ResizeObserver<"u"){const T=new Set;d.value&&T.add(d.value),x.value&&T.add(x.value),p.value&&T.add(p.value),z=new ResizeObserver(V=>{const J=V.some(ne=>T.has(ne.target));Ot(J)}),d.value&&z.observe(d.value),x.value&&z.observe(x.value),p.value&&z.observe(p.value),c.value&&z.observe(c.value)}$=T=>{if(!y.value)return;const V=T.target;V&&(u.value?.contains(V)||x.value?.contains(V)||_e())},document.addEventListener("mousedown",$)}),e.onBeforeUnmount(()=>{$&&(document.removeEventListener("mousedown",$),$=null),z?.disconnect(),z=null,M.value!==null&&(cancelAnimationFrame(M.value),M.value=null)}),(T,V)=>(e.openBlock(),e.createElementBlock("div",e.mergeProps({"data-copilotkit":"","data-testid":"copilot-chat-input-container",class:Ae.value,style:{transform:t.keyboardHeight>0?`translateY(-${t.keyboardHeight}px)`:void 0,transition:"transform 0.2s ease-out",...t.positioning==="absolute"||t.bottomAnchored?{paddingBottom:"var(--copilotkit-license-banner-offset, 0px)"}:{}}},O.value),[e.createElementVNode("div",$a,[e.renderSlot(T.$slots,"layout",{mode:t.mode,isMultiline:F.value,value:B.value,disabled:t.disabled,placeholder:R.value,isProcessing:W.value,sendDisabled:ve.value,menuOpen:y.value,menuItems:L.value,onToggleMenu:Ce,onMenuAction:P,onUpdateValue:Ne,onSubmit:ze,onKeydown:Ye,onSendClick:je,onStartTranscribe:()=>a("start-transcribe"),onCancelTranscribe:()=>a("cancel-transcribe"),onFinishTranscribe:X},()=>[e.createElementVNode("div",{ref_key:"shellRef",ref:l,"data-testid":"copilot-chat-input-shell",class:"cpk:flex cpk:w-full cpk:cursor-text cpk:flex-col cpk:items-center cpk:justify-center cpk:overflow-visible cpk:rounded-[28px] cpk:bg-white cpk:bg-clip-padding cpk:shadow-[0_4px_4px_0_#0000000a,0_0_1px_0_#0000009e] cpk:contain-inline-size cpk:dark:bg-[#303030]","data-layout":F.value?"expanded":"compact",onClick:Z},[e.createElementVNode("div",{ref_key:"gridRef",ref:d,class:e.normalizeClass(["cpk:grid cpk:w-full cpk:gap-x-3 cpk:gap-y-3 cpk:px-3 cpk:py-2",F.value?"cpk:grid-cols-[auto_minmax(0,1fr)_auto] cpk:grid-rows-[auto_auto]":"cpk:grid-cols-[auto_minmax(0,1fr)_auto] cpk:items-center"]),"data-layout":F.value?"expanded":"compact"},[e.createElementVNode("div",{ref_key:"addButtonContainerRef",ref:x,class:e.normalizeClass(["cpk:relative cpk:flex cpk:items-center cpk:col-start-1",F.value?"cpk:row-start-2":"cpk:row-start-1"])},[e.renderSlot(T.$slots,"add-menu-button",{disabled:t.disabled||t.mode==="transcribe"||!ie.value,menuOpen:y.value,toggleMenu:Ce,labels:w.value},()=>[e.createElementVNode("button",{type:"button","data-testid":"copilot-chat-input-add","aria-label":w.value.chatInputToolbarAddButtonLabel,disabled:t.disabled||t.mode==="transcribe"||!ie.value,class:"cpk:ml-1 cpk:inline-flex cpk:h-9 cpk:w-9 cpk:shrink-0 cpk:items-center cpk:justify-center cpk:rounded-full cpk:bg-transparent cpk:text-[#444444] cpk:transition-colors cpk:hover:bg-[#f8f8f8] cpk:hover:text-[#333333] cpk:disabled:cursor-not-allowed cpk:disabled:opacity-50 cpk:disabled:hover:bg-transparent cpk:disabled:hover:text-[#444444] cpk:dark:text-white cpk:dark:hover:bg-[#404040] cpk:dark:hover:text-[#FFFFFF] cpk:dark:disabled:hover:bg-transparent cpk:dark:disabled:hover:text-[#CCCCCC]",onClick:e.withModifiers(Ce,["stop"])},[e.createVNode(e.unref(se.Plus),{class:"cpk:size-[20px]"})],8,Va)]),y.value&&ie.value?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"addMenuRef",ref:u,class:"cpk:absolute cpk:bottom-full cpk:left-0 cpk:z-30 cpk:mb-2 cpk:min-w-[220px] cpk:overflow-hidden cpk:rounded-lg cpk:border cpk:border-border cpk:bg-white cpk:shadow-lg cpk:dark:border-[#3a3a3a] cpk:dark:bg-[#1f1f1f]","data-testid":"copilot-chat-input-add-menu"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(L.value,J=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:J.key},[J.type==="separator"?(e.openBlock(),e.createElementBlock("div",Fa)):J.type==="label"?(e.openBlock(),e.createElementBlock("div",{key:1,class:"cpk:flex cpk:items-center cpk:gap-1 cpk:px-3 cpk:py-1.5 cpk:text-xs cpk:font-semibold cpk:text-muted-foreground",style:e.normalizeStyle({paddingLeft:`${12+J.depth*12}px`})},[e.createElementVNode("span",null,e.toDisplayString(J.label),1),e.createVNode(e.unref(se.ChevronRight),{class:"cpk:size-3"})],4)):(e.openBlock(),e.createElementBlock("button",{key:2,type:"button",role:"menuitem",class:"cpk:w-full cpk:px-3 cpk:py-2 cpk:text-left cpk:text-sm cpk:transition-colors cpk:hover:bg-muted cpk:dark:hover:bg-[#2f2f2f]",style:e.normalizeStyle({paddingLeft:`${12+J.depth*12}px`}),onClick:ne=>P(J.action)},e.toDisplayString(J.label),13,Da))],64))),128))],512)):e.createCommentVNode("",!0)],2),e.createElementVNode("div",{class:e.normalizeClass(["cpk:relative cpk:flex cpk:min-h-[50px] cpk:min-w-0 cpk:flex-col cpk:justify-center",F.value?"cpk:col-span-3 cpk:row-start-1":"cpk:col-start-2 cpk:row-start-1"])},[t.mode==="transcribe"?e.renderSlot(T.$slots,"audio-recorder",{key:0},()=>[e.createVNode(Nn,{ref_key:"audioRecorderRef",ref:k},null,512)]):t.mode==="processing"?(e.openBlock(),e.createElementBlock("div",Oa,[e.createVNode(e.unref(se.Loader2),{class:"cpk:size-[26px] cpk:animate-spin cpk:text-muted-foreground"})])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.renderSlot(T.$slots,"text-area",{value:B.value,disabled:t.disabled,placeholder:R.value,onInput:Xe,onKeydown:Ye,autoFocus:t.autoFocus,isExpanded:F.value,rows:1,labels:w.value},()=>[e.createElementVNode("textarea",{ref_key:"textareaRef",ref:c,"data-testid":"copilot-chat-input-textarea",value:B.value,placeholder:R.value,disabled:t.disabled,rows:"1",class:e.normalizeClass(["cpk:w-full cpk:bg-transparent cpk:py-3 cpk:text-[16px] cpk:font-normal cpk:leading-relaxed cpk:text-foreground cpk:antialiased cpk:outline-none cpk:placeholder:text-[#00000077] cpk:dark:placeholder:text-[#fffc]",F.value?"cpk:px-5":"cpk:pr-5"]),style:{overflow:"auto",resize:"none"},onInput:Xe,onKeydown:Ye,onCompositionstart:V[0]||(V[0]=J=>h.value=!0),onCompositionend:V[1]||(V[1]=J=>h.value=!1)},null,42,La)]),Te.value?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"slashMenuRef",ref:v,"data-testid":"copilot-slash-menu",role:"listbox","aria-label":"Slash commands",class:"cpk:absolute cpk:bottom-full cpk:left-0 cpk:right-0 cpk:z-30 cpk:mb-2 cpk:max-h-64 cpk:overflow-y-auto cpk:rounded-lg cpk:border cpk:border-border cpk:bg-white cpk:shadow-lg cpk:dark:border-[#3a3a3a] cpk:dark:bg-[#1f1f1f]",style:{maxHeight:"200px"}},[Q.value.length===0?(e.openBlock(),e.createElementBlock("div",Pa," No commands found ")):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(Q.value,(J,ne)=>(e.openBlock(),e.createElementBlock("button",{key:`${J.label}-${ne}`,type:"button",role:"option","data-slash-index":ne,"aria-selected":ne===g.value,"data-active":ne===g.value?"true":void 0,class:e.normalizeClass(["cpk:w-full cpk:px-3 cpk:py-2 cpk:text-left cpk:text-sm cpk:transition-colors cpk:hover:bg-muted cpk:dark:hover:bg-[#2f2f2f]",ne===g.value?"cpk:bg-muted cpk:dark:bg-[#2f2f2f]":"cpk:bg-transparent"]),onMouseenter:fe=>g.value=ne,onMousedown:e.withModifiers(fe=>Qe(J),["prevent"])},e.toDisplayString(J.label),43,Ua))),128))],512)):e.createCommentVNode("",!0)],64))],2),e.createElementVNode("div",{ref_key:"actionsContainerRef",ref:p,class:e.normalizeClass(["cpk:flex cpk:items-center cpk:justify-end cpk:gap-2",F.value?"cpk:col-start-3 cpk:row-start-2":"cpk:col-start-3 cpk:row-start-1"])},[t.mode==="transcribe"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[re.value?e.renderSlot(T.$slots,"cancel-transcribe-button",{key:0,disabled:t.disabled,onClick:()=>a("cancel-transcribe"),labels:w.value},()=>[e.createElementVNode("button",{type:"button","data-testid":"copilot-chat-input-cancel-transcribe","aria-label":w.value.chatInputToolbarCancelTranscribeButtonLabel,disabled:t.disabled,class:"cpk:mr-2 cpk:inline-flex cpk:h-9 cpk:w-9 cpk:shrink-0 cpk:items-center cpk:justify-center cpk:rounded-full cpk:bg-transparent cpk:text-[#444444] cpk:transition-colors cpk:hover:bg-[#f8f8f8] cpk:hover:text-[#333333] cpk:disabled:cursor-not-allowed cpk:disabled:opacity-50 cpk:dark:text-white cpk:dark:hover:bg-[#404040] cpk:dark:hover:text-[#FFFFFF]",onClick:V[2]||(V[2]=J=>a("cancel-transcribe"))},[e.createVNode(e.unref(se.X),{class:"cpk:size-[18px]"})],8,za)]):e.createCommentVNode("",!0),pe.value?e.renderSlot(T.$slots,"finish-transcribe-button",{key:1,disabled:t.disabled,onClick:X,labels:w.value},()=>[e.createElementVNode("button",{type:"button","data-testid":"copilot-chat-input-finish-transcribe","aria-label":w.value.chatInputToolbarFinishTranscribeButtonLabel,disabled:t.disabled,class:"cpk:mr-[10px] cpk:inline-flex cpk:h-9 cpk:w-9 cpk:shrink-0 cpk:items-center cpk:justify-center cpk:rounded-full cpk:bg-transparent cpk:text-[#444444] cpk:transition-colors cpk:hover:bg-[#f8f8f8] cpk:hover:text-[#333333] cpk:disabled:cursor-not-allowed cpk:disabled:opacity-50 cpk:dark:text-white cpk:dark:hover:bg-[#404040] cpk:dark:hover:text-[#FFFFFF]",onClick:X},[e.createVNode(e.unref(se.Check),{class:"cpk:size-[18px]"})],8,ja)]):e.createCommentVNode("",!0)],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[K.value?e.renderSlot(T.$slots,"start-transcribe-button",{key:0,disabled:t.disabled,onClick:()=>a("start-transcribe"),labels:w.value},()=>[e.createElementVNode("button",{type:"button","data-testid":"copilot-chat-input-start-transcribe","aria-label":w.value.chatInputToolbarStartTranscribeButtonLabel,disabled:t.disabled,class:"cpk:mr-2 cpk:inline-flex cpk:h-9 cpk:w-9 cpk:shrink-0 cpk:items-center cpk:justify-center cpk:rounded-full cpk:bg-transparent cpk:text-[#444444] cpk:transition-colors cpk:hover:bg-[#f8f8f8] cpk:hover:text-[#333333] cpk:disabled:cursor-not-allowed cpk:disabled:opacity-50 cpk:disabled:hover:bg-transparent cpk:disabled:hover:text-[#444444] cpk:dark:text-white cpk:dark:hover:bg-[#404040] cpk:dark:hover:text-[#FFFFFF] cpk:dark:disabled:hover:bg-transparent cpk:dark:disabled:hover:text-[#CCCCCC]",onClick:V[3]||(V[3]=J=>a("start-transcribe"))},[e.createVNode(e.unref(se.Mic),{class:"cpk:size-[18px]"})],8,_a)]):e.createCommentVNode("",!0),e.renderSlot(T.$slots,"send-button",{disabled:ve.value,isProcessing:W.value,onClick:je},()=>[e.createElementVNode("div",Ha,[e.createElementVNode("button",{type:"button","data-testid":"copilot-chat-input-send","aria-label":"Send message",disabled:ve.value,class:"cpk:inline-flex cpk:h-9 cpk:w-9 cpk:shrink-0 cpk:items-center cpk:justify-center cpk:rounded-full cpk:bg-black cpk:text-white cpk:transition-colors cpk:hover:opacity-70 cpk:disabled:cursor-not-allowed cpk:disabled:opacity-50 cpk:disabled:bg-[#00000014] cpk:disabled:text-[rgb(13,13,13)] cpk:disabled:hover:opacity-100 cpk:dark:bg-white cpk:dark:text-black cpk:dark:disabled:bg-[#454545] cpk:dark:disabled:text-white",onClick:je},[W.value&&H.value?(e.openBlock(),e.createBlock(e.unref(se.Square),{key:0,class:"cpk:size-[18px] cpk:fill-current"})):(e.openBlock(),e.createBlock(e.unref(se.ArrowUp),{key:1,class:"cpk:size-[18px]"}))],8,Wa)])])],64))],2)],10,Na)],8,Ba)])]),ae.value?e.renderSlot(T.$slots,"disclaimer",{key:0,labels:w.value},()=>[e.createElementVNode("p",qa,e.toDisplayString(w.value.chatDisclaimerText),1)]):e.createCommentVNode("",!0)],16))}}),Ka=["data-card-type"],Ga={key:0,class:"cpk:absolute cpk:inset-0 cpk:flex cpk:items-center cpk:justify-center cpk:bg-black/40 cpk:z-10","data-testid":"copilot-chat-attachment-uploading-overlay"},Ja=["onClick"],Qa=["src","alt"],Xa={key:1,class:"cpk:w-full cpk:h-full cpk:relative"},Ya=["src","alt"],Za=["src"],es=["onClick"],ts={key:2,class:"cpk:flex cpk:flex-col cpk:gap-1 cpk:w-full"},ns=["src"],os={key:0,class:"cpk:text-xs cpk:font-medium cpk:overflow-hidden cpk:text-ellipsis cpk:whitespace-nowrap"},as=["onClick"],ss={class:"cpk:w-8 cpk:h-8 cpk:rounded-md cpk:bg-primary cpk:text-primary-foreground cpk:flex cpk:items-center cpk:justify-center cpk:text-[10px] cpk:font-semibold cpk:shrink-0"},rs={class:"cpk:flex cpk:flex-col cpk:min-w-0"},is={class:"cpk:text-xs cpk:font-medium cpk:break-all cpk:leading-tight","data-testid":"copilot-chat-attachment-document-filename"},ls={key:0,class:"cpk:text-[11px] cpk:text-muted-foreground"},cs={key:2,class:"cpk:w-full cpk:h-full cpk:bg-muted-foreground/20","data-testid":"copilot-chat-attachment-placeholder"},us=["onClick"],ds=["src","alt"],ps=["src"],ms=["src","title"],fs={key:1,class:"cpk:w-[90vw] cpk:max-w-[800px] cpk:max-h-[90vh] cpk:overflow-auto cpk:rounded-lg cpk:bg-white cpk:dark:bg-gray-900 cpk:p-6"},gs={key:0,class:"cpk:text-sm cpk:whitespace-pre-wrap cpk:wrap-break-word cpk:text-gray-800 cpk:dark:text-gray-200 cpk:font-mono cpk:m-0","data-testid":"copilot-chat-attachment-lightbox-document-text"},hs=["src","title"],vs={key:2,class:"cpk:flex cpk:flex-col cpk:items-center cpk:gap-4 cpk:p-8 cpk:rounded-lg cpk:bg-white cpk:dark:bg-gray-900","data-testid":"copilot-chat-attachment-lightbox-document-fallback"},ks={class:"cpk:w-16 cpk:h-16 cpk:rounded-xl cpk:bg-primary cpk:text-primary-foreground cpk:flex cpk:items-center cpk:justify-center cpk:text-xl cpk:font-bold"},bs={class:"cpk:text-center"},ys={class:"cpk:text-base cpk:font-medium cpk:text-gray-800 cpk:dark:text-gray-200"},ws={class:"cpk:text-sm cpk:text-gray-500 cpk:dark:text-gray-400 cpk:mt-1"},St=e.defineComponent({__name:"CopilotChatAttachmentQueue",props:{attachments:{default:()=>[]},className:{default:""}},emits:["remove-attachment"],setup(t,{emit:o}){const n=t,a=o,r=e.ref(null),s=e.ref(null),i=e.computed(()=>r.value!==null),l=e.computed(()=>{const h=r.value;if(!h||h.type!=="document")return!1;const C=h.source.mimeType;return u(C)||k(C)}),c=e.computed(()=>{const h=r.value;if(!h||h.type!=="document")return null;const C=h.source.mimeType;if(!k(C)||h.source.type!=="data")return null;try{return atob(h.source.value)}catch{return h.source.value}}),d=e.computed(()=>{const h=r.value;return!h||h.type!=="document"?null:h.source.type==="url"?h.source.value:s.value});e.watch(r,(h,C)=>{if(s.value&&(URL.revokeObjectURL(s.value),s.value=null),!h||h.type!=="document"||h.source.type!=="data"||typeof window>"u")return;const f=h.source.mimeType;if(!u(f)&&!k(f))return;const g=b(h.source.value,f);s.value=g},{immediate:!0}),e.watch(i,(h,C,f)=>{if(!h||typeof document>"u")return;const g=m=>{m.key==="Escape"&&p()};document.addEventListener("keydown",g),f(()=>{document.removeEventListener("keydown",g)})}),e.onBeforeUnmount(()=>{s.value&&(URL.revokeObjectURL(s.value),s.value=null)});function x(h){if(typeof document<"u"){const C=document;if(typeof C.startViewTransition=="function"){C.startViewTransition(()=>{r.value=h});return}}r.value=h}function p(){r.value=null}function v(h){return h.type==="image"||h.type==="video"?"cpk:w-[72px] cpk:h-[72px]":h.type==="audio"?"cpk:min-w-[200px] cpk:max-w-[280px] cpk:flex-col cpk:p-1 cpk:pr-8":"cpk:p-2 cpk:px-3 cpk:pr-8 cpk:max-w-[240px]"}function u(h){return!!h&&h.includes("pdf")}function k(h){return!!h&&h.startsWith("text/")}function b(h,C){try{const f=atob(h),g=new Uint8Array(f.length);for(let y=0;y<f.length;y+=1)g[y]=f.charCodeAt(y);const m=new Blob([g],{type:C||"application/octet-stream"});return URL.createObjectURL(m)}catch(f){return console.error("[CopilotKit] Failed to decode attachment data:",f),null}}return(h,C)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[n.attachments.length>0?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["cpk:flex cpk:flex-wrap cpk:gap-2 cpk:p-2",n.className]),"data-testid":"copilot-chat-attachment-queue"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.attachments,f=>(e.openBlock(),e.createElementBlock("div",{key:f.id,class:e.normalizeClass(["cpk:relative cpk:inline-flex cpk:rounded-lg cpk:overflow-hidden cpk:border cpk:border-border",v(f)]),"data-testid":"copilot-chat-attachment-item","data-card-type":f.type},[f.status==="uploading"?(e.openBlock(),e.createElementBlock("div",Ga,[...C[1]||(C[1]=[e.createElementVNode("div",{class:"cpk:w-5 cpk:h-5 cpk:border-2 cpk:border-white cpk:border-t-transparent cpk:rounded-full cpk:animate-spin"},null,-1)])])):e.createCommentVNode("",!0),f.status==="ready"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[f.type==="image"?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"cpk:w-full cpk:h-full cpk:border-none cpk:bg-transparent cpk:p-0 cpk:cursor-pointer","data-testid":"copilot-chat-attachment-image-button",onClick:g=>x(f)},[e.createElementVNode("img",{src:e.unref(j.getSourceUrl)(f.source),alt:f.filename||"Image attachment",class:"cpk:w-full cpk:h-full cpk:object-cover","data-testid":"copilot-chat-attachment-image-thumbnail"},null,8,Qa)],8,Ja)):f.type==="video"?(e.openBlock(),e.createElementBlock("div",Xa,[f.thumbnail?(e.openBlock(),e.createElementBlock("img",{key:0,src:f.thumbnail,alt:f.filename||"Video thumbnail",class:"cpk:w-full cpk:h-full cpk:object-cover","data-testid":"copilot-chat-attachment-video-thumbnail"},null,8,Ya)):(e.openBlock(),e.createElementBlock("video",{key:1,src:e.unref(j.getSourceUrl)(f.source),preload:"metadata",muted:"",class:"cpk:w-full cpk:h-full cpk:object-cover","data-testid":"copilot-chat-attachment-video-fallback"},null,8,Za)),e.createElementVNode("button",{type:"button",class:"cpk:absolute cpk:inset-0 cpk:flex cpk:items-center cpk:justify-center cpk:z-10 cpk:cursor-pointer cpk:bg-black/20 cpk:border-none cpk:p-0","aria-label":"Play video","data-testid":"copilot-chat-attachment-video-play",onClick:g=>x(f)},[...C[2]||(C[2]=[e.createElementVNode("div",{class:"cpk:w-8 cpk:h-8 cpk:rounded-full cpk:bg-black/60 cpk:flex cpk:items-center cpk:justify-center cpk:text-white cpk:text-xs cpk:font-semibold"}," ▶ ",-1)])],8,es)])):f.type==="audio"?(e.openBlock(),e.createElementBlock("div",ts,[e.createElementVNode("audio",{src:e.unref(j.getSourceUrl)(f.source),controls:"",preload:"metadata",class:"cpk:w-full cpk:h-8","data-testid":"copilot-chat-attachment-audio-player"},null,8,ns),f.filename?(e.openBlock(),e.createElementBlock("span",os,e.toDisplayString(f.filename),1)):e.createCommentVNode("",!0)])):(e.openBlock(),e.createElementBlock("button",{key:3,type:"button",class:e.normalizeClass(["cpk:flex cpk:items-center cpk:gap-2 cpk:w-full cpk:border-none cpk:bg-transparent cpk:p-0 cpk:text-left",u(f.source.mimeType)||k(f.source.mimeType)?"cpk:cursor-pointer":"cpk:cursor-default"]),"data-testid":"copilot-chat-attachment-document-button",onClick:g=>(u(f.source.mimeType)||k(f.source.mimeType))&&x(f)},[e.createElementVNode("div",ss,e.toDisplayString(e.unref(j.getDocumentIcon)(f.source.mimeType??"")),1),e.createElementVNode("div",rs,[e.createElementVNode("span",is,e.toDisplayString(f.filename||"Document"),1),f.size!=null?(e.openBlock(),e.createElementBlock("span",ls,e.toDisplayString(e.unref(j.formatFileSize)(f.size)),1)):e.createCommentVNode("",!0)])],10,as))],64)):(e.openBlock(),e.createElementBlock("div",cs)),e.createElementVNode("button",{type:"button",class:"cpk:absolute cpk:bg-black/60 cpk:text-white cpk:border-none cpk:rounded-full cpk:w-5 cpk:h-5 cpk:flex cpk:items-center cpk:justify-center cpk:cursor-pointer cpk:text-[10px] cpk:z-20 cpk:top-1 cpk:right-1","aria-label":"Remove attachment",onClick:g=>a("remove-attachment",f.id)}," ✕ ",8,us)],10,Ka))),128))],2)):e.createCommentVNode("",!0),(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[r.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"cpk:fixed cpk:inset-0 cpk:z-[9999] cpk:flex cpk:items-center cpk:justify-center cpk:bg-black/80","data-testid":"copilot-chat-attachment-lightbox",onClick:p},[e.createElementVNode("button",{type:"button",class:"cpk:absolute cpk:top-4 cpk:right-4 cpk:text-white cpk:bg-white/10 cpk:hover:bg-white/20 cpk:rounded-full cpk:w-10 cpk:h-10 cpk:flex cpk:items-center cpk:justify-center cpk:cursor-pointer cpk:border-none","aria-label":"Close preview",onClick:e.withModifiers(p,["stop"])}," ✕ "),e.createElementVNode("div",{"data-testid":"copilot-chat-attachment-lightbox-content",onClick:C[0]||(C[0]=e.withModifiers(()=>{},["stop"]))},[r.value.type==="image"?(e.openBlock(),e.createElementBlock("img",{key:0,src:e.unref(j.getSourceUrl)(r.value.source),alt:r.value.filename||"Image attachment",class:"cpk:max-w-[90vw] cpk:max-h-[90vh] cpk:object-contain cpk:rounded-lg","data-testid":"copilot-chat-attachment-lightbox-image"},null,8,ds)):r.value.type==="video"?(e.openBlock(),e.createElementBlock("video",{key:1,src:e.unref(j.getSourceUrl)(r.value.source),controls:"",autoplay:"",class:"cpk:max-w-[90vw] cpk:max-h-[90vh] cpk:rounded-lg","data-testid":"copilot-chat-attachment-lightbox-video"},null,8,ps)):r.value.type==="document"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[l.value&&u(r.value.source.mimeType)&&d.value?(e.openBlock(),e.createElementBlock("iframe",{key:0,src:d.value,title:r.value.filename||"PDF preview",class:"cpk:w-[90vw] cpk:h-[90vh] cpk:max-w-[1000px] cpk:rounded-lg cpk:bg-white","data-testid":"copilot-chat-attachment-lightbox-document-iframe"},null,8,ms)):l.value&&k(r.value.source.mimeType)?(e.openBlock(),e.createElementBlock("div",fs,[c.value!==null?(e.openBlock(),e.createElementBlock("pre",gs,e.toDisplayString(c.value),1)):d.value?(e.openBlock(),e.createElementBlock("iframe",{key:1,src:d.value,title:r.value.filename||"Text preview",class:"cpk:w-full cpk:h-[80vh] cpk:border-none","data-testid":"copilot-chat-attachment-lightbox-document-iframe"},null,8,hs)):e.createCommentVNode("",!0)])):(e.openBlock(),e.createElementBlock("div",vs,[e.createElementVNode("div",ks,e.toDisplayString(e.unref(j.getDocumentIcon)(r.value.source.mimeType??"")),1),e.createElementVNode("div",bs,[e.createElementVNode("div",ys,e.toDisplayString(r.value.filename||"Document"),1),e.createElementVNode("div",ws,e.toDisplayString(r.value.source.mimeType||"Unknown type")+" "+e.toDisplayString(r.value.size!=null?` · ${e.unref(j.formatFileSize)(r.value.size)}`:""),1)]),C[3]||(C[3]=e.createElementVNode("div",{class:"cpk:text-xs cpk:text-gray-400 cpk:dark:text-gray-500"}," No preview available for this file type ",-1))]))],64)):e.createCommentVNode("",!0)])])):e.createCommentVNode("",!0)]))],64))}}),Cs=["data-message-id"],xs=["aria-expanded"],Ss={class:"cpk:font-medium"},Ts={key:0,class:"cpk:inline-flex cpk:items-center cpk:ml-1"},Is={class:"cpk:overflow-hidden"},As={key:0,class:"cpk:pb-2 cpk:pt-1"},Rs={class:"cpk:text-sm cpk:text-muted-foreground"},Es={key:0,class:"cpk:inline-flex cpk:items-center cpk:ml-1 cpk:align-middle"},Pn=e.defineComponent({__name:"CopilotChatReasoningMessage",props:{message:{},messages:{default:()=>[]},isRunning:{type:Boolean,default:!1}},setup(t){const o=t;function n(h){if(h<1)return"a few seconds";if(h<60)return`${Math.round(h)} seconds`;const C=Math.floor(h/60),f=Math.round(h%60);return f===0?`${C} minute${C>1?"s":""}`:`${C}m ${f}s`}const a=e.computed(()=>typeof o.message.content=="string"?o.message.content:""),r=e.computed(()=>a.value.length>0),s=e.computed(()=>o.messages[o.messages.length-1]?.id===o.message.id),i=e.computed(()=>!!(o.isRunning&&s.value)),l=e.ref(0),c=e.ref(i.value),d=e.ref(!1);let x=null,p=null;function v(){p&&(clearInterval(p),p=null)}function u(){x!==null&&(l.value=(Date.now()-x)/1e3)}e.watch(i,h=>{if(h){x===null&&(x=Date.now()),v(),p=setInterval(u,1e3),d.value=!1,c.value=!0;return}v(),u(),d.value||(c.value=!1)},{immediate:!0}),e.onBeforeUnmount(()=>{v()});const k=e.computed(()=>i.value?"Thinking…":`Thought for ${n(l.value)}`);function b(){r.value&&(d.value=!0,c.value=!c.value)}return(h,C)=>(e.openBlock(),e.createElementBlock("div",{"data-copilotkit":"",class:"cpk:my-1","data-message-id":t.message.id},[e.renderSlot(h.$slots,"layout",{message:t.message,messages:t.messages,isRunning:t.isRunning,header:{isOpen:c.value,label:k.value,hasContent:r.value,isStreaming:i.value,onClick:r.value?b:void 0},contentView:{isStreaming:i.value,hasContent:r.value,content:a.value},toggle:{isOpen:c.value,contentView:{isStreaming:i.value,hasContent:r.value,content:a.value}}},()=>[e.renderSlot(h.$slots,"header",{isOpen:c.value,label:k.value,hasContent:r.value,isStreaming:i.value,onClick:r.value?b:void 0},()=>[e.createElementVNode("button",{type:"button",class:e.normalizeClass(["cpk:inline-flex cpk:items-center cpk:gap-1 cpk:py-1 cpk:text-sm cpk:text-muted-foreground cpk:transition-colors cpk:select-none",r.value?"cpk:hover:text-foreground cpk:cursor-pointer":"cpk:cursor-default"]),"aria-expanded":r.value?c.value:void 0,onClick:C[0]||(C[0]=f=>r.value?b():void 0)},[e.createElementVNode("span",Ss,e.toDisplayString(k.value),1),i.value&&!r.value?(e.openBlock(),e.createElementBlock("span",Ts,[...C[1]||(C[1]=[e.createElementVNode("span",{class:"cpk:w-1.5 cpk:h-1.5 cpk:rounded-full cpk:bg-muted-foreground cpk:animate-pulse"},null,-1)])])):e.createCommentVNode("",!0),r.value?(e.openBlock(),e.createBlock(e.unref(se.ChevronRight),{key:1,class:e.normalizeClass(["cpk:size-3.5 cpk:shrink-0 cpk:transition-transform cpk:duration-200",{"cpk:rotate-90":c.value}])},null,8,["class"])):e.createCommentVNode("",!0)],10,xs)]),e.renderSlot(h.$slots,"toggle",{isOpen:c.value,contentView:{isStreaming:i.value,hasContent:r.value,content:a.value}},()=>[e.createElementVNode("div",{class:"cpk:grid cpk:transition-[grid-template-rows] cpk:duration-200 cpk:ease-in-out",style:e.normalizeStyle({gridTemplateRows:c.value?"1fr":"0fr"})},[e.createElementVNode("div",Is,[e.renderSlot(h.$slots,"content-view",{isStreaming:i.value,hasContent:r.value,content:a.value},()=>[r.value||i.value?(e.openBlock(),e.createElementBlock("div",As,[e.createElementVNode("div",Rs,[e.createVNode(e.unref(an.StreamMarkdown),{content:a.value},null,8,["content"]),i.value&&r.value?(e.openBlock(),e.createElementBlock("span",Es,[...C[2]||(C[2]=[e.createElementVNode("span",{class:"cpk:w-2 cpk:h-2 cpk:rounded-full cpk:bg-muted-foreground cpk:animate-pulse-cursor"},null,-1)])])):e.createCommentVNode("",!0)])])):e.createCommentVNode("",!0)])])],4)])])],8,Cs))}}),Ms=["data-message-id"],$s=["data-multiline"],Bs={class:"cpk:w-full cpk:bg-transparent cpk:flex cpk:items-center cpk:justify-end cpk:-mr-[5px] cpk:mt-[4px] cpk:invisible cpk:group-hover:visible"},Ns={class:"cpk:flex cpk:items-center cpk:gap-1 cpk:justify-end"},Vs=["aria-label","title"],Fs=["aria-label","title"],Ds={class:"cpk:flex cpk:items-center cpk:gap-1"},Os=["disabled"],Ls={class:"cpk:text-sm cpk:text-muted-foreground cpk:px-0 cpk:font-medium"},Ps=["disabled"],Un=e.defineComponent({__name:"CopilotChatUserMessage",props:{message:{},branchIndex:{default:0},numberOfBranches:{default:1}},emits:["edit-message","switch-to-branch"],setup(t,{emit:o}){const n=t,a=o,r=be(),s=e.computed(()=>r.value?.labels??Be),i=e.getCurrentInstance(),l=e.ref(!1);let c=null;const d=e.computed(()=>i?.vnode.props??{}),x=["cpk:inline-flex cpk:h-8 cpk:w-8 cpk:items-center cpk:justify-center cpk:rounded-md cpk:p-0","cpk:cursor-pointer cpk:text-[rgb(93,93,93)] cpk:transition-colors cpk:hover:bg-[#E8E8E8]","cpk:hover:text-[rgb(93,93,93)] cpk:dark:text-[rgb(243,243,243)] cpk:dark:hover:bg-[#303030]","cpk:dark:hover:text-[rgb(243,243,243)] cpk:disabled:pointer-events-none cpk:disabled:opacity-50"].join(" ");function p(I){return I?typeof I=="string"?I:I.map(A=>A&&typeof A=="object"&&"type"in A&&A.type==="text"&&typeof A.text=="string"?A.text:"").filter(A=>A.length>0).join(`
|
|
74
|
-
`):""}const v=e.computed(()=>p(n.message.content)),u=e.computed(()=>v.value.includes(`
|
|
75
|
-
`));function k(I){const A=d.value[I];return Array.isArray(A)?A.length>0:!!A}const b=e.computed(()=>k("onEditMessage")),h=e.computed(()=>n.numberOfBranches>1&&k("onSwitchToBranch")),C=e.computed(()=>n.branchIndex>0),f=e.computed(()=>n.branchIndex<n.numberOfBranches-1);function g(){c&&clearTimeout(c),l.value=!0,c=setTimeout(()=>{l.value=!1,c=null},2e3)}async function m(){if(v.value&&!(typeof navigator>"u"||typeof navigator.clipboard?.writeText!="function"))try{await navigator.clipboard.writeText(v.value),g()}catch(I){console.error("Failed to copy to clipboard:",I)}}function y(){if(!b.value)return;const I={message:n.message};a("edit-message",I)}function S(I){if(!h.value)return;const A={branchIndex:I,numberOfBranches:n.numberOfBranches,message:n.message};a("switch-to-branch",A)}function M(){C.value&&S(n.branchIndex-1)}function E(){f.value&&S(n.branchIndex+1)}return e.onBeforeUnmount(()=>{c&&clearTimeout(c)}),(I,A)=>e.renderSlot(I.$slots,"layout",{message:t.message,content:v.value,isMultiline:u.value,showBranchNavigation:h.value,hasEditAction:b.value,branchIndex:t.branchIndex,numberOfBranches:t.numberOfBranches,canGoPrev:C.value,canGoNext:f.value,onCopy:m,onEdit:y,goPrev:M,goNext:E,copied:l.value},()=>[e.createElementVNode("div",e.mergeProps({"data-copilotkit":"","data-testid":"copilot-user-message",class:"cpk:flex cpk:flex-col cpk:items-end cpk:group cpk:pt-10","data-message-id":t.message.id},I.$attrs),[e.renderSlot(I.$slots,"message-renderer",{message:t.message,content:v.value,isMultiline:u.value},()=>[e.createElementVNode("div",{class:e.normalizeClass(["cpk:prose cpk:dark:prose-invert cpk:bg-muted cpk:relative cpk:max-w-[80%] cpk:rounded-[18px] cpk:px-4 cpk:py-1.5 cpk:inline-block cpk:whitespace-pre-wrap",{"cpk:py-3":u.value}]),"data-multiline":u.value?"true":void 0},e.toDisplayString(v.value),11,$s)]),e.renderSlot(I.$slots,"toolbar",{message:t.message,showBranchNavigation:h.value,hasEditAction:b.value},()=>[e.createElementVNode("div",Bs,[e.createElementVNode("div",Ns,[e.renderSlot(I.$slots,"toolbar-items"),e.renderSlot(I.$slots,"copy-button",{onCopy:m,copied:l.value,label:s.value.userMessageToolbarCopyMessageLabel},()=>[e.createElementVNode("button",{"data-testid":"copilot-user-copy-button",type:"button",class:e.normalizeClass(e.unref(x)),"aria-label":s.value.userMessageToolbarCopyMessageLabel,title:s.value.userMessageToolbarCopyMessageLabel,onClick:m},[l.value?(e.openBlock(),e.createBlock(e.unref(se.Check),{key:0,class:"cpk:size-[18px]"})):(e.openBlock(),e.createBlock(e.unref(se.Copy),{key:1,class:"cpk:size-[18px]"}))],10,Vs)]),b.value?e.renderSlot(I.$slots,"edit-button",{key:0,onEdit:y,label:s.value.userMessageToolbarEditMessageLabel},()=>[e.createElementVNode("button",{type:"button",class:e.normalizeClass(e.unref(x)),"aria-label":s.value.userMessageToolbarEditMessageLabel,title:s.value.userMessageToolbarEditMessageLabel,onClick:y},[e.createVNode(e.unref(se.Edit),{class:"cpk:size-[18px]"})],10,Fs)]):e.createCommentVNode("",!0),h.value?e.renderSlot(I.$slots,"branch-navigation",{key:1,branchIndex:t.branchIndex,numberOfBranches:t.numberOfBranches,canGoPrev:C.value,canGoNext:f.value,goPrev:M,goNext:E},()=>[e.createElementVNode("div",Ds,[e.createElementVNode("button",{type:"button",class:e.normalizeClass([e.unref(x),"cpk:h-6 cpk:w-6 cpk:p-0"]),disabled:!C.value,"aria-label":"Previous branch",title:"Previous branch",onClick:M},[e.createVNode(e.unref(se.ChevronLeft),{class:"cpk:size-[20px]"})],10,Os),e.createElementVNode("span",Ls,e.toDisplayString(t.branchIndex+1)+"/"+e.toDisplayString(t.numberOfBranches),1),e.createElementVNode("button",{type:"button",class:e.normalizeClass([e.unref(x),"cpk:h-6 cpk:w-6 cpk:p-0"]),disabled:!f.value,"aria-label":"Next branch",title:"Next branch",onClick:E},[e.createVNode(e.unref(se.ChevronRight),{class:"cpk:size-[20px]"})],10,Ps)])]):e.createCommentVNode("",!0)])])])],16,Ms)])}}),zn=e.defineComponent({__name:"CopilotChatMessageView",props:{messages:{default:()=>[]},isRunning:{type:Boolean,default:!1}},setup(t){const o=t,{copilotkit:n}=xe(),a=be(),r=e.ref(0),s=e.ref(null),i=e.useSlots(),l=e.computed(()=>Object.keys(i)),c=e.computed(()=>a.value?.agentId??j.DEFAULT_AGENT_ID),d=e.computed(()=>(n.value.agents,n.value.getAgent(c.value)));e.watch([c,()=>a.value?.threadId,()=>n.value,()=>n.value.runtimeConnectionStatus],(f,g,m)=>{const y=d.value;if(!y)return;const S=y.subscribe({onStateChanged:()=>{r.value+=1},onRunStartedEvent:()=>{r.value+=1},onRunFinishedEvent:()=>{r.value+=1},onRunErrorEvent:()=>{r.value+=1}});m(()=>S.unsubscribe())},{immediate:!0}),e.watch(()=>n.value,(f,g,m)=>{s.value=f.interruptState;const y=f.subscribe({onInterruptStateChanged:({interruptState:S})=>{s.value=S},onRuntimeConnectionStatusChanged:()=>{r.value+=1}});m(()=>y.unsubscribe())},{immediate:!0});function x(f){const g=new Map;for(const m of f){const y=g.get(m.id);if(y&&m.role==="assistant"&&y.role==="assistant"){const S=m.content||y.content,M=m.toolCalls??y.toolCalls;g.set(m.id,{...y,...m,content:S,toolCalls:M})}else g.set(m.id,m)}return[...g.values()]}const p=e.computed(()=>x(o.messages)),v=e.computed(()=>o.messages[o.messages.length-1]),u=e.computed(()=>o.isRunning&&v.value?.role!=="reasoning");e.watch([()=>o.messages.length,()=>p.value.length],([f,g])=>{process.env.NODE_ENV==="development"&&g<f&&console.warn(`CopilotChatMessageView: Deduplicated ${f-g} message(s) with duplicate IDs.`)},{immediate:!0});function k(f){r.value+=0;const g=c.value,m=a.value?.threadId??"",y=n.value,S=y.getRunIdForMessage(g,m,f.id)??y.getRunIdsForThread(g,m).slice(-1)[0],M=S??`missing-run-id:${f.id}`,E=d.value??y.getAgent(g),I=S&&E?E.messages.filter(U=>y.getRunIdForMessage(g,m,U.id)===S).map(U=>U.id):[f.id],A=E?E.messages.findIndex(U=>U.id===f.id):-1,N=A>=0?A:0,_=S?Math.max(I.indexOf(f.id),0):0,z=S?I.length:1,$=S?y.getStateByRun(g,m,S):void 0;return{runId:M,messageIndex:N,messageIndexInRun:_,numberOfMessagesInRun:z,agentId:g,stateSnapshot:$}}function b(f){return`activity-${f}`}function h(f,g){if(r.value+=0,i[g==="before"?"message-before":"message-after"])return null;const y=c.value,M=[...n.value.renderCustomMessages].filter(E=>E.agentId===void 0||E.agentId===y).sort((E,I)=>{const A=E.agentId!==void 0,N=I.agentId!==void 0;return A===N?0:A?-1:1})[0];return M?.render?{renderer:M.render,props:{...k(f),message:f,position:g}}:null}function C(f){r.value+=0;const g=c.value,m=[...n.value.renderActivityMessages].filter(S=>S.activityType===f.activityType&&(S.agentId===void 0||S.agentId===g)).sort((S,M)=>{const E=S.agentId!==void 0,I=M.agentId!==void 0;return E===I?0:E?-1:1})[0];if(!m)return null;const y=m.content.safeParse(f.content);return y.success?{renderer:m.render,props:{activityType:f.activityType,content:y.data,message:f,agent:d.value}}:null}return(f,g)=>(e.openBlock(),e.createElementBlock("div",e.mergeProps({"data-copilotkit":"",class:"cpk:flex cpk:flex-col"},f.$attrs),[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.value,m=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:m.id},[e.unref(i)["message-before"]?e.renderSlot(f.$slots,"message-before",{key:0,message:m,position:"before",runId:k(m).runId,messageIndex:k(m).messageIndex,messageIndexInRun:k(m).messageIndexInRun,numberOfMessagesInRun:k(m).numberOfMessagesInRun,agentId:k(m).agentId,stateSnapshot:k(m).stateSnapshot}):h(m,"before")?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(h(m,"before").renderer),e.mergeProps({key:1,ref_for:!0},h(m,"before").props),null,16)):e.createCommentVNode("",!0),m.role==="assistant"?e.renderSlot(f.$slots,"assistant-message",{key:2,message:m,messages:t.messages,isRunning:t.isRunning},()=>[e.createVNode(Bn,{message:m,messages:t.messages,"is-running":t.isRunning},e.createSlots({_:2},[e.renderList(l.value,y=>({name:y,fn:e.withCtx(S=>[e.renderSlot(f.$slots,y,e.mergeProps({ref_for:!0},S))])}))]),1032,["message","messages","is-running"])]):m.role==="user"?e.renderSlot(f.$slots,"user-message",{key:3,message:m},()=>[e.createVNode(Un,{message:m},e.createSlots({_:2},[e.renderList(l.value,y=>({name:y,fn:e.withCtx(S=>[e.renderSlot(f.$slots,y,e.mergeProps({ref_for:!0},S))])}))]),1032,["message"])]):m.role==="reasoning"?e.renderSlot(f.$slots,"reasoning-message",{key:4,message:m,messages:t.messages,isRunning:t.isRunning},()=>[e.createVNode(Pn,{message:m,messages:t.messages,"is-running":t.isRunning},null,8,["message","messages","is-running"])]):m.role==="activity"?e.renderSlot(f.$slots,b(m.activityType),{key:5,activityType:m.activityType,content:m.content,message:m,agent:d.value},()=>[e.renderSlot(f.$slots,"activity-message",{activityType:m.activityType,content:m.content,message:m,agent:d.value},()=>[C(m)?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(C(m).renderer),e.mergeProps({key:0,ref_for:!0},C(m).props),null,16)):e.createCommentVNode("",!0)])]):e.createCommentVNode("",!0),e.unref(i)["message-after"]?e.renderSlot(f.$slots,"message-after",{key:6,message:m,position:"after",runId:k(m).runId,messageIndex:k(m).messageIndex,messageIndexInRun:k(m).messageIndexInRun,numberOfMessagesInRun:k(m).numberOfMessagesInRun,agentId:k(m).agentId,stateSnapshot:k(m).stateSnapshot}):h(m,"after")?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(h(m,"after").renderer),e.mergeProps({key:7,ref_for:!0},h(m,"after").props),null,16)):e.createCommentVNode("",!0)],64))),128)),s.value?e.renderSlot(f.$slots,"interrupt",{key:0,event:s.value.event,interrupt:s.value.interrupt,interrupts:s.value.interrupts,result:s.value.result,resolve:s.value.resolve,cancel:s.value.cancel}):e.createCommentVNode("",!0),u.value?e.renderSlot(f.$slots,"cursor",{key:1},()=>[g[0]||(g[0]=e.createElementVNode("div",{class:"cpk:w-[11px] cpk:h-[11px] cpk:rounded-full cpk:bg-foreground cpk:animate-pulse cpk:ml-1","data-testid":"copilot-loading-cursor"},null,-1))]):e.createCommentVNode("",!0)],16))}}),Us=["type","aria-busy","disabled"],zs={key:0,class:"cpk:flex cpk:h-3.5 cpk:w-3.5 cpk:items-center cpk:justify-center cpk:text-muted-foreground cpk:sm:h-4 cpk:sm:w-4"},js={key:1,class:"cpk:flex cpk:h-3.5 cpk:w-3.5 cpk:items-center cpk:justify-center cpk:text-muted-foreground cpk:sm:h-4 cpk:sm:w-4"},_s={class:"cpk:whitespace-nowrap cpk:font-medium cpk:leading-none"},jn=e.defineComponent({__name:"CopilotChatSuggestionPill",props:{icon:{default:void 0},isLoading:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},type:{default:"button"}},setup(t){const o=t,n=e.computed(()=>o.isLoading||o.disabled);return(a,r)=>(e.openBlock(),e.createElementBlock("button",e.mergeProps({"data-copilotkit":"","data-slot":"suggestion-pill","data-testid":"copilot-chat-suggestion-pill",type:t.type,"aria-busy":t.isLoading?"true":void 0,disabled:n.value,class:"cpk:group cpk:inline-flex cpk:h-7 cpk:w-fit cpk:items-center cpk:gap-1 cpk:rounded-full cpk:border cpk:border-border/60 cpk:bg-background cpk:px-2.5 cpk:text-[11px] cpk:leading-none cpk:text-foreground cpk:transition-colors cpk:cursor-pointer cpk:hover:bg-accent/60 cpk:hover:text-foreground cpk:focus-visible:outline-none cpk:focus-visible:ring-2 cpk:focus-visible:ring-ring cpk:focus-visible:ring-offset-2 cpk:focus-visible:ring-offset-background cpk:disabled:cursor-not-allowed cpk:disabled:text-muted-foreground cpk:disabled:hover:bg-background cpk:disabled:hover:text-muted-foreground cpk:pointer-events-auto cpk:sm:h-8 cpk:sm:gap-1.5 cpk:sm:px-3 cpk:sm:text-xs"},a.$attrs),[t.isLoading?(e.openBlock(),e.createElementBlock("span",zs,[e.createVNode(e.unref(se.Loader2),{class:"cpk:h-3.5 cpk:w-3.5 cpk:animate-spin cpk:sm:h-4 cpk:sm:w-4","aria-hidden":"true"})])):a.$slots.icon||t.icon?(e.openBlock(),e.createElementBlock("span",js,[e.renderSlot(a.$slots,"icon",{},()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(t.icon)))])])):e.createCommentVNode("",!0),e.createElementVNode("span",_s,[e.renderSlot(a.$slots,"default")])],16,Us))}}),tt=e.defineComponent({inheritAttrs:!1,__name:"CopilotChatSuggestionView",props:{suggestions:{},loadingIndexes:{default:()=>[]}},emits:["select-suggestion"],setup(t,{emit:o}){const n=t,a=o,r=e.useAttrs(),s=e.computed(()=>new Set(n.loadingIndexes)),i=e.computed(()=>["cpk:flex cpk:flex-wrap cpk:items-center cpk:gap-1.5 cpk:pl-0 cpk:pr-4 cpk:pointer-events-none cpk:sm:gap-2 cpk:@3xl:px-0",r.class]),l=e.computed(()=>{const{class:p,...v}=r;return v});function c(p,v){return s.value.has(p)||v.isLoading===!0}function d(p,v){a("select-suggestion",p,v)}const x=e.computed(()=>({suggestions:n.suggestions,loadingIndexes:n.loadingIndexes,onSelectSuggestion:d,containerClass:i.value,containerAttrs:l.value}));return(p,v)=>e.renderSlot(p.$slots,"layout",e.normalizeProps(e.guardReactiveProps(x.value)),()=>[e.renderSlot(p.$slots,"container",e.normalizeProps(e.guardReactiveProps(x.value)),()=>[e.createElementVNode("div",e.mergeProps({"data-copilotkit":"","data-testid":"copilot-chat-suggestion-view",class:i.value},l.value),[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.suggestions,(u,k)=>e.renderSlot(p.$slots,"suggestion",{key:`${u.title}-${k}`,suggestion:u,index:k,isLoading:c(k,u),onSelect:()=>d(u,k)},()=>[e.createVNode(jn,{"is-loading":c(k,u),type:"button",onClick:b=>d(u,k)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(u.title),1)]),_:2},1032,["is-loading","onClick"])])),128))],16)])])}}),Hs=["pin-to-bottom","pin-to-send","none"];function Ws(t){return t===void 0||t===!0?"pin-to-bottom":t===!1?"none":Hs.includes(t)?t:"pin-to-bottom"}const qs={key:0,class:"cpk:absolute cpk:inset-0 cpk:z-50 cpk:pointer-events-none cpk:flex cpk:items-center cpk:justify-center cpk:bg-primary/5 cpk:border-2 cpk:border-dashed cpk:border-primary/40 cpk:rounded-lg cpk:m-2","data-testid":"copilot-chat-drop-overlay"},Ks={class:"cpk:flex cpk:h-full cpk:flex-col cpk:items-center cpk:justify-center cpk:px-4","data-testid":"copilot-chat-view-welcome-screen"},Gs={class:"cpk:w-full cpk:max-w-3xl cpk:flex cpk:flex-col cpk:items-center"},Js={class:"cpk:mb-6"},Qs={class:"cpk:text-xl cpk:sm:text-2xl cpk:font-medium cpk:text-foreground cpk:text-center"},Xs={class:"cpk:w-full"},Ys={key:0,class:"cpk:mt-4 cpk:flex cpk:justify-center"},Zs={class:"cpk:px-4 cpk:@3xl:px-0 cpk:[div[data-sidebar-chat]_&]:px-8 cpk:[div[data-popup-chat]_&]:px-6"},er={class:"cpk:max-w-3xl cpk:mx-auto"},tr={key:0,class:"cpk:mt-4 cpk:pl-0 cpk:pr-4 cpk:@3xl:px-0"},nr={key:0,class:"cpk:max-w-3xl cpk:mx-auto cpk:w-full cpk:pointer-events-auto"},or=16,ar=12,at=e.defineComponent({__name:"CopilotChatView",props:{messages:{default:()=>[]},autoScroll:{type:[String,Boolean],default:!0},isRunning:{type:Boolean,default:!1},suggestions:{default:()=>[]},suggestionLoadingIndexes:{default:()=>[]},welcomeScreen:{type:Boolean,default:!0},attachments:{},dragOver:{type:Boolean},inputValue:{default:void 0},inputMode:{default:"input"},inputToolsMenu:{default:()=>[]},isConnecting:{type:Boolean,default:!1},hasExplicitThreadId:{type:Boolean,default:!1},onRemoveAttachment:{},onAddFile:{},onDragOver:{},onDragLeave:{},onDrop:{},onFinishTranscribeWithAudio:{type:Function,default:void 0}},emits:["submit-message","stop","input-change","select-suggestion","add-file","start-transcribe","cancel-transcribe","finish-transcribe"],setup(t,{emit:o}){const n=t,a=o,r=be(),s=e.computed(()=>r.value?.labels??Be),i=e.getCurrentInstance(),l=e.useSlots(),c=e.ref(null),d=e.ref(null),x=e.ref(null),p=e.ref(null),v=e.ref(0),u=e.ref(!0),k=e.computed(()=>n.inputValue!==void 0),b=e.ref(n.inputValue??""),h=e.computed(()=>Ws(n.autoScroll)),C=e.computed(()=>h.value==="pin-to-bottom"),f=e.computed(()=>h.value==="pin-to-send");Ma({scrollRef:c,contentRef:d,spacerRef:x,topOffset:16});const{isKeyboardOpen:g,keyboardHeight:m}=On(),y=e.computed(()=>g.value?m.value:0),S=e.computed(()=>k.value?n.inputValue??"":b.value),M=e.computed(()=>!n.isConnecting&&!n.isRunning&&Array.isArray(n.suggestions)&&n.suggestions.length>0),E=e.computed(()=>Array.isArray(n.attachments)&&n.attachments.length>0),I=e.computed(()=>i?.vnode.props??{}),A=e.computed(()=>Object.keys(l).filter(L=>L!=="message-view"&&L!=="scroll-view"&&L!=="feather"&&L!=="scroll-to-bottom-button"&&L!=="input"&&L!=="suggestion-view"&&L!=="welcome-screen"&&L!=="welcome-message")),N=e.computed(()=>n.messages.length===0&&n.welcomeScreen!==!1&&!n.isConnecting&&!n.hasExplicitThreadId),_=e.computed(()=>pe("onAddFile")),z=e.computed(()=>pe("onStop")),$=e.computed(()=>pe("onStartTranscribe")),U=e.computed(()=>pe("onCancelTranscribe")),G=e.computed(()=>pe("onFinishTranscribe")),B=e.computed(()=>typeof n.onFinishTranscribeWithAudio=="function"),w=e.computed(()=>`${v.value+(M.value?4:32)}px`),R=e.computed(()=>!N.value&&!u.value);let F=null,W=null;function ae(){if(typeof ResizeObserver>"u")return;F?.disconnect(),F=null;const L=p.value;L&&(F=new ResizeObserver(Q=>{const Te=u.value,Ne=Q[0]?.contentRect?.height;typeof Ne=="number"?v.value=Ne:q(),H(),C.value&&Te&&K("auto")}),F.observe(L))}function D(){if(typeof ResizeObserver>"u")return;W?.disconnect(),W=null;const L=d.value;L&&(W=new ResizeObserver(()=>{const Q=u.value;H(),C.value&&Q&&K("auto")}),W.observe(L))}e.watch(N,async L=>{L||(await e.nextTick(),q(),ae(),D())}),e.watch(()=>n.inputValue,L=>{k.value&&(b.value=L??"")}),e.watch([()=>n.messages,()=>n.suggestions,()=>n.isRunning],async()=>{const L=u.value;await e.nextTick(),!(!C.value||!L)&&(K("auto"),typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{K("auto")}))},{deep:!0});function H(){const L=c.value;if(!L){u.value=!0;return}const Q=L.scrollHeight-L.scrollTop-L.clientHeight;u.value=Q<=ar}function q(){const L=p.value;v.value=L?.offsetHeight??0}function K(L="smooth"){const Q=c.value;Q&&(typeof Q.scrollTo=="function"?Q.scrollTo({top:Q.scrollHeight,behavior:L}):Q.scrollTop=Q.scrollHeight,H())}function re(){H()}function pe(L){const Q=I.value[L];return Array.isArray(Q)?Q.length>0:!!Q}function he(L){k.value||(b.value=L),a("input-change",L)}function ve(L){a("submit-message",L)}function Ae(){a("stop")}function O(L,Q){a("select-suggestion",L,Q)}function te(){a("add-file")}function ee(L){n.onDragOver?.(L)}function Se(L){n.onDragLeave?.(L)}function Re(L){n.onDrop?.(L)}function me(){a("start-transcribe")}function ie(){a("cancel-transcribe")}function ue(){a("finish-transcribe")}async function de(L){await n.onFinishTranscribeWithAudio?.(L)}const Me=e.computed(()=>{const L={"onUpdate:modelValue":he,onSubmitMessage:ve};return z.value&&(L.onStop=Ae),_.value&&(L.onAddFile=te),$.value&&(L.onStartTranscribe=me),U.value&&(L.onCancelTranscribe=ie),G.value&&(L.onFinishTranscribe=ue),B.value&&(L.onFinishTranscribeWithAudio=de),L});return e.onMounted(async()=>{await e.nextTick(),q(),H(),C.value&&(K("auto"),typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{K("auto")})),ae(),D()}),e.onBeforeUnmount(()=>{F?.disconnect(),W?.disconnect(),F=null,W=null}),(L,Q)=>(e.openBlock(),e.createElementBlock("div",e.mergeProps({"data-copilotkit":"",class:"cpk:@container cpk:relative cpk:h-full","data-testid":"copilot-chat-view"},L.$attrs,{onDragover:ee,onDragleave:Se,onDrop:Re}),[t.dragOver?(e.openBlock(),e.createElementBlock("div",qs,[...Q[3]||(Q[3]=[e.createElementVNode("span",{class:"cpk:text-sm cpk:font-medium cpk:text-primary/70"}," Drop files here ",-1)])])):e.createCommentVNode("",!0),N.value?e.renderSlot(L.$slots,"welcome-screen",{key:1,suggestions:t.suggestions,loadingIndexes:t.suggestionLoadingIndexes,attachments:t.attachments??[],modelValue:S.value,isRunning:t.isRunning,inputMode:t.inputMode,inputToolsMenu:t.inputToolsMenu,onUpdateModelValue:he,onSubmitMessage:ve,onStop:z.value?Ae:void 0,onAddFile:te,onStartTranscribe:me,onCancelTranscribe:ie,onFinishTranscribe:ue,onFinishTranscribeWithAudio:de,onSelectSuggestion:O},()=>[e.createElementVNode("div",Ks,[e.createElementVNode("div",Gs,[e.createElementVNode("div",Js,[e.renderSlot(L.$slots,"welcome-message",{},()=>[e.createElementVNode("h1",Qs,e.toDisplayString(s.value.welcomeMessageText),1)])]),e.createElementVNode("div",Xs,[E.value?(e.openBlock(),e.createBlock(St,{key:0,attachments:t.attachments??[],"class-name":"cpk:mb-2",onRemoveAttachment:Q[0]||(Q[0]=Te=>t.onRemoveAttachment&&t.onRemoveAttachment(Te))},null,8,["attachments"])):e.createCommentVNode("",!0),e.renderSlot(L.$slots,"input",{modelValue:S.value,isRunning:t.isRunning,inputMode:t.inputMode,inputToolsMenu:t.inputToolsMenu,attachments:t.attachments??[],onUpdateModelValue:he,onSubmitMessage:ve,onStop:z.value?Ae:void 0,onAddFile:te,onStartTranscribe:me,onCancelTranscribe:ie,onFinishTranscribe:ue,onFinishTranscribeWithAudio:de},()=>[e.createVNode(et,e.mergeProps({"model-value":S.value,"is-running":t.isRunning,mode:t.inputMode,"tools-menu":t.inputToolsMenu,positioning:"static","show-disclaimer":!0,"keyboard-height":y.value},Me.value),null,16,["model-value","is-running","mode","tools-menu","keyboard-height"])])]),M.value?(e.openBlock(),e.createElementBlock("div",Ys,[e.renderSlot(L.$slots,"suggestion-view",{suggestions:t.suggestions,loadingIndexes:t.suggestionLoadingIndexes,onSelectSuggestion:O},()=>[e.createVNode(tt,{suggestions:t.suggestions,"loading-indexes":t.suggestionLoadingIndexes,onSelectSuggestion:O},null,8,["suggestions","loading-indexes"])])])):e.createCommentVNode("",!0)])])]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.renderSlot(L.$slots,"scroll-view",{messages:t.messages,isRunning:t.isRunning,suggestions:t.suggestions,loadingIndexes:t.suggestionLoadingIndexes,messagePaddingBottom:w.value,showScrollToBottomButton:R.value,onSelectSuggestion:O,onScroll:re,scrollToBottom:K},()=>[e.createElementVNode("div",{ref_key:"scrollContainerRef",ref:c,"data-testid":"copilot-chat-view-scroll",class:"cpk:h-full cpk:max-h-full cpk:min-h-0 cpk:overflow-y-scroll cpk:overflow-x-hidden cpk:relative",onScroll:re},[e.createElementVNode("div",Zs,[e.createElementVNode("div",{ref_key:"scrollContentRef",ref:d,"data-testid":"copilot-scroll-content",style:e.normalizeStyle({paddingBottom:w.value})},[e.createElementVNode("div",er,[e.renderSlot(L.$slots,"message-view",{messages:t.messages,isRunning:t.isRunning},()=>[e.createVNode(zn,{messages:t.messages,"is-running":t.isRunning},e.createSlots({_:2},[e.renderList(A.value,Te=>({name:Te,fn:e.withCtx(Ne=>[e.renderSlot(L.$slots,Te,e.normalizeProps(e.guardReactiveProps(Ne)))])}))]),1032,["messages","is-running"])]),M.value?(e.openBlock(),e.createElementBlock("div",tr,[e.renderSlot(L.$slots,"suggestion-view",{suggestions:t.suggestions,loadingIndexes:t.suggestionLoadingIndexes,onSelectSuggestion:O},()=>[e.createVNode(tt,{class:"cpk:mb-3 cpk:lg:ml-4 cpk:lg:mr-4 cpk:ml-0 cpk:mr-0",suggestions:t.suggestions,"loading-indexes":t.suggestionLoadingIndexes,onSelectSuggestion:O},null,8,["suggestions","loading-indexes"])])])):e.createCommentVNode("",!0)])],4),f.value?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"spacerRef",ref:x,"data-pin-to-send-spacer":"","aria-hidden":"true",style:{height:"0px",flex:"0 0 auto"}},null,512)):e.createCommentVNode("",!0)])],544)]),e.renderSlot(L.$slots,"feather",{},()=>[Q[4]||(Q[4]=e.createElementVNode("div",{"data-testid":"copilot-chat-view-feather"},null,-1))]),R.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"cpk:absolute cpk:inset-x-0 cpk:flex cpk:justify-center cpk:z-30 cpk:pointer-events-none",style:e.normalizeStyle({bottom:`${v.value+or}px`})},[e.renderSlot(L.$slots,"scroll-to-bottom-button",{onClick:()=>K()},()=>[e.createElementVNode("button",{type:"button","data-testid":"copilot-chat-view-scroll-to-bottom",class:"cpk:rounded-full cpk:w-10 cpk:h-10 cpk:p-0 cpk:pointer-events-auto cpk:bg-white cpk:dark:bg-gray-900 cpk:shadow-lg cpk:border cpk:border-gray-200 cpk:dark:border-gray-700 cpk:hover:bg-gray-50 cpk:dark:hover:bg-gray-800 cpk:flex cpk:items-center cpk:justify-center cpk:cursor-pointer",onClick:Q[1]||(Q[1]=Te=>K())},[e.createVNode(e.unref(se.ChevronDown),{class:"cpk:w-4 cpk:h-4 cpk:text-gray-600 cpk:dark:text-white"})])])],4)):e.createCommentVNode("",!0),e.createElementVNode("div",{ref_key:"inputContainerRef",ref:p,class:"cpk:absolute cpk:bottom-0 cpk:left-0 cpk:right-0 cpk:z-20 cpk:pointer-events-none","data-testid":"copilot-input-overlay"},[E.value?(e.openBlock(),e.createElementBlock("div",nr,[e.createVNode(St,{attachments:t.attachments??[],"class-name":"cpk:px-4",onRemoveAttachment:Q[2]||(Q[2]=Te=>t.onRemoveAttachment&&t.onRemoveAttachment(Te))},null,8,["attachments"])])):e.createCommentVNode("",!0),e.renderSlot(L.$slots,"input",{modelValue:S.value,isRunning:t.isRunning,inputMode:t.inputMode,inputToolsMenu:t.inputToolsMenu,attachments:t.attachments??[],onUpdateModelValue:he,onSubmitMessage:ve,onStop:z.value?Ae:void 0,onAddFile:te,onStartTranscribe:me,onCancelTranscribe:ie,onFinishTranscribe:ue,onFinishTranscribeWithAudio:de},()=>[e.createVNode(et,e.mergeProps({"model-value":S.value,"is-running":t.isRunning,mode:t.inputMode,"tools-menu":t.inputToolsMenu,positioning:"static","show-disclaimer":!0,"keyboard-height":y.value,"bottom-anchored":!0},Me.value),null,16,["model-value","is-running","mode","tools-menu","keyboard-height"])])],512)],64))],16))}});function sr(t){const o=e.ref(null),n=(r,s)=>{o.value=null,oe.emitInspectorActiveThread({requestId:r.requestId,threadId:s,agentId:r.agentId,source:"app"})},a=r=>{const s=o.value;!s||s.requestId!==r||(oe.emitInspectorViewThreadResult({requestId:r,threadId:s.threadId,agentId:s.agentId,ok:!1,reason:"connect-failed"}),n(s,s.previousThreadId))};if(oe.isInspectorThreadBridgeEnabled()){const r=oe.onInspectorViewThread(i=>i.agentId!==t.agentId.value?!1:(o.value=o.value?{...o.value,...i}:{...i,previousThreadId:t.baseThreadId.value},oe.emitInspectorViewThreadResult({...i,ok:!0}),oe.emitInspectorActiveThread({...i,source:"override"}),!0)),s=oe.onInspectorStopViewing(i=>{const l=o.value;l&&i.requestId===l.requestId&&i.agentId===l.agentId&&n(l,l.previousThreadId)});e.onBeforeUnmount(()=>{r(),s()})}return e.watch([t.agentId,t.baseThreadId],([r,s])=>{const i=o.value;if(i){if(r!==i.agentId){n(i,i.previousThreadId);return}s!==i.previousThreadId&&s!==i.threadId&&n(i,s)}}),{inspectorThreadId:e.computed(()=>o.value?.threadId??null),inspectorRequestId:e.computed(()=>o.value?.requestId??null),failInspectorOverride:a}}const rr=["accept"],ir={key:2,style:{position:"absolute",bottom:"100px",left:"50%",transform:"translateX(-50%)","background-color":"#ef4444",color:"white",padding:"8px 16px","border-radius":"8px","font-size":"14px","z-index":"50"}},$t=e.defineComponent({inheritAttrs:!1,__name:"CopilotChat",props:{agentId:{},threadId:{},throttleMs:{},labels:{},attachments:{},onError:{},autoScroll:{type:[String,Boolean],default:!0},welcomeScreen:{type:Boolean,default:!0},inputValue:{default:void 0},inputMode:{default:"input"},inputToolsMenu:{default:()=>[]},isConnecting:{type:Boolean},hasExplicitThreadId:{type:Boolean},onFinishTranscribeWithAudio:{type:Function,default:void 0}},emits:["submit-message","stop","input-change","select-suggestion","add-file","start-transcribe","cancel-transcribe","finish-transcribe"],setup(t,{emit:o}){const n=t,a=o,r=e.useAttrs(),s=e.useSlots(),i=be(),{copilotkit:l}=xe(),c=e.computed(()=>Object.keys(s).filter(P=>P!=="chat-view")),d=e.ref(j.randomUUID()),x=e.ref("input"),p=e.ref(n.inputValue??""),v=e.ref(null),u=e.ref(!1),k=e.ref(!1),b=e.ref(!1),h=e.shallowRef(null),C=e.computed(()=>n.agentId??i.value?.agentId??j.DEFAULT_AGENT_ID),f=e.computed(()=>n.threadId??i.value?.threadId),g=e.computed(()=>f.value??d.value),m=e.computed(()=>!!n.threadId||!!i.value?.hasExplicitThreadId),{inspectorThreadId:y,inspectorRequestId:S,failInspectorOverride:M}=sr({agentId:C,baseThreadId:g}),E=e.computed(()=>y.value??g.value),I=e.computed(()=>y.value!==null||m.value),A=e.ref(null),N=e.computed(()=>I.value&&A.value!==E.value),_=Tn(e.computed(()=>n.labels)),z=e.computed(()=>_.value),{agent:$}=gt({agentId:C,throttleMs:e.computed(()=>n.throttleMs)}),{suggestions:U}=Fn({agentId:C}),G=ot(),B=e.computed(()=>G.value.checkFeature("chat"));e.watch(B,P=>{P||console.warn('[CopilotKit] Warning: "chat" feature is not licensed. Visit copilotkit.ai/pricing')},{immediate:!0});const w=e.computed(()=>l.value.audioFileTranscriptionEnabled),R=e.computed(()=>typeof window<"u"&&typeof MediaRecorder<"u"),F=e.computed(()=>w.value&&R.value),{attachments:W,enabled:ae,dragOver:D,fileInputRef:H,containerRef:q,handleFileUpload:K,handleDragOver:re,handleDragLeave:pe,handleDrop:he,removeAttachment:ve,consumeAttachments:Ae}=Dn({config:e.computed(()=>n.attachments)}),O=e.computed(()=>u.value?"processing":x.value),te=e.ref(0),ee=e.computed(()=>[...$.value?.messages??[]]),Se=e.computed(()=>(te.value,$.value?.isRunning??!1)),Re=e.computed(()=>Se.value&&ee.value.length>0),me=e.computed(()=>{for(let P=ee.value.length-1;P>=0;P--){const X=ee.value[P];if(X?.role==="user")return X.id}return null}),ie=e.ref(0);let ue=me.value;e.watch(me,P=>{P&&P!==ue&&(ie.value+=1,ue=P)});const de=e.computed(()=>({id:me.value,sendNonce:ie.value}));e.provide(Ln,de),e.watch(()=>$.value,(P,X,Z)=>{if(!P)return;const le=P.subscribe({onRunStartedEvent:()=>{te.value+=1},onRunFinishedEvent:()=>{te.value+=1},onRunErrorEvent:()=>{te.value+=1}});Z(()=>le.unsubscribe())},{immediate:!0}),e.watch(()=>n.inputValue,P=>{P!==void 0&&(p.value=P)}),e.watch([()=>n.threadId,()=>i.value?.threadId],([P,X],Z)=>{P||X||Z&&(Z[0]||Z[1])&&(d.value=j.randomUUID())}),e.watch([()=>l.value,C,()=>n.onError],([P,X,Z],le,Ie)=>{if(!Z)return;const Ee=P.subscribe({onError:Ve=>{(Ve.context?.agentId===X||!Ve.context?.agentId)&&Z({error:Ve.error,code:Ve.code,context:Ve.context})}});Ie(()=>Ee.unsubscribe())},{immediate:!0}),e.watch([()=>l.value,C,E,S],([P,X,Z,le],Ie,Ee)=>{if(!le)return;const Ve=P.subscribe({onError:Pe=>{Pe.code===oe.CopilotKitCoreErrorCode.AGENT_CONNECT_FAILED&&Pe.context?.agentId===X&&Pe.context?.threadId===Z&&M(le)}});Ee(()=>Ve.unsubscribe())},{immediate:!0}),e.watch([k,()=>l.value,()=>$.value,E,I,S],([P,X,Z,le,Ie,Ee],Ve,Pe)=>{if(!P||typeof window>"u"||!Z)return;const De=h.value;if(De!==null&&De.threadId!==le&&De.inspectorRequestId!==Ee&&(De.inspectorRequestId!==null||Ee!==null))try{X.stopAgent({agent:Z})}catch{}if(Z.threadId=le,!Ie)return;const T=qe.AbstractAgent.prototype,V=Z,J=V.connect!==T.connect,ne=V.connectAgent!==T.connectAgent;if(!J&&!ne){A.value=le;return}const fe=h.value,ce=fe&&fe.core===X&&fe.agent===Z&&fe.threadId===le&&fe.inspectorRequestId===Ee;let ge;if(ce&&fe)ge=fe;else{const ke=new AbortController;Z instanceof qe.HttpAgent&&(Z.abortController=ke),ge={core:X,agent:Z,threadId:le,inspectorRequestId:Ee,abortController:ke,detached:!1},h.value=ge,X.connectAgent({agent:Z}).catch($e=>{ge.detached||$e instanceof qe.AGUIConnectNotImplementedError||(console.error("CopilotChat: connectAgent failed",$e),Ee&&M(Ee))}).finally(()=>{if(ge.detached)return;(typeof requestAnimationFrame=="function"?requestAnimationFrame:Oe=>setTimeout(Oe,16))(()=>{ge.detached||(A.value=ge.threadId)})})}Pe(()=>{const ke=h.value;!ke||ke!==ge||!(b.value||l.value!==ke.core||$.value!==ke.agent||E.value!==ke.threadId)||(ke.detached=!0,ke.abortController.abort(),ke.agent.detachActiveRun?.(),h.value=null)})},{immediate:!0});const Me=e.ref(void 0);e.watch([E,I,()=>$.value],([P,X,Z])=>{const le=Me.value;Me.value=P,Z&&(X||le!==void 0&&P!==le&&Z.setMessages([]))},{immediate:!0}),e.onBeforeUnmount(()=>{b.value=!0}),e.onMounted(()=>{k.value=!0}),e.watch(v,(P,X,Z)=>{if(!P)return;const le=setTimeout(()=>{v.value=null},5e3);Z(()=>clearTimeout(le))});async function L(){const P=$.value;if(P)try{const X=h.value;X&&X.agent===P&&X.threadId===E.value&&(X.detached=!0,X.abortController.abort(),h.value=null,await X.agent.detachActiveRun?.()),await l.value.runAgent({agent:P})}catch(X){console.error("CopilotChat: runAgent failed",X)}}async function Q(P){if(W.value.some(le=>le.status==="uploading")){console.error("[CopilotKit] Cannot send while attachments are uploading");return}if(a("submit-message",P),!$.value){console.error("[CopilotKit] Cannot send message: no agent available");return}const Z=Ae();if(Z.length>0){const le=[];P.trim()&&le.push({type:"text",text:P});for(const Ie of Z)le.push({type:Ie.type,source:Ie.source,metadata:{...Ie.filename?{filename:Ie.filename}:{},...Ie.metadata}});$.value.addMessage({id:j.randomUUID(),role:"user",content:le})}else $.value.addMessage({id:j.randomUUID(),role:"user",content:P});p.value="",await L()}async function Te(P,X){a("select-suggestion",P,X),$.value?.addMessage({id:j.randomUUID(),role:"user",content:P.message}),await L()}function Ne(){const P=$.value;if(P)try{l.value.stopAgent({agent:P})}catch(X){console.error("CopilotChat: stopAgent failed",X);try{P.abortRun()}catch(Z){console.error("CopilotChat: abortRun fallback failed",Z)}}}function Ge(){a("stop"),Re.value&&Ne()}function Je(P){p.value=P,a("input-change",P)}function Qe(){a("add-file"),ae.value&&setTimeout(()=>{H.value?.click()},100)}function ze(){v.value=null,x.value="transcribe",a("start-transcribe")}function Xe(){v.value=null,x.value="input",a("cancel-transcribe")}function je(){x.value="input",a("finish-transcribe")}async function Ye(P){if(n.onFinishTranscribeWithAudio){await n.onFinishTranscribeWithAudio(P);return}u.value=!0;try{v.value=null;const X=await Aa(l.value,P),Z=p.value.trim();p.value=Z?`${Z} ${X.text}`:X.text}catch(X){if(console.error("CopilotChat: Transcription failed",X),X instanceof We){const{code:Z,retryable:le,message:Ie}=X.info;switch(Z){case j.TranscriptionErrorCode.RATE_LIMITED:v.value="Too many requests. Please wait a moment.";break;case j.TranscriptionErrorCode.AUTH_FAILED:v.value="Authentication error. Please check your configuration.";break;case j.TranscriptionErrorCode.AUDIO_TOO_LONG:v.value="Recording is too long. Please try a shorter recording.";break;case j.TranscriptionErrorCode.AUDIO_TOO_SHORT:v.value="Recording is too short. Please try again.";break;case j.TranscriptionErrorCode.INVALID_AUDIO_FORMAT:v.value="Audio format not supported.";break;case j.TranscriptionErrorCode.SERVICE_NOT_CONFIGURED:v.value="Transcription service is not available.";break;case j.TranscriptionErrorCode.NETWORK_ERROR:v.value="Network error. Please check your connection.";break;default:v.value=le?"Transcription failed. Please try again.":Ie}}else v.value="Transcription failed. Please try again."}finally{u.value=!1}}const Ce=e.computed(()=>({messages:ee.value,autoScroll:n.autoScroll,isRunning:Se.value,suggestions:U.value,suggestionLoadingIndexes:[],welcomeScreen:n.welcomeScreen,attachments:W.value,dragOver:D.value,inputValue:p.value,inputMode:O.value,inputToolsMenu:n.inputToolsMenu,isConnecting:N.value,hasExplicitThreadId:I.value,onSubmitMessage:Q,onStop:Re.value?Ge:void 0,onInputChange:Je,onSelectSuggestion:Te,onRemoveAttachment:ve,onAddFile:ae.value?Qe:void 0,onDragOver:ae.value?re:void 0,onDragLeave:ae.value?pe:void 0,onDrop:ae.value?he:void 0,onStartTranscribe:F.value?ze:void 0,onCancelTranscribe:F.value?Xe:void 0,onFinishTranscribe:F.value?je:void 0,onFinishTranscribeWithAudio:F.value?Ye:void 0})),_e=e.computed(()=>{const P={...r,onSubmitMessage:Q,onInputChange:Je,onSelectSuggestion:Te};return Re.value&&(P.onStop=Ge),ae.value&&(P.onAddFile=Qe,P.attachments=W.value,P.onRemoveAttachment=ve,P.dragOver=D.value,P.onDragOver=re,P.onDragLeave=pe,P.onDrop=he),F.value&&(P.onStartTranscribe=ze,P.onCancelTranscribe=Xe,P.onFinishTranscribe=je),P});return(P,X)=>(e.openBlock(),e.createBlock(ft,{"agent-id":C.value,"thread-id":E.value,"has-explicit-thread-id":I.value,labels:z.value},{default:e.withCtx(()=>[e.createElementVNode("div",{ref_key:"attachmentContainerRef",ref:q,style:{display:"contents"}},[e.unref(ae)?(e.openBlock(),e.createElementBlock("input",{key:0,ref_key:"fileInputRef",ref:H,type:"file",multiple:"",accept:n.attachments?.accept??"*/*",style:{display:"none"},onChange:X[0]||(X[0]=Z=>{e.unref(K)(Z)})},null,40,rr)):e.createCommentVNode("",!0),B.value?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(Mt,{key:1,"feature-name":"Chat"})),v.value?(e.openBlock(),e.createElementBlock("div",ir,e.toDisplayString(v.value),1)):e.createCommentVNode("",!0),e.renderSlot(P.$slots,"chat-view",e.normalizeProps(e.guardReactiveProps(Ce.value)),()=>[e.createVNode(at,e.mergeProps(_e.value,{messages:Ce.value.messages,"auto-scroll":Ce.value.autoScroll,"is-running":Ce.value.isRunning,suggestions:Ce.value.suggestions,"suggestion-loading-indexes":Ce.value.suggestionLoadingIndexes,"welcome-screen":Ce.value.welcomeScreen,"input-value":Ce.value.inputValue,"input-mode":Ce.value.inputMode,"input-tools-menu":Ce.value.inputToolsMenu,"is-connecting":Ce.value.isConnecting,"has-explicit-thread-id":Ce.value.hasExplicitThreadId,"on-finish-transcribe-with-audio":Ce.value.onFinishTranscribeWithAudio}),e.createSlots({_:2},[e.renderList(c.value,Z=>({name:Z,fn:e.withCtx(le=>[e.renderSlot(P.$slots,Z,e.normalizeProps(e.guardReactiveProps(le)))])}))]),1040,["messages","auto-scroll","is-running","suggestions","suggestion-loading-indexes","welcome-screen","input-value","input-mode","input-tools-menu","is-connecting","has-explicit-thread-id","on-finish-transcribe-with-audio"])])],512)]),_:3},8,["agent-id","thread-id","has-explicit-thread-id","labels"]))}}),lr=["src"],cr=["src"],ur={key:0,class:"cpk:text-xs cpk:text-muted-foreground cpk:truncate cpk:max-w-[300px]","data-testid":"copilot-chat-attachment-renderer-audio-filename"},dr=["src"],pr={class:"cpk:text-xs cpk:font-bold cpk:uppercase","data-testid":"copilot-chat-attachment-renderer-document-icon"},mr={class:"cpk:text-sm cpk:text-muted-foreground cpk:truncate","data-testid":"copilot-chat-attachment-renderer-document-label"},fr=e.defineComponent({__name:"CopilotChatAttachmentRenderer",props:{type:{},source:{},filename:{default:void 0},className:{default:""}},setup(t){const o=t,n=e.ref(!1),a=e.computed(()=>j.getSourceUrl(o.source)),r=e.computed(()=>o.filename||o.source.mimeType||"Unknown type");return(s,i)=>o.type==="image"&&!n.value?(e.openBlock(),e.createElementBlock("img",{key:0,src:a.value,alt:"Image attachment",class:e.normalizeClass(["cpk:max-w-full cpk:h-auto cpk:rounded-lg",o.className]),"data-testid":"copilot-chat-attachment-renderer-image",onError:i[0]||(i[0]=l=>n.value=!0)},null,42,lr)):o.type==="image"?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(["cpk:flex cpk:flex-col cpk:items-center cpk:justify-center cpk:rounded-lg cpk:bg-muted cpk:p-4 cpk:text-sm cpk:text-muted-foreground",o.className]),"data-testid":"copilot-chat-attachment-renderer-image-fallback"},[...i[1]||(i[1]=[e.createElementVNode("span",null,"Failed to load image",-1)])],2)):o.type==="audio"?(e.openBlock(),e.createElementBlock("div",{key:2,class:e.normalizeClass(["cpk:flex cpk:flex-col cpk:gap-1",o.className]),"data-testid":"copilot-chat-attachment-renderer-audio"},[e.createElementVNode("audio",{src:a.value,controls:"",preload:"metadata",class:"cpk:max-w-[300px] cpk:w-full cpk:h-10"},null,8,cr),o.filename?(e.openBlock(),e.createElementBlock("span",ur,e.toDisplayString(o.filename),1)):e.createCommentVNode("",!0)],2)):o.type==="video"?(e.openBlock(),e.createElementBlock("video",{key:3,src:a.value,controls:"",preload:"metadata",class:e.normalizeClass(["cpk:max-w-[400px] cpk:w-full cpk:rounded-lg",o.className]),"data-testid":"copilot-chat-attachment-renderer-video"},null,10,dr)):(e.openBlock(),e.createElementBlock("div",{key:4,class:e.normalizeClass(["cpk:inline-flex cpk:items-center cpk:gap-2 cpk:px-3 cpk:py-2 cpk:border cpk:border-border cpk:rounded-lg cpk:bg-muted",o.className]),"data-testid":"copilot-chat-attachment-renderer-document"},[e.createElementVNode("span",pr,e.toDisplayString(e.unref(j.getDocumentIcon)(o.source.mimeType??"")),1),e.createElementVNode("span",mr,e.toDisplayString(r.value),1)],2))}});function Ue(t,o,n){n.value=o(t.getState());const a=t.select(o).subscribe(()=>{n.value=o(t.getState())});e.onScopeDispose(()=>a.unsubscribe())}function _n(t){const{copilotkit:o}=xe(),n=oe.ɵcreateThreadStore({fetch:globalThis.fetch}),a=e.computed(()=>e.toValue(t.agentId)),r=e.computed(()=>e.toValue(t.includeArchived)),s=e.computed(()=>e.toValue(t.limit)),i=e.computed(()=>e.toValue(t.enabled)??!0),l=e.computed(()=>o.value.threadEndpoints?.list!==!1),c=e.computed(()=>o.value.threadEndpoints?.mutations!==!1),d=e.computed(()=>!!o.value.runtimeUrl&&o.value.runtimeConnectionStatus===oe.CopilotKitCoreRuntimeConnectionStatus.Connected&&!l.value),x=e.computed(()=>d.value?new Error("Thread endpoints are not available on this CopilotKit runtime"):null),p=e.computed(()=>c.value?null:new Error("Thread mutations are not available on this CopilotKit runtime")),v=e.computed(()=>JSON.stringify(Object.entries(o.value.headers??{}).sort(([N],[_])=>N.localeCompare(_)))),u=e.ref([]),k=e.ref(!1),b=e.ref(null),h=e.ref(null),C=e.ref(!1),f=e.ref(!1),g=e.ref(!1);Ue(n,oe.ɵselectThreads,u),Ue(n,oe.ɵselectThreadsIsLoading,k),Ue(n,oe.ɵselectThreadsError,b),Ue(n,oe.ɵselectFetchMoreError,h),Ue(n,oe.ɵselectHasNextPage,C),Ue(n,oe.ɵselectIsFetchingNextPage,f),Ue(n,oe.ɵselectIsMutating,g),n.start(),e.onScopeDispose(()=>{n.stop()}),e.watch([i,a],([N,_],z,$)=>{N&&(o.value.registerThreadStore(_,n),$(()=>{o.value.unregisterThreadStore(_)}))},{immediate:!0});const m=e.ref(!1);e.watch([()=>o.value.runtimeUrl,()=>o.value.runtimeConnectionStatus,v,()=>o.value.intelligence?.wsUrl,a,r,s,i,l],([N,_,,z,$,U,G,B,w])=>{if(!N||!B){n.setContext(null),m.value=!1;return}if(_!==oe.CopilotKitCoreRuntimeConnectionStatus.Connected)return;if(!w){n.setContext(null),m.value=!1;return}const R={runtimeUrl:N,headers:{...o.value.headers},wsUrl:z,agentId:$,includeArchived:U,limit:G};n.setContext(R),m.value=!0},{immediate:!0});const y=e.computed(()=>o.value.runtimeUrl?null:new Error("Runtime URL is not configured")),S=e.computed(()=>!!o.value.runtimeUrl&&i.value&&!d.value&&!m.value),M=e.computed(()=>y.value||x.value?!1:S.value||k.value),E=e.computed(()=>y.value??x.value??b.value),I=e.computed(()=>b.value);function A(N){return(..._)=>p.value?Promise.reject(p.value):N(..._)}return{threads:e.computed(()=>u.value.map(({id:N,agentId:_,name:z,archived:$,createdAt:U,updatedAt:G,lastRunAt:B})=>({id:N,agentId:_,name:z,archived:$,createdAt:U,updatedAt:G,...B!==void 0?{lastRunAt:B}:{}}))),isLoading:M,error:E,listError:I,fetchMoreError:h,hasMoreThreads:C,isFetchingMoreThreads:f,isMutating:g,fetchMoreThreads:()=>n.fetchNextPage(),refetchThreads:()=>n.refetchThreads(),startNewThread:()=>n.startNewThread(),renameThread:A((N,_)=>n.renameThread(N,_)),archiveThread:A(N=>n.archiveThread(N)),unarchiveThread:A(N=>n.unarchiveThread(N)),deleteThread:A(N=>n.deleteThread(N))}}const Yt="copilot-chat-input-textarea",gr="copilot-chat-view",hr=e.defineComponent({__name:"CopilotThreadsDrawer",props:{agentId:{},onThreadSelect:{},onNewThread:{},onLicensed:{},licenseUrl:{},label:{},recentLabel:{},collapsible:{type:Boolean,default:!0},limit:{},dataTestId:{default:"copilot-threads-drawer"}},emits:["collapse-change"],setup(t,{emit:o}){const n=t,a=o,r=be(),s=ot(),i=e.computed(()=>{const B=s.value.status;return(B==="valid"||B==="expiring")&&s.value.checkFeature("threads")}),l=e.computed(()=>s.value.status===null),c=e.computed(()=>n.agentId??r.value?.agentId??j.DEFAULT_AGENT_ID),d=e.computed(()=>r.value?.threadId??null),x=e.ref(!1),p=e.computed(()=>r.value?r.value.drawerOpen:x.value);function v(B){r.value?r.value.setDrawerOpen?.(B):x.value=B}const u=_n({agentId:c,includeArchived:!0,enabled:i,limit:()=>n.limit});function k(B){return{id:B.id,name:B.name,archived:B.archived,createdAt:B.createdAt,updatedAt:B.updatedAt,...B.lastRunAt!==void 0?{lastRunAt:B.lastRunAt}:{}}}const b=e.computed(()=>u.threads.value.map(k)),h=e.ref(!1),C=e.ref(null),f=e.ref(null);e.onMounted(async()=>{const B=await import("@copilotkit/web-components/threads-drawer");B.defineCopilotKitThreadsDrawer(),C.value=B.COPILOTKIT_THREADS_DRAWER_TAG,h.value=!0}),e.watchEffect(()=>{const B=f.value;B&&(B.threads=b.value,B.loading=u.isLoading.value||l.value,B.error=u.listError.value?.message??null,B.activeThreadId=d.value,B.licensed=i.value||l.value,B.hasMore=u.hasMoreThreads.value,B.fetchingMore=u.isFetchingMoreThreads.value,B.fetchMoreError=u.fetchMoreError.value?.message??null,B.open=p.value,n.label!==void 0&&(B.label=n.label),n.licenseUrl!==void 0&&(B.licenseUrl=n.licenseUrl),n.collapsible!==void 0&&(B.collapsible=n.collapsible))},{flush:"post"});const g=r.value?.registerDrawer?.();g&&e.onScopeDispose(g);function m(B){if(typeof document>"u")return null;const w=B?.closest?.(`[data-testid="${gr}"]`);if(w){const R=w.querySelector(`[data-testid="${Yt}"]`);if(R)return R}return document.querySelector(`[data-testid="${Yt}"]`)}function y(){m(f.value)?.focus()}function S(B){const{threadId:w}=B.detail;n.onThreadSelect?n.onThreadSelect(w):r.value?.setActiveThreadId?.(w,{explicit:!0}),y()}function M(){u.startNewThread(),n.onNewThread?n.onNewThread():r.value?.startNewThread?.()}function E(B){const{threadId:w}=B.detail;u.archiveThread(w).catch(R=>console.error("CopilotThreadsDrawer: archiveThread failed",R))}function I(B){const{threadId:w}=B.detail;u.unarchiveThread(w).catch(R=>console.error("CopilotThreadsDrawer: unarchiveThread failed",R))}function A(B){const{threadId:w}=B.detail,R=w===d.value;u.deleteThread(w).then(()=>{R&&M()}).catch(F=>console.error("CopilotThreadsDrawer: deleteThread failed",F))}function N(){u.refetchThreads()}function _(B){const{collapsed:w}=B.detail;a("collapse-change",w)}function z(B){const{scope:w}=B.detail;w==="fetch-more"?u.fetchMoreThreads():u.refetchThreads()}function $(){u.fetchMoreThreads()}function U(B){const{open:w}=B.detail;v(w)}function G(){n.onLicensed?.()}return(B,w)=>h.value?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(C.value),{key:0,ref_key:"elRef",ref:f,"data-testid":t.dataTestId,"recent-label":t.recentLabel,onThreadSelected:S,onNewThread:M,onArchive:E,onUnarchive:I,onDelete:A,onFilterChange:N,onCollapseChange:_,onRetry:z,onLoadMore:$,onOpenChange:U,onLicensed:G},{default:e.withCtx(()=>[e.renderSlot(B.$slots,"default"),B.$slots.row?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(e.unref(u).threads.value,R=>(e.openBlock(),e.createElementBlock("div",e.mergeProps({key:R.id},{ref_for:!0},{slot:`row:${R.id}`}),[e.renderSlot(B.$slots,"row",{thread:R})],16))),128)):e.createCommentVNode("",!0)]),_:3},40,["data-testid","recent-label"])):e.createCommentVNode("",!0)}}),Bt=e.defineComponent({name:"CopilotChatToggleButtonCloseIcon",inheritAttrs:!1,setup(t,{attrs:o}){return()=>{const{class:n,...a}=o;return e.h(se.X,{...a,class:["cpk:h-6 cpk:w-6",n],strokeWidth:1.75})}}}),Nt=e.defineComponent({name:"CopilotChatToggleButtonOpenIcon",inheritAttrs:!1,setup(t,{attrs:o}){return()=>{const{class:n,...a}=o;return e.h(se.MessageCircle,{...a,class:["cpk:h-6 cpk:w-6",n],strokeWidth:1.75,fill:"currentColor"})}}}),vr=["type","data-state","aria-label","aria-pressed","disabled"],ct="cpk:h-6 cpk:w-6",Zt="cpk:pointer-events-none cpk:absolute cpk:inset-0 cpk:flex cpk:items-center cpk:justify-center cpk:will-change-transform",Vt=e.defineComponent({inheritAttrs:!1,__name:"CopilotChatToggleButton",props:{disabled:{type:Boolean,default:!1},type:{default:"button"}},setup(t){const o=t,n=e.useAttrs(),a=be(),r=e.ref(!1),s=e.computed(()=>a.value?.labels??Be),i=e.computed(()=>a.value?.isModalOpen??r.value),l=e.computed(()=>i.value?s.value.chatToggleCloseLabel:s.value.chatToggleOpenLabel),c=e.computed(()=>["cpk:fixed cpk:bottom-6 cpk:right-6 cpk:z-[1100] cpk:flex cpk:h-14 cpk:w-14 cpk:items-center cpk:justify-center","cpk:rounded-full cpk:border cpk:border-primary cpk:bg-primary cpk:text-primary-foreground","cpk:shadow-sm cpk:transition-all cpk:duration-200 cpk:ease-out","cpk:hover:scale-[1.04] cpk:hover:shadow-md cpk:cursor-pointer cpk:active:scale-[0.96]","cpk:focus-visible:outline-none cpk:focus-visible:ring-2 cpk:focus-visible:ring-primary/50 cpk:focus-visible:ring-offset-2 cpk:focus-visible:ring-offset-background","cpk:disabled:pointer-events-none cpk:disabled:opacity-60",n.class]),d=e.computed(()=>{const{class:k,onClick:b,...h}=n;return h}),x=Object.freeze({transition:"opacity 120ms ease-out, transform 260ms cubic-bezier(0.22, 1, 0.36, 1)"});function p(k){if(a.value?.setModalOpen){a.value.setModalOpen(k);return}r.value=k}function v(){const k=n.onClick;return Array.isArray(k)?k.filter(b=>typeof b=="function"):typeof k=="function"?[k]:[]}function u(k){if(!o.disabled){for(const b of v())b(k);k.defaultPrevented||p(!i.value)}}return(k,b)=>(e.openBlock(),e.createElementBlock("button",e.mergeProps({"data-copilotkit":"",type:t.type,"data-slot":"chat-toggle-button","data-state":i.value?"open":"closed",class:c.value,"aria-label":l.value,"aria-pressed":i.value,disabled:t.disabled},d.value,{onClick:u}),[e.createElementVNode("span",{"aria-hidden":"true","data-slot":"chat-toggle-button-open-icon",class:e.normalizeClass(Zt),style:e.normalizeStyle({...e.unref(x),opacity:i.value?0:1,transform:`scale(${i.value?.75:1}) rotate(${i.value?90:0}deg)`})},[e.renderSlot(k.$slots,"open-icon",{iconClass:ct,isOpen:i.value},()=>[e.createVNode(e.unref(Nt),{class:e.normalizeClass(ct),"aria-hidden":"true",focusable:!1})])],4),e.createElementVNode("span",{"aria-hidden":"true","data-slot":"chat-toggle-button-close-icon",class:e.normalizeClass(Zt),style:e.normalizeStyle({...e.unref(x),opacity:i.value?1:0,transform:`scale(${i.value?1:.75}) rotate(${i.value?0:-90}deg)`})},[e.renderSlot(k.$slots,"close-icon",{iconClass:ct,isOpen:i.value},()=>[e.createVNode(e.unref(Bt),{class:e.normalizeClass(ct),"aria-hidden":"true",focusable:!1})])],4)],16,vr))}}),Hn=e.defineComponent({name:"CopilotModalHeaderCloseButton",inheritAttrs:!1,setup(t,{slots:o}){const n=e.useAttrs(),a=e.computed(()=>typeof n["aria-label"]=="string"?n["aria-label"]:"Close");return()=>{const{class:r,type:s,...i}=n;return e.h("button",{...i,type:typeof s=="string"?s:"button",class:["cpk:inline-flex cpk:size-8 cpk:items-center cpk:justify-center cpk:rounded-full cpk:text-muted-foreground cpk:transition cpk:cursor-pointer","cpk:hover:bg-muted cpk:hover:text-foreground cpk:focus-visible:outline-none cpk:focus-visible:ring-2 cpk:focus-visible:ring-ring",r],"aria-label":a.value},o.default?o.default():[e.h(se.X,{class:"cpk:h-4 cpk:w-4","aria-hidden":!0})])}}}),Wn=e.defineComponent({name:"CopilotModalHeaderTitle",inheritAttrs:!1,setup(t,{attrs:o,slots:n}){return()=>{const{class:a,...r}=o;return e.h("div",{...r,class:["cpk:w-full cpk:text-base cpk:font-medium cpk:leading-none cpk:tracking-tight cpk:text-foreground",a]},n.default?n.default():[])}}}),kr={class:"cpk:flex cpk:w-full cpk:items-center cpk:gap-2"},br={class:"cpk:flex cpk:flex-1 cpk:justify-start"},yr=["aria-expanded"],wr={key:1,"aria-hidden":"true"},Cr={class:"cpk:flex cpk:flex-1 cpk:justify-center cpk:text-center"},xr={class:"cpk:flex cpk:flex-1 cpk:justify-end"},Ft=e.defineComponent({inheritAttrs:!1,__name:"CopilotModalHeader",props:{title:{}},setup(t){const o=t,n=e.useAttrs(),a=be(),r=e.computed(()=>o.title??a.value?.labels.modalHeaderTitle??Be.modalHeaderTitle),s=e.computed(()=>["cpk:flex cpk:items-center cpk:justify-between cpk:border-b cpk:border-border cpk:px-4 cpk:py-4","cpk:bg-background/95 cpk:backdrop-blur cpk:supports-[backdrop-filter]:bg-background/80",n.class]),i=e.computed(()=>{const{class:u,...k}=n;return k});function l(){a.value?.setModalOpen?.(!1)}const c=e.ref(!1);let d=null;function x(){d&&(c.value=d.matches)}e.onMounted(()=>{typeof window>"u"||typeof window.matchMedia!="function"||(d=window.matchMedia(In),d.addEventListener("change",x),x())}),e.onBeforeUnmount(()=>{d?.removeEventListener("change",x),d=null});const p=e.computed(()=>(a.value?.drawerRegistered??!1)&&c.value);function v(){a.value?.setDrawerOpen?.(!a.value?.drawerOpen)}return(u,k)=>(e.openBlock(),e.createElementBlock("header",e.mergeProps({"data-copilotkit":"","data-slot":"copilot-modal-header",class:s.value},i.value),[e.renderSlot(u.$slots,"layout",{title:r.value,onClose:l},()=>[e.createElementVNode("div",kr,[e.createElementVNode("div",br,[p.value?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button","data-testid":"drawer-launcher",class:"cpk:inline-flex cpk:size-8 cpk:items-center cpk:justify-center cpk:rounded-full cpk:text-muted-foreground cpk:transition cpk:cursor-pointer cpk:hover:bg-muted cpk:hover:text-foreground cpk:focus-visible:outline-none cpk:focus-visible:ring-2 cpk:focus-visible:ring-ring","aria-expanded":e.unref(a)?.drawerOpen??!1,"aria-label":"Open threads",onClick:v},[e.createVNode(e.unref(se.PanelLeftOpen),{class:"cpk:h-4 cpk:w-4","aria-hidden":"true"})],8,yr)):(e.openBlock(),e.createElementBlock("span",wr))]),e.createElementVNode("div",Cr,[e.renderSlot(u.$slots,"title-content",{title:r.value},()=>[e.createVNode(e.unref(Wn),null,{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(r.value),1)]),_:1})])]),e.createElementVNode("div",xr,[e.renderSlot(u.$slots,"close-button",{onClose:l},()=>[e.createVNode(e.unref(Hn),{onClick:l})])])])])],16))}}),Sr={key:0,"data-copilotkit":"",class:"cpk:fixed cpk:inset-0 cpk:z-[1200] cpk:flex cpk:max-w-full cpk:flex-col cpk:items-stretch cpk:md:inset-auto cpk:md:bottom-24 cpk:md:right-6 cpk:md:items-end cpk:md:gap-4"},Tr=["aria-label"],Ir={class:"cpk:flex-1 cpk:overflow-hidden","data-popup-chat":""},Ar=420,Rr=560,en=200,Er=e.defineComponent({inheritAttrs:!1,__name:"CopilotPopupViewInternal",props:{width:{default:void 0},height:{default:void 0},clickOutsideToClose:{type:Boolean,default:!1},messages:{default:()=>[]},autoScroll:{type:[String,Boolean],default:!0},isRunning:{type:Boolean,default:!1},suggestions:{default:()=>[]},suggestionLoadingIndexes:{default:()=>[]},welcomeScreen:{type:Boolean,default:!0},attachments:{},dragOver:{type:Boolean},inputValue:{default:void 0},inputMode:{default:"input"},inputToolsMenu:{default:()=>[]},isConnecting:{type:Boolean},hasExplicitThreadId:{type:Boolean},onRemoveAttachment:{},onAddFile:{},onDragOver:{},onDragLeave:{},onDrop:{},onFinishTranscribeWithAudio:{type:Function,default:void 0}},emits:["submit-message","stop","input-change","select-suggestion","add-file","start-transcribe","cancel-transcribe","finish-transcribe"],setup(t,{emit:o}){const n=t,a=o,r=e.useAttrs(),s=be(),i=e.getCurrentInstance(),l=e.computed(()=>i?.vnode.props??{}),c=e.ref(null),d=e.ref(s.value?.isModalOpen??!1),x=e.ref(!1);let p,v;const u=e.computed(()=>s.value?.isModalOpen??!1),k=e.computed(()=>s.value?.labels??Be),b=e.computed(()=>k.value.modalHeaderTitle),h=e.computed(()=>m("onStop")),C=e.computed(()=>u.value&&!x.value?"cpk:pointer-events-auto cpk:translate-y-0 cpk:opacity-100 cpk:md:scale-100":"cpk:pointer-events-none cpk:translate-y-4 cpk:opacity-0 cpk:md:translate-y-5 cpk:md:scale-[0.95]"),f=e.computed(()=>({"--copilot-popup-width":g(n.width,Ar),"--copilot-popup-height":g(n.height,Rr),"--copilot-popup-max-width":"calc(100vw - 3rem)","--copilot-popup-max-height":"calc(100dvh - 7.5rem)",width:"var(--copilot-popup-width)",height:"var(--copilot-popup-height)",maxWidth:"var(--copilot-popup-max-width)",maxHeight:"var(--copilot-popup-max-height)",paddingTop:"env(safe-area-inset-top)",paddingBottom:"env(safe-area-inset-bottom)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)"}));function g(w,R){return typeof w=="number"&&Number.isFinite(w)?`${w}px`:typeof w=="string"&&w.trim().length>0?w:`${R}px`}function m(w){const R=l.value[w];return Array.isArray(R)?R.length>0:!!R}function y(){s.value?.setModalOpen?.(!1)}function S(){s.value?.setModalOpen?.(!0)}function M(){s.value?.setModalOpen?.(!u.value)}function E(w){a("submit-message",w)}function I(){a("stop")}function A(w){a("input-change",w)}function N(w,R){a("select-suggestion",w,R)}function _(){a("add-file")}function z(){a("start-transcribe")}function $(){a("cancel-transcribe")}function U(){a("finish-transcribe")}const G=e.computed(()=>{const w={onSubmitMessage:E,onInputChange:A,onSelectSuggestion:N};return h.value&&(w.onStop=I),m("onAddFile")&&(w.onAddFile=_),m("onStartTranscribe")&&(w.onStartTranscribe=z),m("onCancelTranscribe")&&(w.onCancelTranscribe=$),m("onFinishTranscribe")&&(w.onFinishTranscribe=U),w}),B=e.computed(()=>({...r,...G.value}));return e.watch(u,w=>{if(p&&(clearTimeout(p),p=void 0),w){d.value=!0,x.value=!1;return}d.value&&(x.value=!0,p=setTimeout(()=>{d.value=!1,x.value=!1,p=void 0},en))},{immediate:!0}),e.watch(u,(w,R,F)=>{if(!w||typeof window>"u")return;const W=ae=>{ae.key==="Escape"&&(ae.preventDefault(),y())};window.addEventListener("keydown",W),F(()=>{window.removeEventListener("keydown",W)})},{immediate:!0}),e.watch(u,(w,R,F)=>{w&&(v=setTimeout(()=>{if(typeof document>"u")return;const W=c.value;W&&!W.contains(document.activeElement)&&W.focus({preventScroll:!0})},en),F(()=>{v&&(clearTimeout(v),v=void 0)}))},{immediate:!0}),e.watch([u,()=>n.clickOutsideToClose],([w,R],F,W)=>{if(!w||!R||typeof document>"u")return;const ae=D=>{const H=D.target;!H||c.value?.contains(H)||document.querySelector("[data-slot='chat-toggle-button']")?.contains(H)||y()};document.addEventListener("pointerdown",ae),W(()=>{document.removeEventListener("pointerdown",ae)})},{immediate:!0}),e.onMounted(async()=>{await e.nextTick()}),e.onBeforeUnmount(()=>{p&&clearTimeout(p),v&&clearTimeout(v)}),(w,R)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.renderSlot(w.$slots,"toggle-button",{isOpen:u.value,toggle:M,open:S,close:y},()=>[e.createVNode(Vt)]),d.value?(e.openBlock(),e.createElementBlock("div",Sr,[e.createElementVNode("div",{ref_key:"containerRef",ref:c,tabindex:"-1",role:"dialog","aria-label":k.value.modalHeaderTitle,"data-copilot-popup":"",class:e.normalizeClass(["cpk:relative cpk:flex cpk:h-full cpk:w-full cpk:flex-col cpk:overflow-hidden cpk:bg-background cpk:text-foreground","cpk:origin-bottom cpk:focus:outline-none cpk:transform-gpu cpk:transition-transform cpk:transition-opacity cpk:duration-200 cpk:ease-out","cpk:md:transition-transform cpk:md:transition-opacity","cpk:rounded-none cpk:border cpk:border-border/0 cpk:shadow-none cpk:ring-0","cpk:md:h-[var(--copilot-popup-height)] cpk:md:w-[var(--copilot-popup-width)]","cpk:md:max-h-[var(--copilot-popup-max-height)] cpk:md:max-w-[var(--copilot-popup-max-width)]","cpk:md:origin-bottom-right cpk:md:rounded-2xl cpk:md:border-border cpk:md:shadow-xl cpk:md:ring-1 cpk:md:ring-border/40",C.value]),style:e.normalizeStyle(f.value)},[e.renderSlot(w.$slots,"header",{title:b.value,onClose:y,isOpen:u.value},()=>[e.createVNode(Ft,{title:b.value},null,8,["title"])]),e.createElementVNode("div",Ir,[e.createVNode(at,e.mergeProps({messages:t.messages,"auto-scroll":t.autoScroll,"is-running":t.isRunning,suggestions:t.suggestions,"suggestion-loading-indexes":t.suggestionLoadingIndexes,"welcome-screen":t.welcomeScreen,"input-value":t.inputValue,"input-mode":t.inputMode,"input-tools-menu":t.inputToolsMenu,"on-finish-transcribe-with-audio":t.onFinishTranscribeWithAudio},B.value),e.createSlots({_:2},[w.$slots["message-view"]?{name:"message-view",fn:e.withCtx(F=>[e.renderSlot(w.$slots,"message-view",e.normalizeProps(e.guardReactiveProps(F)))]),key:"0"}:void 0,w.$slots["scroll-view"]?{name:"scroll-view",fn:e.withCtx(F=>[e.renderSlot(w.$slots,"scroll-view",e.normalizeProps(e.guardReactiveProps(F)))]),key:"1"}:void 0,w.$slots.feather?{name:"feather",fn:e.withCtx(()=>[e.renderSlot(w.$slots,"feather")]),key:"2"}:void 0,w.$slots["scroll-to-bottom-button"]?{name:"scroll-to-bottom-button",fn:e.withCtx(F=>[e.renderSlot(w.$slots,"scroll-to-bottom-button",e.normalizeProps(e.guardReactiveProps(F)))]),key:"3"}:void 0,w.$slots.input?{name:"input",fn:e.withCtx(F=>[e.renderSlot(w.$slots,"input",e.normalizeProps(e.guardReactiveProps(F)))]),key:"4"}:void 0,w.$slots["suggestion-view"]?{name:"suggestion-view",fn:e.withCtx(F=>[e.renderSlot(w.$slots,"suggestion-view",e.normalizeProps(e.guardReactiveProps(F)))]),key:"5"}:void 0,w.$slots["welcome-screen"]?{name:"welcome-screen",fn:e.withCtx(F=>[e.renderSlot(w.$slots,"welcome-screen",e.normalizeProps(e.guardReactiveProps(F)))]),key:"6"}:void 0,w.$slots["welcome-message"]?{name:"welcome-message",fn:e.withCtx(()=>[e.renderSlot(w.$slots,"welcome-message")]),key:"7"}:void 0]),1040,["messages","auto-scroll","is-running","suggestions","suggestion-loading-indexes","welcome-screen","input-value","input-mode","input-tools-menu","on-finish-transcribe-with-audio"])])],14,Tr)])):e.createCommentVNode("",!0)],64))}}),qn=e.defineComponent({inheritAttrs:!1,__name:"CopilotPopupView",props:{width:{default:void 0},height:{default:void 0},clickOutsideToClose:{type:Boolean,default:!1},defaultOpen:{type:Boolean,default:!0},messages:{default:()=>[]},autoScroll:{type:[String,Boolean],default:!0},isRunning:{type:Boolean,default:!1},suggestions:{default:()=>[]},suggestionLoadingIndexes:{default:()=>[]},welcomeScreen:{type:Boolean,default:!0},attachments:{},dragOver:{type:Boolean},inputValue:{default:void 0},inputMode:{default:"input"},inputToolsMenu:{default:()=>[]},isConnecting:{type:Boolean},hasExplicitThreadId:{type:Boolean},onRemoveAttachment:{},onAddFile:{},onDragOver:{},onDragLeave:{},onDrop:{},onFinishTranscribeWithAudio:{type:Function,default:void 0}},emits:["submit-message","stop","input-change","select-suggestion","add-file","start-transcribe","cancel-transcribe","finish-transcribe"],setup(t,{emit:o}){const n=t,a=o,r=e.useAttrs(),s=e.getCurrentInstance(),i=e.computed(()=>s?.vnode.props??{});function l(p){const v=i.value[p];return Array.isArray(v)?v.length>0:!!v}const c=e.computed(()=>{const{defaultOpen:p,...v}=n;return v}),d=e.computed(()=>{const p={onSubmitMessage:v=>a("submit-message",v),onStop:()=>a("stop"),onInputChange:v=>a("input-change",v),onSelectSuggestion:(v,u)=>a("select-suggestion",v,u)};return l("onAddFile")&&(p.onAddFile=()=>a("add-file")),l("onStartTranscribe")&&(p.onStartTranscribe=()=>a("start-transcribe")),l("onCancelTranscribe")&&(p.onCancelTranscribe=()=>a("cancel-transcribe")),l("onFinishTranscribe")&&(p.onFinishTranscribe=()=>a("finish-transcribe")),p}),x=e.computed(()=>({...r,...c.value,...d.value}));return(p,v)=>(e.openBlock(),e.createBlock(ft,{"is-modal-default-open":t.defaultOpen},{default:e.withCtx(()=>[e.createVNode(Er,e.normalizeProps(e.guardReactiveProps(x.value)),e.createSlots({_:2},[p.$slots.header?{name:"header",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"header",e.normalizeProps(e.guardReactiveProps(u)))]),key:"0"}:void 0,p.$slots["toggle-button"]?{name:"toggle-button",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"toggle-button",e.normalizeProps(e.guardReactiveProps(u)))]),key:"1"}:void 0,p.$slots["message-view"]?{name:"message-view",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"message-view",e.normalizeProps(e.guardReactiveProps(u)))]),key:"2"}:void 0,p.$slots["scroll-view"]?{name:"scroll-view",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"scroll-view",e.normalizeProps(e.guardReactiveProps(u)))]),key:"3"}:void 0,p.$slots.feather?{name:"feather",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"feather",e.normalizeProps(e.guardReactiveProps(u)))]),key:"4"}:void 0,p.$slots["scroll-to-bottom-button"]?{name:"scroll-to-bottom-button",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"scroll-to-bottom-button",e.normalizeProps(e.guardReactiveProps(u)))]),key:"5"}:void 0,p.$slots.input?{name:"input",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"input",e.normalizeProps(e.guardReactiveProps(u)))]),key:"6"}:void 0,p.$slots["suggestion-view"]?{name:"suggestion-view",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"suggestion-view",e.normalizeProps(e.guardReactiveProps(u)))]),key:"7"}:void 0,p.$slots["welcome-screen"]?{name:"welcome-screen",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"welcome-screen",e.normalizeProps(e.guardReactiveProps(u)))]),key:"8"}:void 0,p.$slots["welcome-message"]?{name:"welcome-message",fn:e.withCtx(()=>[e.renderSlot(p.$slots,"welcome-message")]),key:"9"}:void 0]),1040)]),_:3},8,["is-modal-default-open"]))}}),Mr={"data-copilotkit":"",class:"cpk:h-full cpk:flex cpk:flex-col","data-testid":"copilot-popup-welcome-screen"},$r={class:"cpk:flex-1 cpk:flex cpk:flex-col cpk:items-center cpk:justify-center cpk:px-4"},Br={class:"cpk:text-xl cpk:sm:text-2xl cpk:font-medium cpk:text-foreground cpk:text-center"},Nr={class:"cpk:mb-4 cpk:flex cpk:justify-center cpk:px-4"},Kn=e.defineComponent({__name:"CopilotPopupWelcomeScreen",props:{modelValue:{default:""},isRunning:{type:Boolean,default:!1},inputMode:{default:"input"},inputToolsMenu:{default:()=>[]},onUpdateModelValue:{},onSubmitMessage:{},onStop:{},onAddFile:{type:Function,default:void 0},onStartTranscribe:{type:Function,default:void 0},onCancelTranscribe:{type:Function,default:void 0},onFinishTranscribe:{type:Function,default:void 0},onFinishTranscribeWithAudio:{type:Function,default:void 0},suggestions:{default:()=>[]},loadingIndexes:{default:()=>[]},onSelectSuggestion:{}},setup(t){const o=t,n=be(),a=e.computed(()=>n.value?.labels??Be),r=e.computed(()=>({modelValue:o.modelValue,isRunning:o.isRunning,inputMode:o.inputMode,inputToolsMenu:o.inputToolsMenu,onUpdateModelValue:o.onUpdateModelValue,onSubmitMessage:o.onSubmitMessage,onStop:o.onStop,onAddFile:o.onAddFile,onStartTranscribe:o.onStartTranscribe,onCancelTranscribe:o.onCancelTranscribe,onFinishTranscribe:o.onFinishTranscribe,onFinishTranscribeWithAudio:o.onFinishTranscribeWithAudio})),s=e.computed(()=>({suggestions:o.suggestions,loadingIndexes:o.loadingIndexes,onSelectSuggestion:o.onSelectSuggestion})),i=e.computed(()=>({...r.value,...s.value})),l=e.computed(()=>{const c={"onUpdate:modelValue":o.onUpdateModelValue,onSubmitMessage:o.onSubmitMessage,onStop:o.onStop};return o.onAddFile&&(c.onAddFile=o.onAddFile),o.onStartTranscribe&&(c.onStartTranscribe=o.onStartTranscribe),o.onCancelTranscribe&&(c.onCancelTranscribe=o.onCancelTranscribe),o.onFinishTranscribe&&(c.onFinishTranscribe=o.onFinishTranscribe),o.onFinishTranscribeWithAudio&&(c.onFinishTranscribeWithAudio=o.onFinishTranscribeWithAudio),c});return(c,d)=>e.renderSlot(c.$slots,"layout",e.normalizeProps(e.guardReactiveProps(i.value)),()=>[e.createElementVNode("div",Mr,[e.createElementVNode("div",$r,[e.renderSlot(c.$slots,"welcome-message",{},()=>[e.createElementVNode("h1",Br,e.toDisplayString(a.value.welcomeMessageText),1)])]),e.createElementVNode("div",null,[e.createElementVNode("div",Nr,[e.renderSlot(c.$slots,"suggestion-view",e.normalizeProps(e.guardReactiveProps(s.value)),()=>[e.createVNode(tt,{suggestions:t.suggestions,"loading-indexes":t.loadingIndexes,onSelectSuggestion:t.onSelectSuggestion},null,8,["suggestions","loading-indexes","onSelectSuggestion"])])]),e.renderSlot(c.$slots,"input",e.normalizeProps(e.guardReactiveProps(r.value)),()=>[e.createVNode(et,e.mergeProps({"model-value":t.modelValue,"is-running":t.isRunning,mode:t.inputMode,"tools-menu":t.inputToolsMenu,positioning:"static","show-disclaimer":!0},l.value),null,16,["model-value","is-running","mode","tools-menu"])])])])])}}),Vr=["aria-hidden"],Fr={class:"cpk:flex cpk:h-full cpk:w-full cpk:flex-col cpk:overflow-hidden"},Dr={class:"cpk:flex-1 cpk:overflow-hidden","data-sidebar-chat":""},Or=480,Lr=260,Pr=e.defineComponent({inheritAttrs:!1,__name:"CopilotSidebarViewInternal",props:{width:{default:void 0},messages:{default:()=>[]},autoScroll:{type:[String,Boolean],default:!0},isRunning:{type:Boolean,default:!1},suggestions:{default:()=>[]},suggestionLoadingIndexes:{default:()=>[]},welcomeScreen:{type:Boolean,default:!0},attachments:{},dragOver:{type:Boolean},inputValue:{default:void 0},inputMode:{default:"input"},inputToolsMenu:{default:()=>[]},isConnecting:{type:Boolean},hasExplicitThreadId:{type:Boolean},onRemoveAttachment:{},onAddFile:{},onDragOver:{},onDragLeave:{},onDrop:{},onFinishTranscribeWithAudio:{type:Function,default:void 0}},emits:["submit-message","stop","input-change","select-suggestion","add-file","start-transcribe","cancel-transcribe","finish-transcribe"],setup(t,{emit:o}){const n=t,a=o,r=e.useAttrs(),s=be(),i=e.getCurrentInstance(),l=e.computed(()=>i?.vnode.props??{}),c=e.ref(null),d=e.ref(n.width??Or);let x=null;const p=e.computed(()=>s.value?.isModalOpen??!1),v=e.computed(()=>n.width??d.value),u=e.computed(()=>s.value?.labels.modalHeaderTitle??Be.modalHeaderTitle),k=e.computed(()=>["cpk:fixed cpk:right-0 cpk:top-0 cpk:z-[1200] cpk:flex cpk:h-[100vh] cpk:h-[100dvh] cpk:max-h-screen cpk:w-full","cpk:border-l cpk:border-border cpk:bg-background cpk:text-foreground cpk:shadow-xl","cpk:transition-transform cpk:duration-300 cpk:ease-out",p.value?"cpk:translate-x-0":"cpk:translate-x-full cpk:pointer-events-none",r.class]),b=e.computed(()=>{const{class:R,...F}=r;return F}),h=e.computed(()=>g("onStop")),C=e.computed(()=>({"--sidebar-width":m(v.value),paddingTop:"env(safe-area-inset-top)",paddingBottom:"env(safe-area-inset-bottom)"})),f=e.computed(()=>`
|
|
76
|
-
@media (min-width: 768px) {
|
|
77
|
-
body {
|
|
78
|
-
margin-inline-end: ${y(v.value)};
|
|
79
|
-
transition: margin-inline-end ${Lr}ms ease;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
`);function g(R){const F=l.value[R];return Array.isArray(F)?F.length>0:!!F}function m(R){return typeof R=="number"?`${R}px`:R}function y(R){return typeof R=="number"?`${R}px`:R}function S(){if(n.width!==void 0||!c.value)return;const R=c.value.getBoundingClientRect().width;R>0&&(d.value=R)}function M(){s.value?.setModalOpen?.(!1)}function E(){s.value?.setModalOpen?.(!0)}function I(){s.value?.setModalOpen?.(!p.value)}function A(R){a("submit-message",R)}function N(){a("stop")}function _(R){a("input-change",R)}function z(R,F){a("select-suggestion",R,F)}function $(){a("add-file")}function U(){a("start-transcribe")}function G(){a("cancel-transcribe")}function B(){a("finish-transcribe")}const w=e.computed(()=>{const R={onSubmitMessage:A,onInputChange:_,onSelectSuggestion:z};return h.value&&(R.onStop=N),g("onAddFile")&&(R.onAddFile=$),g("onStartTranscribe")&&(R.onStartTranscribe=U),g("onCancelTranscribe")&&(R.onCancelTranscribe=G),g("onFinishTranscribe")&&(R.onFinishTranscribe=B),R});return e.watch(()=>n.width,R=>{if(R!==void 0){d.value=R;return}S()}),e.onMounted(async()=>{await e.nextTick(),S(),!(n.width!==void 0||!c.value||typeof ResizeObserver>"u")&&(x=new ResizeObserver(()=>{S()}),x.observe(c.value))}),e.onBeforeUnmount(()=>{x?.disconnect(),x=null}),(R,F)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[p.value?(e.openBlock(),e.createBlock(e.resolveDynamicComponent("style"),{key:0},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(f.value),1)]),_:1})):e.createCommentVNode("",!0),e.renderSlot(R.$slots,"toggle-button",{isOpen:p.value,toggle:I,open:E,close:M},()=>[e.createVNode(Vt)]),e.createElementVNode("aside",e.mergeProps({ref_key:"sidebarRef",ref:c,"data-copilotkit":"","data-copilot-sidebar":"",class:k.value,style:C.value,"aria-label":"Copilot chat sidebar","aria-hidden":!p.value,role:"complementary"},b.value),[e.createElementVNode("div",Fr,[e.renderSlot(R.$slots,"header",{title:u.value,onClose:M,isOpen:p.value},()=>[e.createVNode(Ft,{title:u.value},null,8,["title"])]),e.createElementVNode("div",Dr,[e.createVNode(at,e.mergeProps({messages:t.messages,"auto-scroll":t.autoScroll,"is-running":t.isRunning,suggestions:t.suggestions,"suggestion-loading-indexes":t.suggestionLoadingIndexes,"welcome-screen":t.welcomeScreen,"input-value":t.inputValue,"input-mode":t.inputMode,"input-tools-menu":t.inputToolsMenu,"on-finish-transcribe-with-audio":t.onFinishTranscribeWithAudio},w.value),e.createSlots({_:2},[R.$slots["message-view"]?{name:"message-view",fn:e.withCtx(W=>[e.renderSlot(R.$slots,"message-view",e.normalizeProps(e.guardReactiveProps(W)))]),key:"0"}:void 0,R.$slots["scroll-view"]?{name:"scroll-view",fn:e.withCtx(W=>[e.renderSlot(R.$slots,"scroll-view",e.normalizeProps(e.guardReactiveProps(W)))]),key:"1"}:void 0,R.$slots.feather?{name:"feather",fn:e.withCtx(()=>[e.renderSlot(R.$slots,"feather")]),key:"2"}:void 0,R.$slots["scroll-to-bottom-button"]?{name:"scroll-to-bottom-button",fn:e.withCtx(W=>[e.renderSlot(R.$slots,"scroll-to-bottom-button",e.normalizeProps(e.guardReactiveProps(W)))]),key:"3"}:void 0,R.$slots.input?{name:"input",fn:e.withCtx(W=>[e.renderSlot(R.$slots,"input",e.normalizeProps(e.guardReactiveProps(W)))]),key:"4"}:void 0,R.$slots["suggestion-view"]?{name:"suggestion-view",fn:e.withCtx(W=>[e.renderSlot(R.$slots,"suggestion-view",e.normalizeProps(e.guardReactiveProps(W)))]),key:"5"}:void 0,R.$slots["welcome-screen"]?{name:"welcome-screen",fn:e.withCtx(W=>[e.renderSlot(R.$slots,"welcome-screen",e.normalizeProps(e.guardReactiveProps(W)))]),key:"6"}:void 0,R.$slots["welcome-message"]?{name:"welcome-message",fn:e.withCtx(()=>[e.renderSlot(R.$slots,"welcome-message")]),key:"7"}:void 0]),1040,["messages","auto-scroll","is-running","suggestions","suggestion-loading-indexes","welcome-screen","input-value","input-mode","input-tools-menu","on-finish-transcribe-with-audio"])])])],16,Vr)],64))}}),Gn=e.defineComponent({inheritAttrs:!1,__name:"CopilotSidebarView",props:{width:{default:void 0},defaultOpen:{type:Boolean,default:!0},messages:{default:()=>[]},autoScroll:{type:[String,Boolean],default:!0},isRunning:{type:Boolean,default:!1},suggestions:{default:()=>[]},suggestionLoadingIndexes:{default:()=>[]},welcomeScreen:{type:Boolean,default:!0},attachments:{},dragOver:{type:Boolean},inputValue:{default:void 0},inputMode:{default:"input"},inputToolsMenu:{default:()=>[]},isConnecting:{type:Boolean},hasExplicitThreadId:{type:Boolean},onRemoveAttachment:{},onAddFile:{},onDragOver:{},onDragLeave:{},onDrop:{},onFinishTranscribeWithAudio:{type:Function,default:void 0}},emits:["submit-message","stop","input-change","select-suggestion","add-file","start-transcribe","cancel-transcribe","finish-transcribe"],setup(t,{emit:o}){const n=t,a=o,r=e.useAttrs(),s=e.getCurrentInstance(),i=e.computed(()=>s?.vnode.props??{}),l=e.computed(()=>{const{defaultOpen:p,...v}=n;return v}),c=e.computed(()=>({...r,...l.value,...x.value}));function d(p){const v=i.value[p];return Array.isArray(v)?v.length>0:!!v}const x=e.computed(()=>{const p={onSubmitMessage:v=>a("submit-message",v),onStop:()=>a("stop"),onInputChange:v=>a("input-change",v),onSelectSuggestion:(v,u)=>a("select-suggestion",v,u)};return d("onAddFile")&&(p.onAddFile=()=>a("add-file")),d("onStartTranscribe")&&(p.onStartTranscribe=()=>a("start-transcribe")),d("onCancelTranscribe")&&(p.onCancelTranscribe=()=>a("cancel-transcribe")),d("onFinishTranscribe")&&(p.onFinishTranscribe=()=>a("finish-transcribe")),p});return(p,v)=>(e.openBlock(),e.createBlock(ft,{"is-modal-default-open":t.defaultOpen},{default:e.withCtx(()=>[e.createVNode(Pr,e.normalizeProps(e.guardReactiveProps(c.value)),e.createSlots({_:2},[p.$slots.header?{name:"header",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"header",e.normalizeProps(e.guardReactiveProps(u)))]),key:"0"}:void 0,p.$slots["toggle-button"]?{name:"toggle-button",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"toggle-button",e.normalizeProps(e.guardReactiveProps(u)))]),key:"1"}:void 0,p.$slots["message-view"]?{name:"message-view",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"message-view",e.normalizeProps(e.guardReactiveProps(u)))]),key:"2"}:void 0,p.$slots["scroll-view"]?{name:"scroll-view",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"scroll-view",e.normalizeProps(e.guardReactiveProps(u)))]),key:"3"}:void 0,p.$slots.feather?{name:"feather",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"feather",e.normalizeProps(e.guardReactiveProps(u)))]),key:"4"}:void 0,p.$slots["scroll-to-bottom-button"]?{name:"scroll-to-bottom-button",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"scroll-to-bottom-button",e.normalizeProps(e.guardReactiveProps(u)))]),key:"5"}:void 0,p.$slots.input?{name:"input",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"input",e.normalizeProps(e.guardReactiveProps(u)))]),key:"6"}:void 0,p.$slots["suggestion-view"]?{name:"suggestion-view",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"suggestion-view",e.normalizeProps(e.guardReactiveProps(u)))]),key:"7"}:void 0,p.$slots["welcome-screen"]?{name:"welcome-screen",fn:e.withCtx(u=>[e.renderSlot(p.$slots,"welcome-screen",e.normalizeProps(e.guardReactiveProps(u)))]),key:"8"}:void 0,p.$slots["welcome-message"]?{name:"welcome-message",fn:e.withCtx(()=>[e.renderSlot(p.$slots,"welcome-message")]),key:"9"}:void 0]),1040)]),_:3},8,["is-modal-default-open"]))}}),Ur={"data-copilotkit":"",class:"cpk:h-full cpk:flex cpk:flex-col","data-testid":"copilot-sidebar-welcome-screen"},zr={class:"cpk:flex-1 cpk:flex cpk:flex-col cpk:items-center cpk:justify-center cpk:px-4"},jr={class:"cpk:text-xl cpk:sm:text-2xl cpk:font-medium cpk:text-foreground cpk:text-center"},_r={class:"cpk:px-8 cpk:pb-4"},Hr={class:"cpk:max-w-3xl cpk:mx-auto"},Wr={class:"cpk:mb-4 cpk:flex cpk:justify-center"},Jn=e.defineComponent({__name:"CopilotSidebarWelcomeScreen",props:{modelValue:{default:""},isRunning:{type:Boolean,default:!1},inputMode:{default:"input"},inputToolsMenu:{default:()=>[]},onUpdateModelValue:{},onSubmitMessage:{},onStop:{},onAddFile:{type:Function,default:void 0},onStartTranscribe:{type:Function,default:void 0},onCancelTranscribe:{type:Function,default:void 0},onFinishTranscribe:{type:Function,default:void 0},onFinishTranscribeWithAudio:{type:Function,default:void 0},suggestions:{default:()=>[]},loadingIndexes:{default:()=>[]},onSelectSuggestion:{}},setup(t){const o=t,n=be(),a=e.computed(()=>n.value?.labels??Be),r=e.computed(()=>({modelValue:o.modelValue,isRunning:o.isRunning,inputMode:o.inputMode,inputToolsMenu:o.inputToolsMenu,onUpdateModelValue:o.onUpdateModelValue,onSubmitMessage:o.onSubmitMessage,onStop:o.onStop,onAddFile:o.onAddFile,onStartTranscribe:o.onStartTranscribe,onCancelTranscribe:o.onCancelTranscribe,onFinishTranscribe:o.onFinishTranscribe,onFinishTranscribeWithAudio:o.onFinishTranscribeWithAudio})),s=e.computed(()=>({suggestions:o.suggestions,loadingIndexes:o.loadingIndexes,onSelectSuggestion:o.onSelectSuggestion})),i=e.computed(()=>({...r.value,...s.value})),l=e.computed(()=>{const c={"onUpdate:modelValue":o.onUpdateModelValue,onSubmitMessage:o.onSubmitMessage,onStop:o.onStop};return o.onAddFile&&(c.onAddFile=o.onAddFile),o.onStartTranscribe&&(c.onStartTranscribe=o.onStartTranscribe),o.onCancelTranscribe&&(c.onCancelTranscribe=o.onCancelTranscribe),o.onFinishTranscribe&&(c.onFinishTranscribe=o.onFinishTranscribe),o.onFinishTranscribeWithAudio&&(c.onFinishTranscribeWithAudio=o.onFinishTranscribeWithAudio),c});return(c,d)=>e.renderSlot(c.$slots,"layout",e.normalizeProps(e.guardReactiveProps(i.value)),()=>[e.createElementVNode("div",Ur,[e.createElementVNode("div",zr,[e.renderSlot(c.$slots,"welcome-message",{},()=>[e.createElementVNode("h1",jr,e.toDisplayString(a.value.welcomeMessageText),1)])]),e.createElementVNode("div",_r,[e.createElementVNode("div",Hr,[e.createElementVNode("div",Wr,[e.renderSlot(c.$slots,"suggestion-view",e.normalizeProps(e.guardReactiveProps(s.value)),()=>[e.createVNode(tt,{suggestions:t.suggestions,"loading-indexes":t.loadingIndexes,onSelectSuggestion:t.onSelectSuggestion},null,8,["suggestions","loading-indexes","onSelectSuggestion"])])]),e.renderSlot(c.$slots,"input",e.normalizeProps(e.guardReactiveProps(r.value)),()=>[e.createVNode(et,e.mergeProps({"model-value":t.modelValue,"is-running":t.isRunning,mode:t.inputMode,"tools-menu":t.inputToolsMenu,positioning:"static","show-disclaimer":!0},l.value),null,16,["model-value","is-running","mode","tools-menu"])])])])])])}}),qr=e.defineComponent({__name:"CopilotPopup",props:{width:{default:void 0},height:{default:void 0},clickOutsideToClose:{type:Boolean,default:!1},defaultOpen:{type:Boolean,default:!0},agentId:{},threadId:{},throttleMs:{},labels:{},attachments:{},onError:{},autoScroll:{type:[String,Boolean],default:!0},welcomeScreen:{type:Boolean,default:!0},inputValue:{default:void 0},inputMode:{default:"input"},inputToolsMenu:{default:()=>[]},isConnecting:{type:Boolean},hasExplicitThreadId:{type:Boolean},onFinishTranscribeWithAudio:{type:Function,default:void 0}},emits:["submit-message","stop","input-change","select-suggestion","add-file","start-transcribe","cancel-transcribe","finish-transcribe"],setup(t){function o(s){return{onSubmitMessage:s.onSubmitMessage,onInputChange:s.onInputChange,onSelectSuggestion:s.onSelectSuggestion,...s.onStop?{onStop:s.onStop}:{},...s.onAddFile?{onAddFile:s.onAddFile}:{},...s.onStartTranscribe?{onStartTranscribe:s.onStartTranscribe}:{},...s.onCancelTranscribe?{onCancelTranscribe:s.onCancelTranscribe}:{},...s.onFinishTranscribe?{onFinishTranscribe:s.onFinishTranscribe}:{}}}const n=t,a=ot(),r=e.computed(()=>a.value.checkFeature("popup"));return e.watch(r,s=>{s||console.warn('[CopilotKit] Warning: "popup" feature is not licensed. Visit copilotkit.ai/pricing')},{immediate:!0}),(s,i)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[r.value?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(Mt,{key:0,"feature-name":"Popup"})),e.createVNode($t,e.mergeProps(n,{onSubmitMessage:i[0]||(i[0]=l=>s.$emit("submit-message",l)),onStop:i[1]||(i[1]=l=>s.$emit("stop")),onInputChange:i[2]||(i[2]=l=>s.$emit("input-change",l)),onSelectSuggestion:i[3]||(i[3]=(l,c)=>s.$emit("select-suggestion",l,c)),onAddFile:i[4]||(i[4]=l=>s.$emit("add-file")),onStartTranscribe:i[5]||(i[5]=l=>s.$emit("start-transcribe")),onCancelTranscribe:i[6]||(i[6]=l=>s.$emit("cancel-transcribe")),onFinishTranscribe:i[7]||(i[7]=l=>s.$emit("finish-transcribe"))}),{"chat-view":e.withCtx(l=>[s.$slots["chat-view"]?e.renderSlot(s.$slots,"chat-view",e.normalizeProps(e.mergeProps({key:0},l))):(e.openBlock(),e.createBlock(qn,e.mergeProps({key:1,messages:l.messages,"auto-scroll":l.autoScroll,"is-running":l.isRunning,suggestions:l.suggestions,"suggestion-loading-indexes":l.suggestionLoadingIndexes,"welcome-screen":l.welcomeScreen,"input-value":l.inputValue,"input-mode":l.inputMode,"input-tools-menu":l.inputToolsMenu,width:t.width,height:t.height,"click-outside-to-close":t.clickOutsideToClose,"default-open":t.defaultOpen,"on-finish-transcribe-with-audio":l.onFinishTranscribeWithAudio},o(l)),e.createSlots({"welcome-screen":e.withCtx(c=>[s.$slots["welcome-screen"]?e.renderSlot(s.$slots,"welcome-screen",e.normalizeProps(e.mergeProps({key:0},c))):(e.openBlock(),e.createBlock(Kn,e.normalizeProps(e.mergeProps({key:1},c)),e.createSlots({_:2},[s.$slots["welcome-message"]?{name:"welcome-message",fn:e.withCtx(()=>[e.renderSlot(s.$slots,"welcome-message")]),key:"0"}:void 0,s.$slots["suggestion-view"]?{name:"suggestion-view",fn:e.withCtx(d=>[e.renderSlot(s.$slots,"suggestion-view",e.normalizeProps(e.guardReactiveProps(d)))]),key:"1"}:void 0,s.$slots.input?{name:"input",fn:e.withCtx(d=>[e.renderSlot(s.$slots,"input",e.normalizeProps(e.guardReactiveProps(d)))]),key:"2"}:void 0]),1040))]),_:2},[s.$slots.header?{name:"header",fn:e.withCtx(c=>[e.renderSlot(s.$slots,"header",e.normalizeProps(e.guardReactiveProps(c)))]),key:"0"}:void 0,s.$slots["toggle-button"]?{name:"toggle-button",fn:e.withCtx(c=>[e.renderSlot(s.$slots,"toggle-button",e.normalizeProps(e.guardReactiveProps(c)))]),key:"1"}:void 0,s.$slots["message-view"]?{name:"message-view",fn:e.withCtx(c=>[e.renderSlot(s.$slots,"message-view",e.normalizeProps(e.guardReactiveProps(c)))]),key:"2"}:void 0,s.$slots.input?{name:"input",fn:e.withCtx(c=>[e.renderSlot(s.$slots,"input",e.normalizeProps(e.guardReactiveProps(c)))]),key:"3"}:void 0,s.$slots["suggestion-view"]?{name:"suggestion-view",fn:e.withCtx(c=>[e.renderSlot(s.$slots,"suggestion-view",e.normalizeProps(e.guardReactiveProps(c)))]),key:"4"}:void 0]),1040,["messages","auto-scroll","is-running","suggestions","suggestion-loading-indexes","welcome-screen","input-value","input-mode","input-tools-menu","width","height","click-outside-to-close","default-open","on-finish-transcribe-with-audio"]))]),_:3},16)],64))}}),Kr=e.defineComponent({__name:"CopilotSidebar",props:{width:{default:void 0},defaultOpen:{type:Boolean,default:!0},agentId:{},threadId:{},throttleMs:{},labels:{},attachments:{},onError:{},autoScroll:{type:[String,Boolean],default:!0},welcomeScreen:{type:Boolean,default:!0},inputValue:{default:void 0},inputMode:{default:"input"},inputToolsMenu:{default:()=>[]},isConnecting:{type:Boolean},hasExplicitThreadId:{type:Boolean},onFinishTranscribeWithAudio:{type:Function,default:void 0}},emits:["submit-message","stop","input-change","select-suggestion","add-file","start-transcribe","cancel-transcribe","finish-transcribe"],setup(t){function o(s){return{onSubmitMessage:s.onSubmitMessage,onInputChange:s.onInputChange,onSelectSuggestion:s.onSelectSuggestion,...s.onStop?{onStop:s.onStop}:{},...s.onAddFile?{onAddFile:s.onAddFile}:{},...s.onStartTranscribe?{onStartTranscribe:s.onStartTranscribe}:{},...s.onCancelTranscribe?{onCancelTranscribe:s.onCancelTranscribe}:{},...s.onFinishTranscribe?{onFinishTranscribe:s.onFinishTranscribe}:{}}}const n=t,a=ot(),r=e.computed(()=>a.value.checkFeature("sidebar"));return e.watch(r,s=>{s||console.warn('[CopilotKit] Warning: "sidebar" feature is not licensed. Visit copilotkit.ai/pricing')},{immediate:!0}),(s,i)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[r.value?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(Mt,{key:0,"feature-name":"Sidebar"})),e.createVNode($t,e.mergeProps(n,{onSubmitMessage:i[0]||(i[0]=l=>s.$emit("submit-message",l)),onStop:i[1]||(i[1]=l=>s.$emit("stop")),onInputChange:i[2]||(i[2]=l=>s.$emit("input-change",l)),onSelectSuggestion:i[3]||(i[3]=(l,c)=>s.$emit("select-suggestion",l,c)),onAddFile:i[4]||(i[4]=l=>s.$emit("add-file")),onStartTranscribe:i[5]||(i[5]=l=>s.$emit("start-transcribe")),onCancelTranscribe:i[6]||(i[6]=l=>s.$emit("cancel-transcribe")),onFinishTranscribe:i[7]||(i[7]=l=>s.$emit("finish-transcribe"))}),{"chat-view":e.withCtx(l=>[s.$slots["chat-view"]?e.renderSlot(s.$slots,"chat-view",e.normalizeProps(e.mergeProps({key:0},l))):(e.openBlock(),e.createBlock(Gn,e.mergeProps({key:1,messages:l.messages,"auto-scroll":l.autoScroll,"is-running":l.isRunning,suggestions:l.suggestions,"suggestion-loading-indexes":l.suggestionLoadingIndexes,"welcome-screen":l.welcomeScreen,"input-value":l.inputValue,"input-mode":l.inputMode,"input-tools-menu":l.inputToolsMenu,width:t.width,"default-open":t.defaultOpen,"on-finish-transcribe-with-audio":l.onFinishTranscribeWithAudio},o(l)),e.createSlots({"welcome-screen":e.withCtx(c=>[s.$slots["welcome-screen"]?e.renderSlot(s.$slots,"welcome-screen",e.normalizeProps(e.mergeProps({key:0},c))):(e.openBlock(),e.createBlock(Jn,e.normalizeProps(e.mergeProps({key:1},c)),e.createSlots({_:2},[s.$slots["welcome-message"]?{name:"welcome-message",fn:e.withCtx(()=>[e.renderSlot(s.$slots,"welcome-message")]),key:"0"}:void 0,s.$slots["suggestion-view"]?{name:"suggestion-view",fn:e.withCtx(d=>[e.renderSlot(s.$slots,"suggestion-view",e.normalizeProps(e.guardReactiveProps(d)))]),key:"1"}:void 0,s.$slots.input?{name:"input",fn:e.withCtx(d=>[e.renderSlot(s.$slots,"input",e.normalizeProps(e.guardReactiveProps(d)))]),key:"2"}:void 0]),1040))]),_:2},[s.$slots.header?{name:"header",fn:e.withCtx(c=>[e.renderSlot(s.$slots,"header",e.normalizeProps(e.guardReactiveProps(c)))]),key:"0"}:void 0,s.$slots["toggle-button"]?{name:"toggle-button",fn:e.withCtx(c=>[e.renderSlot(s.$slots,"toggle-button",e.normalizeProps(e.guardReactiveProps(c)))]),key:"1"}:void 0,s.$slots["message-view"]?{name:"message-view",fn:e.withCtx(c=>[e.renderSlot(s.$slots,"message-view",e.normalizeProps(e.guardReactiveProps(c)))]),key:"2"}:void 0,s.$slots.input?{name:"input",fn:e.withCtx(c=>[e.renderSlot(s.$slots,"input",e.normalizeProps(e.guardReactiveProps(c)))]),key:"3"}:void 0,s.$slots["suggestion-view"]?{name:"suggestion-view",fn:e.withCtx(c=>[e.renderSlot(s.$slots,"suggestion-view",e.normalizeProps(e.guardReactiveProps(c)))]),key:"4"}:void 0]),1040,["messages","auto-scroll","is-running","suggestions","suggestion-loading-indexes","welcome-screen","input-value","input-mode","input-tools-menu","width","default-open","on-finish-transcribe-with-audio"]))]),_:3},16)],64))}}),Gr=Object.assign($t,{View:at}),Jr=Object.assign(Vt,{OpenIcon:Nt,CloseIcon:Bt}),Qr=Object.assign(Ft,{Title:Wn,CloseButton:Hn}),Xr=Object.assign(qn,{WelcomeScreen:Kn}),Yr=Object.assign(Gn,{WelcomeScreen:Jn});function Zr(t){const{copilotkit:o}=xe(),n=e.computed(()=>e.toValue(t.description)),a=e.computed(()=>e.toValue(t.value)),r=e.computed(()=>typeof a.value=="string"?a.value:JSON.stringify(a.value));e.watch([()=>o.value,n,r],(s,i,l)=>{const c=o.value,d=c.addContext({description:n.value,value:r.value});l(()=>c.removeContext(d))},{immediate:!0})}const ei=[];function Dt(t,o){const{copilotkit:n}=xe(),a=o??ei;e.watch([()=>t.name,()=>t.available,()=>a.length,...a],(r,s,i)=>{const l=n.value,c=t.name;l.getTool({toolName:c,agentId:t.agentId})&&(console.warn(`Tool '${c}' already exists for agent '${t.agentId||"global"}'. Overriding with latest registration.`),l.removeTool(c,t.agentId)),l.addTool(t),t.render&&l.addHookRenderToolCall({name:c,args:t.parameters,agentId:t.agentId,render:t.render}),i(()=>{l.removeTool(c,t.agentId)})},{immediate:!0})}function ti(t,o){const n=`Use this tool to display the "${t.name}" component in the chat. This tool renders a visual UI component for the user.`,a=t.description?`${n}
|
|
83
|
-
|
|
84
|
-
${t.description}`:n;Dt({name:t.name,description:a,parameters:t.parameters,render:({args:r})=>{const s=t.render;return e.h(s,r)},agentId:t.agentId},o)}const ni=[];function Qn(t,o){const{copilotkit:n}=xe(),a=o??ni;e.watch([()=>n.value,()=>t.name,()=>t.agentId,()=>a.length,...a],()=>{const r=i=>typeof t.render=="function"?t.render(i):e.h(t.render,i),s=t.name==="*"&&!t.parameters?ut({name:"*",render:i=>r({...i,parameters:i.args}),...t.agentId?{agentId:t.agentId}:{}}):ut({name:t.name,args:t.parameters,render:i=>r({...i,parameters:i.args}),...t.agentId?{agentId:t.agentId}:{}});n.value.addHookRenderToolCall(s)},{immediate:!0})}const tn=new Set;function oi(t){switch(t){case oe.ToolCallStatus.Complete:return"complete";case oe.ToolCallStatus.Executing:return"executing";case oe.ToolCallStatus.InProgress:return"inProgress";default:{const o=String(t);return tn.has(o)||(tn.add(o),console.warn(`[CopilotKit] Unknown ToolCallStatus "${o}" in default tool-call renderer; falling back to "inProgress".`)),"inProgress"}}}function bt(t){const o=t.parameters!==void 0?t.parameters:t.args,n=t.status,a=n==="inProgress"||n==="executing"||n==="complete"?n:oi(n);return{name:t.name,toolCallId:t.toolCallId,parameters:o,status:a,result:t.result}}function nn(t){try{return JSON.stringify(t,null,2)}catch(o){console.warn("[CopilotKit] Failed to JSON.stringify tool-call payload for default renderer; falling back to String():",o);try{return String(t)}catch(n){return console.warn("[CopilotKit] safeStringifyForPre: value could not be stringified:",n),"[unserializable]"}}}const ai=e.defineComponent({props:{name:{type:String,required:!0},toolCallId:{type:String,required:!0},parameters:{type:null,required:!1,default:void 0},status:{type:String,required:!0},result:{type:null,required:!1,default:void 0}},setup(t){const o=e.ref(!1);return()=>{const n=t.status==="inProgress"||t.status==="executing",a=t.status==="complete",r=n?"Running":a?"Done":t.status;return e.h("div",{"data-testid":"copilot-tool-render","data-tool-name":t.name,"data-tool-call-id":t.toolCallId,"data-status":t.status,"data-args":on(t.parameters),"data-result":on(t.result),style:{marginTop:"8px",paddingBottom:"8px"}},[e.h("div",{style:{borderRadius:"12px",border:"1px solid #e4e4e7",backgroundColor:"#fafafa",padding:"14px 16px"}},[e.h("button",{type:"button","aria-expanded":String(o.value),onClick:()=>{o.value=!o.value},style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",gap:"10px",cursor:"pointer",border:"none",padding:0,margin:0,background:"transparent",textAlign:"left"}},[e.h("span",{"data-testid":"copilot-tool-render-name",style:{fontWeight:"600"}},t.name),e.h("span",{"data-testid":"copilot-tool-render-status"},r)]),o.value?e.h("div",{style:{marginTop:"12px"}},[e.h("div","Arguments"),e.h("pre",nn(t.parameters??{})),t.result!==void 0?e.h("div",[e.h("div","Result"),e.h("pre",typeof t.result=="string"?t.result:nn(t.result))]):null]):null])])}}});function on(t){if(t==null)return"";if(typeof t=="string")return t;try{return JSON.stringify(t)}catch(o){console.warn("[CopilotKit] Failed to JSON.stringify tool-call payload for data-* attribute; falling back to String():",o);try{return String(t)}catch(n){return console.warn("[CopilotKit] safeStringifyForAttr: value could not be stringified:",n),""}}}function si(t,o){const n=t?.render;let a;if(typeof n=="function"){const r=n;a=(s=>{const i=bt(s);return r(i)})}else if(n){const r=n;a=(s=>{const i=bt(s);return e.h(r,{name:i.name,toolCallId:i.toolCallId,parameters:i.parameters,status:i.status,result:i.result})})}else a=(r=>{const s=bt(r);return e.h(ai,{name:s.name,toolCallId:s.toolCallId,parameters:s.parameters,status:s.status,result:s.result})});Qn({name:"*",render:a},o)}function ri(t,o){const{copilotkit:n}=xe(),a=e.ref(null),r=async c=>{a.value&&(a.value(c),a.value=null)},l={...t,handler:async()=>new Promise(c=>{a.value=c}),render:c=>{const d=t.render;return c.status==="inProgress"?e.h(d,{...c,name:t.name,description:t.description||"",respond:void 0}):c.status==="executing"?e.h(d,{...c,name:t.name,description:t.description||"",respond:r}):c.status==="complete"?e.h(d,{...c,name:t.name,description:t.description||"",respond:void 0}):e.h(d,c)}};Dt(l,o),e.onScopeDispose(()=>{n.value.removeHookRenderToolCall(t.name,t.agentId)})}function ii(t){return"instructions"in t}function li(t){return t.map(o=>({...o,isLoading:o.isLoading??!1}))}function ci(t,o){const{copilotkit:n}=xe(),a=be(),r=o??[],s=e.computed(()=>a.value?.agentId??j.DEFAULT_AGENT_ID),i=e.computed(()=>t?t.consumerAgentId:void 0),l=e.computed(()=>{if(!t||t.available==="disabled")return null;if(ii(t))return{...t};const h=li(t.suggestions);return{...t,suggestions:h}}),c=e.computed(()=>l.value?JSON.stringify(l.value):null),d=e.computed(()=>{if(!l.value)return s.value;const h=l.value.consumerAgentId;return!h||h==="*"?s.value:h}),x=e.computed(()=>i.value===void 0||i.value==="*"),p=e.ref(!1),v=e.ref(null),u=e.ref(null),k=()=>{if(!p.value||!x.value)return;if(Object.values(n.value.agents??{}).some(C=>!!C.agentId&&C.isRunning)){v.value=setTimeout(()=>{v.value=null,k()},0);return}p.value=!1,b()},b=()=>{if(l.value){if(x.value){let h=!1;const C=Object.values(n.value.agents??{});for(const f of C){const g=f.agentId;g&&(f.isRunning?h=!0:n.value.reloadSuggestions(g))}p.value=h,h&&v.value===null&&(v.value=setTimeout(()=>{v.value=null,k()},0));return}d.value&&n.value.reloadSuggestions(d.value)}};e.watch([()=>n.value,c],([h,C],f,g)=>{if(!C||!l.value)return;const m=n.value,y=l.value,S=m.addSuggestionsConfig(y);b(),g(()=>m.removeSuggestionsConfig(S))},{immediate:!0}),e.watch([l,c],([h,C])=>{if(!h){u.value=null;return}C&&u.value===C||(C&&(u.value=C),b())},{immediate:!1}),e.watch([l,()=>r.length,...r],([h])=>{!h||r.length===0||b()},{immediate:!0}),e.watch([()=>n.value,p],(h,C,f)=>{f(()=>{v.value!==null&&(clearTimeout(v.value),v.value=null)})},{immediate:!0}),e.watch([()=>n.value,x],([h,C],f,g)=>{if(!C)return;const m=Object.values(h.agents??{}).filter(y=>!!y).map(y=>y.subscribe({onRunStartedEvent:k,onRunFinishedEvent:k,onRunFinalized:k,onRunFailed:k,onRunErrorEvent:k}));g(()=>{for(const y of m)y.unsubscribe()})},{immediate:!0})}const Xn="on_interrupt";function ui(t){return(typeof t=="object"||typeof t=="function")&&t!==null&&typeof Reflect.get(t,"then")=="function"}function di(t){return t instanceof Promise?t:new Promise((o,n)=>{try{t.then(o,n)}catch(a){n(a)}})}function yt(t){return t.kind==="legacy"?t.event:{name:Xn,value:t.interrupts[0]}}function pi(t={}){const{copilotkit:o}=xe(),{agent:n}=gt({agentId:t.agentId}),a=e.shallowRef(null),r=e.shallowRef(null),s={};e.watch(n,(u,k,b)=>{if(!u){a.value=null,r.value=null;return}let h=null,C=null;const f=u.subscribe({onCustomEvent:({event:g})=>{g.name===Xn&&(h={name:g.name,value:g.value})},onRunFinishedEvent:g=>{g.outcome==="interrupt"&&(C=g.interrupts)},onRunStartedEvent:()=>{h=null,C=null;for(const g of Object.keys(s))delete s[g];a.value=null},onRunFinalized:()=>{C&&C.length>0?a.value={kind:"standard",interrupts:C}:h&&(a.value={kind:"legacy",event:h}),h=null,C=null},onRunFailed:()=>{h=null,C=null;for(const g of Object.keys(s))delete s[g];a.value=null}});b(()=>f.unsubscribe())},{immediate:!0});const i=async u=>{if(!u.every(f=>s[f.id]))return;const b=u.find(f=>qe.isInterruptExpired(f));if(b){console.error(`[CopilotKit] useInterrupt: interrupt ${b.id} expired at ${b.expiresAt}; not resuming.`);for(const f of Object.keys(s))delete s[f];a.value=null;return}const h=qe.buildResumeArray(u,s);for(const f of Object.keys(s))delete s[f];const C=n.value;if(C)try{return await o.value.runAgent({agent:C,resume:h})}catch(f){throw console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing",f),a.value=null,f}},l=async(u,k)=>{const b=a.value;if(!b)return;const h=n.value;if(!h)return;if(b.kind==="legacy"){const f=b.event.value;try{return await o.value.runAgent({agent:h,forwardedProps:{command:{resume:u,interruptEvent:f}}})}catch(g){throw console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing",g),a.value=null,g}}b.interrupts.length>1&&k===void 0&&console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${b.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);const C=k??b.interrupts[0]?.id;if(C)return s[C]={status:"resolved",payload:u},i(b.interrupts)},c=async u=>{const k=a.value;if(!k)return;if(k.kind==="legacy"){console.warn("[CopilotKit] useInterrupt: cancel() is not supported for legacy on_interrupt interrupts; dismissing."),a.value=null;return}k.interrupts.length>1&&u===void 0&&console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${k.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);const b=u??k.interrupts[0]?.id;if(b)return s[b]={status:"cancelled"},i(k.interrupts)},d=l,x=c;e.watch(a,(u,k,b)=>{if(!u){r.value=null;return}const h=yt(u);if(t.enabled&&!t.enabled(h)){r.value=null;return}const C=t.handler;if(!C){r.value=null;return}let f=!1;const g=C({event:h,interrupt:u.kind==="standard"?u.interrupts[0]??null:null,interrupts:u.kind==="standard"?u.interrupts:[],resolve:l,cancel:c});ui(g)?di(g).then(m=>{f||(r.value=m)}).catch(m=>{f||(console.error("[CopilotKit] useInterrupt handler failed:",m),r.value=null)}):r.value=g,b(()=>{f=!0})},{immediate:!0});const p=e.computed(()=>a.value?yt(a.value):null),v=e.computed(()=>{const u=a.value;if(!u)return null;const k=yt(u);return t.enabled&&!t.enabled(k)?null:{event:k,interrupt:u.kind==="standard"?u.interrupts[0]??null:null,interrupts:u.kind==="standard"?u.interrupts:[],result:r.value,resolve:l,cancel:c}});return e.watch([()=>o.value,v,()=>t.renderInChat!==!1],([u,k,b],h,C)=>{if(!b)return;u.setInterruptState(k);const f=k;C(()=>{u.interruptState===f&&u.setInterruptState(null)})},{immediate:!0}),e.onScopeDispose(()=>{const u=o.value;t.renderInChat!==!1&&u.interruptState===v.value&&u.setInterruptState(null)}),{interrupt:p,result:r,hasInterrupt:e.computed(()=>v.value!==null),resolve:l,resolveInterrupt:d,cancel:c,cancelInterrupt:x,slotProps:v}}function mi(t){const{agent:o}=gt({agentId:t});return e.computed(()=>{const n=o.value;if(n&&"capabilities"in n)return n.capabilities})}function fi(){const{copilotkit:t}=xe(),o=be();return function(a){const r=o.value;if(!r)return null;const s=r.agentId||j.DEFAULT_AGENT_ID,{threadId:i}=r,l=t.value,c=[...l.renderCustomMessages].filter(y=>y.agentId===void 0||y.agentId===s).sort((y,S)=>{const M=y.agentId!==void 0,E=S.agentId!==void 0;return M===E?0:M?-1:1});if(!c.length)return null;const{message:d,position:x}=a,p=l.getRunIdForMessage(s,i,d.id)??l.getRunIdsForThread(s,i).slice(-1)[0],v=p??`missing-run-id:${d.id}`,u=l.getAgent(s);if(!u)return null;const k=p?u.messages.filter(y=>l.getRunIdForMessage(s,i,y.id)===p).map(y=>y.id):[d.id],b=u.messages.findIndex(y=>y.id===d.id);b<0&&console.warn(`[CopilotKit] useRenderCustomMessages: message "${d.id}" not found in agent "${s}" messages`);const h=Math.max(0,b),C=p?Math.max(k.indexOf(d.id),0):0,f=p?k.length:1,g=p?l.getStateByRun(s,i,p):void 0,m={message:d,position:x,runId:v,messageIndex:h,messageIndexInRun:C,numberOfMessagesInRun:f,agentId:s,stateSnapshot:g};for(const y of c)if(y.render)return{renderer:y.render,props:m};return null}}function gi(){const{copilotkit:t}=xe(),o=be(),n=e.computed(()=>o.value?.agentId??j.DEFAULT_AGENT_ID),a=e.computed(()=>[...t.value.renderActivityMessages]);function r(i){const l=a.value;if(!l.length)return null;const c=l.filter(d=>d.activityType===i);return c.find(d=>d.agentId===n.value)??c.find(d=>d.agentId===void 0)??l.find(d=>d.activityType==="*")??null}function s(i){const l=r(i.activityType);if(!l)return null;const c=l.content.safeParse(i.content);if(!c.success)return console.warn(`Failed to parse content for activity message '${i.activityType}':`,c.error),null;const d=t.value.getAgent(n.value);return{renderer:l.render,props:{activityType:i.activityType,content:c.data,message:i,agent:d}}}return{renderActivityMessage:s,findRenderer:r}}exports.A2UIActivityContentSchema=po;exports.A2UISurfaceActivityType=uo;exports.CopilotChat=Gr;exports.CopilotChatDefaultLabels=Be;exports.CopilotChatToggleButton=Jr;exports.CopilotChatToggleButtonCloseIcon=Bt;exports.CopilotChatToggleButtonOpenIcon=Nt;exports.CopilotKitCoreVue=pn;exports.CopilotModalHeader=Qr;exports.CopilotPopupView=Xr;exports.CopilotSidebarView=Yr;exports.GenerateSandboxedUiArgsSchema=yn;exports.LicenseContextKey=Rt;exports.MCPAppsActivityContentSchema=un;exports.MCPAppsActivityRenderer=dn;exports.MCPAppsActivityType=cn;exports.OpenGenerativeUIActivityRenderer=Cn;exports.OpenGenerativeUIActivityType=kn;exports.OpenGenerativeUIContentSchema=bn;exports.OpenGenerativeUIRenderer=wn;exports.OpenGenerativeUIToolRenderer=xn;exports.UseAgentUpdate=Vn;exports._sfc_main=Rn;exports._sfc_main$1=Bn;exports._sfc_main$10=tt;exports._sfc_main$11=Mn;exports._sfc_main$12=Un;exports._sfc_main$13=at;exports._sfc_main$14=sn;exports._sfc_main$15=na;exports._sfc_main$16=qr;exports._sfc_main$17=Kr;exports._sfc_main$18=hr;exports._sfc_main$2=St;exports._sfc_main$3=fr;exports._sfc_main$4=Nn;exports._sfc_main$5=ft;exports._sfc_main$6=et;exports._sfc_main$7=zn;exports._sfc_main$8=Pn;exports._sfc_main$9=jn;exports.createA2UIMessageRenderer=mn;exports.createDefaultLicenseRef=Sn;exports.defineToolCallRenderer=ut;exports.extractCompleteStyles=gn;exports.getOperationSurfaceId=Ct;exports.processPartialHtml=hn;exports.useAgent=gt;exports.useAgentContext=Zr;exports.useAttachments=Dn;exports.useCapabilities=mi;exports.useComponent=ti;exports.useConfigureSuggestions=ci;exports.useCopilotChatConfiguration=be;exports.useCopilotKit=xe;exports.useDefaultRenderTool=si;exports.useFrontendTool=Dt;exports.useHumanInTheLoop=ri;exports.useInterrupt=pi;exports.useKatexStyles=$n;exports.useKeyboardHeight=On;exports.useLicenseContext=ot;exports.useRenderActivityMessage=gi;exports.useRenderCustomMessages=fi;exports.useRenderTool=Qn;exports.useSandboxFunctions=vn;exports.useSuggestions=Fn;exports.useThreads=_n;exports.vueBasicCatalog=Ke;
|
|
85
|
-
//# sourceMappingURL=use-render-activity-message-CIlNtfvE.cjs.map
|