@m6d/cortex-react 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -167,6 +167,8 @@ export type LandingContext<View> = {
167
167
  */
168
168
  send: (prompt: string) => void;
169
169
  openThread: (thread: ThreadSummary) => void;
170
+ /** Shows the whole history: its screen, or the sidebar in full mode, as the header's `openHistory`. */
171
+ openHistory: () => void;
170
172
  };
171
173
  /** What the history's list receives, the host's own or the widget's. Its header is the header slot. */
172
174
  export type CortexThreadListContext = {
package/dist/index.js CHANGED
@@ -10,4 +10,4 @@ var Q5=Object.create;var{getPrototypeOf:X5,defineProperty:j0,getOwnPropertyNames
10
10
  ${K}`:K,G=[],J="";function N(){if(J.trim())G.push({kind:"markdown",text:Z(J)});J=""}let V=Y.filter((K)=>K.type!=="def");for(let[K,z]of V.entries()){if(z.type!=="table"){J+=z.raw;continue}N();let F=V.slice(K+1).some((B)=>B.raw.trim()!=="");G.push({kind:"table",text:Z(z.raw.trimEnd()),closed:F||!$})}return N(),G}var a5=/^-?(?:0|[1-9]\d*)(?:\.\d*[1-9])?$/;function o5(_){return a5.test(_)&&_!=="-0"&&_.replace(/[-.]/g,"").replace(/^0/,"").length<=15}var t5=32767,Q6=new TextEncoder;function a1(_){return Array.from(_.rows,($)=>Array.from($.cells,s5))}function s5(_){let $=_.cloneNode(!0);if($ instanceof Element)$.querySelectorAll("br").forEach((Y)=>Y.replaceWith(`
11
11
  `));return($.textContent??"").trim()}function o1(_){return new Blob([Z8(Y8(_))],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})}function e5(_){return _.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\ufffe\uffff]/g,"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/_(x[0-9a-f]{4}_)/gi,"_x005F_$1")}function _8(_){let $="";for(let Y=_+1;Y>0;Y=Math.floor((Y-1)/26))$=String.fromCharCode(65+(Y-1)%26)+$;return $}function $8(_){return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>${_.map((Y,Q)=>{let X=Y.map((Z,G)=>{let J=`${_8(G)}${Q+1}`,N=Q===0?' s="1"':"";return Q>0&&o5(Z)?`<c r="${J}"${N}><v>${Z}</v></c>`:`<c r="${J}"${N} t="inlineStr"><is><t xml:space="preserve">${e5(Z.slice(0,t5))}</t></is></c>`}).join("");return`<row r="${Q+1}">${X}</row>`}).join("")}</sheetData></worksheet>`}function Y8(_){return[{name:"[Content_Types].xml",text:'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/></Types>'},{name:"_rels/.rels",text:'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>'},{name:"xl/workbook.xml",text:'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><sheets><sheet name="Sheet1" sheetId="1" r:id="rId1"/></sheets></workbook>'},{name:"xl/_rels/workbook.xml.rels",text:'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/></Relationships>'},{name:"xl/styles.xml",text:'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fonts count="2"><font><sz val="11"/><name val="Calibri"/></font><font><b/><sz val="11"/><name val="Calibri"/></font></fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills><borders count="1"><border/></borders><cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs><cellXfs count="2"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/><xf numFmtId="0" fontId="1" fillId="0" borderId="0" xfId="0" applyFont="1"/></cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles></styleSheet>'},{name:"xl/worksheets/sheet1.xml",text:$8(_)}]}var Q8=Array.from({length:256},(_,$)=>{let Y=$;for(let Q=0;Q<8;Q++)Y=Y&1?3988292384^Y>>>1:Y>>>1;return Y>>>0});function X8(_){let $=4294967295;for(let Y of _)$=(Q8[($^Y)&255]??0)^$>>>8;return($^4294967295)>>>0}function Z8(_){let $=[],Y=[],Q=0;for(let V of _){let K=Q6.encode(V.name),z=Q6.encode(V.text),F=X8(z),B=new DataView(new ArrayBuffer(30));B.setUint32(0,67324752,!0),B.setUint16(4,20,!0),B.setUint16(6,2048,!0),B.setUint32(14,F,!0),B.setUint32(18,z.length,!0),B.setUint32(22,z.length,!0),B.setUint16(26,K.length,!0),$.push(new Uint8Array(B.buffer),K,z);let q=new DataView(new ArrayBuffer(46));q.setUint32(0,33639248,!0),q.setUint16(4,20,!0),q.setUint16(6,20,!0),q.setUint16(8,2048,!0),q.setUint32(16,F,!0),q.setUint32(20,z.length,!0),q.setUint32(24,z.length,!0),q.setUint16(28,K.length,!0),q.setUint32(42,Q,!0),Y.push(new Uint8Array(q.buffer),K),Q+=30+K.length+z.length}let X=Y.reduce((V,K)=>V+K.length,0),Z=new DataView(new ArrayBuffer(22));Z.setUint32(0,101010256,!0),Z.setUint16(8,_.length,!0),Z.setUint16(10,_.length,!0),Z.setUint32(12,X,!0),Z.setUint32(16,Q,!0);let G=[...$,...Y,new Uint8Array(Z.buffer)],J=new Uint8Array(G.reduce((V,K)=>V+K.length,0)),N=0;for(let V of G)J.set(V,N),N+=V.length;return J}var G6=new Set(["flatten","fold","density","impute","regression","loess","quantile","sample"]),G8=`Use Vega-Lite JSON with inline \`data.values\` only, at most 200 rows, and no \`url\` anywhere. Compute folds, trend lines and densities yourself. For several series, write one row per series and x value, or keep one row per x value and draw a layer per series (color by \`datum\`) when that would exceed the row limit. These keys are refused anywhere in the spec: ${[...G6,"params","selection"].join(", ")}. Expressions in \`calculate\`, \`filter\` and \`labelExpr\` may use only datum fields, literals, operators and simple math or date-part functions (no format or timeFormat), so put formatted values in the rows or use an axis \`format\`.`;function J6(_,$){if(_==="url")return"Charts may only use inline data and no URLs.";if(_==="sequence"||_==="graticule")return"Charts may only use inline data.";if(G6.has(_))return"Charts may not use transforms that generate rows.";if(_==="params"||_==="selection"||_==="signals"||_==="on")return"Charts may not be interactive.";if(_==="expr")return"Charts may not carry expressions.";if(J8.has(_)&&typeof $==="string"&&!N8($))return"Charts may only use simple expressions over datum.";if(_==="usermeta")return"Charts may not carry usermeta.";if(typeof $==="string"&&e_($))return"Charts may not reference URLs.";if((_==="width"||_==="height")&&V8($)>4000)return"Charts may be at most 4000 pixels wide or tall.";return}var J8=new Set(["calculate","filter","test","signal","labelExpr"]),X6=new Set(["abs","ceil","floor","round","min","max","sqrt","pow","log","exp","year","month","date","day","hours","minutes","toNumber","toString","toDate","isValid","isNaN","if","indexof","length"]);function N8(_){if(_.length>500||/[\\`]/.test(_))return!1;let $=_.replace(/'[^']*'|"[^"]*"/g,'""');for(let[,Q]of $.matchAll(/([A-Za-z_$][\w$]*)\s*\(/g))if(!X6.has(Q??""))return!1;let Y=$.replace(/(datum|parent)(\s*\.[\w$]+|\s*\[\s*""\s*\])+|\b\d[\w.]*/g,"").matchAll(/[A-Za-z_$][\w$]*/g);for(let[Q]of Y)if(!X6.has(Q)&&!["true","false","null"].includes(Q))return!1;return!0}function V8(_){if(typeof _==="number")return _;let $=_?.step;return typeof $==="number"?$:0}function Z6(_,$){let Y=_?.features,Q=Array.isArray(_)?_.length:Array.isArray(Y)?Y.length:-1;if(Q<0)return J6($,_)??s1(t1(_,$),f_);return Q>200?"Charts may hold at most 200 rows.":void 0}function f_(_,$=""){if($==="values")return Z6(_,$);if($==="datasets")return s1(t1(_),Z6);return J6($,_)??s1(t1(_,$),(Y,Q)=>f_(Y,Q))}function t1(_,$=""){if(Array.isArray(_))return _.map((Y)=>[$,Y]);return _&&typeof _==="object"?Object.entries(_):[]}function s1(_,$){for(let[Y,Q]of _){let X=$(Q,Y);if(X)return X}return}var N6=/url\(([^)]*)\)/gi,e1="src|image|image-set|-webkit-image-set|cross-fade|element",_0=new RegExp(String.raw`\b(url|${e1})\(`,"i"),K8=new RegExp(String.raw`\b(${e1})\(`,"i"),z8=new RegExp(String.raw`\b(${e1})\([^)]*\)`,"gi"),W8=/\\([0-9a-f]{1,6})\s?|\\(.)/gi;function D8(_){return _.replace(W8,($,Y,Q)=>{if(!Y)return Q??"";let X=parseInt(Y,16),Z=X===0||X>=55296&&X<=57343||X>1114111;return String.fromCodePoint(Z?65533:X)})}function V6(_){return _.trim().replace(/^(['"])(.*)\1$/s,"$2").trim()}function e_(_){if(_.includes("\\")||K8.test(_))return!0;for(let[,$]of _.matchAll(N6))if(!V6($??"").startsWith("#"))return!0;return!1}function $0(_){return D8(_).replace(z8,"none").replace(N6,($,Y)=>V6(Y).startsWith("#")?$:"none")}var B6={async mermaid(_,$,{scheme:Y}){let[{default:Q},{default:X}]=await Promise.all([import("mermaid"),import("dompurify")]);if(_0.test($)||$.includes("\\"))throw Error("Diagrams may not reference URLs.");if(/%%\{/.test($))throw Error("Diagrams may not carry init directives.");if(/^\s*---\s*$/m.test($))throw Error("Diagrams may not carry frontmatter.");if(/\bimg\s*:/.test($))throw Error("Diagrams may not embed images.");let Z=q8($);if(!B8.test(Z))throw Error(`Unsupported diagram type: ${Z}`);let G=K6.then(async()=>{if(!z6)Q.initialize({startOnLoad:!1,securityLevel:"strict",htmlLabels:!1}),z6=!0;let V=`%%{init: {"theme": "${Y==="dark"?"dark":"default"}"}}%%
12
12
  ${$}`;return await Q.parse(V),(await Q.render(`cortex-mermaid-${P8()}`,V,_)).svg});K6=G.catch(()=>{return});let J=await G,N=document.createElement("div");return N.innerHTML=X.sanitize(J,{USE_PROFILES:{svg:!0,svgFilters:!0}}),D6(N),_.replaceChildren(...N.childNodes),()=>{_.innerHTML=""}},async "vega-lite"(_,$,{scheme:Y}){let Q=JSON.parse($),X=f_(Q);if(X)throw Error(X);if(!Q||typeof Q!=="object"||Array.isArray(Q))throw Error("A chart needs a JSON object.");let Z=Q,[{default:G},J]=await Promise.all([import("vega-embed"),import("vega")]),N=()=>Promise.reject(Error("Charts may only use inline data."));async function V(D){let H=document.createElement("div"),W=await G(H,L8(Z,D),{actions:!1,renderer:"svg",mode:"vega-lite",loader:{...J.loader(),load:N,sanitize:N},ast:!0,...Y==="dark"?{theme:"dark"}:{},config:{background:"transparent"}});return D6(H),{drawing:H,result:W,width:D}}let K=await V(_.clientWidth);_.replaceChildren(K.drawing);let z=!1,F,B=0;function q(){F??=(async()=>{let D=_.clientWidth;while(!z&&D>0&&D!==K.width&&D!==B){try{let H=await V(D);if(z){H.result.finalize();return}K.result.finalize(),K=H,_.replaceChildren(H.drawing)}catch{B=D}D=_.clientWidth}})().finally(()=>{F=void 0})}let O=new ResizeObserver(q);if(q6(Z))O.observe(_);function P(){let D=document.getElementById(O8),H=_.closest("dialog")??document.body;if(D&&D.parentElement!==H)H.append(D)}return _.addEventListener("pointermove",P),()=>{z=!0,O.disconnect(),_.removeEventListener("pointermove",P),K.result.finalize()}},async map(_,$){let Y=A8(JSON.parse($)),{leaflet:Q,map:X,dispose:Z}=await b_(_,{...Y,interactive:!0});for(let G of Y.markers){let J=Q.marker(G.position).addTo(X);if(G.label){let N=document.createElement("span");N.textContent=G.label,J.bindTooltip(N)}}return Z}},H8={mermaid:{title:"translate_media_mermaid",pending:"translate_media_pending_mermaid"},"vega-lite":{title:"translate_media_vega_lite",pending:"translate_media_pending_vega_lite"},map:{title:"translate_media_map",pending:"translate_media_pending_map"}};function _1(_){return H8[_]??{title:"translate_media",pending:"translate_media_pending"}}function Q0(_){return Object.keys({...B6,..._})}function X0(_,$){let{language:Y,source:Q,context:X,overrides:Z,onError:G}=$,J=_.appendChild(document.createElement("div")),N=Z?.[Y]??B6[Y],V,K=!1;return(N?N(J,Q,X):Promise.reject(Error(`No renderer for ${Y}.`))).then((F)=>{if(K)F();else V=F},(F)=>{if(!K)G(F instanceof Error?F.message:String(F))}),()=>{K=!0,V?.(),J.remove()}}var B8=/^(flowchart|graph|sequenceDiagram|stateDiagram(-v2)?|erDiagram|gantt|pie|classDiagram|journey|timeline|mindmap)$/;function q8(_){let $=_.split(`
13
- `).find((Y)=>/\S/.test(Y)&&!/^\s*%%/.test(Y));return/^\s*(\S+)/.exec($??"")?.[1]??""}function Y0(_){return _===void 0||_==="container"}var F8=["row","column","facet"];function q6(_){let $=_.encoding,Y=typeof $==="object"&&$!==null&&F8.some((Q)=>(Q in $));return(("mark"in _)||("layer"in _))&&Y0(_.width)&&!Y}function U8(_){let $={..._};if(Y0($.width))delete $.width;if(Y0($.height))delete $.height;return $}function L8(_,$){let Y=U8(_);if($<=0||!q6(_))return Y;return{...Y,width:$,height:Y.height??Math.round(Math.min(480,Math.max(200,$/2))),autosize:Y.autosize??{type:"fit",contains:"padding"}}}var O8="vg-tooltip-element",K6=Promise.resolve(),z6=!1,W6=0;function P8(){return W6+=1,W6}var M8=new Set(["image","use","feImage"]);function D6(_){for(let $ of[_,..._.querySelectorAll("*")]){for(let Y of[...$.attributes])if((Y.name==="href"||Y.name==="xlink:href")&&M8.has($.tagName)&&!Y.value.trim().startsWith("#")||e_(Y.value))$.removeAttribute(Y.name);if($.tagName==="style"&&$.textContent)$.textContent=$0($.textContent)}}function A8(_){if(!_||typeof _!=="object")throw Error("A map needs a JSON object.");let $=_,Y=$.zoom??10;if(typeof Y!=="number"||Y<0||Y>22)throw Error("zoom must be 0 to 22.");let Q=$.markers??[];if(!Array.isArray(Q))throw Error("markers must be a list.");return{center:H6($.center,"center"),zoom:Y,markers:Q.map((X,Z)=>{let G=X??{},J=G.label;return{position:H6(G.position,`markers[${Z}].position`),label:typeof J==="string"?J:void 0}})}}function H6(_,$){let Y=Array.isArray(_)?_:[],[Q,X]=Y;if(typeof Q!=="number"||typeof X!=="number"||Math.abs(Q)>90||Math.abs(X)>180)throw Error(`${$} must be [latitude, longitude].`);return{lat:Q,lng:X}}function Z0(_,$){if(_!=="system")return $(_??"light"),()=>{};let Y=window.matchMedia("(prefers-color-scheme: dark)"),Q=()=>$(Y.matches?"dark":"light");return Q(),Y.addEventListener("change",Q),()=>Y.removeEventListener("change",Q)}import j_ from"highlight.js/lib/core";import E8 from"highlight.js/lib/languages/javascript";import k8 from"highlight.js/lib/languages/json";import R8 from"highlight.js/lib/languages/sql";var F6=!1;function I8(){if(F6)return;F6=!0,j_.registerLanguage("javascript",E8),j_.registerLanguage("json",k8),j_.registerLanguage("cypher",R8)}function G0(_,$){if(!_)return"";return I8(),j_.getLanguage($)?j_.highlight(_,{language:$}).value:y8(_)}function y8(_){return _.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function q_(_){if(typeof _==="string"){let $=_.trim();if(!($.startsWith("{")&&$.endsWith("}")||$.startsWith("[")&&$.endsWith("]")))return _;try{return q_(JSON.parse($))}catch{return _}}if(Array.isArray(_))return _.map(($)=>q_($));if(_!==null&&typeof _==="object"){let $={};for(let[Y,Q]of Object.entries(_))$[Y]=q_(Q);return $}return _}function J0(_,$){if(Array.isArray(_)){let Y=_;return{kind:"container",open:"[",close:"]",summary:U6(Y.length,"item","items"),entries:Y.map((Q,X)=>({key:null,value:Q,path:`${$}[${X}]`}))}}if(_!==null&&typeof _==="object"){let Y=Object.entries(_);return{kind:"container",open:"{",close:"}",summary:U6(Y.length,"property","properties"),entries:Y.map(([Q,X])=>({key:Q,value:X,path:`${$}.${Q}`}))}}return{kind:"primitive",text:C8(_),className:w8(_)}}function U6(_,$,Y){return`${_} ${_===1?$:Y}`}function C8(_){if(_===null||_===void 0)return"null";if(typeof _==="string")return JSON.stringify(_);if(typeof _==="number"||typeof _==="boolean")return String(_);return JSON.stringify(_)??"null"}function w8(_){if(_===null||_===void 0)return"cortex-json-tree__null";if(typeof _==="string")return"cortex-json-tree__string";if(typeof _==="number")return"cortex-json-tree__number";if(typeof _==="boolean")return"cortex-json-tree__boolean";return""}function N0(_){if(!_)return null;try{return JSON.parse(_)}catch{return _}}function V0(_){if(!_)return"";try{return JSON.stringify(JSON.parse(_),null,2)}catch{return _}}function r(_,$,Y=Date.now()){let Q=new Date(_);if(Number.isNaN(Q.getTime()))return"";let X=Q.toDateString()===new Date(Y).toDateString();return new Intl.DateTimeFormat($,{...X?{}:{dateStyle:"medium"},timeStyle:"short"}).format(Q)}function g_(_,$){let Y=URL.createObjectURL(_),Q=document.createElement("a");Q.href=Y,Q.download=$,document.body.append(Q),Q.click(),Q.remove(),setTimeout(()=>URL.revokeObjectURL(Y),40000)}class $_{onUpdate;fullText="";displayedLength=0;animationFrameId=null;isDone=!1;releases=[];static DRAIN_FRACTION=0.03;static MIN_CHARS_PER_FRAME=1;static DONE_DRAIN_FRACTION=0.1;static FADE_WINDOW_MS=500;constructor(_){this.onUpdate=_}seed(_){this.fullText=_,this.displayedLength=_.length,this.releases=[],this.onUpdate(_,[])}update(_,$){if(this.fullText=_,this.isDone=$,this.displayedLength=Math.min(this.displayedLength,this.fullText.length),this.releases=this.releases.filter((Y)=>Y.from<this.displayedLength),$&&this.displayedLength>=this.fullText.length){this.onUpdate(this.fullText,[]),this.stopAnimation();return}if(!this.animationFrameId)this.scheduleFrame()}destroy(){this.stopAnimation()}scheduleFrame(){this.animationFrameId=requestAnimationFrame((_)=>this.tick(_))}tick(_){let $=this.fullText.length-this.displayedLength;if($<=0){this.animationFrameId=null;return}let Y=this.isDone?$_.DONE_DRAIN_FRACTION:$_.DRAIN_FRACTION,Q=Math.max($_.MIN_CHARS_PER_FRAME,Math.ceil($*Y));if(this.releases=this.releases.filter((X)=>_-X.at<$_.FADE_WINDOW_MS),this.releases.push({from:this.displayedLength,at:_}),this.displayedLength=Math.min(this.fullText.length,this.displayedLength+Q),this.onUpdate(this.fullText.substring(0,this.displayedLength),this.releases.map((X)=>({length:this.displayedLength-X.from,age:_-X.at}))),this.displayedLength<this.fullText.length)this.scheduleFrame();else this.animationFrameId=null}stopAnimation(){if(this.animationFrameId)cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null}}var K0=new WeakMap;function z0(_,$){let Y=_.closest(".cortex-widget__screen"),Q=Y?.querySelector(".cortex-message-list");if(!Y||!Q||!_.value.trim())return;let X=getComputedStyle(_),Z=_.getBoundingClientRect(),G=(J)=>parseFloat(X[`padding${J}`])+parseFloat(X[`border${J}Width`]);K0.set(Y,{text:$,textarea:_,from:new DOMRect(Z.left+G("Left"),Z.top+G("Top"),Z.width-G("Left")-G("Right"),Z.height-G("Top")-G("Bottom")),rtl:X.direction==="rtl",scrollTop:Q.scrollTop})}function W0(_,$){let Y=_.closest(".cortex-widget__screen"),Q=Y?K0.get(Y):void 0;if(!Y||!Q)return;K0.delete(Y);let X=_.querySelectorAll(":scope > .cortex-message"),Z=X[X.length-1]?.querySelector(".cortex-text-bubble--user"),G=_.closest(".cortex-message-list");if(!Z||!G||Q.text!==$||!Q.textarea.isConnected)return;Z.closest(".cortex-message-part")?.getAnimations().forEach((D)=>D.finish()),$1(G);let J=Z.getBoundingClientRect(),N=Y.getBoundingClientRect(),V=getComputedStyle(Z),K=parseFloat(V.paddingTop)+parseFloat(V.borderTopWidth),z=Q.rtl?parseFloat(V.paddingRight)+parseFloat(V.borderRightWidth):parseFloat(V.paddingLeft)+parseFloat(V.borderLeftWidth),F=Q.rtl?Q.from.right+z-J.width:Q.from.left-z,B=G.scrollTop-Q.scrollTop;if(B)_.style.setProperty("--cortex-slide",`${B}px`),_.classList.remove("cortex-message-list__content--settling"),_.offsetWidth,_.classList.add("cortex-message-list__content--settling"),_.getAnimations()[0]?.finished.then(()=>_.classList.remove("cortex-message-list__content--settling"),()=>{return});let q=Z.cloneNode(!0);q.classList.add("cortex-send-flight"),q.setAttribute("aria-hidden","true"),Object.assign(q.style,{left:`${J.left-N.left}px`,top:`${J.top-N.top}px`,width:`${J.width}px`}),q.style.setProperty("--cortex-fly-x",`${F-J.left}px`),q.style.setProperty("--cortex-fly-y",`${Q.from.top-K-J.top}px`),Z.style.visibility="hidden",Y.append(q);let O=G.scrollTop,P=()=>{q.style.top=`${J.top-N.top-(G.scrollTop-O)}px`};G.addEventListener("scroll",P,{passive:!0}),P6(q).then(()=>{G.removeEventListener("scroll",P),Z.style.visibility="",q.remove()})}function $1(_){_.scrollTop=O6(_)}function D0(_){return O6(_)-_.scrollTop}function O6(_){let $=_.querySelector(".cortex-message-list__content");if(!$)return _.scrollHeight-_.clientHeight;let Y=getComputedStyle(_);return $.offsetHeight+parseFloat(Y.paddingTop)+parseFloat(Y.paddingBottom)-_.clientHeight}function H0(_){let $=!1,Y=_.parentElement,Q=typeof ResizeObserver>"u"?void 0:new ResizeObserver(X);Q?.observe(Y);function X(){let Z=Y.querySelector(":scope > .cortex-working-thinking, :scope > .cortex-message > .cortex-message-parts > [data-cortex-frontier]");if(!Z)return!1;return _.style.setProperty("--cortex-avatar-y",`${S8(Z,Y)-_.offsetHeight/2}px`),!0}return{sync(Z){if(Z===$){if(Z)X();return}if(Z){if(!X())return;_.classList.remove("cortex-working-avatar--leaving"),_.offsetWidth,_.classList.add("cortex-working-avatar--shown"),$=!0;return}$=!1,_.classList.add("cortex-working-avatar--leaving"),P6(_,!0).then(()=>{if($)return;_.classList.remove("cortex-working-avatar--shown","cortex-working-avatar--leaving")})},dispose(){Q?.disconnect()}}}function S8(_,$){let Y=_.querySelector(".cortex-text-bubble");if(!Y)return L6(_,$)+_.offsetHeight/2;let Q=getComputedStyle(Y);return L6(Y,$)+parseFloat(Q.paddingTop)+parseFloat(Q.borderTopWidth)+parseFloat(Q.lineHeight)/2}function L6(_,$){let Y=0;for(let Q=_;Q instanceof HTMLElement&&Q!==$;)Y+=Q.offsetTop,Q=Q.offsetParent;return Y}function P6(_,$=!1){return Promise.allSettled(_.getAnimations({subtree:$}).map((Y)=>Y.finished))}var b8=2;function B0(_){let $=!1,Y=!1,Q=!1,X=!1,Z=!1,G=!1,J,N=new Set,V=0,K=!1;function z(){if($&&V===0)return!1;if(V+=1,!$)$=!0,_.setRunning(!0);return!0}function F(D){if(V-=1,D)K=!0;else if(V===0&&!K)$=!1,_.setRunning(!1)}async function B(D,H){for(let W=0;W<b8;W+=1){let M=await _.refreshMessages().catch(()=>{return});if(!_.isAlive())return!1;if(!M)continue;if(!__(M).some((k)=>k.id===D.id))return!0;if(await _.deliver(H).then(()=>!0,()=>!1))return!0}return!1}async function q(D,H){let W;try{let n=H({toolCallId:D.id,toolName:D.name,input:D.input},{threadId:_.threadId});if(n===null||n===void 0)return;W=await Promise.resolve(n)}catch{N.delete(D.id);return}if(W===null||W===void 0)return;if(!_.isAlive())return;let M=z(),A={toolCallId:D.id,tool:D.name,output:W},k=await _.deliver(A).then(()=>!0,()=>B(D,A));if(M)F(k);if(!k)N.delete(D.id)}function O(D){let H=__(D),W=_.onToolCall();if(!W)return H.length>0;for(let M of H){if(M.state!=="input-complete"||N.has(M.id))continue;N.add(M.id),q(M,W)}return H.length>0}async function P(D){let H=X;if(X=!1,!H&&$){if(O(D()))return;if(Q)_.reloadThreads().catch(()=>{});else _.setRunning(!1)}if(J===void 0&&(G||H))return;J=void 0;let W=await _.refreshMessages();if(!H&&$&&W)O(W)}return{chunkArrived(){Y=!0},transcriptCarried(D){if(G=!0,J!==void 0&&J<=D)J=void 0},transcriptUpdated(D){if(!Z){_.refreshMessages();return}J=Math.max(J??0,Date.parse(D))},streamFailed(){if(Q=!0,Y)_.onTurnFinished();else _.onSendFailed()},loadingChanged(D,H){if(D){Z=!0,Q=!1,G=!1;return}if(!Z)return;Z=!1,_.onTurnFinished(),P(H)},hydrated(D,H){if(H)return;setTimeout(()=>{if(_.isAlive())O(D)},0)},sendStarted(){_.setRunning(!0),$=!0,Y=!1},abortConfirmed(){X=!0,_.setRunning(!1)}}}function m_(_){if(_.input.total<=0)return null;return Math.round(_.input.cacheRead/_.input.total*100)}import{createContext as M6,useContext as A6}from"react";var q0=M6(void 0);function L(){let _=A6(q0);if(!_)throw Error("useCortex must be used inside <CortexChatWidget>");return _}var F0={messages:[],isAgentWorking:!1,isLoadingMessages:!1,hasPendingToolCalls:!1},U0=M6(F0);function F_(){return A6(U0)}import{useEffect as T8,useState as v8}from"react";function E6(_,$){let[Y,Q]=v8();return T8(()=>{return Q(void 0),n1(_,Q)},[_,$]),Y}import{useRef as c8}from"react";import{useRef as f8,useState as j8,useSyncExternalStore as g8}from"react";function k6(_,$){let Y=f8($);Y.current=$;let[Q]=j8(()=>b1({api:_,ensureThread:()=>Y.current()})),X=g8(Q.subscribe,Q.getState,Q.getState);return{store:Q,value:{items:X,...T1(X),accept:Q.accept,remove:Q.remove,consumeReady:Q.consumeReady}}}import{useEffect as m8,useRef as x8}from"react";function R6(_,$){let Y=x8(void 0);m8(()=>{if($===Y.current)return;_.clear(Y.current),Y.current=$},[$,_])}import{useRef as I6}from"react";function y6(_){let $=I6([]),Y=I6(void 0);function Q(){let Z=_.selectedRef.current;if(Z)return Promise.resolve(Z.id);return Y.current??=_.api.createThread().then((G)=>{return Y.current=void 0,_.onCreated(G),G.id},(G)=>{throw Y.current=void 0,G}),Y.current}async function X(Z,G=[]){let J=_.sessionRef.current;if(J){await J.send(Z,G);return}$.current.push({prompt:Z,attachments:G});try{await Q()}catch(N){throw $.current=[],N}}return{ensureThread:Q,send:X,pendingSendRef:$}}import{useRef as h8,useState as u8}from"react";function C6(_){let[$,Y]=u8(),Q=$?.thread,X=Q?_.threads?.find((V)=>V.id===Q.id)??Q:void 0,Z=h8(X);Z.current=X;function G(V,K){if(Z.current?.id===V.id&&_.hasSession())return;let z=Z.current;if(Z.current=V,Y({thread:V,mode:K,epoch:0}),z&&z.id!==V.id)_.getHooks()?.onThreadDeselected?.(z);_.getHooks()?.onThreadSelected?.(V)}function J(){let V=Z.current;if(!V&&!_.hasSession())return;if(Z.current=void 0,Y(void 0),V)_.getHooks()?.onThreadDeselected?.(V)}function N(V,K){Y((z)=>({thread:V,mode:"reload",epoch:(z?.epoch??0)+1,initialMessages:K}))}return{session:$,selected:X,selectedRef:Z,select:G,deselect:J,remount:N}}function w6(_){let{api:$,threads:Y}=_,Q=c8(void 0),X=C6({threads:Y.threads,getHooks:_.getHooks,hasSession:()=>Q.current!==void 0}),Z=y6({api:$,sessionRef:Q,selectedRef:X.selectedRef,onCreated:(V)=>{Y.upsert(V),X.select(V,"skip")}}),G=k6($,Z.ensureThread);R6(G.store,X.selected?.id);async function J(V){if(X.selectedRef.current?.id===V)X.deselect();await Y.remove(V)}function N(V){X.select(V,"load")}return{sessionRef:Q,selection:X,queue:G,deleteThread:J,openThread:N,...Z}}import{useEffect as p8,useRef as d8}from"react";function S6(_){let $=d8(_);$.current=_,p8(()=>{$.current.onMount();let Y=!1,Q=l1({getConfig:()=>$.current.getConfig(),onEvent:(X)=>$.current.onEvent(X),onOpen:()=>{if(Y)$.current.onReconnect();Y=!0}});return()=>Q.close()},[])}function b6(_){let{threads:$,selectedRef:Y,sessionRef:Q}=_;function X(G){$.applyEvent(G);let J=Y.current?.id;switch(G.type){case"thread:deleted":if(J===G.payload.threadId)_.deselect();break;case"thread:run-started":if(J===G.payload.thread.id)Q.current?.reattach(G.payload.thread);break;case"thread:messages-updated":Q.current?.transcriptUpdated(G.payload.thread.id,G.payload.thread.updatedAt);break}}function Z(){_.onReconnect(),$.reload().then((G)=>{let J=Y.current;if(!J)return;Q.current?.reattach(G.find((N)=>N.id===J.id)??J)})}return{onEvent:X,onReconnect:Z}}function T6(_){return{abort:async()=>{await _.current?.abort()},addToolResult:($,Y,Q)=>_.current?.addToolResult($,Y,Q)??Promise.resolve(),respondToApproval:($,Y)=>_.current?.respondToApproval($,Y)??Promise.resolve()}}import{useState as l8}from"react";function v6(_){let[$,Y]=l8();async function Q(){let N=t_(await _.listThreads());return Y(N),N}function X(N){Y((V)=>T_(V??[],N))}function Z(N,V){Y((K)=>{let z=K?.find((F)=>F.id===N);return z?T_(K??[],{...z,isRunning:V}):K})}async function G(N){await _.deleteThread(N),Y((V)=>V?s_(V,N):V)}function J(N){Y((V)=>{let K=i1(V??[],N);return V||K.length?K:V})}return{threads:$,reload:Q,upsert:X,setRunning:Z,remove:G,applyEvent:J}}import{useState as f6}from"react";function j6(_){let[$,Y]=f6("chat"),[Q,X]=f6(!1);return{screen:$,sidebarOpen:Q,showChat:()=>{Y("chat"),X(!1)},openHistory:()=>_==="full"?X(!0):Y("threads"),closeHistory:()=>_==="full"?X(!1):Y("chat"),closeSidebar:()=>X(!1)}}import{forwardRef as s8,useEffect as e8,useImperativeHandle as _4,useRef as c6,useState as $4}from"react";function U(..._){return _.filter(Boolean).join(" ")}import{useState as n8}from"react";function g6(_,$){let[Y,Q]=n8(!1);return{dragging:Y,onDragOver:(X)=>{if(X.preventDefault(),_)Q(!0)},onDragLeave:(X)=>{if(!X.currentTarget.contains(X.relatedTarget))Q(!1)},onDrop:(X)=>{if(X.preventDefault(),Q(!1),_)$([...X.dataTransfer.files])},onPaste:(X)=>{let Z=X.clipboardData.files;if(!_||!Z.length)return;X.preventDefault(),$([...Z])}}}var S={bubble:"M13.5 7.6c0 2.4-2.5 4.4-5.5 4.4-.6 0-1.2-.08-1.7-.23L3 13l.8-2.3C3 9.8 2.5 8.7 2.5 7.6 2.5 5.2 5 3.2 8 3.2s5.5 2 5.5 4.4Z",chevronDown:"M3 4.5L6 7.5L9 4.5",chevronDownLarge:"m5.75 8.25 4.25 4.25 4.25-4.25",file:["M4 1.5h5.172a2 2 0 0 1 1.414.586l2.328 2.328a2 2 0 0 1 .586 1.414V12.5a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-9a2 2 0 0 1 2-2Z","M9.5 1.5v2a2 2 0 0 0 2 2h2"]};import{jsx as a,jsxs as L0}from"react/jsx-runtime";function m6(){let{queue:_,t:$}=L();if(!_.items.length)return null;return a("div",{className:"cortex-attachment-queue",children:_.items.map((Y)=>L0("div",{className:U("cortex-attachment-chip",Y.status==="error"&&"cortex-attachment-chip--error"),title:Y.status==="error"?$("translate_attachment_rejected"):"",children:[Y.status==="uploading"||Y.status==="deleting"?L0("svg",{className:"cortex-attachment-chip__spinner",viewBox:"0 0 16 16",fill:"none",children:[a("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",className:"cortex-attachment-chip__spinner-track"}),a("path",{d:"M14 8a6 6 0 0 0-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}):L0("svg",{viewBox:"0 0 16 16",className:"cortex-attachment-chip__icon",fill:"none",children:[a("path",{d:S.file[0],stroke:"currentColor",strokeWidth:"1.25"}),a("path",{d:S.file[1],stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round"})]}),a("span",{className:"cortex-attachment-chip__name",children:Y.filename}),a("button",{type:"button",onClick:()=>_.remove(Y.localId),className:"cortex-attachment-chip__remove",disabled:Y.status==="deleting","aria-label":$("translate_remove_attachment"),children:a("svg",{viewBox:"0 0 16 16",fill:"none",children:a("path",{d:"M4.5 4.5l7 7m0-7l-7 7",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})})]},Y.localId))})}import{useRef as i8}from"react";import{jsx as J_,jsxs as x6,Fragment as a8}from"react/jsx-runtime";var r8=H1.join(",");function h6({attachmentsEnabled:_,canSend:$,onSend:Y}){let{t:Q,queue:X}=L(),Z=i8(null);return x6("div",{className:"cortex-widget__input-actions",children:[_&&x6(a8,{children:[J_("button",{type:"button",onClick:()=>Z.current?.click(),className:"cortex-widget__attach-btn","aria-label":Q("translate_attach_files"),children:J_("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:J_("path",{d:"M10.5 5.5 6.2 9.8a1.4 1.4 0 0 0 2 2l4.6-4.6a2.8 2.8 0 0 0-4-4L4.2 7.8a4.2 4.2 0 0 0 6 6l4-4",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}),J_("input",{ref:Z,type:"file",multiple:!0,accept:r8,onChange:(G)=>{X.accept([...G.target.files??[]]),G.target.value=""},className:"cortex-widget__file-input"})]}),J_("button",{onClick:Y,"aria-label":Q("translate_send"),className:U("cortex-widget__send-btn",!$&&"cortex-widget__send-btn--empty",$&&"cortex-widget__send-btn--ready"),disabled:!$,children:J_("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:"cortex-widget__send-icon",children:J_("path",{d:"M3 8h10M9 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})}import{useLayoutEffect as o8}from"react";import{jsx as t8}from"react/jsx-runtime";function u6(_){let{t:$}=L();o8(()=>{let Q=_.inputRef.current;if(!Q)return;Q.style.height="0px",Q.style.height=`${Q.scrollHeight}px`},[_.inputRef,_.value]);function Y(Q){if(Q.key==="Enter"&&!Q.shiftKey)Q.preventDefault(),_.onSubmit()}return t8("textarea",{ref:_.inputRef,onKeyDown:Y,onPaste:_.onPaste,value:_.value,onChange:(Q)=>_.onChange(Q.target.value),placeholder:_.dragging?$("translate_drop_files_here"):_.disabled?"":$("translate_type_a_message"),disabled:_.disabled,rows:1,className:U("cortex-widget__textarea",_.disabled&&"cortex-widget__textarea--disabled")})}import{jsx as U_,jsxs as O0}from"react/jsx-runtime";var p6=s8(function($,Y){let{t:Q,queue:X,send:Z,abort:G,capabilities:J}=L(),{isAgentWorking:N}=F_(),V=J?.attachments??!1,[K,z]=$4(""),F=g6(V,X.accept),B=c6(null);_4(Y,()=>({focusInput:()=>B.current?.focus()}));let q=c6(N);e8(()=>{if(q.current&&!N)B.current?.focus();q.current=N},[N]);let O=!X.busy&&(Boolean(K.trim())||X.hasReady);function P(){if(N||!O)return;let D=K.trim()||Q("translate_attachment_caption"),H=X.consumeReady();if(B.current)z0(B.current,D);z(""),Z(D,H.map((W)=>W.summary))}return O0("div",{className:"cortex-widget__input-area",onDragOver:F.onDragOver,onDragLeave:F.onDragLeave,onDrop:F.onDrop,children:[U_(m6,{}),O0("div",{className:U("cortex-widget__input-box",N&&"cortex-widget__input-box--disabled",!N&&"cortex-widget__input-box--enabled",F.dragging&&"cortex-widget__input-box--dragging"),children:[U_(u6,{inputRef:B,value:K,onChange:z,onSubmit:P,onPaste:F.onPaste,disabled:N,dragging:F.dragging}),N?O0("button",{onClick:()=>void G(),className:"cortex-stop-btn",children:[U_("span",{className:"cortex-stop-btn__ring"}),U_("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"cortex-stop-btn__icon",children:U_("rect",{x:"1",y:"1",width:"10",height:"10",rx:"2.5",fill:"currentColor"})})]}):U_(h6,{attachmentsEnabled:V,canSend:O,onSend:P})]})]})});import{jsx as d6}from"react/jsx-runtime";function Y1({capabilities:_,composerRef:$}){let{t:Y}=L();if(_===void 0)return null;return _.messages===!1?d6("p",{className:"cortex-widget__messages-disabled",children:Y("translate_messages_disabled")}):d6(p6,{ref:$})}import{jsx as v,jsxs as Q1}from"react/jsx-runtime";function l6(_){let{t:$}=L(),Y=v("button",{type:"button",onClick:_.newChat,"aria-label":$("translate_new_chat"),title:$("translate_new_chat"),className:"cortex-widget__header-btn cortex-widget__new-btn",children:v("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:v("path",{d:"M8 3v10M3 8h10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})});if(_.screen==="threads")return Q1("div",{className:"cortex-widget__threads-header",children:[v("button",{type:"button",onClick:_.closeHistory,"aria-label":$("translate_back"),className:"cortex-widget__header-btn cortex-widget__back-btn",children:v("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"cortex-widget__back-icon",children:v("path",{d:"M10 3L5 8l5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),Q1("div",{children:[v("h2",{className:"cortex-widget__threads-title",children:$("translate_history")}),v("p",{className:"cortex-widget__threads-count",children:$(C_(_.threadCount,"translate_one_conversation","translate_n_conversations"),{count:_.threadCount})})]}),Y]});return Q1("div",{className:"cortex-widget__chat-header",children:[v("button",{onClick:_.openHistory,className:"cortex-widget__sidebar-toggle-btn",children:v("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:v("path",{d:"M2.5 4h11M2.5 8h11M2.5 12h11",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),v("div",{className:"cortex-widget__chat-title-wrap",children:v("p",{className:"cortex-widget__chat-title",children:_.title??_.agentName??$("translate_new_chat")})}),_.debug.shown&&v("button",{onClick:_.toggleDebug,className:U("cortex-widget__debug-btn",_.debug.on?"cortex-widget__debug-btn--on":"cortex-widget__debug-btn--off"),children:_.debug.on?$("translate_debug"):$("translate_normal")}),Y,v("button",{type:"button",onClick:_.openHistory,"aria-label":$("translate_history"),title:$("translate_history"),className:"cortex-widget__header-btn cortex-widget__history-btn",children:Q1("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[v("circle",{cx:"8",cy:"8",r:"5.75",stroke:"currentColor",strokeWidth:"1.3"}),v("path",{d:"M8 5v3l2 1.5",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]})})]})}import{jsx as o,jsxs as n6}from"react/jsx-runtime";function i6(_){let{locale:$,t:Y}=L();return n6("div",{className:"cortex-widget__landing",children:[o("div",{className:"cortex-widget__landing-icon",children:o("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",children:o("path",{d:S.bubble,stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}),o("p",{className:"cortex-widget__landing-greeting",children:_.greeting}),!!_.suggestions.length&&o("div",{className:"cortex-widget__landing-chips",children:_.suggestions.map((Q,X)=>o("button",{type:"button",onClick:()=>_.send(Q.prompt),className:"cortex-widget__landing-chip",children:Q.title},X))}),_.composer,!!_.threads?.length&&o("div",{className:"cortex-widget__landing-recent",children:_.threads.slice(0,2).map((Q)=>{let X=r(Q.updatedAt,$);return n6("button",{type:"button",onClick:()=>_.openThread(Q),className:"cortex-widget__landing-recent-item",children:[o("p",{className:"cortex-widget__landing-recent-title",children:Q.title??Y("translate_untitled")}),X&&o("p",{className:"cortex-widget__landing-recent-time",children:X})]},Q.id)})})]})}import{useCallback as n_,useEffect as I0,useLayoutEffect as y0,useMemo as c4,useRef as W_,useState as C0}from"react";import{memo as h4}from"react";import{Fragment as g4}from"react";import{useRef as Y4,useState as Q4}from"react";import{jsx as L_,jsxs as X4}from"react/jsx-runtime";function h({value:_,className:$}){let{t:Y}=L(),[Q,X]=Q4(!1),Z=Y4(null);async function G(J){J.stopPropagation(),J.preventDefault();try{if(await navigator.clipboard.writeText(_),X(!0),Z.current)clearTimeout(Z.current);Z.current=setTimeout(()=>X(!1),1500)}catch{}}return L_("span",{className:U("cortex-copy-btn",$),children:L_("button",{className:U("cortex-copy-btn__button",Q&&"cortex-copy-btn__button--copied"),onClick:(J)=>void G(J),"aria-label":Q?Y("translate_copied"):Y("translate_copy"),type:"button",children:Q?L_("svg",{className:"cortex-copy-btn__icon cortex-copy-btn__icon--check",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",children:L_("path",{d:"M5 13l4 4L19 7",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"})}):X4("svg",{className:"cortex-copy-btn__icon",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",children:[L_("rect",{x:"9",y:"9",width:"12",height:"12",rx:"2",stroke:"currentColor",strokeWidth:"2"}),L_("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})})})}import{jsx as X1,jsxs as r6}from"react/jsx-runtime";function a6(){let{t:_}=L();return r6("div",{className:"cortex-aborted-flag",children:[X1("span",{className:"cortex-aborted-flag__line"}),r6("span",{className:"cortex-aborted-flag__label",children:[X1("svg",{className:"cortex-aborted-flag__icon",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:X1("path",{d:"M6 1.5v5M6 8.75v.5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})}),_("translate_aborted")]}),X1("span",{className:"cortex-aborted-flag__line"})]})}import{jsx as O_,jsxs as o6}from"react/jsx-runtime";function t6(_){let{api:$,t:Y}=L();async function Q(X){let{blob:Z,name:G}=await $.downloadAttachment(X);g_(Z,G)}return O_("div",{className:U("cortex-message-attachments",_.isUser&&"cortex-message-attachments--user"),children:_.attachments.map((X)=>o6("button",{type:"button",onClick:()=>void Q(X.id),className:"cortex-message-attachment","aria-label":`${Y("translate_download")}: ${X.filename}`,children:[o6("svg",{viewBox:"0 0 16 16",className:"cortex-message-attachment__icon",fill:"none",children:[O_("path",{d:S.file[0],stroke:"currentColor",strokeWidth:"1.25"}),O_("path",{d:S.file[1],stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round"})]}),O_("span",{className:"cortex-message-attachment__name",children:X.filename}),O_("svg",{viewBox:"0 0 16 16",className:"cortex-message-attachment__dl-icon",fill:"none",children:O_("path",{d:"M8 3v7m0 0L5.5 7.5M8 10l2.5-2.5M3 13h10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]},X.id))})}import{useRef as J4,useState as x_}from"react";import{useMemo as Z4,useState as G4}from"react";import{jsx as x,jsxs as N_,Fragment as Z1}from"react/jsx-runtime";function Y_({data:_,expandDepth:$,className:Y}){let Q=Z4(()=>q_(_),[_]),[X,Z]=G4({});function G(N,V){return X[N]??V>=$}function J(N,V){Z((K)=>({...K,[N]:!G(N,V)}))}return x("div",{className:U("cortex-json-tree",Y),children:x(s6,{value:Q,path:"$",depth:0,isCollapsed:G,toggle:J})})}function s6({value:_,path:$,depth:Y,isCollapsed:Q,toggle:X}){let Z=J0(_,$);if(Z.kind==="primitive")return x("span",{className:Z.className,children:Z.text});if(Z.entries.length===0)return N_("span",{className:"cortex-json-tree__bracket",children:[Z.open,Z.close]});let G=Q($,Y);function J(N){X($,Y),N.stopPropagation()}return N_(Z1,{children:[N_("span",{className:"cortex-json-tree__toggle",onClick:J,role:"button",children:[x("span",{className:U("cortex-json-tree__arrow",G&&"cortex-json-tree__arrow--collapsed"),children:"▾"}),x("span",{className:"cortex-json-tree__bracket",children:Z.open})]}),G?N_(Z1,{children:[x("span",{className:"cortex-json-tree__collapsed-hint",onClick:J,role:"button",children:Z.summary}),x("span",{className:"cortex-json-tree__bracket",children:Z.close})]}):N_(Z1,{children:[x("div",{className:"cortex-json-tree__indent",children:Z.entries.map((N,V)=>N_("div",{className:"cortex-json-tree__line",children:[N.key!==null&&N_(Z1,{children:[x("span",{className:"cortex-json-tree__key",children:`"${N.key}"`}),x("span",{className:"cortex-json-tree__colon",children:": "})]}),x(s6,{value:N.value,path:N.path,depth:Y+1,isCollapsed:Q,toggle:X}),V<Z.entries.length-1&&x("span",{className:"cortex-json-tree__comma",children:","})]},N.path))}),x("span",{className:"cortex-json-tree__bracket",children:Z.close})]})]})}function R(_){return _.toLocaleString("en-US")}import{jsx as P_,jsxs as M_}from"react/jsx-runtime";function e6({usage:_}){let{t:$}=L();return M_("div",{className:"cortex-llm-inspector__usage-rows",children:[M_("div",{className:"cortex-llm-inspector__usage-row",children:[P_("span",{className:"cortex-llm-inspector__usage-lbl",children:$("translate_input")}),P_("span",{className:"cortex-llm-inspector__usage-val",children:R(_.input.total)}),M_("span",{className:"cortex-llm-inspector__usage-detail",children:[$("translate_fresh")," ",R(_.input.noCache)," · ",$("translate_read")," ",R(_.input.cacheRead)," · ",$("translate_write")," ",R(_.input.cacheWrite)]})]}),M_("div",{className:"cortex-llm-inspector__usage-row",children:[P_("span",{className:"cortex-llm-inspector__usage-lbl",children:$("translate_output")}),P_("span",{className:"cortex-llm-inspector__usage-val",children:R(_.output.total)}),M_("span",{className:"cortex-llm-inspector__usage-detail",children:[$("translate_text")," ",R(_.output.text)," · ",$("translate_reasoning")," ",R(_.output.reasoning)]})]}),M_("div",{className:"cortex-llm-inspector__usage-row cortex-llm-inspector__usage-row--total",children:[P_("span",{className:"cortex-llm-inspector__usage-lbl",children:$("translate_total")}),P_("span",{className:"cortex-llm-inspector__usage-val",children:R(_.total)})]})]})}import{jsx as _2,jsxs as G1}from"react/jsx-runtime";function $2({usage:_}){let $=m_(_);return G1("span",{className:"cortex-llm-inspector__step-metrics",children:[G1("span",{className:"cortex-llm-inspector__metric",children:[_2("span",{className:"cortex-llm-inspector__dot cortex-llm-inspector__dot--input"}),R(_.input.total)]}),G1("span",{className:"cortex-llm-inspector__metric",children:[_2("span",{className:"cortex-llm-inspector__dot cortex-llm-inspector__dot--output"}),R(_.output.total)]}),$!==null&&G1("span",{className:"cortex-llm-inspector__cache-pct",children:[$,"%"]})]})}import{jsx as y,jsxs as Q_}from"react/jsx-runtime";function Y2({messageId:_}){let{t:$,api:Y}=L(),[Q,X]=x_(!1),[Z,G]=x_(!1),[J,N]=x_([]),[V,K]=x_(null),[z,F]=x_({}),B=J4(!1);async function q(){if(!B.current){G(!0);try{N(await Y.listLlmRequests(_))}finally{G(!1),B.current=!0}}X((W)=>!W)}function O(W){K((M)=>M===W?null:W)}function P(W){return z[W]??"prompt"}function D(W,M){F((A)=>({...A,[W]:M}))}function H(W){return P(W.id)==="prompt"?W.prompt:W.output}return Q_("div",{className:U("cortex-llm-inspector",Q&&"cortex-llm-inspector--open"),children:[Q_("button",{className:"cortex-llm-inspector__trigger",onClick:()=>void q(),children:[y("svg",{className:"cortex-llm-inspector__icon",width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:y("path",{d:"M6 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8ZM0 6a6 6 0 1 1 10.89 3.477l4.817 4.816a1 1 0 0 1-1.414 1.414l-4.816-4.816A6 6 0 0 1 0 6Z",fill:"currentColor"})}),y("span",{children:$("translate_inspect_llm_requests")}),Z?y("span",{className:"cortex-llm-inspector__loading",children:$("translate_loading")}):J.length>0?y("span",{className:"cortex-llm-inspector__badge",children:J.length}):null,y("svg",{className:"cortex-llm-inspector__chevron",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:y("path",{d:S.chevronDown,stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})})]}),y("div",{className:"cortex-llm-inspector__panel-wrapper",children:y("div",{className:"cortex-llm-inspector__panel-inner",children:Q_("div",{className:"cortex-llm-inspector__panel",children:[J.length===0&&!Z&&y("div",{className:"cortex-llm-inspector__empty",children:$("translate_no_llm_requests")}),J.map((W,M)=>Q_("div",{className:U("cortex-llm-inspector__step",V===W.id&&"cortex-llm-inspector__step--expanded"),children:[Q_("button",{className:"cortex-llm-inspector__step-header",onClick:()=>O(W.id),children:[y("span",{className:"cortex-llm-inspector__step-label",children:$("translate_step_n",{number:M+1})}),W.tokenUsage&&y($2,{usage:W.tokenUsage}),y("svg",{className:"cortex-llm-inspector__step-chevron",width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",children:y("path",{d:S.chevronDown,stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})})]}),y("div",{className:"cortex-llm-inspector__step-body-wrapper",children:y("div",{className:"cortex-llm-inspector__step-body-inner",children:Q_("div",{className:"cortex-llm-inspector__step-body",children:[W.tokenUsage&&y(e6,{usage:W.tokenUsage}),Q_("div",{className:"cortex-llm-inspector__tabs",children:[y("button",{className:U("cortex-llm-inspector__tab",P(W.id)==="prompt"&&"cortex-llm-inspector__tab--active"),onClick:()=>D(W.id,"prompt"),children:$("translate_request")}),y("button",{className:U("cortex-llm-inspector__tab",P(W.id)==="response"&&"cortex-llm-inspector__tab--active"),onClick:()=>D(W.id,"response"),children:$("translate_response")})]}),Q_("div",{className:"cortex-llm-inspector__json-pane",children:[y(h,{className:"cortex-llm-inspector__json-copy",value:V0(H(W))}),y(Y_,{data:N0(H(W)),expandDepth:2})]})]})})})]},W.id))]})})})]})}import{useState as N4}from"react";import{jsx as E,jsxs as b}from"react/jsx-runtime";function Q2({usage:_,modelId:$}){let{t:Y}=L(),[Q,X]=N4(!1),Z=m_(_)??0;return b("div",{className:U("cortex-token-usage",Q&&"cortex-token-usage--expanded"),children:[b("button",{className:"cortex-token-usage__summary",onClick:()=>X((G)=>!G),children:[b("span",{className:"cortex-token-usage__total",children:[E("span",{className:"cortex-token-usage__total-number",children:R(_.total)}),E("span",{className:"cortex-token-usage__total-label",children:Y("translate_tokens")})]}),$?E("span",{className:"cortex-token-usage__model",children:$}):null,b("span",{className:"cortex-token-usage__pills",children:[b("span",{className:"cortex-token-usage__pill",children:[E("span",{className:"cortex-token-usage__dot cortex-token-usage__dot--input"}),R(_.input.total)]}),b("span",{className:"cortex-token-usage__pill",children:[E("span",{className:"cortex-token-usage__dot cortex-token-usage__dot--output"}),R(_.output.total)]})]}),Z>0&&b("span",{className:"cortex-token-usage__cache-badge",children:[Z,"%"]}),E("svg",{className:"cortex-token-usage__chevron",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:E("path",{d:S.chevronDown,stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})})]}),E("div",{className:"cortex-token-usage__details",children:E("div",{className:"cortex-token-usage__details-inner",children:b("div",{className:"cortex-token-usage__columns",children:[b("div",{className:"cortex-token-usage__col",children:[b("div",{className:"cortex-token-usage__col-header",children:[E("span",{className:"cortex-token-usage__dot cortex-token-usage__dot--input"}),E("span",{className:"cortex-token-usage__col-label",children:Y("translate_input")}),E("span",{className:"cortex-token-usage__col-total",children:R(_.input.total)})]}),b("div",{className:"cortex-token-usage__rows",children:[_.input.noCache?b("div",{className:"cortex-token-usage__row",children:[E("span",{className:"cortex-token-usage__row-label",children:Y("translate_fresh")}),E("span",{className:"cortex-token-usage__row-value",children:R(_.input.noCache)})]}):null,_.input.cacheRead?b("div",{className:"cortex-token-usage__row",children:[E("span",{className:"cortex-token-usage__row-label",children:Y("translate_cache_read")}),E("span",{className:"cortex-token-usage__row-value",children:R(_.input.cacheRead)})]}):null,_.input.cacheWrite?b("div",{className:"cortex-token-usage__row",children:[E("span",{className:"cortex-token-usage__row-label",children:Y("translate_cache_write")}),E("span",{className:"cortex-token-usage__row-value",children:R(_.input.cacheWrite)})]}):null]}),Z>0&&b("div",{className:"cortex-token-usage__cache-bar-row",children:[E("div",{className:"cortex-token-usage__cache-bar",children:E("div",{className:"cortex-token-usage__cache-fill",style:{width:`${Z}%`}})}),E("span",{className:"cortex-token-usage__cache-label",children:Y("translate_n_percent_cached",{percent:Z})})]})]}),b("div",{className:"cortex-token-usage__col",children:[b("div",{className:"cortex-token-usage__col-header",children:[E("span",{className:"cortex-token-usage__dot cortex-token-usage__dot--output"}),E("span",{className:"cortex-token-usage__col-label",children:Y("translate_output")}),E("span",{className:"cortex-token-usage__col-total",children:R(_.output.total)})]}),b("div",{className:"cortex-token-usage__rows",children:[_.output.text?b("div",{className:"cortex-token-usage__row",children:[E("span",{className:"cortex-token-usage__row-label",children:Y("translate_text")}),E("span",{className:"cortex-token-usage__row-value",children:R(_.output.text)})]}):null,_.output.reasoning?b("div",{className:"cortex-token-usage__row",children:[E("span",{className:"cortex-token-usage__row-label",children:Y("translate_reasoning")}),E("span",{className:"cortex-token-usage__row-value",children:R(_.output.reasoning)})]}):null]})]})]})})})]})}import{jsx as X2,jsxs as V4}from"react/jsx-runtime";function Z2({messageId:_,isAssistant:$,metadata:Y}){let{tokenUsage:Q}=Y;if(!Q&&!$)return null;return V4("div",{className:"cortex-message-debug-zone",children:[Q&&X2(Q2,{usage:Q,modelId:Y.modelId}),$&&X2(Y2,{messageId:_})]})}import{jsx as u,jsxs as h_}from"react/jsx-runtime";function G2(_){let{reasoningPart:$,streaming:Y=!1}=_,{t:Q}=L();return h_("details",{className:"cortex-reasoning-details",children:[h_("summary",{className:"cortex-reasoning-details__summary",children:[h_("div",{className:"cortex-reasoning-details__header",children:[u("span",{className:"cortex-reasoning-details__icon",children:h_("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"none","aria-hidden":"true",children:[u("path",{d:"M10 2C6.686 2 4 4.686 4 8c0 1.655.672 3.154 1.757 4.243.362.363.576.858.576 1.371V14.5a1 1 0 0 0 1 1h5.334a1 1 0 0 0 1-1v-.886c0-.513.214-1.008.576-1.371A5.978 5.978 0 0 0 16 8c0-3.314-2.686-6-6-6Z",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"}),u("path",{d:"M7.5 17.5h5M8.5 8a2 2 0 0 1 2-2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]})}),u("div",{className:"cortex-reasoning-details__title-group",children:h_("div",{className:"cortex-reasoning-details__title-row",children:[u("div",{className:"cortex-reasoning-details__title",children:Q("translate_reasoning")}),u("span",{className:U("cortex-reasoning-details__badge",Y?"cortex-reasoning-details__badge--streaming":"cortex-reasoning-details__badge--done"),children:Y?Q("translate_streaming"):Q("translate_done")})]})})]}),u("span",{className:"cortex-reasoning-details__chevron","aria-hidden":"true",children:u("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"none",children:u("path",{d:S.chevronDownLarge,stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),u("div",{className:"cortex-reasoning-details__body",children:u("div",{className:"cortex-reasoning-details__content",children:u("pre",{className:"cortex-reasoning-details__pre",children:$.content.trim()?$.content:Q("translate_no_reasoning")})})})]})}import{useEffect as D2,useMemo as M4,useRef as M0,useState as A4}from"react";import{useEffect as W4,useState as J2}from"react";import{useRef as K4,useState as z4}from"react";import{jsx as t,jsxs as J1}from"react/jsx-runtime";function A_(_){let{label:$,ready:Y=!0,actions:Q,expanded:X,children:Z}=_,{t:G}=L(),J=K4(null),[N,V]=z4(!1);return J1("div",{className:"cortex-expandable",children:[Y&&J1("div",{className:"cortex-expandable__toolbar",role:"group","aria-label":$,children:[Q,t("button",{type:"button",className:"cortex-expandable__action","aria-label":G("translate_expand",{name:$}),title:G("translate_expand",{name:$}),onClick:()=>{V(!0),J.current?.showModal()},children:t("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:t("path",{d:"M9.5 2.5h4v4M6.5 13.5h-4v-4M13.5 2.5 9 7M2.5 13.5 7 9",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),t("div",{className:"cortex-expandable__content",children:Z}),J1("dialog",{ref:J,className:"cortex-expandable__dialog","aria-label":$,closedby:"any",onClose:()=>V(!1),children:[J1("div",{className:"cortex-expandable__head",children:[t("span",{className:"cortex-expandable__title",children:$}),Q,t("button",{type:"button",className:"cortex-expandable__action","aria-label":G("translate_close"),title:G("translate_close"),onClick:()=>J.current?.close(),children:t("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:t("path",{d:"M4 4l8 8M12 4l-8 8",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})})]}),N&&t("div",{className:"cortex-expandable__body",children:X})]})]})}import{jsx as u_,jsxs as D4}from"react/jsx-runtime";function N2(_){let{id:$,alt:Y,attachment:Q}=_,{api:X,t:Z}=L(),[G,J]=J2(),[N,V]=J2(!1);if(W4(()=>{let K,z=!1;return J(void 0),V(!1),X.downloadAttachment($).then(({blob:F})=>{if(z)return;K=URL.createObjectURL(F),J(K)},()=>{if(!z)V(!0)}),()=>{if(z=!0,K)URL.revokeObjectURL(K)}},[X,$]),N)return u_("p",{className:"cortex-attachment-image__caption",children:Y?Z("translate_image_unavailable_alt",{alt:Y}):Z("translate_image_unavailable")});if(!G)return null;return D4("figure",{className:"cortex-attachment-image",children:[u_(A_,{label:Q?.filename||Y||Z("translate_image"),expanded:u_("img",{className:"cortex-attachment-image__expanded",src:G,alt:Y}),children:u_("img",{src:G,alt:Y})}),Q&&u_("figcaption",{className:"cortex-attachment-image__caption",children:Q.filename})]})}import{useEffect as H4,useRef as B4,useState as P0}from"react";import{jsx as j,jsxs as c_,Fragment as U4}from"react/jsx-runtime";function q4(_){let{t:$}=L();if(!_.pending&&!_.debugMode)return null;return c_("div",{className:"cortex-media-block__head",children:[_.debugMode&&j("span",{className:"cortex-media-block__lang",children:_.language}),_.pending&&j("span",{className:"cortex-media-block__pending",children:$(_1(_.language).pending)}),_.debugMode&&_.closed&&c_("span",{className:"cortex-media-block__actions",children:[_.onToggleSource&&j("button",{type:"button",className:"cortex-media-block__action","aria-pressed":_.sourceShown,onClick:_.onToggleSource,children:$("translate_media_source")}),j(h,{value:_.source})]})]})}function V2(_){let{debugMode:$,t:Y}=L();return j("div",{className:"cortex-media-block__body",children:c_("p",{className:"cortex-media-block__error",children:[_.cutOff?Y("translate_media_cut_off"):Y("translate_media_failed"),!_.cutOff&&$&&` ${_.reason}`]})})}function K2(_){let{language:$,source:Y,closed:Q,hidden:X,onError:Z}=_,{config:G,scheme:J}=L(),N=B4(null);return H4(()=>{Z(void 0);let V=N.current;if(!Q||!J||!V)return;return X0(V,{language:$,source:Y,context:{scheme:J},overrides:G.mediaRenderers,onError:Z})},[$,Y,Q,J,G.mediaRenderers,Z]),j("div",{ref:N,hidden:X,className:U("cortex-media-block__body",`cortex-media-block__body--${$}`)})}function F4(_){let[$,Y]=P0();return c_(U4,{children:[$&&j(V2,{cutOff:!1,reason:$}),j(K2,{language:_.language,source:_.source,closed:!0,hidden:Boolean($),onError:Y})]})}function z2(_){let{language:$,source:Y,closed:Q,streaming:X}=_,{debugMode:Z,t:G}=L(),[J,N]=P0(),[V,K]=P0(!1),z=!Q&&!X,F=z||Boolean(J);return c_("div",{className:"cortex-media-block",children:[j(q4,{language:$,source:Y,pending:!Q&&X,closed:Q,debugMode:Z,sourceShown:V,onToggleSource:F?void 0:()=>K((q)=>!q)}),F&&j(V2,{cutOff:z,reason:J}),j(A_,{label:G(_1($).title),ready:Q&&!F,expanded:j(F4,{language:$,source:Y}),children:j(K2,{language:$,source:Y,closed:Q,hidden:F,onError:N})}),Z&&(F||V)&&j("pre",{className:"cortex-media-block__source",children:Y})]})}import{useMemo as L4,useRef as O4}from"react";import{jsx as V_}from"react/jsx-runtime";var P4="M8 2.5v7.5M5 7l3 3 3-3M2.75 11v1.25a1.25 1.25 0 0 0 1.25 1.25h8a1.25 1.25 0 0 0 1.25-1.25V11";function W2(_){let{t:$}=L(),Y=O4(null),Q=L4(()=>({__html:v_(_.text)}),[_.text]);function X(){let Z=Y.current?.querySelector("table");if(Z)g_(o1(a1(Z)),"table.xlsx")}return V_("div",{className:"cortex-table-block",children:V_(A_,{label:$("translate_table"),ready:_.closed,actions:V_("button",{type:"button",className:"cortex-expandable__action","aria-label":$("translate_table_export"),title:$("translate_table_export"),onClick:X,children:V_("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:V_("path",{d:P4,stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}),expanded:V_("div",{className:"cortex-table-block__expanded",dangerouslySetInnerHTML:Q}),children:V_("div",{ref:Y,dangerouslySetInnerHTML:Q})})})}import{jsx as E_}from"react/jsx-runtime";function H2(_){let{role:$,textPart:Y,streaming:Q=!1,attachments:X=[]}=_,{config:Z}=L(),G=$==="assistant"&&Q?"":Y.content,[J,N]=A4({text:G,fading:[]}),V=M0(G),K=M0(null),z=M0(!0);D2(()=>{function q(O,P){V.current=O,N((D)=>D.text===O&&!D.fading.length&&!P.length?D:{text:O,fading:P})}if($!=="assistant"||!Q){K.current?.destroy(),K.current=null,q(Y.content,[]),z.current=!1;return}if(!K.current)K.current=new $_(q),K.current.seed(V.current);if(z.current){z.current=!1,K.current.seed(Y.content);return}K.current.update(Y.content,!1)},[$,Q,Y]),D2(()=>()=>{K.current?.destroy(),K.current=null},[]);let F=M4(()=>{let q=$==="assistant"?r1(J.text,Q0(Z.mediaRenderers)):[{kind:"markdown",text:J.text}];return q.map((O,P)=>O.kind==="markdown"?{...O,html:{__html:v_(O.text,P===q.length-1?J.fading:[])}}:O)},[$,J,Z.mediaRenderers]),B=Q||J.text!==Y.content;return E_("div",{className:U("cortex-text-part",$==="assistant"&&"cortex-text-part--assistant",$==="user"&&"cortex-text-part--user"),children:E_("div",{className:U("cortex-text-bubble",$==="assistant"&&"cortex-text-bubble--assistant",$==="user"&&"cortex-text-bubble--user"),children:F.map((q,O)=>{switch(q.kind){case"markdown":return E_("div",{dangerouslySetInnerHTML:q.html},O);case"media":return E_(z2,{...q,streaming:B},O);case"table":return E_(W2,{text:q.text,closed:q.closed||!B},O);case"attachment":return E_(N2,{id:q.id,alt:q.alt,attachment:X.find((P)=>P.id.toLowerCase()===q.id)},O)}})})})}import{jsx as g,jsxs as X_}from"react/jsx-runtime";function B2({toolCallPart:_}){let{t:$}=L(),{state:Y,approval:Q}=_,X=_.output,Z=M1(_);if(Y==="complete")return X_("div",{className:"cortex-debug-tool__section cortex-debug-tool__section--success",children:[X_("div",{className:"cortex-debug-tool__section-bar",children:[g("span",{className:"cortex-debug-tool__section-label cortex-debug-tool__section-label--success",children:$("translate_output")}),g("span",{className:"cortex-debug-tool__section-lang",children:"json"}),g(h,{value:Z})]}),g("div",{dir:"ltr",className:"cortex-debug-tool__tree",children:g(Y_,{data:X,expandDepth:2})})]});if(Y==="error")return X_("div",{className:"cortex-debug-tool__section cortex-debug-tool__section--error",children:[X_("div",{className:"cortex-debug-tool__section-bar",children:[g("span",{className:"cortex-debug-tool__section-label cortex-debug-tool__section-label--error",children:$("translate_error")}),g(h,{value:Z})]}),g("pre",{dir:"ltr",className:"cortex-debug-tool__error-pre",children:Z})]});if(Y==="approval-requested")return X_("div",{className:"cortex-debug-tool__section cortex-debug-tool__section--approval",children:[X_("div",{className:"cortex-debug-tool__section-bar",children:[g("span",{className:"cortex-debug-tool__section-label cortex-debug-tool__section-label--approval",children:$("translate_approval_requested")}),g("span",{className:"cortex-debug-tool__section-lang",children:Q?.id})]}),g("div",{className:"cortex-debug-tool__message cortex-debug-tool__message--approval",children:$("translate_waiting_for_approval")})]});if(Y==="approval-responded")return X_("div",{className:"cortex-debug-tool__section cortex-debug-tool__section--approval",children:[X_("div",{className:"cortex-debug-tool__section-bar",children:[g("span",{className:"cortex-debug-tool__section-label cortex-debug-tool__section-label--approval",children:$("translate_approval_response")}),g("span",{className:"cortex-debug-tool__section-lang",children:Q?.id})]}),g("div",{className:"cortex-debug-tool__message cortex-debug-tool__message--approval",children:$(Q?.approved?"translate_tool_approved":"translate_tool_response_received")})]});return null}import{jsx as E4,jsxs as k4}from"react/jsx-runtime";function q2({toolCallPart:_}){let{t:$}=L(),Y=P1(_);return k4("span",{className:U("cortex-debug-tool__state",Y.modifier&&`cortex-debug-tool__state--${Y.modifier}`),children:[Y.pulse&&E4("span",{className:U("cortex-debug-tool__pulse",Y.pulse==="violet"&&"cortex-debug-tool__pulse--violet")}),$(Y.labelKey)]})}import{jsx as T,jsxs as s}from"react/jsx-runtime";function F2({toolCallPart:_}){let{t:$}=L(),{codeSnippets:Y,remainingInput:Q,remainingInputText:X}=A1(_.input);return s("details",{className:"cortex-debug-tool","data-state":_.state,children:[T("summary",{className:"cortex-debug-tool__summary",children:s("div",{className:"cortex-debug-tool__header",children:[s("div",{className:"cortex-debug-tool__meta",children:[T("div",{className:"cortex-debug-tool__title-row",children:T("span",{className:"cortex-debug-tool__name",title:_.name,children:_.name})}),T("div",{className:"cortex-debug-tool__id-row",children:T("span",{className:"cortex-debug-tool__id",children:_.id})})]}),s("div",{className:"cortex-debug-tool__actions",children:[T(q2,{toolCallPart:_}),T("svg",{className:"cortex-debug-tool__chevron",width:"14",height:"14",viewBox:"0 0 20 20",fill:"none",children:T("path",{d:S.chevronDownLarge,stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]})]})}),s("div",{className:"cortex-debug-tool__body",children:[Y.map((Z)=>s("div",{className:"cortex-debug-tool__section",children:[s("div",{className:"cortex-debug-tool__section-bar",children:[T("span",{className:"cortex-debug-tool__section-label",children:Z.key}),T("span",{className:"cortex-debug-tool__section-lang",children:Z.lang}),T(h,{value:Z.value})]}),T("pre",{dir:"ltr",className:"cortex-debug-tool__pre",children:T("code",{className:"hljs",dangerouslySetInnerHTML:{__html:G0(Z.value,Z.lang)}})})]},Z.key)),!!Q&&s("div",{className:"cortex-debug-tool__section",children:[s("div",{className:"cortex-debug-tool__section-bar",children:[T("span",{className:"cortex-debug-tool__section-label",children:$("translate_input")}),T("span",{className:"cortex-debug-tool__section-lang",children:"json"}),T(h,{value:X})]}),T("div",{dir:"ltr",className:"cortex-debug-tool__tree",children:T(Y_,{data:Q,expandDepth:2})})]}),T(B2,{toolCallPart:_})]})]})}import{useEffect as R4,useRef as I4,useState as U2}from"react";import{jsx as p_,jsxs as L2}from"react/jsx-runtime";function K_({activity:_,className:$}){let{t:Y}=L(),Q=k1(_),[X,Z]=U2(0),[G,J]=U2("idle"),N=I4(Q.length);return N.current=Q.length,R4(()=>{let V,K;function z(){V=setTimeout(()=>{J("exiting"),V=setTimeout(()=>{Z((F)=>(F+1)%N.current),J("enter-start"),K=requestAnimationFrame(()=>{J("entering"),V=setTimeout(()=>{J("idle"),z()},300)})},300)},2000)}return z(),()=>{if(V)clearTimeout(V);if(K)cancelAnimationFrame(K)}},[]),L2("div",{className:U("cortex-subtle-activity",$),children:[L2("div",{className:"cortex-subtle-activity__dots",children:[p_("span",{className:"cortex-subtle-activity__dot"}),p_("span",{className:"cortex-subtle-activity__dot cortex-subtle-activity__dot--d1"}),p_("span",{className:"cortex-subtle-activity__dot cortex-subtle-activity__dot--d2"})]}),p_("div",{className:"cortex-subtle-activity__label-mask",children:p_("span",{className:U("cortex-subtle-activity__label",`cortex-subtle-activity__label--${G}`),children:Y(Q[X])})})]})}import{useEffect as k2,useRef as A0,useState as E2}from"react";import{jsx as c,jsxs as k_,Fragment as y4}from"react/jsx-runtime";function O2({toolCallPart:_,asking:$}){let{t:Y,locale:Q,respondToApproval:X}=L(),{sentence:Z,decision:G,decisionKey:J}=E1(_,Q),N=`cortex-approval-${_.id}`,V=u0(_),K=G==="pending",{state:z,active:F}=i(_);return k_("div",{className:U("cortex-approval-card",K&&"cortex-approval-card--asking"),children:[K?k_(y4,{children:[k_("div",{className:"cortex-approval-card__head",children:[c("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:c("path",{d:"M8 1.75 2.75 3.75v4c0 3 2.2 5.3 5.25 6.5 3.05-1.2 5.25-3.5 5.25-6.5v-4L8 1.75Z",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"})}),Y("translate_approval_needed")]}),c("p",{className:"cortex-approval-card__sentence",id:N,children:Z})]}):k_("div",{className:"cortex-approval-card__line",children:[k_("span",{className:"cortex-tool-pill__icon","aria-hidden":"true",children:[c("span",{className:U("cortex-tool-pill__spinner",F&&"cortex-tool-pill__spinner--visible")}),c("svg",{className:U("cortex-tool-pill__svg cortex-tool-pill__svg--check",z==="complete"&&"cortex-tool-pill__svg--visible"),viewBox:"0 0 20 20",fill:"none",children:c("path",{d:"M5.5 10.5 L8.5 13.5 L14.5 7",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),c("svg",{className:U("cortex-tool-pill__svg cortex-tool-pill__svg--error",z==="error"&&"cortex-tool-pill__svg--visible"),viewBox:"0 0 20 20",fill:"none",children:c("path",{d:"M6.5 6.5 L13.5 13.5 M13.5 6.5 L6.5 13.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})]}),J&&c("span",{className:"cortex-approval-card__decision",children:Y(J)}),c("span",{className:"cortex-approval-card__summary",children:Z})]}),K&&$&&k_("div",{className:"cortex-approval-card__foot",children:[c("button",{type:"button",className:"cortex-approval-card__button cortex-approval-card__button--approve","aria-describedby":N,onClick:()=>void X(V,!0),children:Y("translate_approve")}),c("button",{type:"button",className:"cortex-approval-card__button","aria-describedby":N,onClick:()=>void X(V,!1),children:Y("translate_deny")})]})]})}import{useEffect as P2,useRef as N1,useState as M2}from"react";import{jsx as C,jsxs as p}from"react/jsx-runtime";function A2({toolCallPart:_,setOutput:$}){let{t:Y}=L(),{state:Q,id:X,input:Z}=_;if(Q==="complete"||Q==="error"){let G=c1(_.output);return G?C(w4,{position:G}):p("div",{className:"cortex-tool-pill",children:[C("span",{className:"cortex-tool-pill__icon",children:C("svg",{className:U("cortex-tool-pill__svg cortex-tool-pill__svg--visible",Q==="error"&&"cortex-tool-pill__svg--error"),viewBox:"0 0 20 20",fill:"none",children:C("path",{d:"M6.5 6.5 L13.5 13.5 M13.5 6.5 L6.5 13.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}),C("span",{className:"cortex-tool-pill__title",children:Y("translate_location_not_shared")})]})}if(Q!=="input-complete")return null;return C(C4,{center:u1(Z),submit:$},X)}function C4({center:_,submit:$}){let{t:Y}=L(),Q=N1(null),X=N1(void 0),[Z,G]=M2(a_),J=N1({center:_,submit:$});J.current={center:_,submit:$},P2(()=>{let V=Q.current;if(!V)return;let K=x1(V,{center:J.current.center,onState:G,submit:(z)=>J.current.submit(z)});return X.current=K,K.start(),()=>{if(K.dispose(),X.current===K)X.current=void 0}},[]);let N=p1(Z);return p("div",{className:"cortex-location-input",children:[p("div",{className:"cortex-location-input__map",children:[C("div",{className:"cortex-location-input__canvas",ref:Q}),C("button",{type:"button",className:"cortex-location-input__locate","aria-label":Y("translate_location_locate"),title:Y("translate_location_locate"),disabled:Z.locating||Z.submitting,onClick:()=>X.current?.locate(),children:C(S4,{})})]}),p("div",{className:"cortex-location-input__foot",children:[Z.position&&!Z.deliveryFailed?C("span",{className:"cortex-location-input__coords",children:o_(Z.position)}):p("span",{className:U("cortex-location-input__hint",N.failed&&"cortex-location-input__hint--failed"),children:[Z.locating&&C("span",{className:"cortex-location-input__spinner"}),Y(N.key)]}),p("span",{className:"cortex-location-input__actions",children:[C("button",{type:"button",className:"cortex-location-input__skip",disabled:Z.submitting,onClick:()=>X.current?.cancel(),children:Y("translate_location_skip")}),C("button",{type:"button",className:"cortex-location-input__send",disabled:!Z.position||Z.submitting,onClick:()=>X.current?.confirm(),children:Y("translate_location_send")})]})]})]})}function w4({position:_}){let{t:$}=L(),Y=N1(null),[Q,X]=M2(!1),{lat:Z,lng:G}=_;return P2(()=>{let J=Y.current;if(!J)return;return X(!1),h1(J,{lat:Z,lng:G},()=>X(!0))},[Z,G]),p("div",{className:"cortex-location-input cortex-location-input--settled",children:[p("div",{className:"cortex-location-input__map cortex-location-input__map--still",children:[C("div",{className:"cortex-location-input__canvas",ref:Y,hidden:Q}),Q&&C("span",{className:"cortex-location-input__still-failed",children:$("translate_location_map_failed")})]}),p("div",{className:"cortex-location-input__body",children:[p("span",{className:"cortex-location-input__title",children:[C("svg",{viewBox:"0 0 20 20",fill:"none",children:C("path",{d:"M5.5 10.5 L8.5 13.5 L14.5 7",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),$("translate_location_shared")]}),C("span",{className:"cortex-location-input__coords",children:o_(_)})]})]})}function S4(){return p("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:[C("circle",{cx:"10",cy:"10",r:"5.5"}),C("circle",{cx:"10",cy:"10",r:"1.6",fill:"currentColor",stroke:"none"}),C("path",{d:"M10 1.5v3M10 15.5v3M1.5 10h3M15.5 10h3"})]})}import{jsx as I,jsxs as d_}from"react/jsx-runtime";var b4=new Map([[r_,A2]]);function R2({message:_,toolCallPart:$,agentWorking:Y}){let{config:Q,addToolResult:X}=L(),Z=$.state==="input-complete"&&!Y,G=$.state==="approval-requested"&&!Y,J=Q.toolComponents?.[$.name]??(Z||f($.state)?b4.get($.name):void 0);return I("div",{className:"cortex-tool-call-animated",children:J?I(J,{toolCallPart:$,message:_,setOutput:(N)=>X($.id,$.name,N)}):Z?I(T4,{toolCallPart:$}):I(I2,{toolCallPart:$,asking:G})})}function T4({toolCallPart:_}){let{api:$,t:Y,addToolResult:Q,selectedThread:X,config:Z}=L(),G=X?.id,[J,N]=E2({phase:"initiating"}),[V]=E2(Z.trustSameOriginEmbeds),K=A0(void 0),z=A0({api:$,addToolResult:Q,toolName:_.name});if(z.current={api:$,addToolResult:Q,toolName:_.name},k2(()=>{if(!G)return;let B=g1({initiate:()=>z.current.api.initiateToolCall(G,_.id),onState:N,submit:(O)=>z.current.addToolResult(_.id,z.current.toolName,O)});K.current=B,B.start();let q=(O)=>B.handleMessage(O);return window.addEventListener("message",q),()=>{if(window.removeEventListener("message",q),B.dispose(),K.current===B)K.current=void 0}},[_.id,G]),!G||J.phase==="unavailable"||J.phase==="settling")return I(I2,{toolCallPart:_,asking:!1});let F=d_("div",{className:"cortex-client-tool-embed",children:[d_("div",{className:"cortex-client-tool-embed__bar",children:[I("span",{children:Y("translate_client_tool_title")}),I("button",{type:"button",className:"cortex-client-tool-embed__cancel",onClick:()=>K.current?.cancel(),children:Y("translate_client_tool_cancel")})]}),J.phase==="embedded"?I("iframe",{className:"cortex-client-tool-embed__frame",src:J.embedUrl,sandbox:v1(J.embedUrl,window.location.origin,V),title:Y("translate_client_tool_title"),ref:(B)=>K.current?.setSource(B?.contentWindow),onLoad:(B)=>{if(!f1(J.embedUrl,window.location.origin,V)&&j1(B.currentTarget,window.location.origin))K.current?.terminate()}}):J.phase==="error"?d_("div",{className:"cortex-client-tool-embed__status",children:[I("span",{children:Y("translate_client_tool_failed")}),I("button",{type:"button",className:"cortex-client-tool-embed__retry",onClick:()=>void K.current?.start(),children:Y("translate_client_tool_retry")})]}):I("div",{className:"cortex-client-tool-embed__status",children:Y("translate_client_tool_loading")})]});return J.phase==="embedded"&&J.surface==="modal"?I(v4,{label:Y("translate_client_tool_title"),onCancel:()=>K.current?.cancel(),children:F}):F}function v4({label:_,onCancel:$,children:Y}){let Q=A0(null);return k2(()=>{let X=Q.current;return X?.showModal(),()=>X?.close()},[]),I("dialog",{ref:Q,className:"cortex-client-tool-embed-dialog","aria-label":_,onCancel:(X)=>{X.preventDefault(),$()},children:Y})}function I2({toolCallPart:_,asking:$}){return i(_).gated?I(O2,{toolCallPart:_,asking:$}):I(f4,{toolCallPart:_})}function f4({toolCallPart:_}){let{t:$}=L(),{state:Y,active:Q,titleKey:X,statement:Z,rowCount:G}=i(_);return d_("div",{className:"cortex-tool-pill",children:[d_("span",{className:"cortex-tool-pill__icon",children:[I("span",{className:U("cortex-tool-pill__spinner",Q&&"cortex-tool-pill__spinner--visible")}),I("svg",{className:U("cortex-tool-pill__svg","cortex-tool-pill__svg--check",Y==="complete"&&"cortex-tool-pill__svg--visible"),viewBox:"0 0 20 20",fill:"none",children:I("path",{d:"M5.5 10.5 L8.5 13.5 L14.5 7",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),I("svg",{className:U("cortex-tool-pill__svg","cortex-tool-pill__svg--error",Y==="error"&&"cortex-tool-pill__svg--visible"),viewBox:"0 0 20 20",fill:"none",children:I("path",{d:"M6.5 6.5 L13.5 13.5 M13.5 6.5 L6.5 13.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})]}),I("span",{className:U("cortex-tool-pill__title",Y==="error"&&"cortex-tool-pill__title--error",Y==="starting"&&Z&&"cortex-tool-pill__title--pending"),children:Z??$(X)}),G!==void 0&&I("span",{className:"cortex-tool-pill__meta",children:$("translate_rows_read",{count:G})})]})}import{jsx as E0}from"react/jsx-runtime";function y2({message:_,toolCallPart:$,agentWorking:Y}){if(!f($.state)&&!i($).statement){if($.name==="queryGraph")return E0(K_,{activity:"graph"});if($.name==="executeCode")return E0(K_,{activity:"code"})}return E0(R2,{toolCallPart:$,message:_,agentWorking:Y})}import{jsx as R_,jsxs as j4}from"react/jsx-runtime";function C2(_){let{message:$,part:Y,debugMode:Q,animate:X,streaming:Z,agentWorking:G,attachments:J}=_,{t:N}=L();function V(){switch(Y.type){case"text":return R_(H2,{textPart:Y,role:$.role,streaming:Z,attachments:J});case"thinking":return Q?R_(G2,{reasoningPart:Y,streaming:Z}):R_(K_,{activity:"reasoning",className:"cortex-reasoning-animated"});case"tool-call":return Q?R_(F2,{toolCallPart:Y}):R_(y2,{toolCallPart:Y,message:$,agentWorking:G});default:return j4("p",{className:"cortex-unhandled-type",children:[N("translate_unhandled_type")," ",Y.type]})}}return R_("div",{className:U("cortex-message-part",X&&"cortex-message-part--animated",_.folded&&"cortex-message-part--folded"),"data-cortex-frontier":_.frontier?"":void 0,children:V()})}import{jsx as e,jsxs as k0}from"react/jsx-runtime";function m4({isUser:_,clipboardText:$,createdAt:Y}){let{locale:Q}=L();return k0("div",{className:U("cortex-message-actions",_&&"cortex-message-actions--user"),children:[$&&e(h,{value:$}),Y&&e("time",{className:"cortex-message-actions__time",dateTime:Y,children:r(Y,Q)})]})}function x4({count:_,animate:$,onOpen:Y}){let{t:Q}=L();return e("button",{type:"button",className:U("cortex-tool-fold",$&&"cortex-message-part--animated"),onClick:Y,children:Q(C_(_,"translate_one_more_step","translate_n_more_steps"),{count:_})})}function w2(_){let{message:$,parts:Y,metadata:Q,debugMode:X,animate:Z,isStreaming:G,agentWorking:J,closesTurn:N,fold:V,onOpenRun:K,frontier:z}=_,F=$.role==="assistant",B=$.role==="user",q=G?Y.length-1:-1,O=Q?.attachments??[],P=Y.filter((k)=>V?.get(k)?.kind!=="hidden"),D=P.filter((k)=>k.type==="text").at(-1),H=D?Y.indexOf(D):-1,W=(B||F)&&!G&&H>=0,M=D!==P.at(-1)?H:-1,A=W&&e(m4,{isUser:B,clipboardText:R1(Y),createdAt:Q?.createdAt});return k0("div",{className:"cortex-message-parts",children:[Y.map((k,n)=>{let Z_=V?.get(k);return k0(g4,{children:[e(C2,{part:k,message:$,debugMode:X,animate:Z,streaming:n===q,agentWorking:J,attachments:O,frontier:k===z,folded:Z_?.kind==="hidden"}),Z_?.kind==="more"&&e(x4,{count:Z_.count,animate:Z,onOpen:()=>K(Z_.runId)}),n===M&&A]},$.parts.indexOf(k))}),O.length>0&&e(t6,{attachments:O,isUser:B}),Q?.isAborted&&e(a6,{}),M===-1&&A,X&&Q&&N&&e(Z2,{messageId:$.id,isAssistant:F,metadata:Q})]})}import{jsx as z_,jsxs as R0}from"react/jsx-runtime";function S2({firing:_,debugMode:$}){let{t:Y,locale:Q}=L();return R0("div",{className:U("cortex-trigger-block",$&&"cortex-trigger-block--debug"),children:[R0("div",{className:"cortex-trigger-block__head",children:[z_("svg",{className:"cortex-trigger-block__icon",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:z_("path",{d:"M6.75 1 2.5 6.75h3l-.25 4.25L9.5 5.25h-3z",fill:"currentColor"})}),$&&z_("span",{children:Y("translate_trigger_fired")}),z_("span",{className:"cortex-trigger-block__name",children:_.name}),z_("time",{className:"cortex-trigger-block__time",dateTime:_.firedAt,children:r(_.firedAt,Q)})]}),$&&R0("details",{className:"cortex-trigger-block__payload",children:[z_("summary",{children:Y("translate_trigger_payload")}),z_(Y_,{data:_.payload,expandDepth:2})]})]})}import{jsx as l_}from"react/jsx-runtime";var b2=h4(function($){let{message:Y,metadata:Q,isStreaming:X,agentWorking:Z,closesTurn:G,debugMode:J,animate:N,fold:V,onOpenRun:K,workingTurn:z,frontier:F}=$,B=B_(Y.parts,{debugMode:J,isStreaming:X});if(Q?.trigger)return l_("div",{className:"cortex-message",children:l_(S2,{firing:Q.trigger,debugMode:J})});if(B.length===0&&!Q?.attachments?.length)return l_("div",{className:"cortex-message"});return l_("div",{className:U("cortex-message",z&&"cortex-message--working-turn"),children:l_(w2,{message:Y,parts:B,metadata:Q,debugMode:J,animate:N,isStreaming:X,agentWorking:Z,closesTurn:G,fold:V,onOpenRun:K,frontier:F})})});import{jsx as V1}from"react/jsx-runtime";var u4=[{role:"user",lines:[13,9]},{role:"assistant",lines:[16,18,12]},{role:"user",lines:[11]},{role:"assistant",lines:[14,15]}];function T2(){return V1("div",{className:"cortex-widget__messages-skeleton",children:u4.map((_,$)=>V1("div",{className:`cortex-widget__msg-skel cortex-widget__msg-skel--${_.role}`,children:V1("div",{className:`cortex-widget__msg-skel-bubble cortex-widget__msg-skel-bubble--${_.role}`,children:_.lines.map((Y)=>V1("div",{className:"cortex-skeleton cortex-widget__msg-skel-line",style:{width:`${Y}rem`}},Y))})},$))})}import{jsx as d,jsxs as K1,Fragment as i4}from"react/jsx-runtime";function p4(_){let $=W_(null),Y=W_(null),Q=W_(!0),X=W_(!0),Z=W_(!1),G=n_(()=>{if(Z.current)return;Z.current=!0,queueMicrotask(()=>{Z.current=!1;let K=$.current;if(!K)return;$1(K),X.current=!0,Q.current=!1})},[]);I0(()=>{let K=Y.current;if(!_||!$.current||!K)return;if(G(),typeof ResizeObserver>"u")return;let z=0,F=new ResizeObserver(([B])=>{let q=B?.contentRect.height??0,O=q>z;if(z=q,O&&(Q.current||X.current))G()});return F.observe(K),()=>F.disconnect()},[_,G]);let J=n_(()=>{Q.current=!0},[]),N=n_(()=>{if(Q.current)G()},[G]);function V(){let K=$.current;if(K)X.current=D0(K)<100}return{containerRef:$,contentRef:Y,onScroll:V,pin:J,settlePinned:N}}function d4({pin:_,settlePinned:$,contentRef:Y},Q,X){let[Z,G]=C0(!1);I0(()=>{G(!1),_(),queueMicrotask(()=>G(!0))},[Q,_]);let J=X[X.length-1],N=J?.role==="user"?J.id:void 0,V=N?J?.parts.find((K)=>K.type==="text")?.content:void 0;return y0(()=>{if(!N)return;_();let K=Y.current;if(K&&V!==void 0)W0(K,V)},[N,V,_,Y]),I0(()=>{$()},[X,$]),Z}function l4(_,$,Y,Q){let[X,Z]=C0(new Set),G=n_((V)=>Z((K)=>new Set(K).add(V)),[]),[J]=C0(C1);return{folds:c4(()=>J(_,{agentWorking:$,debugMode:Y,opened:X,foldable:Q}),[J,_,$,Y,X,Q]),openRun:G}}function n4({working:_}){let $=W_(null),Y=W_(void 0);return y0(()=>{let Q=$.current;if(!Q)return;let X=H0(Q);return Y.current=X,()=>{X.dispose(),Y.current=void 0}},[]),y0(()=>Y.current?.sync(_)),K1("div",{ref:$,className:"cortex-working-avatar","aria-hidden":"true",children:[K1("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d("path",{d:"M9.94 15.5a2 2 0 0 0-1.44-1.44l-6.13-1.58a.5.5 0 0 1 0-.96L8.5 9.94A2 2 0 0 0 9.94 8.5l1.58-6.14a.5.5 0 0 1 .96 0l1.58 6.14a2 2 0 0 0 1.44 1.44l6.14 1.58a.5.5 0 0 1 0 .96l-6.14 1.58a2 2 0 0 0-1.44 1.44l-1.58 6.14a.5.5 0 0 1-.96 0z"}),d("path",{d:"M20 3v4M22 5h-4M4 17v2M5 18H3"})]}),d("span",{className:"cortex-working-avatar__ring"})]})}function v2(_){let{config:$,selectedThread:Y}=L(),{messages:Q,isAgentWorking:X,isLoadingMessages:Z,hasPendingToolCalls:G}=F_(),{capabilities:J,composerRef:N,debugMode:V}=_,K=!Z||X,z=p4(K),F=d4(z,Y?.id,Q),B=X?w_(Q)?.id:void 0,q=$.toolComponents,O=n_((A)=>I1(A,q),[q]),{folds:P,openRun:D}=l4(Q,X,V,O),H=Q.map((A)=>A.role).lastIndexOf("user"),W=X&&!V,M=W?y1(Q,{foldable:O}):void 0;return K1(i4,{children:[!K?d(T2,{}):d("div",{className:_.className,children:d("div",{ref:z.containerRef,className:"cortex-message-list",onScroll:z.onScroll,children:K1("div",{ref:z.contentRef,className:"cortex-message-list__content",children:[Q.map((A,k)=>d(b2,{message:A,metadata:A.metadata,isStreaming:A.id===B,agentWorking:X,fold:P.get(A.id),onOpenRun:D,closesTurn:A.role==="assistant"&&Q[k+1]?.role!=="assistant",debugMode:V,animate:F,workingTurn:W&&k>H,frontier:A.id===B?M:void 0},A.id)),X&&!M&&d("div",{className:"cortex-working-thinking","data-cortex-frontier":"",children:d(K_,{activity:"reasoning"})}),d(n4,{working:X},Y?.id)]})})}),!G&&d(Y1,{capabilities:J,composerRef:N})]})}import{jsx as f2,jsxs as r4}from"react/jsx-runtime";function j2(_){let{debugMode:$,selectedThread:Y}=L(),{screens:Q}=_;return r4("div",{className:U("cortex-widget__screen",Q.screen==="chat"&&"cortex-widget__screen--active",Q.screen!=="chat"&&"cortex-widget__screen--right"),children:[_.header,Y?f2(v2,{className:"cortex-widget__messages",debugMode:$,capabilities:_.capabilities,composerRef:_.composerRef}):_.landing,f2("div",{className:"cortex-widget__sidebar-backdrop",onClick:Q.closeSidebar})]})}import{useState as e4}from"react";import{useEffect as w0,useRef as h2,useState as S0}from"react";import{useChat as s4}from"@tanstack/ai-react";import{useEffect as a4,useLayoutEffect as o4,useState as t4}from"react";function g2(_,{sessionRef:$,pendingSendRef:Y}){let[Q]=t4(_);return o4(()=>{return $.current=Q,()=>{if($.current===Q)$.current=void 0}},[Q,$]),a4(()=>{if(!Y.current.length)return;let X=setTimeout(()=>{let Z=Y.current;Y.current=[],(async()=>{for(let{prompt:G,attachments:J}of Z)await Q.send(G,J)})()});return()=>clearTimeout(X)},[Q,Y]),Q}import{useRef as m2}from"react";function x2(_){let $=m2(_);$.current=_;let Y=m2(Promise.resolve(void 0));async function Q(X){let Z=$.current;if(!Z.isAlive()||X!==Z.threadId)return;return S1({api:Z.api,threadId:X,isStale:()=>!$.current.isAlive(),isStreaming:()=>$.current.isStreaming(),setMessages:(G)=>$.current.setMessages(G)})}return function(Z){return Y.current=Y.current.then(()=>Q(Z)),Y.current}}function u2(_){let{thread:$,api:Y}=_,Q=h2(!0),[X,Z]=S0(!1),G=h2(null),J=x2({api:Y,threadId:$.id,isAlive:()=>Q.current,isStreaming:()=>G.current.chat.isLoading,setMessages:(H)=>G.current.chat.setMessages(H)}),[N]=S0(()=>B0({threadId:$.id,isAlive:()=>Q.current,onToolCall:()=>G.current.props.configRef.current.hooks?.onToolCall,deliver:(H)=>G.current.chat.addToolResult(H),setRunning:(H)=>G.current.props.setRunning($.id,H),reloadThreads:()=>G.current.props.reloadThreads(),refreshMessages:()=>J($.id),onTurnFinished:()=>G.current.props.onTurnFinished(),onSendFailed:()=>G.current.props.onSendFailed()})),[V]=S0(()=>w1({api:Y,thread:{id:$.id,isRunning:$.isRunning},mode:_.mode,localMessages:()=>G.current.chat.messages,onHydrated:(H)=>{if(Q.current)N.hydrated(H,$.isRunning)},onTranscriptCarried:(H)=>{if(Q.current)N.transcriptCarried(H)},setLoadingMessages:(H)=>{if(Q.current)Z(H)}})),K=s4({threadId:$.id,persistence:!0,initialMessages:_.initialMessages,connection:V,onChunk:()=>{if(Q.current)N.chunkArrived()},onError:()=>{if(Q.current)N.streamFailed()}});G.current={chat:K,props:_};async function z(H,W){N.sendStarted();let M={id:S_(),role:"user",parts:[{type:"text",content:H}],metadata:{createdAt:new Date().toISOString(),attachments:W}};await G.current.chat.append(M)}async function F(){if(!G.current.chat.isLoading)return;let{aborted:H}=await Y.abortStream($.id).catch(()=>({aborted:!1}));if(!Q.current)return;if(H)N.abortConfirmed();G.current.chat.stop()}function B(H,W,M){return G.current.chat.addToolResult({toolCallId:H,tool:W,output:M}).catch((A)=>{throw J($.id),A})}function q(H,W){return m1(G.current.chat,H,W)}function O(H){if(G.current.chat.isLoading)return;if(H.isRunning){G.current.props.remount(H,G.current.chat.messages);return}J(H.id)}w0(()=>{return Q.current=!0,()=>{Q.current=!1}},[]),g2(()=>({threadId:$.id,send:z,abort:F,addToolResult:B,respondToApproval:q,reattach:O,transcriptUpdated:(H,W)=>{if(H===$.id)N.transcriptUpdated(W)}}),{sessionRef:_.sessionRef,pendingSendRef:_.pendingSendRef});let{messages:P,isLoading:D}=K;return w0(()=>{N.loadingChanged(D,()=>G.current.chat.messages)},[N,D]),w0(()=>{G.current.props.publish({messages:P,isAgentWorking:D,isLoadingMessages:X,hasPendingToolCalls:!D&&__(P).length>0})},[P,D,X]),null}import{jsx as _7,jsxs as $7}from"react/jsx-runtime";function c2({selection:_,threads:$,children:Y,...Q}){let{session:X}=_,[Z,G]=e4(),J=X&&`${X.thread.id}:${X.epoch}`,N=X&&Z&&(Z.key===J||X.mode==="reload")?Z.value:F0;return $7(U0.Provider,{value:N,children:[X&&J&&_7(u2,{thread:X.thread,mode:X.mode,initialMessages:X.initialMessages,setRunning:$.setRunning,reloadThreads:$.reload,remount:_.remount,publish:(V)=>G({key:J,value:V}),...Q},J),Y]})}import{jsx as w,jsxs as D_,Fragment as Y7}from"react/jsx-runtime";function p2(_){let{locale:$,t:Y}=L(),{threads:Q}=_;return w("div",{className:"cortex-widget__threads-list",children:Q===void 0?[1,2,3,4].map((X)=>D_("div",{className:"cortex-widget__thread-skeleton",children:[w("div",{className:"cortex-skeleton cortex-widget__thread-skeleton-icon"}),w("div",{className:"cortex-widget__thread-skeleton-lines",children:w("div",{className:"cortex-skeleton cortex-widget__thread-skeleton-line",style:{width:`${40+X*12}%`}})})]},X)):D_(Y7,{children:[Q.map((X)=>{let Z=X.id===_.selectedThreadId,G=r(X.updatedAt,$);return D_("button",{onClick:()=>_.openThread(X),className:U("cortex-widget__thread-item",Z&&"cortex-widget__thread-item--active"),children:[w("div",{className:U("cortex-widget__thread-icon",Z&&"cortex-widget__thread-icon--active"),children:w("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:w("path",{d:S.bubble,stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}),D_("div",{className:"cortex-widget__thread-info",children:[D_("div",{className:"cortex-widget__thread-title-row",children:[w("p",{className:U("cortex-widget__thread-title",Z&&"cortex-widget__thread-title--active"),children:X.title??Y("translate_untitled")}),X.isRunning&&D_("span",{className:U("cortex-widget__thread-running",Z&&"cortex-widget__thread-running--active"),children:[w("span",{className:"cortex-widget__thread-running-dot"}),Y("translate_running")]})]}),G&&w("p",{className:"cortex-widget__thread-time",children:G})]}),w("span",{role:"button",tabIndex:0,onClick:(J)=>{J.stopPropagation(),_.deleteThread(X.id)},onKeyDown:(J)=>{if(J.key!=="Enter"&&J.key!==" ")return;J.preventDefault(),J.stopPropagation(),_.deleteThread(X.id)},className:U("cortex-widget__thread-delete",Z&&"cortex-widget__thread-delete--active"),children:w("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",children:w("path",{d:"M4 4l8 8M12 4l-8 8",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"})})}),w("svg",{className:U("cortex-widget__thread-arrow",Z&&"cortex-widget__thread-arrow--active"),width:"10",height:"10",viewBox:"0 0 16 16",fill:"none",children:w("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]},X.id)}),!Q.length&&D_("div",{className:"cortex-widget__threads-empty",children:[w("div",{className:"cortex-widget__threads-empty-icon",children:w("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",className:"cortex-widget__threads-empty-svg",children:w("path",{d:S.bubble,stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}),w("p",{className:"cortex-widget__threads-empty-title",children:Y("translate_no_threads_yet")}),w("p",{className:"cortex-widget__threads-empty-subtitle",children:Y("translate_start_a_new_conversation")}),w("button",{onClick:_.newChat,className:"cortex-widget__new-chat-btn cortex-widget__new-chat-btn--empty-state",children:Y("translate_new_chat")})]})]})})}import{useSyncExternalStore as Q7}from"react";function d2(_){return Q7(($)=>{let Y=window.matchMedia(_);return Y.addEventListener("change",$),()=>Y.removeEventListener("change",$)},()=>window.matchMedia(_).matches,()=>!1)}import{jsx as Z7,jsxs as n2}from"react/jsx-runtime";var X7="(max-width: 768px)";function l2(_){_.preventDefault()}function i2(_){let{screens:$}=_,Y=d2(X7),Q=_.viewMode==="full"?Y&&!$.sidebarOpen:$.screen!=="threads";return Z7("div",{className:U("cortex-widget",_.className),"data-cortex-theme":_.theme,children:n2("div",{className:U("cortex-widget__container",_.viewMode==="full"&&"cortex-widget__container--full",$.sidebarOpen&&"cortex-widget__container--sidebar-open"),onDragOver:l2,onDrop:l2,children:[n2("div",{className:U("cortex-widget__screen",$.screen==="threads"&&"cortex-widget__screen--active",$.screen!=="threads"&&"cortex-widget__screen--left"),"aria-hidden":Q||void 0,inert:Q||void 0,children:[_.header,_.threadList]}),_.children]})})}import{jsx as l}from"react/jsx-runtime";var J7={header:l6,landing:i6,threadList:p2};function b0(_,$){return _?.[$]??J7[$]}function N7(_){let{isAgentWorking:$}=F_();return l(_.component,{..._.context,isWorking:$})}function V7({config:_,className:$,slots:Y}){let Q=r2(_);Q.current=_;let[X]=z1(()=>U1(()=>Q.current.transport)),Z=v6(X),[G,J]=z1(!1),[N,V]=z1();G7(()=>Z0(_.theme,V),[_.theme]);let K=_.viewMode??"helper",z=j6(K),[F,B]=z1(0),q=E6(X,F),O=r2(null),P=w6({api:X,threads:Z,getHooks:()=>Q.current.hooks}),{sessionRef:D,selection:H,queue:W,send:M,pendingSendRef:A}=P,{selected:k,selectedRef:n}=H,Z_=b6({threads:Z,selectedRef:n,sessionRef:D,deselect:H.deselect,onReconnect:()=>B((m)=>m+1)});S6({getConfig:()=>Q.current,onEvent:Z_.onEvent,onMount:()=>void Z.reload(),onReconnect:Z_.onReconnect});let i_=L1(_.locale),a2={config:_,locale:i_,t:(m,W1)=>G_(i_,m,W1),api:X,debugMode:G,scheme:N,capabilities:q,selectedThread:k,send:M,...T6(D),queue:W.value};function o2(){W.store.discardConsumed(),setTimeout(()=>O.current?.focusInput())}function t2(){W.store.restoreConsumed(n.current?.id)}function T0(m){P.openThread(m),z.showChat()}function v0(){H.deselect(),z.showChat()}function s2(){J((m)=>!m)}function f0(m){let W1={screen:m,viewMode:K,title:k?.title??null,agentName:H_(_.agentName,i_),threadCount:Z.threads?.length??0,debug:{shown:Boolean(_.showDebugButton),on:G},newChat:v0,openHistory:z.openHistory,closeHistory:z.closeHistory,toggleDebug:s2};return l(N7,{component:b0(Y,"header"),context:W1})}let e2=b0(Y,"landing"),_5={...O1(q,i_,(m)=>void M(m)),threads:Z.threads,composer:l("div",{className:"cortex-widget__landing-composer",children:l(Y1,{capabilities:q})}),openThread:T0},$5=b0(Y,"threadList"),Y5={threads:Z.threads,selectedThreadId:k?.id,openThread:T0,deleteThread:(m)=>void P.deleteThread(m),newChat:v0};return l(q0.Provider,{value:a2,children:l(c2,{selection:H,threads:Z,api:X,configRef:Q,sessionRef:D,pendingSendRef:A,onTurnFinished:o2,onSendFailed:t2,children:l(i2,{className:$,theme:_.theme,viewMode:K,screens:z,header:f0("threads"),threadList:l($5,{...Y5}),children:l(j2,{screens:z,capabilities:q,composerRef:O,header:f0("chat"),landing:l(e2,{..._5})})})})})}export{V7 as CortexChatWidget};
13
+ `).find((Y)=>/\S/.test(Y)&&!/^\s*%%/.test(Y));return/^\s*(\S+)/.exec($??"")?.[1]??""}function Y0(_){return _===void 0||_==="container"}var F8=["row","column","facet"];function q6(_){let $=_.encoding,Y=typeof $==="object"&&$!==null&&F8.some((Q)=>(Q in $));return(("mark"in _)||("layer"in _))&&Y0(_.width)&&!Y}function U8(_){let $={..._};if(Y0($.width))delete $.width;if(Y0($.height))delete $.height;return $}function L8(_,$){let Y=U8(_);if($<=0||!q6(_))return Y;return{...Y,width:$,height:Y.height??Math.round(Math.min(480,Math.max(200,$/2))),autosize:Y.autosize??{type:"fit",contains:"padding"}}}var O8="vg-tooltip-element",K6=Promise.resolve(),z6=!1,W6=0;function P8(){return W6+=1,W6}var M8=new Set(["image","use","feImage"]);function D6(_){for(let $ of[_,..._.querySelectorAll("*")]){for(let Y of[...$.attributes])if((Y.name==="href"||Y.name==="xlink:href")&&M8.has($.tagName)&&!Y.value.trim().startsWith("#")||e_(Y.value))$.removeAttribute(Y.name);if($.tagName==="style"&&$.textContent)$.textContent=$0($.textContent)}}function A8(_){if(!_||typeof _!=="object")throw Error("A map needs a JSON object.");let $=_,Y=$.zoom??10;if(typeof Y!=="number"||Y<0||Y>22)throw Error("zoom must be 0 to 22.");let Q=$.markers??[];if(!Array.isArray(Q))throw Error("markers must be a list.");return{center:H6($.center,"center"),zoom:Y,markers:Q.map((X,Z)=>{let G=X??{},J=G.label;return{position:H6(G.position,`markers[${Z}].position`),label:typeof J==="string"?J:void 0}})}}function H6(_,$){let Y=Array.isArray(_)?_:[],[Q,X]=Y;if(typeof Q!=="number"||typeof X!=="number"||Math.abs(Q)>90||Math.abs(X)>180)throw Error(`${$} must be [latitude, longitude].`);return{lat:Q,lng:X}}function Z0(_,$){if(_!=="system")return $(_??"light"),()=>{};let Y=window.matchMedia("(prefers-color-scheme: dark)"),Q=()=>$(Y.matches?"dark":"light");return Q(),Y.addEventListener("change",Q),()=>Y.removeEventListener("change",Q)}import j_ from"highlight.js/lib/core";import E8 from"highlight.js/lib/languages/javascript";import k8 from"highlight.js/lib/languages/json";import R8 from"highlight.js/lib/languages/sql";var F6=!1;function I8(){if(F6)return;F6=!0,j_.registerLanguage("javascript",E8),j_.registerLanguage("json",k8),j_.registerLanguage("cypher",R8)}function G0(_,$){if(!_)return"";return I8(),j_.getLanguage($)?j_.highlight(_,{language:$}).value:y8(_)}function y8(_){return _.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function q_(_){if(typeof _==="string"){let $=_.trim();if(!($.startsWith("{")&&$.endsWith("}")||$.startsWith("[")&&$.endsWith("]")))return _;try{return q_(JSON.parse($))}catch{return _}}if(Array.isArray(_))return _.map(($)=>q_($));if(_!==null&&typeof _==="object"){let $={};for(let[Y,Q]of Object.entries(_))$[Y]=q_(Q);return $}return _}function J0(_,$){if(Array.isArray(_)){let Y=_;return{kind:"container",open:"[",close:"]",summary:U6(Y.length,"item","items"),entries:Y.map((Q,X)=>({key:null,value:Q,path:`${$}[${X}]`}))}}if(_!==null&&typeof _==="object"){let Y=Object.entries(_);return{kind:"container",open:"{",close:"}",summary:U6(Y.length,"property","properties"),entries:Y.map(([Q,X])=>({key:Q,value:X,path:`${$}.${Q}`}))}}return{kind:"primitive",text:C8(_),className:w8(_)}}function U6(_,$,Y){return`${_} ${_===1?$:Y}`}function C8(_){if(_===null||_===void 0)return"null";if(typeof _==="string")return JSON.stringify(_);if(typeof _==="number"||typeof _==="boolean")return String(_);return JSON.stringify(_)??"null"}function w8(_){if(_===null||_===void 0)return"cortex-json-tree__null";if(typeof _==="string")return"cortex-json-tree__string";if(typeof _==="number")return"cortex-json-tree__number";if(typeof _==="boolean")return"cortex-json-tree__boolean";return""}function N0(_){if(!_)return null;try{return JSON.parse(_)}catch{return _}}function V0(_){if(!_)return"";try{return JSON.stringify(JSON.parse(_),null,2)}catch{return _}}function r(_,$,Y=Date.now()){let Q=new Date(_);if(Number.isNaN(Q.getTime()))return"";let X=Q.toDateString()===new Date(Y).toDateString();return new Intl.DateTimeFormat($,{...X?{}:{dateStyle:"medium"},timeStyle:"short"}).format(Q)}function g_(_,$){let Y=URL.createObjectURL(_),Q=document.createElement("a");Q.href=Y,Q.download=$,document.body.append(Q),Q.click(),Q.remove(),setTimeout(()=>URL.revokeObjectURL(Y),40000)}class $_{onUpdate;fullText="";displayedLength=0;animationFrameId=null;isDone=!1;releases=[];static DRAIN_FRACTION=0.03;static MIN_CHARS_PER_FRAME=1;static DONE_DRAIN_FRACTION=0.1;static FADE_WINDOW_MS=500;constructor(_){this.onUpdate=_}seed(_){this.fullText=_,this.displayedLength=_.length,this.releases=[],this.onUpdate(_,[])}update(_,$){if(this.fullText=_,this.isDone=$,this.displayedLength=Math.min(this.displayedLength,this.fullText.length),this.releases=this.releases.filter((Y)=>Y.from<this.displayedLength),$&&this.displayedLength>=this.fullText.length){this.onUpdate(this.fullText,[]),this.stopAnimation();return}if(!this.animationFrameId)this.scheduleFrame()}destroy(){this.stopAnimation()}scheduleFrame(){this.animationFrameId=requestAnimationFrame((_)=>this.tick(_))}tick(_){let $=this.fullText.length-this.displayedLength;if($<=0){this.animationFrameId=null;return}let Y=this.isDone?$_.DONE_DRAIN_FRACTION:$_.DRAIN_FRACTION,Q=Math.max($_.MIN_CHARS_PER_FRAME,Math.ceil($*Y));if(this.releases=this.releases.filter((X)=>_-X.at<$_.FADE_WINDOW_MS),this.releases.push({from:this.displayedLength,at:_}),this.displayedLength=Math.min(this.fullText.length,this.displayedLength+Q),this.onUpdate(this.fullText.substring(0,this.displayedLength),this.releases.map((X)=>({length:this.displayedLength-X.from,age:_-X.at}))),this.displayedLength<this.fullText.length)this.scheduleFrame();else this.animationFrameId=null}stopAnimation(){if(this.animationFrameId)cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null}}var K0=new WeakMap;function z0(_,$){let Y=_.closest(".cortex-widget__screen"),Q=Y?.querySelector(".cortex-message-list");if(!Y||!Q||!_.value.trim())return;let X=getComputedStyle(_),Z=_.getBoundingClientRect(),G=(J)=>parseFloat(X[`padding${J}`])+parseFloat(X[`border${J}Width`]);K0.set(Y,{text:$,textarea:_,from:new DOMRect(Z.left+G("Left"),Z.top+G("Top"),Z.width-G("Left")-G("Right"),Z.height-G("Top")-G("Bottom")),rtl:X.direction==="rtl",scrollTop:Q.scrollTop})}function W0(_,$){let Y=_.closest(".cortex-widget__screen"),Q=Y?K0.get(Y):void 0;if(!Y||!Q)return;K0.delete(Y);let X=_.querySelectorAll(":scope > .cortex-message"),Z=X[X.length-1]?.querySelector(".cortex-text-bubble--user"),G=_.closest(".cortex-message-list");if(!Z||!G||Q.text!==$||!Q.textarea.isConnected)return;Z.closest(".cortex-message-part")?.getAnimations().forEach((D)=>D.finish()),$1(G);let J=Z.getBoundingClientRect(),N=Y.getBoundingClientRect(),V=getComputedStyle(Z),K=parseFloat(V.paddingTop)+parseFloat(V.borderTopWidth),z=Q.rtl?parseFloat(V.paddingRight)+parseFloat(V.borderRightWidth):parseFloat(V.paddingLeft)+parseFloat(V.borderLeftWidth),F=Q.rtl?Q.from.right+z-J.width:Q.from.left-z,B=G.scrollTop-Q.scrollTop;if(B)_.style.setProperty("--cortex-slide",`${B}px`),_.classList.remove("cortex-message-list__content--settling"),_.offsetWidth,_.classList.add("cortex-message-list__content--settling"),_.getAnimations()[0]?.finished.then(()=>_.classList.remove("cortex-message-list__content--settling"),()=>{return});let q=Z.cloneNode(!0);q.classList.add("cortex-send-flight"),q.setAttribute("aria-hidden","true"),Object.assign(q.style,{left:`${J.left-N.left}px`,top:`${J.top-N.top}px`,width:`${J.width}px`}),q.style.setProperty("--cortex-fly-x",`${F-J.left}px`),q.style.setProperty("--cortex-fly-y",`${Q.from.top-K-J.top}px`),Z.style.visibility="hidden",Y.append(q);let O=G.scrollTop,P=()=>{q.style.top=`${J.top-N.top-(G.scrollTop-O)}px`};G.addEventListener("scroll",P,{passive:!0}),P6(q).then(()=>{G.removeEventListener("scroll",P),Z.style.visibility="",q.remove()})}function $1(_){_.scrollTop=O6(_)}function D0(_){return O6(_)-_.scrollTop}function O6(_){let $=_.querySelector(".cortex-message-list__content");if(!$)return _.scrollHeight-_.clientHeight;let Y=getComputedStyle(_);return $.offsetHeight+parseFloat(Y.paddingTop)+parseFloat(Y.paddingBottom)-_.clientHeight}function H0(_){let $=!1,Y=_.parentElement,Q=typeof ResizeObserver>"u"?void 0:new ResizeObserver(X);Q?.observe(Y);function X(){let Z=Y.querySelector(":scope > .cortex-working-thinking, :scope > .cortex-message > .cortex-message-parts > [data-cortex-frontier]");if(!Z)return!1;return _.style.setProperty("--cortex-avatar-y",`${S8(Z,Y)-_.offsetHeight/2}px`),!0}return{sync(Z){if(Z===$){if(Z)X();return}if(Z){if(!X())return;_.classList.remove("cortex-working-avatar--leaving"),_.offsetWidth,_.classList.add("cortex-working-avatar--shown"),$=!0;return}$=!1,_.classList.add("cortex-working-avatar--leaving"),P6(_,!0).then(()=>{if($)return;_.classList.remove("cortex-working-avatar--shown","cortex-working-avatar--leaving")})},dispose(){Q?.disconnect()}}}function S8(_,$){let Y=_.querySelector(".cortex-text-bubble");if(!Y)return L6(_,$)+_.offsetHeight/2;let Q=getComputedStyle(Y);return L6(Y,$)+parseFloat(Q.paddingTop)+parseFloat(Q.borderTopWidth)+parseFloat(Q.lineHeight)/2}function L6(_,$){let Y=0;for(let Q=_;Q instanceof HTMLElement&&Q!==$;)Y+=Q.offsetTop,Q=Q.offsetParent;return Y}function P6(_,$=!1){return Promise.allSettled(_.getAnimations({subtree:$}).map((Y)=>Y.finished))}var b8=2;function B0(_){let $=!1,Y=!1,Q=!1,X=!1,Z=!1,G=!1,J,N=new Set,V=0,K=!1;function z(){if($&&V===0)return!1;if(V+=1,!$)$=!0,_.setRunning(!0);return!0}function F(D){if(V-=1,D)K=!0;else if(V===0&&!K)$=!1,_.setRunning(!1)}async function B(D,H){for(let W=0;W<b8;W+=1){let M=await _.refreshMessages().catch(()=>{return});if(!_.isAlive())return!1;if(!M)continue;if(!__(M).some((k)=>k.id===D.id))return!0;if(await _.deliver(H).then(()=>!0,()=>!1))return!0}return!1}async function q(D,H){let W;try{let n=H({toolCallId:D.id,toolName:D.name,input:D.input},{threadId:_.threadId});if(n===null||n===void 0)return;W=await Promise.resolve(n)}catch{N.delete(D.id);return}if(W===null||W===void 0)return;if(!_.isAlive())return;let M=z(),A={toolCallId:D.id,tool:D.name,output:W},k=await _.deliver(A).then(()=>!0,()=>B(D,A));if(M)F(k);if(!k)N.delete(D.id)}function O(D){let H=__(D),W=_.onToolCall();if(!W)return H.length>0;for(let M of H){if(M.state!=="input-complete"||N.has(M.id))continue;N.add(M.id),q(M,W)}return H.length>0}async function P(D){let H=X;if(X=!1,!H&&$){if(O(D()))return;if(Q)_.reloadThreads().catch(()=>{});else _.setRunning(!1)}if(J===void 0&&(G||H))return;J=void 0;let W=await _.refreshMessages();if(!H&&$&&W)O(W)}return{chunkArrived(){Y=!0},transcriptCarried(D){if(G=!0,J!==void 0&&J<=D)J=void 0},transcriptUpdated(D){if(!Z){_.refreshMessages();return}J=Math.max(J??0,Date.parse(D))},streamFailed(){if(Q=!0,Y)_.onTurnFinished();else _.onSendFailed()},loadingChanged(D,H){if(D){Z=!0,Q=!1,G=!1;return}if(!Z)return;Z=!1,_.onTurnFinished(),P(H)},hydrated(D,H){if(H)return;setTimeout(()=>{if(_.isAlive())O(D)},0)},sendStarted(){_.setRunning(!0),$=!0,Y=!1},abortConfirmed(){X=!0,_.setRunning(!1)}}}function m_(_){if(_.input.total<=0)return null;return Math.round(_.input.cacheRead/_.input.total*100)}import{createContext as M6,useContext as A6}from"react";var q0=M6(void 0);function L(){let _=A6(q0);if(!_)throw Error("useCortex must be used inside <CortexChatWidget>");return _}var F0={messages:[],isAgentWorking:!1,isLoadingMessages:!1,hasPendingToolCalls:!1},U0=M6(F0);function F_(){return A6(U0)}import{useEffect as T8,useState as v8}from"react";function E6(_,$){let[Y,Q]=v8();return T8(()=>{return Q(void 0),n1(_,Q)},[_,$]),Y}import{useRef as c8}from"react";import{useRef as f8,useState as j8,useSyncExternalStore as g8}from"react";function k6(_,$){let Y=f8($);Y.current=$;let[Q]=j8(()=>b1({api:_,ensureThread:()=>Y.current()})),X=g8(Q.subscribe,Q.getState,Q.getState);return{store:Q,value:{items:X,...T1(X),accept:Q.accept,remove:Q.remove,consumeReady:Q.consumeReady}}}import{useEffect as m8,useRef as x8}from"react";function R6(_,$){let Y=x8(void 0);m8(()=>{if($===Y.current)return;_.clear(Y.current),Y.current=$},[$,_])}import{useRef as I6}from"react";function y6(_){let $=I6([]),Y=I6(void 0);function Q(){let Z=_.selectedRef.current;if(Z)return Promise.resolve(Z.id);return Y.current??=_.api.createThread().then((G)=>{return Y.current=void 0,_.onCreated(G),G.id},(G)=>{throw Y.current=void 0,G}),Y.current}async function X(Z,G=[]){let J=_.sessionRef.current;if(J){await J.send(Z,G);return}$.current.push({prompt:Z,attachments:G});try{await Q()}catch(N){throw $.current=[],N}}return{ensureThread:Q,send:X,pendingSendRef:$}}import{useRef as h8,useState as u8}from"react";function C6(_){let[$,Y]=u8(),Q=$?.thread,X=Q?_.threads?.find((V)=>V.id===Q.id)??Q:void 0,Z=h8(X);Z.current=X;function G(V,K){if(Z.current?.id===V.id&&_.hasSession())return;let z=Z.current;if(Z.current=V,Y({thread:V,mode:K,epoch:0}),z&&z.id!==V.id)_.getHooks()?.onThreadDeselected?.(z);_.getHooks()?.onThreadSelected?.(V)}function J(){let V=Z.current;if(!V&&!_.hasSession())return;if(Z.current=void 0,Y(void 0),V)_.getHooks()?.onThreadDeselected?.(V)}function N(V,K){Y((z)=>({thread:V,mode:"reload",epoch:(z?.epoch??0)+1,initialMessages:K}))}return{session:$,selected:X,selectedRef:Z,select:G,deselect:J,remount:N}}function w6(_){let{api:$,threads:Y}=_,Q=c8(void 0),X=C6({threads:Y.threads,getHooks:_.getHooks,hasSession:()=>Q.current!==void 0}),Z=y6({api:$,sessionRef:Q,selectedRef:X.selectedRef,onCreated:(V)=>{Y.upsert(V),X.select(V,"skip")}}),G=k6($,Z.ensureThread);R6(G.store,X.selected?.id);async function J(V){if(X.selectedRef.current?.id===V)X.deselect();await Y.remove(V)}function N(V){X.select(V,"load")}return{sessionRef:Q,selection:X,queue:G,deleteThread:J,openThread:N,...Z}}import{useEffect as p8,useRef as d8}from"react";function S6(_){let $=d8(_);$.current=_,p8(()=>{$.current.onMount();let Y=!1,Q=l1({getConfig:()=>$.current.getConfig(),onEvent:(X)=>$.current.onEvent(X),onOpen:()=>{if(Y)$.current.onReconnect();Y=!0}});return()=>Q.close()},[])}function b6(_){let{threads:$,selectedRef:Y,sessionRef:Q}=_;function X(G){$.applyEvent(G);let J=Y.current?.id;switch(G.type){case"thread:deleted":if(J===G.payload.threadId)_.deselect();break;case"thread:run-started":if(J===G.payload.thread.id)Q.current?.reattach(G.payload.thread);break;case"thread:messages-updated":Q.current?.transcriptUpdated(G.payload.thread.id,G.payload.thread.updatedAt);break}}function Z(){_.onReconnect(),$.reload().then((G)=>{let J=Y.current;if(!J)return;Q.current?.reattach(G.find((N)=>N.id===J.id)??J)})}return{onEvent:X,onReconnect:Z}}function T6(_){return{abort:async()=>{await _.current?.abort()},addToolResult:($,Y,Q)=>_.current?.addToolResult($,Y,Q)??Promise.resolve(),respondToApproval:($,Y)=>_.current?.respondToApproval($,Y)??Promise.resolve()}}import{useState as l8}from"react";function v6(_){let[$,Y]=l8();async function Q(){let N=t_(await _.listThreads());return Y(N),N}function X(N){Y((V)=>T_(V??[],N))}function Z(N,V){Y((K)=>{let z=K?.find((F)=>F.id===N);return z?T_(K??[],{...z,isRunning:V}):K})}async function G(N){await _.deleteThread(N),Y((V)=>V?s_(V,N):V)}function J(N){Y((V)=>{let K=i1(V??[],N);return V||K.length?K:V})}return{threads:$,reload:Q,upsert:X,setRunning:Z,remove:G,applyEvent:J}}import{useState as f6}from"react";function j6(_){let[$,Y]=f6("chat"),[Q,X]=f6(!1);return{screen:$,sidebarOpen:Q,showChat:()=>{Y("chat"),X(!1)},openHistory:()=>_==="full"?X(!0):Y("threads"),closeHistory:()=>_==="full"?X(!1):Y("chat"),closeSidebar:()=>X(!1)}}import{forwardRef as s8,useEffect as e8,useImperativeHandle as _4,useRef as c6,useState as $4}from"react";function U(..._){return _.filter(Boolean).join(" ")}import{useState as n8}from"react";function g6(_,$){let[Y,Q]=n8(!1);return{dragging:Y,onDragOver:(X)=>{if(X.preventDefault(),_)Q(!0)},onDragLeave:(X)=>{if(!X.currentTarget.contains(X.relatedTarget))Q(!1)},onDrop:(X)=>{if(X.preventDefault(),Q(!1),_)$([...X.dataTransfer.files])},onPaste:(X)=>{let Z=X.clipboardData.files;if(!_||!Z.length)return;X.preventDefault(),$([...Z])}}}var S={bubble:"M13.5 7.6c0 2.4-2.5 4.4-5.5 4.4-.6 0-1.2-.08-1.7-.23L3 13l.8-2.3C3 9.8 2.5 8.7 2.5 7.6 2.5 5.2 5 3.2 8 3.2s5.5 2 5.5 4.4Z",chevronDown:"M3 4.5L6 7.5L9 4.5",chevronDownLarge:"m5.75 8.25 4.25 4.25 4.25-4.25",file:["M4 1.5h5.172a2 2 0 0 1 1.414.586l2.328 2.328a2 2 0 0 1 .586 1.414V12.5a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-9a2 2 0 0 1 2-2Z","M9.5 1.5v2a2 2 0 0 0 2 2h2"]};import{jsx as a,jsxs as L0}from"react/jsx-runtime";function m6(){let{queue:_,t:$}=L();if(!_.items.length)return null;return a("div",{className:"cortex-attachment-queue",children:_.items.map((Y)=>L0("div",{className:U("cortex-attachment-chip",Y.status==="error"&&"cortex-attachment-chip--error"),title:Y.status==="error"?$("translate_attachment_rejected"):"",children:[Y.status==="uploading"||Y.status==="deleting"?L0("svg",{className:"cortex-attachment-chip__spinner",viewBox:"0 0 16 16",fill:"none",children:[a("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",className:"cortex-attachment-chip__spinner-track"}),a("path",{d:"M14 8a6 6 0 0 0-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}):L0("svg",{viewBox:"0 0 16 16",className:"cortex-attachment-chip__icon",fill:"none",children:[a("path",{d:S.file[0],stroke:"currentColor",strokeWidth:"1.25"}),a("path",{d:S.file[1],stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round"})]}),a("span",{className:"cortex-attachment-chip__name",children:Y.filename}),a("button",{type:"button",onClick:()=>_.remove(Y.localId),className:"cortex-attachment-chip__remove",disabled:Y.status==="deleting","aria-label":$("translate_remove_attachment"),children:a("svg",{viewBox:"0 0 16 16",fill:"none",children:a("path",{d:"M4.5 4.5l7 7m0-7l-7 7",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})})]},Y.localId))})}import{useRef as i8}from"react";import{jsx as J_,jsxs as x6,Fragment as a8}from"react/jsx-runtime";var r8=H1.join(",");function h6({attachmentsEnabled:_,canSend:$,onSend:Y}){let{t:Q,queue:X}=L(),Z=i8(null);return x6("div",{className:"cortex-widget__input-actions",children:[_&&x6(a8,{children:[J_("button",{type:"button",onClick:()=>Z.current?.click(),className:"cortex-widget__attach-btn","aria-label":Q("translate_attach_files"),children:J_("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:J_("path",{d:"M10.5 5.5 6.2 9.8a1.4 1.4 0 0 0 2 2l4.6-4.6a2.8 2.8 0 0 0-4-4L4.2 7.8a4.2 4.2 0 0 0 6 6l4-4",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}),J_("input",{ref:Z,type:"file",multiple:!0,accept:r8,onChange:(G)=>{X.accept([...G.target.files??[]]),G.target.value=""},className:"cortex-widget__file-input"})]}),J_("button",{onClick:Y,"aria-label":Q("translate_send"),className:U("cortex-widget__send-btn",!$&&"cortex-widget__send-btn--empty",$&&"cortex-widget__send-btn--ready"),disabled:!$,children:J_("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:"cortex-widget__send-icon",children:J_("path",{d:"M3 8h10M9 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})}import{useLayoutEffect as o8}from"react";import{jsx as t8}from"react/jsx-runtime";function u6(_){let{t:$}=L();o8(()=>{let Q=_.inputRef.current;if(!Q)return;Q.style.height="0px",Q.style.height=`${Q.scrollHeight}px`},[_.inputRef,_.value]);function Y(Q){if(Q.key==="Enter"&&!Q.shiftKey)Q.preventDefault(),_.onSubmit()}return t8("textarea",{ref:_.inputRef,onKeyDown:Y,onPaste:_.onPaste,value:_.value,onChange:(Q)=>_.onChange(Q.target.value),placeholder:_.dragging?$("translate_drop_files_here"):_.disabled?"":$("translate_type_a_message"),disabled:_.disabled,rows:1,className:U("cortex-widget__textarea",_.disabled&&"cortex-widget__textarea--disabled")})}import{jsx as U_,jsxs as O0}from"react/jsx-runtime";var p6=s8(function($,Y){let{t:Q,queue:X,send:Z,abort:G,capabilities:J}=L(),{isAgentWorking:N}=F_(),V=J?.attachments??!1,[K,z]=$4(""),F=g6(V,X.accept),B=c6(null);_4(Y,()=>({focusInput:()=>B.current?.focus()}));let q=c6(N);e8(()=>{if(q.current&&!N)B.current?.focus();q.current=N},[N]);let O=!X.busy&&(Boolean(K.trim())||X.hasReady);function P(){if(N||!O)return;let D=K.trim()||Q("translate_attachment_caption"),H=X.consumeReady();if(B.current)z0(B.current,D);z(""),Z(D,H.map((W)=>W.summary))}return O0("div",{className:"cortex-widget__input-area",onDragOver:F.onDragOver,onDragLeave:F.onDragLeave,onDrop:F.onDrop,children:[U_(m6,{}),O0("div",{className:U("cortex-widget__input-box",N&&"cortex-widget__input-box--disabled",!N&&"cortex-widget__input-box--enabled",F.dragging&&"cortex-widget__input-box--dragging"),children:[U_(u6,{inputRef:B,value:K,onChange:z,onSubmit:P,onPaste:F.onPaste,disabled:N,dragging:F.dragging}),N?O0("button",{onClick:()=>void G(),className:"cortex-stop-btn",children:[U_("span",{className:"cortex-stop-btn__ring"}),U_("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"cortex-stop-btn__icon",children:U_("rect",{x:"1",y:"1",width:"10",height:"10",rx:"2.5",fill:"currentColor"})})]}):U_(h6,{attachmentsEnabled:V,canSend:O,onSend:P})]})]})});import{jsx as d6}from"react/jsx-runtime";function Y1({capabilities:_,composerRef:$}){let{t:Y}=L();if(_===void 0)return null;return _.messages===!1?d6("p",{className:"cortex-widget__messages-disabled",children:Y("translate_messages_disabled")}):d6(p6,{ref:$})}import{jsx as v,jsxs as Q1}from"react/jsx-runtime";function l6(_){let{t:$}=L(),Y=v("button",{type:"button",onClick:_.newChat,"aria-label":$("translate_new_chat"),title:$("translate_new_chat"),className:"cortex-widget__header-btn cortex-widget__new-btn",children:v("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:v("path",{d:"M8 3v10M3 8h10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})});if(_.screen==="threads")return Q1("div",{className:"cortex-widget__threads-header",children:[v("button",{type:"button",onClick:_.closeHistory,"aria-label":$("translate_back"),className:"cortex-widget__header-btn cortex-widget__back-btn",children:v("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"cortex-widget__back-icon",children:v("path",{d:"M10 3L5 8l5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),Q1("div",{children:[v("h2",{className:"cortex-widget__threads-title",children:$("translate_history")}),v("p",{className:"cortex-widget__threads-count",children:$(C_(_.threadCount,"translate_one_conversation","translate_n_conversations"),{count:_.threadCount})})]}),Y]});return Q1("div",{className:"cortex-widget__chat-header",children:[v("button",{onClick:_.openHistory,className:"cortex-widget__sidebar-toggle-btn",children:v("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:v("path",{d:"M2.5 4h11M2.5 8h11M2.5 12h11",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),v("div",{className:"cortex-widget__chat-title-wrap",children:v("p",{className:"cortex-widget__chat-title",children:_.title??_.agentName??$("translate_new_chat")})}),_.debug.shown&&v("button",{onClick:_.toggleDebug,className:U("cortex-widget__debug-btn",_.debug.on?"cortex-widget__debug-btn--on":"cortex-widget__debug-btn--off"),children:_.debug.on?$("translate_debug"):$("translate_normal")}),Y,v("button",{type:"button",onClick:_.openHistory,"aria-label":$("translate_history"),title:$("translate_history"),className:"cortex-widget__header-btn cortex-widget__history-btn",children:Q1("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[v("circle",{cx:"8",cy:"8",r:"5.75",stroke:"currentColor",strokeWidth:"1.3"}),v("path",{d:"M8 5v3l2 1.5",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]})})]})}import{jsx as o,jsxs as n6}from"react/jsx-runtime";function i6(_){let{locale:$,t:Y}=L();return n6("div",{className:"cortex-widget__landing",children:[o("div",{className:"cortex-widget__landing-icon",children:o("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",children:o("path",{d:S.bubble,stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}),o("p",{className:"cortex-widget__landing-greeting",children:_.greeting}),!!_.suggestions.length&&o("div",{className:"cortex-widget__landing-chips",children:_.suggestions.map((Q,X)=>o("button",{type:"button",onClick:()=>_.send(Q.prompt),className:"cortex-widget__landing-chip",children:Q.title},X))}),_.composer,!!_.threads?.length&&o("div",{className:"cortex-widget__landing-recent",children:_.threads.slice(0,2).map((Q)=>{let X=r(Q.updatedAt,$);return n6("button",{type:"button",onClick:()=>_.openThread(Q),className:"cortex-widget__landing-recent-item",children:[o("p",{className:"cortex-widget__landing-recent-title",children:Q.title??Y("translate_untitled")}),X&&o("p",{className:"cortex-widget__landing-recent-time",children:X})]},Q.id)})})]})}import{useCallback as n_,useEffect as I0,useLayoutEffect as y0,useMemo as c4,useRef as W_,useState as C0}from"react";import{memo as h4}from"react";import{Fragment as g4}from"react";import{useRef as Y4,useState as Q4}from"react";import{jsx as L_,jsxs as X4}from"react/jsx-runtime";function h({value:_,className:$}){let{t:Y}=L(),[Q,X]=Q4(!1),Z=Y4(null);async function G(J){J.stopPropagation(),J.preventDefault();try{if(await navigator.clipboard.writeText(_),X(!0),Z.current)clearTimeout(Z.current);Z.current=setTimeout(()=>X(!1),1500)}catch{}}return L_("span",{className:U("cortex-copy-btn",$),children:L_("button",{className:U("cortex-copy-btn__button",Q&&"cortex-copy-btn__button--copied"),onClick:(J)=>void G(J),"aria-label":Q?Y("translate_copied"):Y("translate_copy"),type:"button",children:Q?L_("svg",{className:"cortex-copy-btn__icon cortex-copy-btn__icon--check",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",children:L_("path",{d:"M5 13l4 4L19 7",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"})}):X4("svg",{className:"cortex-copy-btn__icon",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",children:[L_("rect",{x:"9",y:"9",width:"12",height:"12",rx:"2",stroke:"currentColor",strokeWidth:"2"}),L_("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})})})}import{jsx as X1,jsxs as r6}from"react/jsx-runtime";function a6(){let{t:_}=L();return r6("div",{className:"cortex-aborted-flag",children:[X1("span",{className:"cortex-aborted-flag__line"}),r6("span",{className:"cortex-aborted-flag__label",children:[X1("svg",{className:"cortex-aborted-flag__icon",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:X1("path",{d:"M6 1.5v5M6 8.75v.5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})}),_("translate_aborted")]}),X1("span",{className:"cortex-aborted-flag__line"})]})}import{jsx as O_,jsxs as o6}from"react/jsx-runtime";function t6(_){let{api:$,t:Y}=L();async function Q(X){let{blob:Z,name:G}=await $.downloadAttachment(X);g_(Z,G)}return O_("div",{className:U("cortex-message-attachments",_.isUser&&"cortex-message-attachments--user"),children:_.attachments.map((X)=>o6("button",{type:"button",onClick:()=>void Q(X.id),className:"cortex-message-attachment","aria-label":`${Y("translate_download")}: ${X.filename}`,children:[o6("svg",{viewBox:"0 0 16 16",className:"cortex-message-attachment__icon",fill:"none",children:[O_("path",{d:S.file[0],stroke:"currentColor",strokeWidth:"1.25"}),O_("path",{d:S.file[1],stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round"})]}),O_("span",{className:"cortex-message-attachment__name",children:X.filename}),O_("svg",{viewBox:"0 0 16 16",className:"cortex-message-attachment__dl-icon",fill:"none",children:O_("path",{d:"M8 3v7m0 0L5.5 7.5M8 10l2.5-2.5M3 13h10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]},X.id))})}import{useRef as J4,useState as x_}from"react";import{useMemo as Z4,useState as G4}from"react";import{jsx as x,jsxs as N_,Fragment as Z1}from"react/jsx-runtime";function Y_({data:_,expandDepth:$,className:Y}){let Q=Z4(()=>q_(_),[_]),[X,Z]=G4({});function G(N,V){return X[N]??V>=$}function J(N,V){Z((K)=>({...K,[N]:!G(N,V)}))}return x("div",{className:U("cortex-json-tree",Y),children:x(s6,{value:Q,path:"$",depth:0,isCollapsed:G,toggle:J})})}function s6({value:_,path:$,depth:Y,isCollapsed:Q,toggle:X}){let Z=J0(_,$);if(Z.kind==="primitive")return x("span",{className:Z.className,children:Z.text});if(Z.entries.length===0)return N_("span",{className:"cortex-json-tree__bracket",children:[Z.open,Z.close]});let G=Q($,Y);function J(N){X($,Y),N.stopPropagation()}return N_(Z1,{children:[N_("span",{className:"cortex-json-tree__toggle",onClick:J,role:"button",children:[x("span",{className:U("cortex-json-tree__arrow",G&&"cortex-json-tree__arrow--collapsed"),children:"▾"}),x("span",{className:"cortex-json-tree__bracket",children:Z.open})]}),G?N_(Z1,{children:[x("span",{className:"cortex-json-tree__collapsed-hint",onClick:J,role:"button",children:Z.summary}),x("span",{className:"cortex-json-tree__bracket",children:Z.close})]}):N_(Z1,{children:[x("div",{className:"cortex-json-tree__indent",children:Z.entries.map((N,V)=>N_("div",{className:"cortex-json-tree__line",children:[N.key!==null&&N_(Z1,{children:[x("span",{className:"cortex-json-tree__key",children:`"${N.key}"`}),x("span",{className:"cortex-json-tree__colon",children:": "})]}),x(s6,{value:N.value,path:N.path,depth:Y+1,isCollapsed:Q,toggle:X}),V<Z.entries.length-1&&x("span",{className:"cortex-json-tree__comma",children:","})]},N.path))}),x("span",{className:"cortex-json-tree__bracket",children:Z.close})]})]})}function R(_){return _.toLocaleString("en-US")}import{jsx as P_,jsxs as M_}from"react/jsx-runtime";function e6({usage:_}){let{t:$}=L();return M_("div",{className:"cortex-llm-inspector__usage-rows",children:[M_("div",{className:"cortex-llm-inspector__usage-row",children:[P_("span",{className:"cortex-llm-inspector__usage-lbl",children:$("translate_input")}),P_("span",{className:"cortex-llm-inspector__usage-val",children:R(_.input.total)}),M_("span",{className:"cortex-llm-inspector__usage-detail",children:[$("translate_fresh")," ",R(_.input.noCache)," · ",$("translate_read")," ",R(_.input.cacheRead)," · ",$("translate_write")," ",R(_.input.cacheWrite)]})]}),M_("div",{className:"cortex-llm-inspector__usage-row",children:[P_("span",{className:"cortex-llm-inspector__usage-lbl",children:$("translate_output")}),P_("span",{className:"cortex-llm-inspector__usage-val",children:R(_.output.total)}),M_("span",{className:"cortex-llm-inspector__usage-detail",children:[$("translate_text")," ",R(_.output.text)," · ",$("translate_reasoning")," ",R(_.output.reasoning)]})]}),M_("div",{className:"cortex-llm-inspector__usage-row cortex-llm-inspector__usage-row--total",children:[P_("span",{className:"cortex-llm-inspector__usage-lbl",children:$("translate_total")}),P_("span",{className:"cortex-llm-inspector__usage-val",children:R(_.total)})]})]})}import{jsx as _2,jsxs as G1}from"react/jsx-runtime";function $2({usage:_}){let $=m_(_);return G1("span",{className:"cortex-llm-inspector__step-metrics",children:[G1("span",{className:"cortex-llm-inspector__metric",children:[_2("span",{className:"cortex-llm-inspector__dot cortex-llm-inspector__dot--input"}),R(_.input.total)]}),G1("span",{className:"cortex-llm-inspector__metric",children:[_2("span",{className:"cortex-llm-inspector__dot cortex-llm-inspector__dot--output"}),R(_.output.total)]}),$!==null&&G1("span",{className:"cortex-llm-inspector__cache-pct",children:[$,"%"]})]})}import{jsx as y,jsxs as Q_}from"react/jsx-runtime";function Y2({messageId:_}){let{t:$,api:Y}=L(),[Q,X]=x_(!1),[Z,G]=x_(!1),[J,N]=x_([]),[V,K]=x_(null),[z,F]=x_({}),B=J4(!1);async function q(){if(!B.current){G(!0);try{N(await Y.listLlmRequests(_))}finally{G(!1),B.current=!0}}X((W)=>!W)}function O(W){K((M)=>M===W?null:W)}function P(W){return z[W]??"prompt"}function D(W,M){F((A)=>({...A,[W]:M}))}function H(W){return P(W.id)==="prompt"?W.prompt:W.output}return Q_("div",{className:U("cortex-llm-inspector",Q&&"cortex-llm-inspector--open"),children:[Q_("button",{className:"cortex-llm-inspector__trigger",onClick:()=>void q(),children:[y("svg",{className:"cortex-llm-inspector__icon",width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:y("path",{d:"M6 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8ZM0 6a6 6 0 1 1 10.89 3.477l4.817 4.816a1 1 0 0 1-1.414 1.414l-4.816-4.816A6 6 0 0 1 0 6Z",fill:"currentColor"})}),y("span",{children:$("translate_inspect_llm_requests")}),Z?y("span",{className:"cortex-llm-inspector__loading",children:$("translate_loading")}):J.length>0?y("span",{className:"cortex-llm-inspector__badge",children:J.length}):null,y("svg",{className:"cortex-llm-inspector__chevron",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:y("path",{d:S.chevronDown,stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})})]}),y("div",{className:"cortex-llm-inspector__panel-wrapper",children:y("div",{className:"cortex-llm-inspector__panel-inner",children:Q_("div",{className:"cortex-llm-inspector__panel",children:[J.length===0&&!Z&&y("div",{className:"cortex-llm-inspector__empty",children:$("translate_no_llm_requests")}),J.map((W,M)=>Q_("div",{className:U("cortex-llm-inspector__step",V===W.id&&"cortex-llm-inspector__step--expanded"),children:[Q_("button",{className:"cortex-llm-inspector__step-header",onClick:()=>O(W.id),children:[y("span",{className:"cortex-llm-inspector__step-label",children:$("translate_step_n",{number:M+1})}),W.tokenUsage&&y($2,{usage:W.tokenUsage}),y("svg",{className:"cortex-llm-inspector__step-chevron",width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",children:y("path",{d:S.chevronDown,stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})})]}),y("div",{className:"cortex-llm-inspector__step-body-wrapper",children:y("div",{className:"cortex-llm-inspector__step-body-inner",children:Q_("div",{className:"cortex-llm-inspector__step-body",children:[W.tokenUsage&&y(e6,{usage:W.tokenUsage}),Q_("div",{className:"cortex-llm-inspector__tabs",children:[y("button",{className:U("cortex-llm-inspector__tab",P(W.id)==="prompt"&&"cortex-llm-inspector__tab--active"),onClick:()=>D(W.id,"prompt"),children:$("translate_request")}),y("button",{className:U("cortex-llm-inspector__tab",P(W.id)==="response"&&"cortex-llm-inspector__tab--active"),onClick:()=>D(W.id,"response"),children:$("translate_response")})]}),Q_("div",{className:"cortex-llm-inspector__json-pane",children:[y(h,{className:"cortex-llm-inspector__json-copy",value:V0(H(W))}),y(Y_,{data:N0(H(W)),expandDepth:2})]})]})})})]},W.id))]})})})]})}import{useState as N4}from"react";import{jsx as E,jsxs as b}from"react/jsx-runtime";function Q2({usage:_,modelId:$}){let{t:Y}=L(),[Q,X]=N4(!1),Z=m_(_)??0;return b("div",{className:U("cortex-token-usage",Q&&"cortex-token-usage--expanded"),children:[b("button",{className:"cortex-token-usage__summary",onClick:()=>X((G)=>!G),children:[b("span",{className:"cortex-token-usage__total",children:[E("span",{className:"cortex-token-usage__total-number",children:R(_.total)}),E("span",{className:"cortex-token-usage__total-label",children:Y("translate_tokens")})]}),$?E("span",{className:"cortex-token-usage__model",children:$}):null,b("span",{className:"cortex-token-usage__pills",children:[b("span",{className:"cortex-token-usage__pill",children:[E("span",{className:"cortex-token-usage__dot cortex-token-usage__dot--input"}),R(_.input.total)]}),b("span",{className:"cortex-token-usage__pill",children:[E("span",{className:"cortex-token-usage__dot cortex-token-usage__dot--output"}),R(_.output.total)]})]}),Z>0&&b("span",{className:"cortex-token-usage__cache-badge",children:[Z,"%"]}),E("svg",{className:"cortex-token-usage__chevron",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:E("path",{d:S.chevronDown,stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})})]}),E("div",{className:"cortex-token-usage__details",children:E("div",{className:"cortex-token-usage__details-inner",children:b("div",{className:"cortex-token-usage__columns",children:[b("div",{className:"cortex-token-usage__col",children:[b("div",{className:"cortex-token-usage__col-header",children:[E("span",{className:"cortex-token-usage__dot cortex-token-usage__dot--input"}),E("span",{className:"cortex-token-usage__col-label",children:Y("translate_input")}),E("span",{className:"cortex-token-usage__col-total",children:R(_.input.total)})]}),b("div",{className:"cortex-token-usage__rows",children:[_.input.noCache?b("div",{className:"cortex-token-usage__row",children:[E("span",{className:"cortex-token-usage__row-label",children:Y("translate_fresh")}),E("span",{className:"cortex-token-usage__row-value",children:R(_.input.noCache)})]}):null,_.input.cacheRead?b("div",{className:"cortex-token-usage__row",children:[E("span",{className:"cortex-token-usage__row-label",children:Y("translate_cache_read")}),E("span",{className:"cortex-token-usage__row-value",children:R(_.input.cacheRead)})]}):null,_.input.cacheWrite?b("div",{className:"cortex-token-usage__row",children:[E("span",{className:"cortex-token-usage__row-label",children:Y("translate_cache_write")}),E("span",{className:"cortex-token-usage__row-value",children:R(_.input.cacheWrite)})]}):null]}),Z>0&&b("div",{className:"cortex-token-usage__cache-bar-row",children:[E("div",{className:"cortex-token-usage__cache-bar",children:E("div",{className:"cortex-token-usage__cache-fill",style:{width:`${Z}%`}})}),E("span",{className:"cortex-token-usage__cache-label",children:Y("translate_n_percent_cached",{percent:Z})})]})]}),b("div",{className:"cortex-token-usage__col",children:[b("div",{className:"cortex-token-usage__col-header",children:[E("span",{className:"cortex-token-usage__dot cortex-token-usage__dot--output"}),E("span",{className:"cortex-token-usage__col-label",children:Y("translate_output")}),E("span",{className:"cortex-token-usage__col-total",children:R(_.output.total)})]}),b("div",{className:"cortex-token-usage__rows",children:[_.output.text?b("div",{className:"cortex-token-usage__row",children:[E("span",{className:"cortex-token-usage__row-label",children:Y("translate_text")}),E("span",{className:"cortex-token-usage__row-value",children:R(_.output.text)})]}):null,_.output.reasoning?b("div",{className:"cortex-token-usage__row",children:[E("span",{className:"cortex-token-usage__row-label",children:Y("translate_reasoning")}),E("span",{className:"cortex-token-usage__row-value",children:R(_.output.reasoning)})]}):null]})]})]})})})]})}import{jsx as X2,jsxs as V4}from"react/jsx-runtime";function Z2({messageId:_,isAssistant:$,metadata:Y}){let{tokenUsage:Q}=Y;if(!Q&&!$)return null;return V4("div",{className:"cortex-message-debug-zone",children:[Q&&X2(Q2,{usage:Q,modelId:Y.modelId}),$&&X2(Y2,{messageId:_})]})}import{jsx as u,jsxs as h_}from"react/jsx-runtime";function G2(_){let{reasoningPart:$,streaming:Y=!1}=_,{t:Q}=L();return h_("details",{className:"cortex-reasoning-details",children:[h_("summary",{className:"cortex-reasoning-details__summary",children:[h_("div",{className:"cortex-reasoning-details__header",children:[u("span",{className:"cortex-reasoning-details__icon",children:h_("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"none","aria-hidden":"true",children:[u("path",{d:"M10 2C6.686 2 4 4.686 4 8c0 1.655.672 3.154 1.757 4.243.362.363.576.858.576 1.371V14.5a1 1 0 0 0 1 1h5.334a1 1 0 0 0 1-1v-.886c0-.513.214-1.008.576-1.371A5.978 5.978 0 0 0 16 8c0-3.314-2.686-6-6-6Z",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"}),u("path",{d:"M7.5 17.5h5M8.5 8a2 2 0 0 1 2-2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]})}),u("div",{className:"cortex-reasoning-details__title-group",children:h_("div",{className:"cortex-reasoning-details__title-row",children:[u("div",{className:"cortex-reasoning-details__title",children:Q("translate_reasoning")}),u("span",{className:U("cortex-reasoning-details__badge",Y?"cortex-reasoning-details__badge--streaming":"cortex-reasoning-details__badge--done"),children:Y?Q("translate_streaming"):Q("translate_done")})]})})]}),u("span",{className:"cortex-reasoning-details__chevron","aria-hidden":"true",children:u("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"none",children:u("path",{d:S.chevronDownLarge,stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),u("div",{className:"cortex-reasoning-details__body",children:u("div",{className:"cortex-reasoning-details__content",children:u("pre",{className:"cortex-reasoning-details__pre",children:$.content.trim()?$.content:Q("translate_no_reasoning")})})})]})}import{useEffect as D2,useMemo as M4,useRef as M0,useState as A4}from"react";import{useEffect as W4,useState as J2}from"react";import{useRef as K4,useState as z4}from"react";import{jsx as t,jsxs as J1}from"react/jsx-runtime";function A_(_){let{label:$,ready:Y=!0,actions:Q,expanded:X,children:Z}=_,{t:G}=L(),J=K4(null),[N,V]=z4(!1);return J1("div",{className:"cortex-expandable",children:[Y&&J1("div",{className:"cortex-expandable__toolbar",role:"group","aria-label":$,children:[Q,t("button",{type:"button",className:"cortex-expandable__action","aria-label":G("translate_expand",{name:$}),title:G("translate_expand",{name:$}),onClick:()=>{V(!0),J.current?.showModal()},children:t("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:t("path",{d:"M9.5 2.5h4v4M6.5 13.5h-4v-4M13.5 2.5 9 7M2.5 13.5 7 9",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),t("div",{className:"cortex-expandable__content",children:Z}),J1("dialog",{ref:J,className:"cortex-expandable__dialog","aria-label":$,closedby:"any",onClose:()=>V(!1),children:[J1("div",{className:"cortex-expandable__head",children:[t("span",{className:"cortex-expandable__title",children:$}),Q,t("button",{type:"button",className:"cortex-expandable__action","aria-label":G("translate_close"),title:G("translate_close"),onClick:()=>J.current?.close(),children:t("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:t("path",{d:"M4 4l8 8M12 4l-8 8",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})})]}),N&&t("div",{className:"cortex-expandable__body",children:X})]})]})}import{jsx as u_,jsxs as D4}from"react/jsx-runtime";function N2(_){let{id:$,alt:Y,attachment:Q}=_,{api:X,t:Z}=L(),[G,J]=J2(),[N,V]=J2(!1);if(W4(()=>{let K,z=!1;return J(void 0),V(!1),X.downloadAttachment($).then(({blob:F})=>{if(z)return;K=URL.createObjectURL(F),J(K)},()=>{if(!z)V(!0)}),()=>{if(z=!0,K)URL.revokeObjectURL(K)}},[X,$]),N)return u_("p",{className:"cortex-attachment-image__caption",children:Y?Z("translate_image_unavailable_alt",{alt:Y}):Z("translate_image_unavailable")});if(!G)return null;return D4("figure",{className:"cortex-attachment-image",children:[u_(A_,{label:Q?.filename||Y||Z("translate_image"),expanded:u_("img",{className:"cortex-attachment-image__expanded",src:G,alt:Y}),children:u_("img",{src:G,alt:Y})}),Q&&u_("figcaption",{className:"cortex-attachment-image__caption",children:Q.filename})]})}import{useEffect as H4,useRef as B4,useState as P0}from"react";import{jsx as j,jsxs as c_,Fragment as U4}from"react/jsx-runtime";function q4(_){let{t:$}=L();if(!_.pending&&!_.debugMode)return null;return c_("div",{className:"cortex-media-block__head",children:[_.debugMode&&j("span",{className:"cortex-media-block__lang",children:_.language}),_.pending&&j("span",{className:"cortex-media-block__pending",children:$(_1(_.language).pending)}),_.debugMode&&_.closed&&c_("span",{className:"cortex-media-block__actions",children:[_.onToggleSource&&j("button",{type:"button",className:"cortex-media-block__action","aria-pressed":_.sourceShown,onClick:_.onToggleSource,children:$("translate_media_source")}),j(h,{value:_.source})]})]})}function V2(_){let{debugMode:$,t:Y}=L();return j("div",{className:"cortex-media-block__body",children:c_("p",{className:"cortex-media-block__error",children:[_.cutOff?Y("translate_media_cut_off"):Y("translate_media_failed"),!_.cutOff&&$&&` ${_.reason}`]})})}function K2(_){let{language:$,source:Y,closed:Q,hidden:X,onError:Z}=_,{config:G,scheme:J}=L(),N=B4(null);return H4(()=>{Z(void 0);let V=N.current;if(!Q||!J||!V)return;return X0(V,{language:$,source:Y,context:{scheme:J},overrides:G.mediaRenderers,onError:Z})},[$,Y,Q,J,G.mediaRenderers,Z]),j("div",{ref:N,hidden:X,className:U("cortex-media-block__body",`cortex-media-block__body--${$}`)})}function F4(_){let[$,Y]=P0();return c_(U4,{children:[$&&j(V2,{cutOff:!1,reason:$}),j(K2,{language:_.language,source:_.source,closed:!0,hidden:Boolean($),onError:Y})]})}function z2(_){let{language:$,source:Y,closed:Q,streaming:X}=_,{debugMode:Z,t:G}=L(),[J,N]=P0(),[V,K]=P0(!1),z=!Q&&!X,F=z||Boolean(J);return c_("div",{className:"cortex-media-block",children:[j(q4,{language:$,source:Y,pending:!Q&&X,closed:Q,debugMode:Z,sourceShown:V,onToggleSource:F?void 0:()=>K((q)=>!q)}),F&&j(V2,{cutOff:z,reason:J}),j(A_,{label:G(_1($).title),ready:Q&&!F,expanded:j(F4,{language:$,source:Y}),children:j(K2,{language:$,source:Y,closed:Q,hidden:F,onError:N})}),Z&&(F||V)&&j("pre",{className:"cortex-media-block__source",children:Y})]})}import{useMemo as L4,useRef as O4}from"react";import{jsx as V_}from"react/jsx-runtime";var P4="M8 2.5v7.5M5 7l3 3 3-3M2.75 11v1.25a1.25 1.25 0 0 0 1.25 1.25h8a1.25 1.25 0 0 0 1.25-1.25V11";function W2(_){let{t:$}=L(),Y=O4(null),Q=L4(()=>({__html:v_(_.text)}),[_.text]);function X(){let Z=Y.current?.querySelector("table");if(Z)g_(o1(a1(Z)),"table.xlsx")}return V_("div",{className:"cortex-table-block",children:V_(A_,{label:$("translate_table"),ready:_.closed,actions:V_("button",{type:"button",className:"cortex-expandable__action","aria-label":$("translate_table_export"),title:$("translate_table_export"),onClick:X,children:V_("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:V_("path",{d:P4,stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}),expanded:V_("div",{className:"cortex-table-block__expanded",dangerouslySetInnerHTML:Q}),children:V_("div",{ref:Y,dangerouslySetInnerHTML:Q})})})}import{jsx as E_}from"react/jsx-runtime";function H2(_){let{role:$,textPart:Y,streaming:Q=!1,attachments:X=[]}=_,{config:Z}=L(),G=$==="assistant"&&Q?"":Y.content,[J,N]=A4({text:G,fading:[]}),V=M0(G),K=M0(null),z=M0(!0);D2(()=>{function q(O,P){V.current=O,N((D)=>D.text===O&&!D.fading.length&&!P.length?D:{text:O,fading:P})}if($!=="assistant"||!Q){K.current?.destroy(),K.current=null,q(Y.content,[]),z.current=!1;return}if(!K.current)K.current=new $_(q),K.current.seed(V.current);if(z.current){z.current=!1,K.current.seed(Y.content);return}K.current.update(Y.content,!1)},[$,Q,Y]),D2(()=>()=>{K.current?.destroy(),K.current=null},[]);let F=M4(()=>{let q=$==="assistant"?r1(J.text,Q0(Z.mediaRenderers)):[{kind:"markdown",text:J.text}];return q.map((O,P)=>O.kind==="markdown"?{...O,html:{__html:v_(O.text,P===q.length-1?J.fading:[])}}:O)},[$,J,Z.mediaRenderers]),B=Q||J.text!==Y.content;return E_("div",{className:U("cortex-text-part",$==="assistant"&&"cortex-text-part--assistant",$==="user"&&"cortex-text-part--user"),children:E_("div",{className:U("cortex-text-bubble",$==="assistant"&&"cortex-text-bubble--assistant",$==="user"&&"cortex-text-bubble--user"),children:F.map((q,O)=>{switch(q.kind){case"markdown":return E_("div",{dangerouslySetInnerHTML:q.html},O);case"media":return E_(z2,{...q,streaming:B},O);case"table":return E_(W2,{text:q.text,closed:q.closed||!B},O);case"attachment":return E_(N2,{id:q.id,alt:q.alt,attachment:X.find((P)=>P.id.toLowerCase()===q.id)},O)}})})})}import{jsx as g,jsxs as X_}from"react/jsx-runtime";function B2({toolCallPart:_}){let{t:$}=L(),{state:Y,approval:Q}=_,X=_.output,Z=M1(_);if(Y==="complete")return X_("div",{className:"cortex-debug-tool__section cortex-debug-tool__section--success",children:[X_("div",{className:"cortex-debug-tool__section-bar",children:[g("span",{className:"cortex-debug-tool__section-label cortex-debug-tool__section-label--success",children:$("translate_output")}),g("span",{className:"cortex-debug-tool__section-lang",children:"json"}),g(h,{value:Z})]}),g("div",{dir:"ltr",className:"cortex-debug-tool__tree",children:g(Y_,{data:X,expandDepth:2})})]});if(Y==="error")return X_("div",{className:"cortex-debug-tool__section cortex-debug-tool__section--error",children:[X_("div",{className:"cortex-debug-tool__section-bar",children:[g("span",{className:"cortex-debug-tool__section-label cortex-debug-tool__section-label--error",children:$("translate_error")}),g(h,{value:Z})]}),g("pre",{dir:"ltr",className:"cortex-debug-tool__error-pre",children:Z})]});if(Y==="approval-requested")return X_("div",{className:"cortex-debug-tool__section cortex-debug-tool__section--approval",children:[X_("div",{className:"cortex-debug-tool__section-bar",children:[g("span",{className:"cortex-debug-tool__section-label cortex-debug-tool__section-label--approval",children:$("translate_approval_requested")}),g("span",{className:"cortex-debug-tool__section-lang",children:Q?.id})]}),g("div",{className:"cortex-debug-tool__message cortex-debug-tool__message--approval",children:$("translate_waiting_for_approval")})]});if(Y==="approval-responded")return X_("div",{className:"cortex-debug-tool__section cortex-debug-tool__section--approval",children:[X_("div",{className:"cortex-debug-tool__section-bar",children:[g("span",{className:"cortex-debug-tool__section-label cortex-debug-tool__section-label--approval",children:$("translate_approval_response")}),g("span",{className:"cortex-debug-tool__section-lang",children:Q?.id})]}),g("div",{className:"cortex-debug-tool__message cortex-debug-tool__message--approval",children:$(Q?.approved?"translate_tool_approved":"translate_tool_response_received")})]});return null}import{jsx as E4,jsxs as k4}from"react/jsx-runtime";function q2({toolCallPart:_}){let{t:$}=L(),Y=P1(_);return k4("span",{className:U("cortex-debug-tool__state",Y.modifier&&`cortex-debug-tool__state--${Y.modifier}`),children:[Y.pulse&&E4("span",{className:U("cortex-debug-tool__pulse",Y.pulse==="violet"&&"cortex-debug-tool__pulse--violet")}),$(Y.labelKey)]})}import{jsx as T,jsxs as s}from"react/jsx-runtime";function F2({toolCallPart:_}){let{t:$}=L(),{codeSnippets:Y,remainingInput:Q,remainingInputText:X}=A1(_.input);return s("details",{className:"cortex-debug-tool","data-state":_.state,children:[T("summary",{className:"cortex-debug-tool__summary",children:s("div",{className:"cortex-debug-tool__header",children:[s("div",{className:"cortex-debug-tool__meta",children:[T("div",{className:"cortex-debug-tool__title-row",children:T("span",{className:"cortex-debug-tool__name",title:_.name,children:_.name})}),T("div",{className:"cortex-debug-tool__id-row",children:T("span",{className:"cortex-debug-tool__id",children:_.id})})]}),s("div",{className:"cortex-debug-tool__actions",children:[T(q2,{toolCallPart:_}),T("svg",{className:"cortex-debug-tool__chevron",width:"14",height:"14",viewBox:"0 0 20 20",fill:"none",children:T("path",{d:S.chevronDownLarge,stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]})]})}),s("div",{className:"cortex-debug-tool__body",children:[Y.map((Z)=>s("div",{className:"cortex-debug-tool__section",children:[s("div",{className:"cortex-debug-tool__section-bar",children:[T("span",{className:"cortex-debug-tool__section-label",children:Z.key}),T("span",{className:"cortex-debug-tool__section-lang",children:Z.lang}),T(h,{value:Z.value})]}),T("pre",{dir:"ltr",className:"cortex-debug-tool__pre",children:T("code",{className:"hljs",dangerouslySetInnerHTML:{__html:G0(Z.value,Z.lang)}})})]},Z.key)),!!Q&&s("div",{className:"cortex-debug-tool__section",children:[s("div",{className:"cortex-debug-tool__section-bar",children:[T("span",{className:"cortex-debug-tool__section-label",children:$("translate_input")}),T("span",{className:"cortex-debug-tool__section-lang",children:"json"}),T(h,{value:X})]}),T("div",{dir:"ltr",className:"cortex-debug-tool__tree",children:T(Y_,{data:Q,expandDepth:2})})]}),T(B2,{toolCallPart:_})]})]})}import{useEffect as R4,useRef as I4,useState as U2}from"react";import{jsx as p_,jsxs as L2}from"react/jsx-runtime";function K_({activity:_,className:$}){let{t:Y}=L(),Q=k1(_),[X,Z]=U2(0),[G,J]=U2("idle"),N=I4(Q.length);return N.current=Q.length,R4(()=>{let V,K;function z(){V=setTimeout(()=>{J("exiting"),V=setTimeout(()=>{Z((F)=>(F+1)%N.current),J("enter-start"),K=requestAnimationFrame(()=>{J("entering"),V=setTimeout(()=>{J("idle"),z()},300)})},300)},2000)}return z(),()=>{if(V)clearTimeout(V);if(K)cancelAnimationFrame(K)}},[]),L2("div",{className:U("cortex-subtle-activity",$),children:[L2("div",{className:"cortex-subtle-activity__dots",children:[p_("span",{className:"cortex-subtle-activity__dot"}),p_("span",{className:"cortex-subtle-activity__dot cortex-subtle-activity__dot--d1"}),p_("span",{className:"cortex-subtle-activity__dot cortex-subtle-activity__dot--d2"})]}),p_("div",{className:"cortex-subtle-activity__label-mask",children:p_("span",{className:U("cortex-subtle-activity__label",`cortex-subtle-activity__label--${G}`),children:Y(Q[X])})})]})}import{useEffect as k2,useRef as A0,useState as E2}from"react";import{jsx as c,jsxs as k_,Fragment as y4}from"react/jsx-runtime";function O2({toolCallPart:_,asking:$}){let{t:Y,locale:Q,respondToApproval:X}=L(),{sentence:Z,decision:G,decisionKey:J}=E1(_,Q),N=`cortex-approval-${_.id}`,V=u0(_),K=G==="pending",{state:z,active:F}=i(_);return k_("div",{className:U("cortex-approval-card",K&&"cortex-approval-card--asking"),children:[K?k_(y4,{children:[k_("div",{className:"cortex-approval-card__head",children:[c("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:c("path",{d:"M8 1.75 2.75 3.75v4c0 3 2.2 5.3 5.25 6.5 3.05-1.2 5.25-3.5 5.25-6.5v-4L8 1.75Z",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"})}),Y("translate_approval_needed")]}),c("p",{className:"cortex-approval-card__sentence",id:N,children:Z})]}):k_("div",{className:"cortex-approval-card__line",children:[k_("span",{className:"cortex-tool-pill__icon","aria-hidden":"true",children:[c("span",{className:U("cortex-tool-pill__spinner",F&&"cortex-tool-pill__spinner--visible")}),c("svg",{className:U("cortex-tool-pill__svg cortex-tool-pill__svg--check",z==="complete"&&"cortex-tool-pill__svg--visible"),viewBox:"0 0 20 20",fill:"none",children:c("path",{d:"M5.5 10.5 L8.5 13.5 L14.5 7",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),c("svg",{className:U("cortex-tool-pill__svg cortex-tool-pill__svg--error",z==="error"&&"cortex-tool-pill__svg--visible"),viewBox:"0 0 20 20",fill:"none",children:c("path",{d:"M6.5 6.5 L13.5 13.5 M13.5 6.5 L6.5 13.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})]}),J&&c("span",{className:"cortex-approval-card__decision",children:Y(J)}),c("span",{className:"cortex-approval-card__summary",children:Z})]}),K&&$&&k_("div",{className:"cortex-approval-card__foot",children:[c("button",{type:"button",className:"cortex-approval-card__button cortex-approval-card__button--approve","aria-describedby":N,onClick:()=>void X(V,!0),children:Y("translate_approve")}),c("button",{type:"button",className:"cortex-approval-card__button","aria-describedby":N,onClick:()=>void X(V,!1),children:Y("translate_deny")})]})]})}import{useEffect as P2,useRef as N1,useState as M2}from"react";import{jsx as C,jsxs as p}from"react/jsx-runtime";function A2({toolCallPart:_,setOutput:$}){let{t:Y}=L(),{state:Q,id:X,input:Z}=_;if(Q==="complete"||Q==="error"){let G=c1(_.output);return G?C(w4,{position:G}):p("div",{className:"cortex-tool-pill",children:[C("span",{className:"cortex-tool-pill__icon",children:C("svg",{className:U("cortex-tool-pill__svg cortex-tool-pill__svg--visible",Q==="error"&&"cortex-tool-pill__svg--error"),viewBox:"0 0 20 20",fill:"none",children:C("path",{d:"M6.5 6.5 L13.5 13.5 M13.5 6.5 L6.5 13.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}),C("span",{className:"cortex-tool-pill__title",children:Y("translate_location_not_shared")})]})}if(Q!=="input-complete")return null;return C(C4,{center:u1(Z),submit:$},X)}function C4({center:_,submit:$}){let{t:Y}=L(),Q=N1(null),X=N1(void 0),[Z,G]=M2(a_),J=N1({center:_,submit:$});J.current={center:_,submit:$},P2(()=>{let V=Q.current;if(!V)return;let K=x1(V,{center:J.current.center,onState:G,submit:(z)=>J.current.submit(z)});return X.current=K,K.start(),()=>{if(K.dispose(),X.current===K)X.current=void 0}},[]);let N=p1(Z);return p("div",{className:"cortex-location-input",children:[p("div",{className:"cortex-location-input__map",children:[C("div",{className:"cortex-location-input__canvas",ref:Q}),C("button",{type:"button",className:"cortex-location-input__locate","aria-label":Y("translate_location_locate"),title:Y("translate_location_locate"),disabled:Z.locating||Z.submitting,onClick:()=>X.current?.locate(),children:C(S4,{})})]}),p("div",{className:"cortex-location-input__foot",children:[Z.position&&!Z.deliveryFailed?C("span",{className:"cortex-location-input__coords",children:o_(Z.position)}):p("span",{className:U("cortex-location-input__hint",N.failed&&"cortex-location-input__hint--failed"),children:[Z.locating&&C("span",{className:"cortex-location-input__spinner"}),Y(N.key)]}),p("span",{className:"cortex-location-input__actions",children:[C("button",{type:"button",className:"cortex-location-input__skip",disabled:Z.submitting,onClick:()=>X.current?.cancel(),children:Y("translate_location_skip")}),C("button",{type:"button",className:"cortex-location-input__send",disabled:!Z.position||Z.submitting,onClick:()=>X.current?.confirm(),children:Y("translate_location_send")})]})]})]})}function w4({position:_}){let{t:$}=L(),Y=N1(null),[Q,X]=M2(!1),{lat:Z,lng:G}=_;return P2(()=>{let J=Y.current;if(!J)return;return X(!1),h1(J,{lat:Z,lng:G},()=>X(!0))},[Z,G]),p("div",{className:"cortex-location-input cortex-location-input--settled",children:[p("div",{className:"cortex-location-input__map cortex-location-input__map--still",children:[C("div",{className:"cortex-location-input__canvas",ref:Y,hidden:Q}),Q&&C("span",{className:"cortex-location-input__still-failed",children:$("translate_location_map_failed")})]}),p("div",{className:"cortex-location-input__body",children:[p("span",{className:"cortex-location-input__title",children:[C("svg",{viewBox:"0 0 20 20",fill:"none",children:C("path",{d:"M5.5 10.5 L8.5 13.5 L14.5 7",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),$("translate_location_shared")]}),C("span",{className:"cortex-location-input__coords",children:o_(_)})]})]})}function S4(){return p("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:[C("circle",{cx:"10",cy:"10",r:"5.5"}),C("circle",{cx:"10",cy:"10",r:"1.6",fill:"currentColor",stroke:"none"}),C("path",{d:"M10 1.5v3M10 15.5v3M1.5 10h3M15.5 10h3"})]})}import{jsx as I,jsxs as d_}from"react/jsx-runtime";var b4=new Map([[r_,A2]]);function R2({message:_,toolCallPart:$,agentWorking:Y}){let{config:Q,addToolResult:X}=L(),Z=$.state==="input-complete"&&!Y,G=$.state==="approval-requested"&&!Y,J=Q.toolComponents?.[$.name]??(Z||f($.state)?b4.get($.name):void 0);return I("div",{className:"cortex-tool-call-animated",children:J?I(J,{toolCallPart:$,message:_,setOutput:(N)=>X($.id,$.name,N)}):Z?I(T4,{toolCallPart:$}):I(I2,{toolCallPart:$,asking:G})})}function T4({toolCallPart:_}){let{api:$,t:Y,addToolResult:Q,selectedThread:X,config:Z}=L(),G=X?.id,[J,N]=E2({phase:"initiating"}),[V]=E2(Z.trustSameOriginEmbeds),K=A0(void 0),z=A0({api:$,addToolResult:Q,toolName:_.name});if(z.current={api:$,addToolResult:Q,toolName:_.name},k2(()=>{if(!G)return;let B=g1({initiate:()=>z.current.api.initiateToolCall(G,_.id),onState:N,submit:(O)=>z.current.addToolResult(_.id,z.current.toolName,O)});K.current=B,B.start();let q=(O)=>B.handleMessage(O);return window.addEventListener("message",q),()=>{if(window.removeEventListener("message",q),B.dispose(),K.current===B)K.current=void 0}},[_.id,G]),!G||J.phase==="unavailable"||J.phase==="settling")return I(I2,{toolCallPart:_,asking:!1});let F=d_("div",{className:"cortex-client-tool-embed",children:[d_("div",{className:"cortex-client-tool-embed__bar",children:[I("span",{children:Y("translate_client_tool_title")}),I("button",{type:"button",className:"cortex-client-tool-embed__cancel",onClick:()=>K.current?.cancel(),children:Y("translate_client_tool_cancel")})]}),J.phase==="embedded"?I("iframe",{className:"cortex-client-tool-embed__frame",src:J.embedUrl,sandbox:v1(J.embedUrl,window.location.origin,V),title:Y("translate_client_tool_title"),ref:(B)=>K.current?.setSource(B?.contentWindow),onLoad:(B)=>{if(!f1(J.embedUrl,window.location.origin,V)&&j1(B.currentTarget,window.location.origin))K.current?.terminate()}}):J.phase==="error"?d_("div",{className:"cortex-client-tool-embed__status",children:[I("span",{children:Y("translate_client_tool_failed")}),I("button",{type:"button",className:"cortex-client-tool-embed__retry",onClick:()=>void K.current?.start(),children:Y("translate_client_tool_retry")})]}):I("div",{className:"cortex-client-tool-embed__status",children:Y("translate_client_tool_loading")})]});return J.phase==="embedded"&&J.surface==="modal"?I(v4,{label:Y("translate_client_tool_title"),onCancel:()=>K.current?.cancel(),children:F}):F}function v4({label:_,onCancel:$,children:Y}){let Q=A0(null);return k2(()=>{let X=Q.current;return X?.showModal(),()=>X?.close()},[]),I("dialog",{ref:Q,className:"cortex-client-tool-embed-dialog","aria-label":_,onCancel:(X)=>{X.preventDefault(),$()},children:Y})}function I2({toolCallPart:_,asking:$}){return i(_).gated?I(O2,{toolCallPart:_,asking:$}):I(f4,{toolCallPart:_})}function f4({toolCallPart:_}){let{t:$}=L(),{state:Y,active:Q,titleKey:X,statement:Z,rowCount:G}=i(_);return d_("div",{className:"cortex-tool-pill",children:[d_("span",{className:"cortex-tool-pill__icon",children:[I("span",{className:U("cortex-tool-pill__spinner",Q&&"cortex-tool-pill__spinner--visible")}),I("svg",{className:U("cortex-tool-pill__svg","cortex-tool-pill__svg--check",Y==="complete"&&"cortex-tool-pill__svg--visible"),viewBox:"0 0 20 20",fill:"none",children:I("path",{d:"M5.5 10.5 L8.5 13.5 L14.5 7",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),I("svg",{className:U("cortex-tool-pill__svg","cortex-tool-pill__svg--error",Y==="error"&&"cortex-tool-pill__svg--visible"),viewBox:"0 0 20 20",fill:"none",children:I("path",{d:"M6.5 6.5 L13.5 13.5 M13.5 6.5 L6.5 13.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})]}),I("span",{className:U("cortex-tool-pill__title",Y==="error"&&"cortex-tool-pill__title--error",Y==="starting"&&Z&&"cortex-tool-pill__title--pending"),children:Z??$(X)}),G!==void 0&&I("span",{className:"cortex-tool-pill__meta",children:$("translate_rows_read",{count:G})})]})}import{jsx as E0}from"react/jsx-runtime";function y2({message:_,toolCallPart:$,agentWorking:Y}){if(!f($.state)&&!i($).statement){if($.name==="queryGraph")return E0(K_,{activity:"graph"});if($.name==="executeCode")return E0(K_,{activity:"code"})}return E0(R2,{toolCallPart:$,message:_,agentWorking:Y})}import{jsx as R_,jsxs as j4}from"react/jsx-runtime";function C2(_){let{message:$,part:Y,debugMode:Q,animate:X,streaming:Z,agentWorking:G,attachments:J}=_,{t:N}=L();function V(){switch(Y.type){case"text":return R_(H2,{textPart:Y,role:$.role,streaming:Z,attachments:J});case"thinking":return Q?R_(G2,{reasoningPart:Y,streaming:Z}):R_(K_,{activity:"reasoning",className:"cortex-reasoning-animated"});case"tool-call":return Q?R_(F2,{toolCallPart:Y}):R_(y2,{toolCallPart:Y,message:$,agentWorking:G});default:return j4("p",{className:"cortex-unhandled-type",children:[N("translate_unhandled_type")," ",Y.type]})}}return R_("div",{className:U("cortex-message-part",X&&"cortex-message-part--animated",_.folded&&"cortex-message-part--folded"),"data-cortex-frontier":_.frontier?"":void 0,children:V()})}import{jsx as e,jsxs as k0}from"react/jsx-runtime";function m4({isUser:_,clipboardText:$,createdAt:Y}){let{locale:Q}=L();return k0("div",{className:U("cortex-message-actions",_&&"cortex-message-actions--user"),children:[$&&e(h,{value:$}),Y&&e("time",{className:"cortex-message-actions__time",dateTime:Y,children:r(Y,Q)})]})}function x4({count:_,animate:$,onOpen:Y}){let{t:Q}=L();return e("button",{type:"button",className:U("cortex-tool-fold",$&&"cortex-message-part--animated"),onClick:Y,children:Q(C_(_,"translate_one_more_step","translate_n_more_steps"),{count:_})})}function w2(_){let{message:$,parts:Y,metadata:Q,debugMode:X,animate:Z,isStreaming:G,agentWorking:J,closesTurn:N,fold:V,onOpenRun:K,frontier:z}=_,F=$.role==="assistant",B=$.role==="user",q=G?Y.length-1:-1,O=Q?.attachments??[],P=Y.filter((k)=>V?.get(k)?.kind!=="hidden"),D=P.filter((k)=>k.type==="text").at(-1),H=D?Y.indexOf(D):-1,W=(B||F)&&!G&&H>=0,M=D!==P.at(-1)?H:-1,A=W&&e(m4,{isUser:B,clipboardText:R1(Y),createdAt:Q?.createdAt});return k0("div",{className:"cortex-message-parts",children:[Y.map((k,n)=>{let Z_=V?.get(k);return k0(g4,{children:[e(C2,{part:k,message:$,debugMode:X,animate:Z,streaming:n===q,agentWorking:J,attachments:O,frontier:k===z,folded:Z_?.kind==="hidden"}),Z_?.kind==="more"&&e(x4,{count:Z_.count,animate:Z,onOpen:()=>K(Z_.runId)}),n===M&&A]},$.parts.indexOf(k))}),O.length>0&&e(t6,{attachments:O,isUser:B}),Q?.isAborted&&e(a6,{}),M===-1&&A,X&&Q&&N&&e(Z2,{messageId:$.id,isAssistant:F,metadata:Q})]})}import{jsx as z_,jsxs as R0}from"react/jsx-runtime";function S2({firing:_,debugMode:$}){let{t:Y,locale:Q}=L();return R0("div",{className:U("cortex-trigger-block",$&&"cortex-trigger-block--debug"),children:[R0("div",{className:"cortex-trigger-block__head",children:[z_("svg",{className:"cortex-trigger-block__icon",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:z_("path",{d:"M6.75 1 2.5 6.75h3l-.25 4.25L9.5 5.25h-3z",fill:"currentColor"})}),$&&z_("span",{children:Y("translate_trigger_fired")}),z_("span",{className:"cortex-trigger-block__name",children:_.name}),z_("time",{className:"cortex-trigger-block__time",dateTime:_.firedAt,children:r(_.firedAt,Q)})]}),$&&R0("details",{className:"cortex-trigger-block__payload",children:[z_("summary",{children:Y("translate_trigger_payload")}),z_(Y_,{data:_.payload,expandDepth:2})]})]})}import{jsx as l_}from"react/jsx-runtime";var b2=h4(function($){let{message:Y,metadata:Q,isStreaming:X,agentWorking:Z,closesTurn:G,debugMode:J,animate:N,fold:V,onOpenRun:K,workingTurn:z,frontier:F}=$,B=B_(Y.parts,{debugMode:J,isStreaming:X});if(Q?.trigger)return l_("div",{className:"cortex-message",children:l_(S2,{firing:Q.trigger,debugMode:J})});if(B.length===0&&!Q?.attachments?.length)return l_("div",{className:"cortex-message"});return l_("div",{className:U("cortex-message",z&&"cortex-message--working-turn"),children:l_(w2,{message:Y,parts:B,metadata:Q,debugMode:J,animate:N,isStreaming:X,agentWorking:Z,closesTurn:G,fold:V,onOpenRun:K,frontier:F})})});import{jsx as V1}from"react/jsx-runtime";var u4=[{role:"user",lines:[13,9]},{role:"assistant",lines:[16,18,12]},{role:"user",lines:[11]},{role:"assistant",lines:[14,15]}];function T2(){return V1("div",{className:"cortex-widget__messages-skeleton",children:u4.map((_,$)=>V1("div",{className:`cortex-widget__msg-skel cortex-widget__msg-skel--${_.role}`,children:V1("div",{className:`cortex-widget__msg-skel-bubble cortex-widget__msg-skel-bubble--${_.role}`,children:_.lines.map((Y)=>V1("div",{className:"cortex-skeleton cortex-widget__msg-skel-line",style:{width:`${Y}rem`}},Y))})},$))})}import{jsx as d,jsxs as K1,Fragment as i4}from"react/jsx-runtime";function p4(_){let $=W_(null),Y=W_(null),Q=W_(!0),X=W_(!0),Z=W_(!1),G=n_(()=>{if(Z.current)return;Z.current=!0,queueMicrotask(()=>{Z.current=!1;let K=$.current;if(!K)return;$1(K),X.current=!0,Q.current=!1})},[]);I0(()=>{let K=Y.current;if(!_||!$.current||!K)return;if(G(),typeof ResizeObserver>"u")return;let z=0,F=new ResizeObserver(([B])=>{let q=B?.contentRect.height??0,O=q>z;if(z=q,O&&(Q.current||X.current))G()});return F.observe(K),()=>F.disconnect()},[_,G]);let J=n_(()=>{Q.current=!0},[]),N=n_(()=>{if(Q.current)G()},[G]);function V(){let K=$.current;if(K)X.current=D0(K)<100}return{containerRef:$,contentRef:Y,onScroll:V,pin:J,settlePinned:N}}function d4({pin:_,settlePinned:$,contentRef:Y},Q,X){let[Z,G]=C0(!1);I0(()=>{G(!1),_(),queueMicrotask(()=>G(!0))},[Q,_]);let J=X[X.length-1],N=J?.role==="user"?J.id:void 0,V=N?J?.parts.find((K)=>K.type==="text")?.content:void 0;return y0(()=>{if(!N)return;_();let K=Y.current;if(K&&V!==void 0)W0(K,V)},[N,V,_,Y]),I0(()=>{$()},[X,$]),Z}function l4(_,$,Y,Q){let[X,Z]=C0(new Set),G=n_((V)=>Z((K)=>new Set(K).add(V)),[]),[J]=C0(C1);return{folds:c4(()=>J(_,{agentWorking:$,debugMode:Y,opened:X,foldable:Q}),[J,_,$,Y,X,Q]),openRun:G}}function n4({working:_}){let $=W_(null),Y=W_(void 0);return y0(()=>{let Q=$.current;if(!Q)return;let X=H0(Q);return Y.current=X,()=>{X.dispose(),Y.current=void 0}},[]),y0(()=>Y.current?.sync(_)),K1("div",{ref:$,className:"cortex-working-avatar","aria-hidden":"true",children:[K1("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d("path",{d:"M9.94 15.5a2 2 0 0 0-1.44-1.44l-6.13-1.58a.5.5 0 0 1 0-.96L8.5 9.94A2 2 0 0 0 9.94 8.5l1.58-6.14a.5.5 0 0 1 .96 0l1.58 6.14a2 2 0 0 0 1.44 1.44l6.14 1.58a.5.5 0 0 1 0 .96l-6.14 1.58a2 2 0 0 0-1.44 1.44l-1.58 6.14a.5.5 0 0 1-.96 0z"}),d("path",{d:"M20 3v4M22 5h-4M4 17v2M5 18H3"})]}),d("span",{className:"cortex-working-avatar__ring"})]})}function v2(_){let{config:$,selectedThread:Y}=L(),{messages:Q,isAgentWorking:X,isLoadingMessages:Z,hasPendingToolCalls:G}=F_(),{capabilities:J,composerRef:N,debugMode:V}=_,K=!Z||X,z=p4(K),F=d4(z,Y?.id,Q),B=X?w_(Q)?.id:void 0,q=$.toolComponents,O=n_((A)=>I1(A,q),[q]),{folds:P,openRun:D}=l4(Q,X,V,O),H=Q.map((A)=>A.role).lastIndexOf("user"),W=X&&!V,M=W?y1(Q,{foldable:O}):void 0;return K1(i4,{children:[!K?d(T2,{}):d("div",{className:_.className,children:d("div",{ref:z.containerRef,className:"cortex-message-list",onScroll:z.onScroll,children:K1("div",{ref:z.contentRef,className:"cortex-message-list__content",children:[Q.map((A,k)=>d(b2,{message:A,metadata:A.metadata,isStreaming:A.id===B,agentWorking:X,fold:P.get(A.id),onOpenRun:D,closesTurn:A.role==="assistant"&&Q[k+1]?.role!=="assistant",debugMode:V,animate:F,workingTurn:W&&k>H,frontier:A.id===B?M:void 0},A.id)),X&&!M&&d("div",{className:"cortex-working-thinking","data-cortex-frontier":"",children:d(K_,{activity:"reasoning"})}),d(n4,{working:X},Y?.id)]})})}),!G&&d(Y1,{capabilities:J,composerRef:N})]})}import{jsx as f2,jsxs as r4}from"react/jsx-runtime";function j2(_){let{debugMode:$,selectedThread:Y}=L(),{screens:Q}=_;return r4("div",{className:U("cortex-widget__screen",Q.screen==="chat"&&"cortex-widget__screen--active",Q.screen!=="chat"&&"cortex-widget__screen--right"),children:[_.header,Y?f2(v2,{className:"cortex-widget__messages",debugMode:$,capabilities:_.capabilities,composerRef:_.composerRef}):_.landing,f2("div",{className:"cortex-widget__sidebar-backdrop",onClick:Q.closeSidebar})]})}import{useState as e4}from"react";import{useEffect as w0,useRef as h2,useState as S0}from"react";import{useChat as s4}from"@tanstack/ai-react";import{useEffect as a4,useLayoutEffect as o4,useState as t4}from"react";function g2(_,{sessionRef:$,pendingSendRef:Y}){let[Q]=t4(_);return o4(()=>{return $.current=Q,()=>{if($.current===Q)$.current=void 0}},[Q,$]),a4(()=>{if(!Y.current.length)return;let X=setTimeout(()=>{let Z=Y.current;Y.current=[],(async()=>{for(let{prompt:G,attachments:J}of Z)await Q.send(G,J)})()});return()=>clearTimeout(X)},[Q,Y]),Q}import{useRef as m2}from"react";function x2(_){let $=m2(_);$.current=_;let Y=m2(Promise.resolve(void 0));async function Q(X){let Z=$.current;if(!Z.isAlive()||X!==Z.threadId)return;return S1({api:Z.api,threadId:X,isStale:()=>!$.current.isAlive(),isStreaming:()=>$.current.isStreaming(),setMessages:(G)=>$.current.setMessages(G)})}return function(Z){return Y.current=Y.current.then(()=>Q(Z)),Y.current}}function u2(_){let{thread:$,api:Y}=_,Q=h2(!0),[X,Z]=S0(!1),G=h2(null),J=x2({api:Y,threadId:$.id,isAlive:()=>Q.current,isStreaming:()=>G.current.chat.isLoading,setMessages:(H)=>G.current.chat.setMessages(H)}),[N]=S0(()=>B0({threadId:$.id,isAlive:()=>Q.current,onToolCall:()=>G.current.props.configRef.current.hooks?.onToolCall,deliver:(H)=>G.current.chat.addToolResult(H),setRunning:(H)=>G.current.props.setRunning($.id,H),reloadThreads:()=>G.current.props.reloadThreads(),refreshMessages:()=>J($.id),onTurnFinished:()=>G.current.props.onTurnFinished(),onSendFailed:()=>G.current.props.onSendFailed()})),[V]=S0(()=>w1({api:Y,thread:{id:$.id,isRunning:$.isRunning},mode:_.mode,localMessages:()=>G.current.chat.messages,onHydrated:(H)=>{if(Q.current)N.hydrated(H,$.isRunning)},onTranscriptCarried:(H)=>{if(Q.current)N.transcriptCarried(H)},setLoadingMessages:(H)=>{if(Q.current)Z(H)}})),K=s4({threadId:$.id,persistence:!0,initialMessages:_.initialMessages,connection:V,onChunk:()=>{if(Q.current)N.chunkArrived()},onError:()=>{if(Q.current)N.streamFailed()}});G.current={chat:K,props:_};async function z(H,W){N.sendStarted();let M={id:S_(),role:"user",parts:[{type:"text",content:H}],metadata:{createdAt:new Date().toISOString(),attachments:W}};await G.current.chat.append(M)}async function F(){if(!G.current.chat.isLoading)return;let{aborted:H}=await Y.abortStream($.id).catch(()=>({aborted:!1}));if(!Q.current)return;if(H)N.abortConfirmed();G.current.chat.stop()}function B(H,W,M){return G.current.chat.addToolResult({toolCallId:H,tool:W,output:M}).catch((A)=>{throw J($.id),A})}function q(H,W){return m1(G.current.chat,H,W)}function O(H){if(G.current.chat.isLoading)return;if(H.isRunning){G.current.props.remount(H,G.current.chat.messages);return}J(H.id)}w0(()=>{return Q.current=!0,()=>{Q.current=!1}},[]),g2(()=>({threadId:$.id,send:z,abort:F,addToolResult:B,respondToApproval:q,reattach:O,transcriptUpdated:(H,W)=>{if(H===$.id)N.transcriptUpdated(W)}}),{sessionRef:_.sessionRef,pendingSendRef:_.pendingSendRef});let{messages:P,isLoading:D}=K;return w0(()=>{N.loadingChanged(D,()=>G.current.chat.messages)},[N,D]),w0(()=>{G.current.props.publish({messages:P,isAgentWorking:D,isLoadingMessages:X,hasPendingToolCalls:!D&&__(P).length>0})},[P,D,X]),null}import{jsx as _7,jsxs as $7}from"react/jsx-runtime";function c2({selection:_,threads:$,children:Y,...Q}){let{session:X}=_,[Z,G]=e4(),J=X&&`${X.thread.id}:${X.epoch}`,N=X&&Z&&(Z.key===J||X.mode==="reload")?Z.value:F0;return $7(U0.Provider,{value:N,children:[X&&J&&_7(u2,{thread:X.thread,mode:X.mode,initialMessages:X.initialMessages,setRunning:$.setRunning,reloadThreads:$.reload,remount:_.remount,publish:(V)=>G({key:J,value:V}),...Q},J),Y]})}import{jsx as w,jsxs as D_,Fragment as Y7}from"react/jsx-runtime";function p2(_){let{locale:$,t:Y}=L(),{threads:Q}=_;return w("div",{className:"cortex-widget__threads-list",children:Q===void 0?[1,2,3,4].map((X)=>D_("div",{className:"cortex-widget__thread-skeleton",children:[w("div",{className:"cortex-skeleton cortex-widget__thread-skeleton-icon"}),w("div",{className:"cortex-widget__thread-skeleton-lines",children:w("div",{className:"cortex-skeleton cortex-widget__thread-skeleton-line",style:{width:`${40+X*12}%`}})})]},X)):D_(Y7,{children:[Q.map((X)=>{let Z=X.id===_.selectedThreadId,G=r(X.updatedAt,$);return D_("button",{onClick:()=>_.openThread(X),className:U("cortex-widget__thread-item",Z&&"cortex-widget__thread-item--active"),children:[w("div",{className:U("cortex-widget__thread-icon",Z&&"cortex-widget__thread-icon--active"),children:w("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:w("path",{d:S.bubble,stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}),D_("div",{className:"cortex-widget__thread-info",children:[D_("div",{className:"cortex-widget__thread-title-row",children:[w("p",{className:U("cortex-widget__thread-title",Z&&"cortex-widget__thread-title--active"),children:X.title??Y("translate_untitled")}),X.isRunning&&D_("span",{className:U("cortex-widget__thread-running",Z&&"cortex-widget__thread-running--active"),children:[w("span",{className:"cortex-widget__thread-running-dot"}),Y("translate_running")]})]}),G&&w("p",{className:"cortex-widget__thread-time",children:G})]}),w("span",{role:"button",tabIndex:0,onClick:(J)=>{J.stopPropagation(),_.deleteThread(X.id)},onKeyDown:(J)=>{if(J.key!=="Enter"&&J.key!==" ")return;J.preventDefault(),J.stopPropagation(),_.deleteThread(X.id)},className:U("cortex-widget__thread-delete",Z&&"cortex-widget__thread-delete--active"),children:w("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",children:w("path",{d:"M4 4l8 8M12 4l-8 8",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"})})}),w("svg",{className:U("cortex-widget__thread-arrow",Z&&"cortex-widget__thread-arrow--active"),width:"10",height:"10",viewBox:"0 0 16 16",fill:"none",children:w("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]},X.id)}),!Q.length&&D_("div",{className:"cortex-widget__threads-empty",children:[w("div",{className:"cortex-widget__threads-empty-icon",children:w("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",className:"cortex-widget__threads-empty-svg",children:w("path",{d:S.bubble,stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}),w("p",{className:"cortex-widget__threads-empty-title",children:Y("translate_no_threads_yet")}),w("p",{className:"cortex-widget__threads-empty-subtitle",children:Y("translate_start_a_new_conversation")}),w("button",{onClick:_.newChat,className:"cortex-widget__new-chat-btn cortex-widget__new-chat-btn--empty-state",children:Y("translate_new_chat")})]})]})})}import{useSyncExternalStore as Q7}from"react";function d2(_){return Q7(($)=>{let Y=window.matchMedia(_);return Y.addEventListener("change",$),()=>Y.removeEventListener("change",$)},()=>window.matchMedia(_).matches,()=>!1)}import{jsx as Z7,jsxs as n2}from"react/jsx-runtime";var X7="(max-width: 768px)";function l2(_){_.preventDefault()}function i2(_){let{screens:$}=_,Y=d2(X7),Q=_.viewMode==="full"?Y&&!$.sidebarOpen:$.screen!=="threads";return Z7("div",{className:U("cortex-widget",_.className),"data-cortex-theme":_.theme,children:n2("div",{className:U("cortex-widget__container",_.viewMode==="full"&&"cortex-widget__container--full",$.sidebarOpen&&"cortex-widget__container--sidebar-open"),onDragOver:l2,onDrop:l2,children:[n2("div",{className:U("cortex-widget__screen",$.screen==="threads"&&"cortex-widget__screen--active",$.screen!=="threads"&&"cortex-widget__screen--left"),"aria-hidden":Q||void 0,inert:Q||void 0,children:[_.header,_.threadList]}),_.children]})})}import{jsx as l}from"react/jsx-runtime";var J7={header:l6,landing:i6,threadList:p2};function b0(_,$){return _?.[$]??J7[$]}function N7(_){let{isAgentWorking:$}=F_();return l(_.component,{..._.context,isWorking:$})}function V7({config:_,className:$,slots:Y}){let Q=r2(_);Q.current=_;let[X]=z1(()=>U1(()=>Q.current.transport)),Z=v6(X),[G,J]=z1(!1),[N,V]=z1();G7(()=>Z0(_.theme,V),[_.theme]);let K=_.viewMode??"helper",z=j6(K),[F,B]=z1(0),q=E6(X,F),O=r2(null),P=w6({api:X,threads:Z,getHooks:()=>Q.current.hooks}),{sessionRef:D,selection:H,queue:W,send:M,pendingSendRef:A}=P,{selected:k,selectedRef:n}=H,Z_=b6({threads:Z,selectedRef:n,sessionRef:D,deselect:H.deselect,onReconnect:()=>B((m)=>m+1)});S6({getConfig:()=>Q.current,onEvent:Z_.onEvent,onMount:()=>void Z.reload(),onReconnect:Z_.onReconnect});let i_=L1(_.locale),a2={config:_,locale:i_,t:(m,W1)=>G_(i_,m,W1),api:X,debugMode:G,scheme:N,capabilities:q,selectedThread:k,send:M,...T6(D),queue:W.value};function o2(){W.store.discardConsumed(),setTimeout(()=>O.current?.focusInput())}function t2(){W.store.restoreConsumed(n.current?.id)}function T0(m){P.openThread(m),z.showChat()}function v0(){H.deselect(),z.showChat()}function s2(){J((m)=>!m)}function f0(m){let W1={screen:m,viewMode:K,title:k?.title??null,agentName:H_(_.agentName,i_),threadCount:Z.threads?.length??0,debug:{shown:Boolean(_.showDebugButton),on:G},newChat:v0,openHistory:z.openHistory,closeHistory:z.closeHistory,toggleDebug:s2};return l(N7,{component:b0(Y,"header"),context:W1})}let e2=b0(Y,"landing"),_5={...O1(q,i_,(m)=>void M(m)),threads:Z.threads,composer:l("div",{className:"cortex-widget__landing-composer",children:l(Y1,{capabilities:q})}),openThread:T0,openHistory:z.openHistory},$5=b0(Y,"threadList"),Y5={threads:Z.threads,selectedThreadId:k?.id,openThread:T0,deleteThread:(m)=>void P.deleteThread(m),newChat:v0};return l(q0.Provider,{value:a2,children:l(c2,{selection:H,threads:Z,api:X,configRef:Q,sessionRef:D,pendingSendRef:A,onTurnFinished:o2,onSendFailed:t2,children:l(i2,{className:$,theme:_.theme,viewMode:K,screens:z,header:f0("threads"),threadList:l($5,{...Y5}),children:l(j2,{screens:z,capabilities:q,composerRef:O,header:f0("chat"),landing:l(e2,{..._5})})})})})}export{V7 as CortexChatWidget};
package/dist/styles.css CHANGED
@@ -1799,6 +1799,10 @@ cortex-llm-usage-chips {
1799
1799
  display: block;
1800
1800
  max-width: 100%;
1801
1801
  height: auto;
1802
+ direction: ltr;
1803
+ }
1804
+ .cortex-media-block__body svg text {
1805
+ unicode-bidi: plaintext;
1802
1806
  }
1803
1807
  .cortex-media-block__body > div > svg {
1804
1808
  margin-inline: auto;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m6d/cortex-react",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "React chat widget SDK for cortex servers",
5
5
  "license": "MIT",
6
6
  "sideEffects": [