(function(global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lit'), require('lit/directives/style-map.js'), require('lit/directives/unsafe-html.js'), require('marked'), require('lucide'), require('@copilotkitnext/core')) : typeof define === 'function' && define.amd ? define(['exports', 'lit', 'lit/directives/style-map.js', 'lit/directives/unsafe-html.js', 'marked', 'lucide', '@copilotkitnext/core'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitNextWebInspector = {}), global.Lit,global.LitDirectivesStyleMap,global.LitDirectivesUnsafeHtml,global.marked,global.lucide,global.CopilotKitNextCore)); })(this, function(exports, lit, lit_directives_style_map_js, lit_directives_unsafe_html_js, marked, lucide, _copilotkitnext_core) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); //#region src/styles/generated.css var generated_default = "/*! tailwindcss v4.1.18 | MIT License | https://tailwindcss.com */\n@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-translate-z:0;--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-space-y-reverse:0;--tw-divide-y-reverse:0;--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial;--tw-scale-x:1;--tw-scale-y:1;--tw-scale-z:1;--tw-outline-style:solid}}}@layer theme{:root,:host{--font-sans:ui-sans-serif,system-ui,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\",\"Noto Color Emoji\";--font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace;--color-amber-50:oklch(98.7% .022 95.277);--color-amber-100:oklch(96.2% .059 95.617);--color-amber-200:oklch(92.4% .12 95.746);--color-amber-600:oklch(66.6% .179 58.318);--color-amber-700:oklch(55.5% .163 48.998);--color-amber-800:oklch(47.3% .137 46.201);--color-amber-900:oklch(41.4% .112 45.904);--color-green-100:oklch(96.2% .044 156.743);--color-green-700:oklch(52.7% .154 150.069);--color-green-800:oklch(44.8% .119 151.328);--color-emerald-50:oklch(97.9% .021 166.113);--color-emerald-200:oklch(90.5% .093 164.15);--color-emerald-500:oklch(69.6% .17 162.48);--color-emerald-700:oklch(50.8% .118 165.612);--color-sky-50:oklch(97.7% .013 236.62);--color-sky-200:oklch(90.1% .058 230.902);--color-sky-700:oklch(50% .134 242.749);--color-blue-50:oklch(97% .014 254.604);--color-blue-100:oklch(93.2% .032 255.585);--color-blue-200:oklch(88.2% .059 254.128);--color-blue-600:oklch(54.6% .245 262.881);--color-blue-700:oklch(48.8% .243 264.376);--color-blue-800:oklch(42.4% .199 265.638);--color-violet-50:oklch(96.9% .016 293.756);--color-violet-200:oklch(89.4% .057 293.283);--color-violet-700:oklch(49.1% .27 292.581);--color-purple-50:oklch(97.7% .014 308.299);--color-purple-200:oklch(90.2% .063 306.703);--color-purple-700:oklch(49.6% .265 301.924);--color-fuchsia-50:oklch(97.7% .017 320.058);--color-fuchsia-200:oklch(90.3% .076 319.62);--color-fuchsia-700:oklch(51.8% .253 323.949);--color-rose-50:oklch(96.9% .015 12.422);--color-rose-200:oklch(89.2% .058 10.001);--color-rose-500:oklch(64.5% .246 16.439);--color-rose-600:oklch(58.6% .253 17.585);--color-rose-700:oklch(51.4% .222 16.935);--color-rose-800:oklch(45.5% .188 13.697);--color-rose-900:oklch(41% .159 10.272);--color-slate-200:oklch(92.9% .013 255.508);--color-slate-800:oklch(27.9% .041 260.031);--color-slate-900:oklch(20.8% .042 265.755);--color-slate-950:oklch(12.9% .042 264.695);--color-gray-50:oklch(98.5% .002 247.839);--color-gray-100:oklch(96.7% .003 264.542);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-300:oklch(87.2% .01 258.338);--color-gray-400:oklch(70.7% .022 261.325);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-600:oklch(44.6% .03 256.802);--color-gray-700:oklch(37.3% .034 259.733);--color-gray-800:oklch(27.8% .033 256.848);--color-gray-900:oklch(21% .034 264.665);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-xs:20rem;--container-md:28rem;--container-2xl:42rem;--text-xs:.75rem;--text-xs--line-height:calc(1/.75);--text-sm:.875rem;--text-sm--line-height:calc(1.25/.875);--text-lg:1.125rem;--text-lg--line-height:calc(1.75/1.125);--font-weight-medium:500;--font-weight-semibold:600;--leading-snug:1.375;--leading-relaxed:1.625;--radius-sm:.25rem;--radius-md:.375rem;--radius-lg:.5rem;--radius-xl:.75rem;--animate-pulse:pulse 2s cubic-bezier(.4,0,.6,1)infinite;--blur-sm:8px;--blur-md:12px;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4,0,.2,1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif,system-ui,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\",\"Noto Color Emoji\");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}:host{font-family:var(--font-sans);color:var(--color-slate-900);background-color:#0000;display:block}}@layer components;@layer utilities{.pointer-events-auto{pointer-events:auto}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.static{position:static}.sticky{position:sticky}.top-0{top:calc(var(--spacing)*0)}.right-0{right:calc(var(--spacing)*0)}.right-1{right:calc(var(--spacing)*1)}.bottom-1{bottom:calc(var(--spacing)*1)}.left-0{left:calc(var(--spacing)*0)}.z-10{z-index:10}.z-30{z-index:30}.z-40{z-index:40}.z-50{z-index:50}.m-0{margin:calc(var(--spacing)*0)}.mx-4{margin-inline:calc(var(--spacing)*4)}.my-1{margin-block:calc(var(--spacing)*1)}.my-3{margin-block:calc(var(--spacing)*3)}.mt-0\\.5{margin-top:calc(var(--spacing)*.5)}.mt-1{margin-top:calc(var(--spacing)*1)}.mt-1\\.5{margin-top:calc(var(--spacing)*1.5)}.mt-2{margin-top:calc(var(--spacing)*2)}.mb-1{margin-bottom:calc(var(--spacing)*1)}.mb-2{margin-bottom:calc(var(--spacing)*2)}.mb-3{margin-bottom:calc(var(--spacing)*3)}.mb-4{margin-bottom:calc(var(--spacing)*4)}.ml-auto{margin-left:auto}.box-border{box-sizing:border-box}.block{display:block}.flex{display:flex}.grid{display:grid}.inline-block{display:inline-block}.inline-flex{display:inline-flex}.h-1\\.5{height:calc(var(--spacing)*1.5)}.h-3{height:calc(var(--spacing)*3)}.h-3\\.5{height:calc(var(--spacing)*3.5)}.h-5{height:calc(var(--spacing)*5)}.h-6{height:calc(var(--spacing)*6)}.h-7{height:calc(var(--spacing)*7)}.h-8{height:calc(var(--spacing)*8)}.h-10{height:calc(var(--spacing)*10)}.h-12{height:calc(var(--spacing)*12)}.h-40{height:calc(var(--spacing)*40)}.h-full{height:100%}.max-h-64{max-height:calc(var(--spacing)*64)}.max-h-96{max-height:calc(var(--spacing)*96)}.w-1\\.5{width:calc(var(--spacing)*1.5)}.w-3{width:calc(var(--spacing)*3)}.w-3\\.5{width:calc(var(--spacing)*3.5)}.w-5{width:calc(var(--spacing)*5)}.w-6{width:calc(var(--spacing)*6)}.w-7{width:calc(var(--spacing)*7)}.w-8{width:calc(var(--spacing)*8)}.w-10{width:calc(var(--spacing)*10)}.w-12{width:calc(var(--spacing)*12)}.w-40{width:calc(var(--spacing)*40)}.w-auto{width:auto}.w-full{width:100%}.max-w-2xl{max-width:var(--container-2xl)}.max-w-\\[240px\\]{max-width:240px}.max-w-md{max-width:var(--container-md)}.max-w-xs{max-width:var(--container-xs)}.min-w-0{min-width:calc(var(--spacing)*0)}.min-w-\\[160px\\]{min-width:160px}.min-w-\\[200px\\]{min-width:200px}.flex-1{flex:1}.shrink-0{flex-shrink:0}.table-fixed{table-layout:fixed}.border-collapse{border-collapse:collapse}.-translate-y-\\[2px\\]{--tw-translate-y:calc(2px*-1);translate:var(--tw-translate-x)var(--tw-translate-y)}.rotate-180{rotate:180deg}.transform{transform:var(--tw-rotate-x,)var(--tw-rotate-y,)var(--tw-rotate-z,)var(--tw-skew-x,)var(--tw-skew-y,)}.animate-pulse{animation:var(--animate-pulse)}.cursor-grab{cursor:grab}.cursor-grabbing{cursor:grabbing}.cursor-nwse-resize{cursor:nwse-resize}.cursor-pointer{cursor:pointer}.touch-none{touch-action:none}.resize{resize:both}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.items-start{align-items:flex-start}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.gap-1{gap:calc(var(--spacing)*1)}.gap-1\\.5{gap:calc(var(--spacing)*1.5)}.gap-2{gap:calc(var(--spacing)*2)}.gap-3{gap:calc(var(--spacing)*3)}.gap-4{gap:calc(var(--spacing)*4)}:where(.space-y-1>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*1)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*1)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-2>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*2)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*2)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*3)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*3)*calc(1 - var(--tw-space-y-reverse)))}:where(.divide-y>:not(:last-child)){--tw-divide-y-reverse:0;border-bottom-style:var(--tw-border-style);border-top-style:var(--tw-border-style);border-top-width:calc(1px*var(--tw-divide-y-reverse));border-bottom-width:calc(1px*calc(1 - var(--tw-divide-y-reverse)))}:where(.divide-gray-200>:not(:last-child)){border-color:var(--color-gray-200)}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-x-hidden{overflow-x:hidden}.overflow-y-auto{overflow-y:auto}.rounded{border-radius:.25rem}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius-lg)}.rounded-md{border-radius:var(--radius-md)}.rounded-sm{border-radius:var(--radius-sm)}.rounded-xl{border-radius:var(--radius-xl)}.border{border-style:var(--tw-border-style);border-width:1px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-r{border-right-style:var(--tw-border-style);border-right-width:1px}.border-b{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.border-l{border-left-style:var(--tw-border-style);border-left-width:1px}.border-dashed{--tw-border-style:dashed;border-style:dashed}.border-amber-200{border-color:var(--color-amber-200)}.border-blue-200{border-color:var(--color-blue-200)}.border-emerald-200{border-color:var(--color-emerald-200)}.border-fuchsia-200{border-color:var(--color-fuchsia-200)}.border-gray-100{border-color:var(--color-gray-100)}.border-gray-200{border-color:var(--color-gray-200)}.border-purple-200{border-color:var(--color-purple-200)}.border-rose-200{border-color:var(--color-rose-200)}.border-sky-200{border-color:var(--color-sky-200)}.border-slate-200{border-color:var(--color-slate-200)}.border-violet-200{border-color:var(--color-violet-200)}.border-white\\/20{border-color:#fff3}@supports (color:color-mix(in lab, red, red)){.border-white\\/20{border-color:color-mix(in oklab,var(--color-white)20%,transparent)}}.bg-amber-50{background-color:var(--color-amber-50)}.bg-amber-100{background-color:var(--color-amber-100)}.bg-blue-50{background-color:var(--color-blue-50)}.bg-blue-100{background-color:var(--color-blue-100)}.bg-emerald-50{background-color:var(--color-emerald-50)}.bg-emerald-500{background-color:var(--color-emerald-500)}.bg-fuchsia-50{background-color:var(--color-fuchsia-50)}.bg-gray-50{background-color:var(--color-gray-50)}.bg-gray-50\\/50{background-color:#f9fafb80}@supports (color:color-mix(in lab, red, red)){.bg-gray-50\\/50{background-color:color-mix(in oklab,var(--color-gray-50)50%,transparent)}}.bg-gray-100{background-color:var(--color-gray-100)}.bg-gray-400{background-color:var(--color-gray-400)}.bg-gray-900{background-color:var(--color-gray-900)}.bg-green-100{background-color:var(--color-green-100)}.bg-purple-50{background-color:var(--color-purple-50)}.bg-rose-50{background-color:var(--color-rose-50)}.bg-rose-500{background-color:var(--color-rose-500)}.bg-rose-600{background-color:var(--color-rose-600)}.bg-sky-50{background-color:var(--color-sky-50)}.bg-slate-900{background-color:var(--color-slate-900)}.bg-slate-950\\/95{background-color:#020618f2}@supports (color:color-mix(in lab, red, red)){.bg-slate-950\\/95{background-color:color-mix(in oklab,var(--color-slate-950)95%,transparent)}}.bg-violet-50{background-color:var(--color-violet-50)}.bg-white{background-color:var(--color-white)}.bg-white\\/60{background-color:#fff9}@supports (color:color-mix(in lab, red, red)){.bg-white\\/60{background-color:color-mix(in oklab,var(--color-white)60%,transparent)}}.bg-white\\/95{background-color:#fffffff2}@supports (color:color-mix(in lab, red, red)){.bg-white\\/95{background-color:color-mix(in oklab,var(--color-white)95%,transparent)}}.p-2{padding:calc(var(--spacing)*2)}.p-3{padding:calc(var(--spacing)*3)}.p-4{padding:calc(var(--spacing)*4)}.px-1{padding-inline:calc(var(--spacing)*1)}.px-1\\.5{padding-inline:calc(var(--spacing)*1.5)}.px-2{padding-inline:calc(var(--spacing)*2)}.px-3{padding-inline:calc(var(--spacing)*3)}.px-4{padding-inline:calc(var(--spacing)*4)}.py-0\\.5{padding-block:calc(var(--spacing)*.5)}.py-1{padding-block:calc(var(--spacing)*1)}.py-1\\.5{padding-block:calc(var(--spacing)*1.5)}.py-2{padding-block:calc(var(--spacing)*2)}.py-2\\.5{padding-block:calc(var(--spacing)*2.5)}.py-3{padding-block:calc(var(--spacing)*3)}.py-4{padding-block:calc(var(--spacing)*4)}.py-8{padding-block:calc(var(--spacing)*8)}.text-center{text-align:center}.text-left{text-align:left}.align-middle{vertical-align:middle}.align-top{vertical-align:top}.font-mono{font-family:var(--font-mono)}.text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.text-\\[9px\\]{font-size:9px}.text-\\[10px\\]{font-size:10px}.text-\\[11px\\]{font-size:11px}.leading-relaxed{--tw-leading:var(--leading-relaxed);line-height:var(--leading-relaxed)}.leading-snug{--tw-leading:var(--leading-snug);line-height:var(--leading-snug)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.break-words{overflow-wrap:break-word}.whitespace-nowrap{white-space:nowrap}.whitespace-pre-wrap{white-space:pre-wrap}.text-amber-600{color:var(--color-amber-600)}.text-amber-700{color:var(--color-amber-700)}.text-amber-800{color:var(--color-amber-800)}.text-amber-900{color:var(--color-amber-900)}.text-blue-600{color:var(--color-blue-600)}.text-blue-700{color:var(--color-blue-700)}.text-blue-800{color:var(--color-blue-800)}.text-emerald-700{color:var(--color-emerald-700)}.text-fuchsia-700{color:var(--color-fuchsia-700)}.text-gray-300{color:var(--color-gray-300)}.text-gray-400{color:var(--color-gray-400)}.text-gray-500{color:var(--color-gray-500)}.text-gray-600{color:var(--color-gray-600)}.text-gray-700{color:var(--color-gray-700)}.text-gray-800{color:var(--color-gray-800)}.text-gray-900{color:var(--color-gray-900)}.text-green-700{color:var(--color-green-700)}.text-green-800{color:var(--color-green-800)}.text-purple-700{color:var(--color-purple-700)}.text-rose-700{color:var(--color-rose-700)}.text-rose-800{color:var(--color-rose-800)}.text-rose-900{color:var(--color-rose-900)}.text-sky-700{color:var(--color-sky-700)}.text-slate-800{color:var(--color-slate-800)}.text-slate-900{color:var(--color-slate-900)}.text-violet-700{color:var(--color-violet-700)}.text-white{color:var(--color-white)}.italic{font-style:italic}.opacity-0{opacity:0}.opacity-80{opacity:.8}.shadow-\\[0_12px_30px_rgba\\(15\\,23\\,42\\,0\\.12\\)\\]{--tw-shadow:0 12px 30px var(--tw-shadow-color,#0f172a1f);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a),0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-md{--tw-shadow:0 4px 6px -1px var(--tw-shadow-color,#0000001a),0 2px 4px -2px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-sm{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring-1{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(1px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring-black\\/5{--tw-ring-color:#0000000d}@supports (color:color-mix(in lab, red, red)){.ring-black\\/5{--tw-ring-color:color-mix(in oklab,var(--color-black)5%,transparent)}}.ring-transparent{--tw-ring-color:transparent}.ring-white\\/10{--tw-ring-color:#ffffff1a}@supports (color:color-mix(in lab, red, red)){.ring-white\\/10{--tw-ring-color:color-mix(in oklab,var(--color-white)10%,transparent)}}.backdrop-blur-md{--tw-backdrop-blur:blur(var(--blur-md));-webkit-backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,)}.backdrop-blur-sm{--tw-backdrop-blur:blur(var(--blur-sm));-webkit-backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,)}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.outline-none{--tw-outline-style:none;outline-style:none}.select-none{-webkit-user-select:none;user-select:none}@media (hover:hover){.group-hover\\:opacity-100:is(:where(.group):hover *){opacity:1}.hover\\:scale-105:hover{--tw-scale-x:105%;--tw-scale-y:105%;--tw-scale-z:105%;scale:var(--tw-scale-x)var(--tw-scale-y)}.hover\\:border-gray-300:hover{border-color:var(--color-gray-300)}.hover\\:border-white\\/30:hover{border-color:#ffffff4d}@supports (color:color-mix(in lab, red, red)){.hover\\:border-white\\/30:hover{border-color:color-mix(in oklab,var(--color-white)30%,transparent)}}.hover\\:bg-blue-50\\/50:hover{background-color:#eff6ff80}@supports (color:color-mix(in lab, red, red)){.hover\\:bg-blue-50\\/50:hover{background-color:color-mix(in oklab,var(--color-blue-50)50%,transparent)}}.hover\\:bg-gray-50:hover{background-color:var(--color-gray-50)}.hover\\:bg-gray-100:hover{background-color:var(--color-gray-100)}.hover\\:bg-gray-200:hover{background-color:var(--color-gray-200)}.hover\\:bg-gray-800:hover{background-color:var(--color-gray-800)}.hover\\:bg-slate-900\\/95:hover{background-color:#0f172bf2}@supports (color:color-mix(in lab, red, red)){.hover\\:bg-slate-900\\/95:hover{background-color:color-mix(in oklab,var(--color-slate-900)95%,transparent)}}.hover\\:text-gray-600:hover{color:var(--color-gray-600)}.hover\\:text-gray-900:hover{color:var(--color-gray-900)}}.focus\\:border-gray-300:focus{border-color:var(--color-gray-300)}.focus\\:bg-gray-50:focus{background-color:var(--color-gray-50)}.focus\\:ring-2:focus{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(2px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.focus\\:ring-gray-200:focus{--tw-ring-color:var(--color-gray-200)}.focus\\:outline-none:focus{--tw-outline-style:none;outline-style:none}.focus-visible\\:outline:focus-visible{outline-style:var(--tw-outline-style);outline-width:1px}.focus-visible\\:outline-2:focus-visible{outline-style:var(--tw-outline-style);outline-width:2px}.focus-visible\\:outline-offset-2:focus-visible{outline-offset:2px}.focus-visible\\:outline-gray-300:focus-visible{outline-color:var(--color-gray-300)}.focus-visible\\:outline-gray-400:focus-visible{outline-color:var(--color-gray-400)}.focus-visible\\:outline-rose-500:focus-visible{outline-color:var(--color-rose-500)}.disabled\\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\\:opacity-50:disabled{opacity:.5}@media (min-width:48rem){.md\\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}}.\\[\\&\\>svg\\]\\:\\!h-8>svg{height:calc(var(--spacing)*8)!important}.\\[\\&\\>svg\\]\\:\\!w-8>svg{width:calc(var(--spacing)*8)!important}.sr-only{clip:rect(0,0,0,0);white-space:nowrap;border-width:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}}@property --tw-translate-x{syntax:\"*\";inherits:false;initial-value:0}@property --tw-translate-y{syntax:\"*\";inherits:false;initial-value:0}@property --tw-translate-z{syntax:\"*\";inherits:false;initial-value:0}@property --tw-rotate-x{syntax:\"*\";inherits:false}@property --tw-rotate-y{syntax:\"*\";inherits:false}@property --tw-rotate-z{syntax:\"*\";inherits:false}@property --tw-skew-x{syntax:\"*\";inherits:false}@property --tw-skew-y{syntax:\"*\";inherits:false}@property --tw-space-y-reverse{syntax:\"*\";inherits:false;initial-value:0}@property --tw-divide-y-reverse{syntax:\"*\";inherits:false;initial-value:0}@property --tw-border-style{syntax:\"*\";inherits:false;initial-value:solid}@property --tw-leading{syntax:\"*\";inherits:false}@property --tw-font-weight{syntax:\"*\";inherits:false}@property --tw-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:\"*\";inherits:false}@property --tw-shadow-alpha{syntax:\"\";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:\"*\";inherits:false}@property --tw-inset-shadow-alpha{syntax:\"\";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:\"*\";inherits:false}@property --tw-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:\"*\";inherits:false}@property --tw-inset-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:\"*\";inherits:false}@property --tw-ring-offset-width{syntax:\"\";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:\"*\";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-backdrop-blur{syntax:\"*\";inherits:false}@property --tw-backdrop-brightness{syntax:\"*\";inherits:false}@property --tw-backdrop-contrast{syntax:\"*\";inherits:false}@property --tw-backdrop-grayscale{syntax:\"*\";inherits:false}@property --tw-backdrop-hue-rotate{syntax:\"*\";inherits:false}@property --tw-backdrop-invert{syntax:\"*\";inherits:false}@property --tw-backdrop-opacity{syntax:\"*\";inherits:false}@property --tw-backdrop-saturate{syntax:\"*\";inherits:false}@property --tw-backdrop-sepia{syntax:\"*\";inherits:false}@property --tw-scale-x{syntax:\"*\";inherits:false;initial-value:1}@property --tw-scale-y{syntax:\"*\";inherits:false;initial-value:1}@property --tw-scale-z{syntax:\"*\";inherits:false;initial-value:1}@property --tw-outline-style{syntax:\"*\";inherits:false;initial-value:solid}@keyframes pulse{50%{opacity:.5}}"; //#endregion //#region src/assets/inspector-logo.svg var inspector_logo_default = "data:image/svg+xml,%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A"; //#endregion //#region src/assets/inspector-logo-icon.svg var inspector_logo_icon_default = "data:image/svg+xml,%0A%0A %0A %0A %0A %0A %0A%0A"; //#endregion //#region src/lib/context-helpers.ts function updateSizeFromElement(state, element, fallback) { const rect = element.getBoundingClientRect(); state.size = { width: rect.width || fallback.width, height: rect.height || fallback.height }; } function clampSize(size, viewport, edgeMargin, minWidth, minHeight) { const maxWidth = Math.max(minWidth, viewport.width - edgeMargin * 2); const maxHeight = Math.max(minHeight, viewport.height - edgeMargin * 2); return { width: clamp(size.width, minWidth, maxWidth), height: clamp(size.height, minHeight, maxHeight) }; } function constrainToViewport(state, position, viewport, edgeMargin) { const maxX = Math.max(edgeMargin, viewport.width - state.size.width - edgeMargin); const maxY = Math.max(edgeMargin, viewport.height - state.size.height - edgeMargin); return { x: clamp(position.x, edgeMargin, maxX), y: clamp(position.y, edgeMargin, maxY) }; } function keepPositionWithinViewport(state, viewport, edgeMargin) { state.position = constrainToViewport(state, state.position, viewport, edgeMargin); } function centerContext(state, viewport, edgeMargin) { state.position = constrainToViewport(state, { x: Math.round((viewport.width - state.size.width) / 2), y: Math.round((viewport.height - state.size.height) / 2) }, viewport, edgeMargin); updateAnchorFromPosition(state, viewport, edgeMargin); return state.position; } function updateAnchorFromPosition(state, viewport, edgeMargin) { const centerX = state.position.x + state.size.width / 2; const centerY = state.position.y + state.size.height / 2; const horizontal = centerX < viewport.width / 2 ? "left" : "right"; const vertical = centerY < viewport.height / 2 ? "top" : "bottom"; state.anchor = { horizontal, vertical }; const maxHorizontalOffset = Math.max(edgeMargin, viewport.width - state.size.width - edgeMargin); const maxVerticalOffset = Math.max(edgeMargin, viewport.height - state.size.height - edgeMargin); state.anchorOffset = { x: horizontal === "left" ? clamp(state.position.x, edgeMargin, maxHorizontalOffset) : clamp(viewport.width - state.position.x - state.size.width, edgeMargin, maxHorizontalOffset), y: vertical === "top" ? clamp(state.position.y, edgeMargin, maxVerticalOffset) : clamp(viewport.height - state.position.y - state.size.height, edgeMargin, maxVerticalOffset) }; } function applyAnchorPosition(state, viewport, edgeMargin) { const maxHorizontalOffset = Math.max(edgeMargin, viewport.width - state.size.width - edgeMargin); const maxVerticalOffset = Math.max(edgeMargin, viewport.height - state.size.height - edgeMargin); const horizontalOffset = clamp(state.anchorOffset.x, edgeMargin, maxHorizontalOffset); const verticalOffset = clamp(state.anchorOffset.y, edgeMargin, maxVerticalOffset); const x = state.anchor.horizontal === "left" ? horizontalOffset : viewport.width - state.size.width - horizontalOffset; const y = state.anchor.vertical === "top" ? verticalOffset : viewport.height - state.size.height - verticalOffset; state.anchorOffset = { x: horizontalOffset, y: verticalOffset }; state.position = constrainToViewport(state, { x, y }, viewport, edgeMargin); return state.position; } function clamp(value, min, max) { return Math.min(Math.max(min, value), max); } //#endregion //#region src/lib/persistence.ts function loadInspectorState(storageKey) { if (typeof window === "undefined") return null; const raw = window.localStorage.getItem(storageKey); if (raw) try { const parsed = JSON.parse(raw); if (parsed && typeof parsed === "object") return parsed; } catch (_unused) {} if (typeof document !== "undefined") { const prefix = `${storageKey}=`; const entry = document.cookie.split("; ").find((cookie) => cookie.startsWith(prefix)); if (entry) { const legacyRaw = entry.substring(prefix.length); try { const parsed = JSON.parse(decodeURIComponent(legacyRaw)); if (parsed && typeof parsed === "object") return parsed; } catch (_unused2) { return null; } } } return null; } function saveInspectorState(storageKey, state) { if (typeof window === "undefined") return; try { window.localStorage.setItem(storageKey, JSON.stringify(state)); } catch (error) { console.warn("Failed to persist inspector state", error); } } function isValidAnchor(value) { if (!value || typeof value !== "object") return false; const candidate = value; return (candidate.horizontal === "left" || candidate.horizontal === "right") && (candidate.vertical === "top" || candidate.vertical === "bottom"); } function isValidPosition(value) { if (!value || typeof value !== "object") return false; const candidate = value; return isFiniteNumber(candidate.x) && isFiniteNumber(candidate.y); } function isValidSize(value) { if (!value || typeof value !== "object") return false; const candidate = value; return isFiniteNumber(candidate.width) && isFiniteNumber(candidate.height); } function isFiniteNumber(value) { return typeof value === "number" && Number.isFinite(value); } function isValidDockMode(value) { return value === "floating" || value === "docked-left"; } //#endregion //#region src/index.ts const WEB_INSPECTOR_TAG = "cpk-web-inspector"; const EDGE_MARGIN = 16; const DRAG_THRESHOLD = 6; const MIN_WINDOW_WIDTH = 600; const MIN_WINDOW_WIDTH_DOCKED_LEFT = 420; const MIN_WINDOW_HEIGHT = 200; const INSPECTOR_STORAGE_KEY = "cpk:inspector:state"; const ANNOUNCEMENT_STORAGE_KEY = "cpk:inspector:announcements"; const ANNOUNCEMENT_URL = "https://cdn.copilotkit.ai/announcements.json"; const DEFAULT_BUTTON_SIZE = { width: 48, height: 48 }; const DEFAULT_WINDOW_SIZE = { width: 840, height: 560 }; const DOCKED_LEFT_WIDTH = 500; const MAX_AGENT_EVENTS = 200; const MAX_TOTAL_EVENTS = 500; const AGENT_EVENT_TYPES = [ "RUN_STARTED", "RUN_FINISHED", "RUN_ERROR", "TEXT_MESSAGE_START", "TEXT_MESSAGE_CONTENT", "TEXT_MESSAGE_END", "TOOL_CALL_START", "TOOL_CALL_ARGS", "TOOL_CALL_END", "TOOL_CALL_RESULT", "STATE_SNAPSHOT", "STATE_DELTA", "MESSAGES_SNAPSHOT", "RAW_EVENT", "CUSTOM_EVENT", "REASONING_START", "REASONING_MESSAGE_START", "REASONING_MESSAGE_CONTENT", "REASONING_MESSAGE_END", "REASONING_END", "REASONING_ENCRYPTED_VALUE" ]; var WebInspectorElement = class extends lit.LitElement { constructor(..._args) { super(..._args); this._core = null; this.coreSubscriber = null; this.coreUnsubscribe = null; this.runtimeStatus = null; this.coreProperties = {}; this.lastCoreError = null; this.agentSubscriptions = /* @__PURE__ */ new Map(); this.agentEvents = /* @__PURE__ */ new Map(); this.agentMessages = /* @__PURE__ */ new Map(); this.agentStates = /* @__PURE__ */ new Map(); this.flattenedEvents = []; this.eventCounter = 0; this.contextStore = {}; this.pointerId = null; this.dragStart = null; this.dragOffset = { x: 0, y: 0 }; this.isDragging = false; this.pointerContext = null; this.isOpen = false; this.draggedDuringInteraction = false; this.ignoreNextButtonClick = false; this.selectedMenu = "ag-ui-events"; this.contextMenuOpen = false; this.dockMode = "floating"; this.previousBodyMargins = null; this.transitionTimeoutId = null; this.pendingSelectedContext = null; this.autoAttachCore = true; this.attemptedAutoAttach = false; this.cachedTools = []; this.toolSignature = ""; this.eventFilterText = ""; this.eventTypeFilter = "all"; this.announcementMarkdown = null; this.announcementHtml = null; this.announcementTimestamp = null; this.announcementPreviewText = null; this.hasUnseenAnnouncement = false; this.announcementLoaded = false; this.announcementLoadError = null; this.announcementPromise = null; this.showAnnouncementPreview = true; this.contextState = { button: { position: { x: EDGE_MARGIN, y: EDGE_MARGIN }, size: { ...DEFAULT_BUTTON_SIZE }, anchor: { horizontal: "right", vertical: "top" }, anchorOffset: { x: EDGE_MARGIN, y: EDGE_MARGIN } }, window: { position: { x: EDGE_MARGIN, y: EDGE_MARGIN }, size: { ...DEFAULT_WINDOW_SIZE }, anchor: { horizontal: "right", vertical: "top" }, anchorOffset: { x: EDGE_MARGIN, y: EDGE_MARGIN } } }; this.hasCustomPosition = { button: false, window: false }; this.resizePointerId = null; this.resizeStart = null; this.resizeInitialSize = null; this.isResizing = false; this.menuItems = [ { key: "ag-ui-events", label: "AG-UI Events", icon: "Zap" }, { key: "agents", label: "Agent", icon: "Bot" }, { key: "frontend-tools", label: "Frontend Tools", icon: "Hammer" }, { key: "agent-context", label: "Context", icon: "FileText" } ]; this.handlePointerDown = (event) => { var _target$setPointerCap; if (this.dockMode !== "floating" && this.isOpen) return; const target = event.currentTarget; const context = (target === null || target === void 0 ? void 0 : target.dataset.dragContext) === "window" ? "window" : "button"; const eventTarget = event.target; if (context === "window" && (eventTarget === null || eventTarget === void 0 ? void 0 : eventTarget.closest("button"))) return; this.pointerContext = context; this.measureContext(context); event.preventDefault(); this.pointerId = event.pointerId; this.dragStart = { x: event.clientX, y: event.clientY }; const state = this.contextState[context]; this.dragOffset = { x: event.clientX - state.position.x, y: event.clientY - state.position.y }; this.isDragging = false; this.draggedDuringInteraction = false; this.ignoreNextButtonClick = false; target === null || target === void 0 || (_target$setPointerCap = target.setPointerCapture) === null || _target$setPointerCap === void 0 || _target$setPointerCap.call(target, this.pointerId); }; this.handlePointerMove = (event) => { if (this.pointerId !== event.pointerId || !this.dragStart || !this.pointerContext) return; const distance = Math.hypot(event.clientX - this.dragStart.x, event.clientY - this.dragStart.y); if (!this.isDragging && distance < DRAG_THRESHOLD) return; event.preventDefault(); this.setDragging(true); this.draggedDuringInteraction = true; const desired = { x: event.clientX - this.dragOffset.x, y: event.clientY - this.dragOffset.y }; const constrained = this.constrainToViewport(desired, this.pointerContext); this.contextState[this.pointerContext].position = constrained; this.updateHostTransform(this.pointerContext); }; this.handlePointerUp = (event) => { var _this$pointerContext; if (this.pointerId !== event.pointerId) return; const target = event.currentTarget; if (target === null || target === void 0 ? void 0 : target.hasPointerCapture(this.pointerId)) target.releasePointerCapture(this.pointerId); const context = (_this$pointerContext = this.pointerContext) !== null && _this$pointerContext !== void 0 ? _this$pointerContext : this.activeContext; if (this.isDragging && this.pointerContext) { event.preventDefault(); this.setDragging(false); if (this.pointerContext === "window") { this.updateAnchorFromPosition(this.pointerContext); this.hasCustomPosition.window = true; this.applyAnchorPosition(this.pointerContext); } else if (this.pointerContext === "button") { this.snapButtonToCorner(); this.hasCustomPosition.button = true; if (this.draggedDuringInteraction) this.ignoreNextButtonClick = true; } } else if (context === "button" && !this.isOpen && !this.draggedDuringInteraction) this.openInspector(); this.resetPointerTracking(); }; this.handlePointerCancel = (event) => { if (this.pointerId !== event.pointerId) return; const target = event.currentTarget; if (target === null || target === void 0 ? void 0 : target.hasPointerCapture(this.pointerId)) target.releasePointerCapture(this.pointerId); this.resetPointerTracking(); }; this.handleButtonClick = (event) => { if (this.isDragging) { event.preventDefault(); return; } if (this.ignoreNextButtonClick) { event.preventDefault(); this.ignoreNextButtonClick = false; return; } if (!this.isOpen) { event.preventDefault(); this.openInspector(); } }; this.handleClosePointerDown = (event) => { event.stopPropagation(); event.preventDefault(); }; this.handleCloseClick = () => { this.closeInspector(); }; this.handleResizePointerDown = (event) => { var _target$setPointerCap2; event.stopPropagation(); event.preventDefault(); this.hasCustomPosition.window = true; this.isResizing = true; this.resizePointerId = event.pointerId; this.resizeStart = { x: event.clientX, y: event.clientY }; this.resizeInitialSize = { ...this.contextState.window.size }; if (document.body && this.dockMode !== "floating") document.body.style.transition = ""; const target = event.currentTarget; target === null || target === void 0 || (_target$setPointerCap2 = target.setPointerCapture) === null || _target$setPointerCap2 === void 0 || _target$setPointerCap2.call(target, event.pointerId); }; this.handleResizePointerMove = (event) => { if (!this.isResizing || this.resizePointerId !== event.pointerId || !this.resizeStart || !this.resizeInitialSize) return; event.preventDefault(); const deltaX = event.clientX - this.resizeStart.x; const deltaY = event.clientY - this.resizeStart.y; const state = this.contextState.window; if (this.dockMode === "docked-left") { state.size = this.clampWindowSize({ width: this.resizeInitialSize.width + deltaX, height: state.size.height }); if (document.body) document.body.style.marginLeft = `${state.size.width}px`; } else { state.size = this.clampWindowSize({ width: this.resizeInitialSize.width + deltaX, height: this.resizeInitialSize.height + deltaY }); this.keepPositionWithinViewport("window"); this.updateAnchorFromPosition("window"); } this.requestUpdate(); this.updateHostTransform("window"); }; this.handleResizePointerUp = (event) => { if (this.resizePointerId !== event.pointerId) return; const target = event.currentTarget; if (target === null || target === void 0 ? void 0 : target.hasPointerCapture(this.resizePointerId)) target.releasePointerCapture(this.resizePointerId); if (this.dockMode === "floating") { this.updateAnchorFromPosition("window"); this.applyAnchorPosition("window"); } this.persistState(); this.resetResizeTracking(); }; this.handleResizePointerCancel = (event) => { if (this.resizePointerId !== event.pointerId) return; const target = event.currentTarget; if (target === null || target === void 0 ? void 0 : target.hasPointerCapture(this.resizePointerId)) target.releasePointerCapture(this.resizePointerId); if (this.dockMode === "floating") { this.updateAnchorFromPosition("window"); this.applyAnchorPosition("window"); } this.persistState(); this.resetResizeTracking(); }; this.handleResize = () => { this.measureContext("button"); this.applyAnchorPosition("button"); this.measureContext("window"); if (this.hasCustomPosition.window) this.applyAnchorPosition("window"); else this.centerContext("window"); this.updateHostTransform(); }; this.contextOptions = [{ key: "all-agents", label: "All Agents" }]; this.selectedContext = "all-agents"; this.expandedRows = /* @__PURE__ */ new Set(); this.copiedEvents = /* @__PURE__ */ new Set(); this.expandedTools = /* @__PURE__ */ new Set(); this.expandedContextItems = /* @__PURE__ */ new Set(); this.copiedContextItems = /* @__PURE__ */ new Set(); this.handleClearEvents = () => { if (this.selectedContext === "all-agents") { this.agentEvents.clear(); this.flattenedEvents = []; } else { this.agentEvents.delete(this.selectedContext); this.flattenedEvents = this.flattenedEvents.filter((event) => event.agentId !== this.selectedContext); } this.expandedRows.clear(); this.copiedEvents.clear(); this.requestUpdate(); }; this.handleGlobalPointerDown = (event) => { if (!this.contextMenuOpen) return; if (!event.composedPath().some((node) => { var _node$dataset; return node instanceof HTMLElement && ((_node$dataset = node.dataset) === null || _node$dataset === void 0 ? void 0 : _node$dataset.contextDropdownRoot) === "true"; })) { this.contextMenuOpen = false; this.requestUpdate(); } }; this.handleDismissAnnouncement = () => { this.markAnnouncementSeen(); }; } get core() { return this._core; } set core(value) { const oldValue = this._core; if (oldValue === value) return; this.detachFromCore(); this._core = value !== null && value !== void 0 ? value : null; this.requestUpdate("core", oldValue); if (this._core) this.attachToCore(this._core); } attachToCore(core) { this.runtimeStatus = core.runtimeConnectionStatus; this.coreProperties = core.properties; this.lastCoreError = null; this.coreSubscriber = { onRuntimeConnectionStatusChanged: ({ status }) => { this.runtimeStatus = status; this.requestUpdate(); }, onPropertiesChanged: ({ properties }) => { this.coreProperties = properties; this.requestUpdate(); }, onError: ({ code, error }) => { this.lastCoreError = { code, message: error.message }; this.requestUpdate(); }, onAgentsChanged: ({ agents }) => { this.processAgentsChanged(agents); }, onContextChanged: ({ context }) => { this.contextStore = this.normalizeContextStore(context); this.requestUpdate(); } }; this.coreUnsubscribe = core.subscribe(this.coreSubscriber).unsubscribe; this.processAgentsChanged(core.agents); if (core.context) this.contextStore = this.normalizeContextStore(core.context); } detachFromCore() { if (this.coreUnsubscribe) { this.coreUnsubscribe(); this.coreUnsubscribe = null; } this.coreSubscriber = null; this.runtimeStatus = null; this.lastCoreError = null; this.coreProperties = {}; this.cachedTools = []; this.toolSignature = ""; this.teardownAgentSubscriptions(); } teardownAgentSubscriptions() { for (const unsubscribe of this.agentSubscriptions.values()) unsubscribe(); this.agentSubscriptions.clear(); this.agentEvents.clear(); this.agentMessages.clear(); this.agentStates.clear(); this.flattenedEvents = []; this.eventCounter = 0; } processAgentsChanged(agents) { const seenAgentIds = /* @__PURE__ */ new Set(); for (const agent of Object.values(agents)) { if (!(agent === null || agent === void 0 ? void 0 : agent.agentId)) continue; seenAgentIds.add(agent.agentId); this.subscribeToAgent(agent); } for (const agentId of Array.from(this.agentSubscriptions.keys())) if (!seenAgentIds.has(agentId)) { this.unsubscribeFromAgent(agentId); this.agentEvents.delete(agentId); this.agentMessages.delete(agentId); this.agentStates.delete(agentId); } this.updateContextOptions(seenAgentIds); this.refreshToolsSnapshot(); this.requestUpdate(); } refreshToolsSnapshot() { if (!this._core) { if (this.cachedTools.length > 0) { this.cachedTools = []; this.toolSignature = ""; this.requestUpdate(); } return; } const tools = this.extractToolsFromAgents(); const signature = JSON.stringify(tools.map((tool) => ({ agentId: tool.agentId, name: tool.name, type: tool.type, hasDescription: Boolean(tool.description), hasParameters: Boolean(tool.parameters) }))); if (signature !== this.toolSignature) { this.toolSignature = signature; this.cachedTools = tools; this.requestUpdate(); } } tryAutoAttachCore() { var _globalWindow$copilot; if (this.attemptedAutoAttach || this._core || !this.autoAttachCore || typeof window === "undefined") return; this.attemptedAutoAttach = true; const globalWindow = window; const foundCore = [ globalWindow.__COPILOTKIT_CORE__, (_globalWindow$copilot = globalWindow.copilotkit) === null || _globalWindow$copilot === void 0 ? void 0 : _globalWindow$copilot.core, globalWindow.copilotkitCore ].find((candidate) => !!candidate && typeof candidate === "object"); if (foundCore) this.core = foundCore; } subscribeToAgent(agent) { if (!agent.agentId) return; const agentId = agent.agentId; this.unsubscribeFromAgent(agentId); const { unsubscribe } = agent.subscribe({ onRunStartedEvent: ({ event }) => { this.recordAgentEvent(agentId, "RUN_STARTED", event); }, onRunFinishedEvent: ({ event, result }) => { this.recordAgentEvent(agentId, "RUN_FINISHED", { event, result }); }, onRunErrorEvent: ({ event }) => { this.recordAgentEvent(agentId, "RUN_ERROR", event); }, onTextMessageStartEvent: ({ event }) => { this.recordAgentEvent(agentId, "TEXT_MESSAGE_START", event); }, onTextMessageContentEvent: ({ event, textMessageBuffer }) => { this.recordAgentEvent(agentId, "TEXT_MESSAGE_CONTENT", { event, textMessageBuffer }); }, onTextMessageEndEvent: ({ event, textMessageBuffer }) => { this.recordAgentEvent(agentId, "TEXT_MESSAGE_END", { event, textMessageBuffer }); }, onToolCallStartEvent: ({ event }) => { this.recordAgentEvent(agentId, "TOOL_CALL_START", event); }, onToolCallArgsEvent: ({ event, toolCallBuffer, toolCallName, partialToolCallArgs }) => { this.recordAgentEvent(agentId, "TOOL_CALL_ARGS", { event, toolCallBuffer, toolCallName, partialToolCallArgs }); }, onToolCallEndEvent: ({ event, toolCallArgs, toolCallName }) => { this.recordAgentEvent(agentId, "TOOL_CALL_END", { event, toolCallArgs, toolCallName }); }, onToolCallResultEvent: ({ event }) => { this.recordAgentEvent(agentId, "TOOL_CALL_RESULT", event); }, onStateSnapshotEvent: ({ event }) => { this.recordAgentEvent(agentId, "STATE_SNAPSHOT", event); this.syncAgentState(agent); }, onStateDeltaEvent: ({ event }) => { this.recordAgentEvent(agentId, "STATE_DELTA", event); this.syncAgentState(agent); }, onMessagesSnapshotEvent: ({ event }) => { this.recordAgentEvent(agentId, "MESSAGES_SNAPSHOT", event); this.syncAgentMessages(agent); }, onMessagesChanged: () => { this.syncAgentMessages(agent); }, onRawEvent: ({ event }) => { this.recordAgentEvent(agentId, "RAW_EVENT", event); }, onCustomEvent: ({ event }) => { this.recordAgentEvent(agentId, "CUSTOM_EVENT", event); }, onReasoningStartEvent: ({ event }) => { this.recordAgentEvent(agentId, "REASONING_START", event); }, onReasoningMessageStartEvent: ({ event }) => { this.recordAgentEvent(agentId, "REASONING_MESSAGE_START", event); }, onReasoningMessageContentEvent: ({ event, reasoningMessageBuffer }) => { this.recordAgentEvent(agentId, "REASONING_MESSAGE_CONTENT", { event, reasoningMessageBuffer }); }, onReasoningMessageEndEvent: ({ event, reasoningMessageBuffer }) => { this.recordAgentEvent(agentId, "REASONING_MESSAGE_END", { event, reasoningMessageBuffer }); }, onReasoningEndEvent: ({ event }) => { this.recordAgentEvent(agentId, "REASONING_END", event); }, onReasoningEncryptedValueEvent: ({ event }) => { this.recordAgentEvent(agentId, "REASONING_ENCRYPTED_VALUE", event); } }); this.agentSubscriptions.set(agentId, unsubscribe); this.syncAgentMessages(agent); this.syncAgentState(agent); if (!this.agentEvents.has(agentId)) this.agentEvents.set(agentId, []); } unsubscribeFromAgent(agentId) { const unsubscribe = this.agentSubscriptions.get(agentId); if (unsubscribe) { unsubscribe(); this.agentSubscriptions.delete(agentId); } } recordAgentEvent(agentId, type, payload) { var _this$agentEvents$get; const eventId = `${agentId}:${++this.eventCounter}`; const normalizedPayload = this.normalizeEventPayload(type, payload); const event = { id: eventId, agentId, type, timestamp: Date.now(), payload: normalizedPayload }; const nextAgentEvents = [event, ...(_this$agentEvents$get = this.agentEvents.get(agentId)) !== null && _this$agentEvents$get !== void 0 ? _this$agentEvents$get : []].slice(0, MAX_AGENT_EVENTS); this.agentEvents.set(agentId, nextAgentEvents); this.flattenedEvents = [event, ...this.flattenedEvents].slice(0, MAX_TOTAL_EVENTS); this.refreshToolsSnapshot(); this.requestUpdate(); } syncAgentMessages(agent) { if (!(agent === null || agent === void 0 ? void 0 : agent.agentId)) return; const messages = this.normalizeAgentMessages(agent.messages); if (messages) this.agentMessages.set(agent.agentId, messages); else this.agentMessages.delete(agent.agentId); this.requestUpdate(); } syncAgentState(agent) { if (!(agent === null || agent === void 0 ? void 0 : agent.agentId)) return; const state = agent.state; if (state === void 0 || state === null) this.agentStates.delete(agent.agentId); else this.agentStates.set(agent.agentId, this.sanitizeForLogging(state)); this.requestUpdate(); } updateContextOptions(agentIds) { const nextOptions = [{ key: "all-agents", label: "All Agents" }, ...Array.from(agentIds).sort((a, b) => a.localeCompare(b)).map((id) => ({ key: id, label: id }))]; if (this.contextOptions.length !== nextOptions.length || this.contextOptions.some((option, index) => { var _nextOptions$index; return option.key !== ((_nextOptions$index = nextOptions[index]) === null || _nextOptions$index === void 0 ? void 0 : _nextOptions$index.key); })) this.contextOptions = nextOptions; const pendingContext = this.pendingSelectedContext; if (pendingContext) { if (pendingContext === "all-agents" || agentIds.has(pendingContext)) { if (this.selectedContext !== pendingContext) { this.selectedContext = pendingContext; this.expandedRows.clear(); } this.pendingSelectedContext = null; } else if (agentIds.size > 0) this.pendingSelectedContext = null; } if (!nextOptions.some((option) => option.key === this.selectedContext) && this.pendingSelectedContext === null) { let nextSelected = "all-agents"; if (agentIds.has("default")) nextSelected = "default"; else if (agentIds.size > 0) nextSelected = Array.from(agentIds).sort((a, b) => a.localeCompare(b))[0]; if (this.selectedContext !== nextSelected) { this.selectedContext = nextSelected; this.expandedRows.clear(); this.persistState(); } } } getEventsForSelectedContext() { var _this$agentEvents$get2; if (this.selectedContext === "all-agents") return this.flattenedEvents; return (_this$agentEvents$get2 = this.agentEvents.get(this.selectedContext)) !== null && _this$agentEvents$get2 !== void 0 ? _this$agentEvents$get2 : []; } filterEvents(events) { const query = this.eventFilterText.trim().toLowerCase(); return events.filter((event) => { if (this.eventTypeFilter !== "all" && event.type !== this.eventTypeFilter) return false; if (!query) return true; const payloadText = this.stringifyPayload(event.payload, false).toLowerCase(); return event.type.toLowerCase().includes(query) || event.agentId.toLowerCase().includes(query) || payloadText.includes(query); }); } getLatestStateForAgent(agentId) { var _this$agentEvents$get3; if (this.agentStates.has(agentId)) { const value = this.agentStates.get(agentId); return value === void 0 ? null : value; } const stateEvent = ((_this$agentEvents$get3 = this.agentEvents.get(agentId)) !== null && _this$agentEvents$get3 !== void 0 ? _this$agentEvents$get3 : []).find((e) => e.type === "STATE_SNAPSHOT"); if (!stateEvent) return null; return stateEvent.payload; } getLatestMessagesForAgent(agentId) { const messages = this.agentMessages.get(agentId); return messages !== null && messages !== void 0 ? messages : null; } getAgentStatus(agentId) { var _this$agentEvents$get4; const events = (_this$agentEvents$get4 = this.agentEvents.get(agentId)) !== null && _this$agentEvents$get4 !== void 0 ? _this$agentEvents$get4 : []; if (events.length === 0) return "idle"; const runEvent = events.find((e) => e.type === "RUN_STARTED" || e.type === "RUN_FINISHED" || e.type === "RUN_ERROR"); if (!runEvent) return "idle"; if (runEvent.type === "RUN_ERROR") return "error"; if (runEvent.type === "RUN_STARTED") return events.find((e) => e.type === "RUN_FINISHED" && e.timestamp > runEvent.timestamp) ? "idle" : "running"; return "idle"; } getAgentStats(agentId) { var _this$agentEvents$get5, _messages$length, _events$0$timestamp, _events$; const events = (_this$agentEvents$get5 = this.agentEvents.get(agentId)) !== null && _this$agentEvents$get5 !== void 0 ? _this$agentEvents$get5 : []; const messages = this.agentMessages.get(agentId); const toolCallCount = messages ? messages.reduce((count, message) => { var _message$toolCalls$le, _message$toolCalls; return count + ((_message$toolCalls$le = (_message$toolCalls = message.toolCalls) === null || _message$toolCalls === void 0 ? void 0 : _message$toolCalls.length) !== null && _message$toolCalls$le !== void 0 ? _message$toolCalls$le : 0); }, 0) : events.filter((e) => e.type === "TOOL_CALL_END").length; const messageCount = (_messages$length = messages === null || messages === void 0 ? void 0 : messages.length) !== null && _messages$length !== void 0 ? _messages$length : 0; return { totalEvents: events.length, lastActivity: (_events$0$timestamp = (_events$ = events[0]) === null || _events$ === void 0 ? void 0 : _events$.timestamp) !== null && _events$0$timestamp !== void 0 ? _events$0$timestamp : null, messages: messageCount, toolCalls: toolCallCount, errors: events.filter((e) => e.type === "RUN_ERROR").length }; } renderToolCallDetails(toolCalls) { if (!Array.isArray(toolCalls) || toolCalls.length === 0) return lit.nothing; return lit.html`
${toolCalls.map((call, index) => { var _ref, _call$function$name, _call$function, _call$function2; const functionName = (_ref = (_call$function$name = (_call$function = call.function) === null || _call$function === void 0 ? void 0 : _call$function.name) !== null && _call$function$name !== void 0 ? _call$function$name : call.toolName) !== null && _ref !== void 0 ? _ref : "Unknown function"; const callId = typeof (call === null || call === void 0 ? void 0 : call.id) === "string" ? call.id : `tool-call-${index + 1}`; const argsString = this.formatToolCallArguments((_call$function2 = call.function) === null || _call$function2 === void 0 ? void 0 : _call$function2.arguments); return lit.html`
${functionName} ID: ${callId}
${argsString ? lit.html`
${argsString}
` : lit.nothing}
`; })}
`; } formatToolCallArguments(args) { if (args === void 0 || args === null || args === "") return null; if (typeof args === "string") try { const parsed = JSON.parse(args); return JSON.stringify(parsed, null, 2); } catch (_unused) { return args; } if (typeof args === "object") try { return JSON.stringify(args, null, 2); } catch (_unused2) { return String(args); } return String(args); } hasRenderableState(state) { if (state === null || state === void 0) return false; if (Array.isArray(state)) return state.length > 0; if (typeof state === "object") return Object.keys(state).length > 0; if (typeof state === "string") { const trimmed = state.trim(); return trimmed.length > 0 && trimmed !== "{}"; } return true; } formatStateForDisplay(state) { if (state === null || state === void 0) return ""; if (typeof state === "string") { const trimmed = state.trim(); if (trimmed.length === 0) return ""; try { const parsed = JSON.parse(trimmed); return JSON.stringify(parsed, null, 2); } catch (_unused3) { return state; } } if (typeof state === "object") try { return JSON.stringify(state, null, 2); } catch (_unused4) { return String(state); } return String(state); } getEventBadgeClasses(type) { const base = "font-mono text-[10px] font-medium inline-flex items-center rounded-sm px-1.5 py-0.5 border"; if (type.startsWith("RUN_")) return `${base} bg-blue-50 text-blue-700 border-blue-200`; if (type.startsWith("TEXT_MESSAGE")) return `${base} bg-emerald-50 text-emerald-700 border-emerald-200`; if (type.startsWith("TOOL_CALL")) return `${base} bg-amber-50 text-amber-700 border-amber-200`; if (type.startsWith("REASONING")) return `${base} bg-fuchsia-50 text-fuchsia-700 border-fuchsia-200`; if (type.startsWith("STATE")) return `${base} bg-violet-50 text-violet-700 border-violet-200`; if (type.startsWith("MESSAGES")) return `${base} bg-sky-50 text-sky-700 border-sky-200`; if (type === "RUN_ERROR") return `${base} bg-rose-50 text-rose-700 border-rose-200`; return `${base} bg-gray-100 text-gray-600 border-gray-200`; } stringifyPayload(payload, pretty) { try { var _JSON$stringify; if (payload === void 0) return pretty ? "undefined" : "undefined"; if (typeof payload === "string") return payload; return (_JSON$stringify = JSON.stringify(payload, null, pretty ? 2 : 0)) !== null && _JSON$stringify !== void 0 ? _JSON$stringify : ""; } catch (error) { console.warn("Failed to stringify inspector payload", error); return String(payload); } } extractEventFromPayload(payload) { if (payload && typeof payload === "object" && "event" in payload) return payload.event; return payload; } async copyToClipboard(text, eventId) { try { await navigator.clipboard.writeText(text); this.copiedEvents.add(eventId); this.requestUpdate(); setTimeout(() => { this.copiedEvents.delete(eventId); this.requestUpdate(); }, 2e3); } catch (err) { console.error("Failed to copy to clipboard:", err); } } connectedCallback() { super.connectedCallback(); if (typeof window !== "undefined") { window.addEventListener("resize", this.handleResize); window.addEventListener("pointerdown", this.handleGlobalPointerDown); this.hydrateStateFromStorageEarly(); this.tryAutoAttachCore(); this.ensureAnnouncementLoading(); } } disconnectedCallback() { super.disconnectedCallback(); if (typeof window !== "undefined") { window.removeEventListener("resize", this.handleResize); window.removeEventListener("pointerdown", this.handleGlobalPointerDown); } this.removeDockStyles(); this.detachFromCore(); } firstUpdated() { if (typeof window === "undefined") return; if (!this._core) this.tryAutoAttachCore(); this.measureContext("button"); this.measureContext("window"); this.contextState.button.anchor = { horizontal: "right", vertical: "top" }; this.contextState.button.anchorOffset = { x: EDGE_MARGIN, y: EDGE_MARGIN }; this.contextState.window.anchor = { horizontal: "right", vertical: "top" }; this.contextState.window.anchorOffset = { x: EDGE_MARGIN, y: EDGE_MARGIN }; this.hydrateStateFromStorage(); if (this.isOpen && this.dockMode !== "floating") this.applyDockStyles(true); this.applyAnchorPosition("button"); if (this.dockMode === "floating") if (this.hasCustomPosition.window) this.applyAnchorPosition("window"); else this.centerContext("window"); this.ensureAnnouncementLoading(); this.updateHostTransform(this.isOpen ? "window" : "button"); } render() { return this.isOpen ? this.renderWindow() : this.renderButton(); } renderButton() { return lit.html` `; } renderWindow() { const windowState = this.contextState.window; const isDocked = this.dockMode !== "floating"; const isTransitioning = this.hasAttribute("data-transitioning"); const windowStyles = isDocked ? this.getDockedWindowStyles() : { width: `${Math.round(windowState.size.width)}px`, height: `${Math.round(windowState.size.height)}px`, minWidth: `${MIN_WINDOW_WIDTH}px`, minHeight: `${MIN_WINDOW_HEIGHT}px` }; const hasContextDropdown = this.contextOptions.length > 0; const contextDropdown = hasContextDropdown ? this.renderContextDropdown() : lit.nothing; const coreStatus = this.getCoreStatusSummary(); const agentSelector = hasContextDropdown ? contextDropdown : lit.html`
${this.renderIcon("Bot")} No agents available
`; return lit.html`
${isDocked ? lit.html` ` : lit.nothing}
Inspector logo
${agentSelector}
${this.renderDockControls()}
${this.menuItems.map(({ key, label, icon }) => { const isSelected = this.selectedMenu === key; return lit.html` `; })}
${this.renderAnnouncementPanel()} ${this.renderCoreWarningBanner()} ${this.renderMainContent()}
${this.renderIcon("Activity")} ${coreStatus.label} ${coreStatus.description}
`; } hydrateStateFromStorageEarly() { if (typeof document === "undefined" || typeof window === "undefined") return; const persisted = loadInspectorState(INSPECTOR_STORAGE_KEY); if (!persisted) return; if (typeof persisted.isOpen === "boolean") this.isOpen = persisted.isOpen; if (isValidDockMode(persisted.dockMode)) this.dockMode = persisted.dockMode; if (typeof persisted.selectedMenu === "string") { const validMenu = this.menuItems.find((item) => item.key === persisted.selectedMenu); if (validMenu) this.selectedMenu = validMenu.key; } if (typeof persisted.selectedContext === "string") { this.selectedContext = persisted.selectedContext; this.pendingSelectedContext = persisted.selectedContext; } } hydrateStateFromStorage() { if (typeof document === "undefined" || typeof window === "undefined") return; const persisted = loadInspectorState(INSPECTOR_STORAGE_KEY); if (!persisted) return; const persistedButton = persisted.button; if (persistedButton) { if (isValidAnchor(persistedButton.anchor)) this.contextState.button.anchor = persistedButton.anchor; if (isValidPosition(persistedButton.anchorOffset)) this.contextState.button.anchorOffset = persistedButton.anchorOffset; if (typeof persistedButton.hasCustomPosition === "boolean") this.hasCustomPosition.button = persistedButton.hasCustomPosition; } const persistedWindow = persisted.window; if (persistedWindow) { if (isValidAnchor(persistedWindow.anchor)) this.contextState.window.anchor = persistedWindow.anchor; if (isValidPosition(persistedWindow.anchorOffset)) this.contextState.window.anchorOffset = persistedWindow.anchorOffset; if (isValidSize(persistedWindow.size)) this.contextState.window.size = this.clampWindowSize(persistedWindow.size); if (typeof persistedWindow.hasCustomPosition === "boolean") this.hasCustomPosition.window = persistedWindow.hasCustomPosition; } if (typeof persisted.selectedContext === "string") { this.selectedContext = persisted.selectedContext; this.pendingSelectedContext = persisted.selectedContext; } } get activeContext() { return this.isOpen ? "window" : "button"; } measureContext(context) { var _this$renderRoot; const selector = context === "window" ? ".inspector-window" : ".console-button"; const element = (_this$renderRoot = this.renderRoot) === null || _this$renderRoot === void 0 ? void 0 : _this$renderRoot.querySelector(selector); if (!element) return; const fallback = context === "window" ? DEFAULT_WINDOW_SIZE : DEFAULT_BUTTON_SIZE; updateSizeFromElement(this.contextState[context], element, fallback); } centerContext(context) { if (typeof window === "undefined") return; const viewport = this.getViewportSize(); centerContext(this.contextState[context], viewport, EDGE_MARGIN); if (context === this.activeContext) this.updateHostTransform(context); this.hasCustomPosition[context] = false; this.persistState(); } ensureWindowPlacement() { if (typeof window === "undefined") return; if (!this.hasCustomPosition.window) { this.centerContext("window"); return; } const viewport = this.getViewportSize(); keepPositionWithinViewport(this.contextState.window, viewport, EDGE_MARGIN); updateAnchorFromPosition(this.contextState.window, viewport, EDGE_MARGIN); this.updateHostTransform("window"); this.persistState(); } constrainToViewport(position, context) { if (typeof window === "undefined") return position; const viewport = this.getViewportSize(); return constrainToViewport(this.contextState[context], position, viewport, EDGE_MARGIN); } keepPositionWithinViewport(context) { if (typeof window === "undefined") return; const viewport = this.getViewportSize(); keepPositionWithinViewport(this.contextState[context], viewport, EDGE_MARGIN); } getViewportSize() { if (typeof window === "undefined") return { ...DEFAULT_WINDOW_SIZE }; return { width: window.innerWidth, height: window.innerHeight }; } persistState() { var _state$selectedContex; const state = { button: { anchor: this.contextState.button.anchor, anchorOffset: this.contextState.button.anchorOffset, hasCustomPosition: this.hasCustomPosition.button }, window: { anchor: this.contextState.window.anchor, anchorOffset: this.contextState.window.anchorOffset, size: { width: Math.round(this.contextState.window.size.width), height: Math.round(this.contextState.window.size.height) }, hasCustomPosition: this.hasCustomPosition.window }, isOpen: this.isOpen, dockMode: this.dockMode, selectedMenu: this.selectedMenu, selectedContext: this.selectedContext }; saveInspectorState(INSPECTOR_STORAGE_KEY, state); this.pendingSelectedContext = (_state$selectedContex = state.selectedContext) !== null && _state$selectedContex !== void 0 ? _state$selectedContex : null; } clampWindowSize(size) { const minWidth = this.dockMode === "docked-left" ? MIN_WINDOW_WIDTH_DOCKED_LEFT : MIN_WINDOW_WIDTH; if (typeof window === "undefined") return { width: Math.max(minWidth, size.width), height: Math.max(MIN_WINDOW_HEIGHT, size.height) }; return clampSize(size, this.getViewportSize(), EDGE_MARGIN, minWidth, MIN_WINDOW_HEIGHT); } setDockMode(mode) { if (this.dockMode === mode) return; this.startHostTransition(); this.removeDockStyles(); this.dockMode = mode; if (mode !== "floating") { if (mode === "docked-left") this.contextState.window.size.width = DOCKED_LEFT_WIDTH; this.applyDockStyles(); } else { this.contextState.window.size = { ...DEFAULT_WINDOW_SIZE }; this.centerContext("window"); } this.persistState(); this.requestUpdate(); this.updateHostTransform("window"); } startHostTransition(duration = 300) { this.setAttribute("data-transitioning", "true"); if (this.transitionTimeoutId !== null) clearTimeout(this.transitionTimeoutId); this.transitionTimeoutId = setTimeout(() => { this.removeAttribute("data-transitioning"); this.transitionTimeoutId = null; }, duration); } applyDockStyles(skipTransition = false) { if (typeof document === "undefined" || !document.body) return; const computedStyle = window.getComputedStyle(document.body); this.previousBodyMargins = { left: computedStyle.marginLeft, bottom: computedStyle.marginBottom }; if (!this.isResizing && !skipTransition) document.body.style.transition = "margin 300ms ease"; if (this.dockMode === "docked-left") document.body.style.marginLeft = `${this.contextState.window.size.width}px`; if (!this.isResizing && !skipTransition) setTimeout(() => { if (document.body) document.body.style.transition = ""; }, 300); } removeDockStyles() { if (typeof document === "undefined" || !document.body) return; if (!this.isResizing) document.body.style.transition = "margin 300ms ease"; if (this.previousBodyMargins) { document.body.style.marginLeft = this.previousBodyMargins.left; document.body.style.marginBottom = this.previousBodyMargins.bottom; this.previousBodyMargins = null; } else { document.body.style.marginLeft = ""; document.body.style.marginBottom = ""; } setTimeout(() => { if (document.body) document.body.style.transition = ""; }, 300); } updateHostTransform(context = this.activeContext) { if (context !== this.activeContext) return; if (this.isOpen && this.dockMode === "docked-left") this.style.transform = `translate3d(0, 0, 0)`; else { const { position } = this.contextState[context]; this.style.transform = `translate3d(${position.x}px, ${position.y}px, 0)`; } } setDragging(value) { if (this.isDragging !== value) { this.isDragging = value; this.requestUpdate(); } } updateAnchorFromPosition(context) { if (typeof window === "undefined") return; const viewport = this.getViewportSize(); updateAnchorFromPosition(this.contextState[context], viewport, EDGE_MARGIN); } snapButtonToCorner() { if (typeof window === "undefined") return; const viewport = this.getViewportSize(); const state = this.contextState.button; const centerX = state.position.x + state.size.width / 2; const centerY = state.position.y + state.size.height / 2; state.anchor = { horizontal: centerX < viewport.width / 2 ? "left" : "right", vertical: centerY < viewport.height / 2 ? "top" : "bottom" }; state.anchorOffset = { x: EDGE_MARGIN, y: EDGE_MARGIN }; this.startHostTransition(); this.applyAnchorPosition("button"); } applyAnchorPosition(context) { if (typeof window === "undefined") return; const viewport = this.getViewportSize(); applyAnchorPosition(this.contextState[context], viewport, EDGE_MARGIN); this.updateHostTransform(context); this.persistState(); } resetResizeTracking() { this.resizePointerId = null; this.resizeStart = null; this.resizeInitialSize = null; this.isResizing = false; } resetPointerTracking() { this.pointerId = null; this.dragStart = null; this.pointerContext = null; this.setDragging(false); this.draggedDuringInteraction = false; } openInspector() { if (this.isOpen) return; this.showAnnouncementPreview = false; this.ensureAnnouncementLoading(); this.isOpen = true; this.persistState(); if (this.dockMode !== "floating") this.applyDockStyles(); this.ensureWindowPlacement(); this.requestUpdate(); this.updateComplete.then(() => { this.measureContext("window"); if (this.dockMode === "floating") if (this.hasCustomPosition.window) this.applyAnchorPosition("window"); else this.centerContext("window"); else this.updateHostTransform("window"); }); } closeInspector() { if (!this.isOpen) return; this.isOpen = false; if (this.dockMode !== "floating") this.removeDockStyles(); this.persistState(); this.updateHostTransform("button"); this.requestUpdate(); this.updateComplete.then(() => { this.measureContext("button"); this.applyAnchorPosition("button"); }); } renderIcon(name) { const iconNode = lucide.icons[name]; if (!iconNode) return lit.nothing; return (0, lit_directives_unsafe_html_js.unsafeHTML)(`${iconNode.map(([tag, attrs]) => `<${tag} ${this.serializeAttributes(attrs)} />`).join("")}`); } renderDockControls() { if (this.dockMode === "floating") return lit.html` `; else return lit.html` `; } getDockedWindowStyles() { if (this.dockMode === "docked-left") return { position: "fixed", top: "0", left: "0", bottom: "0", width: `${Math.round(this.contextState.window.size.width)}px`, height: "100vh", minWidth: `${MIN_WINDOW_WIDTH_DOCKED_LEFT}px`, borderRadius: "0" }; return { width: `${Math.round(this.contextState.window.size.width)}px`, height: `${Math.round(this.contextState.window.size.height)}px`, minWidth: `${MIN_WINDOW_WIDTH}px`, minHeight: `${MIN_WINDOW_HEIGHT}px` }; } handleDockClick(mode) { this.setDockMode(mode); } serializeAttributes(attributes) { return Object.entries(attributes).filter(([key, value]) => key !== "key" && value !== void 0 && value !== null && value !== "").map(([key, value]) => `${key}="${String(value).replace(/"/g, """)}"`).join(" "); } sanitizeForLogging(value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) { if (value === void 0) return "[undefined]"; if (value === null || typeof value === "number" || typeof value === "boolean") return value; if (typeof value === "string") return value; if (typeof value === "bigint" || typeof value === "symbol" || typeof value === "function") return String(value); if (value instanceof Date) return value.toISOString(); if (Array.isArray(value)) { if (depth >= 4) return "[Truncated depth]"; return value.map((item) => this.sanitizeForLogging(item, depth + 1, seen)); } if (typeof value === "object") { if (seen.has(value)) return "[Circular]"; seen.add(value); if (depth >= 4) return "[Truncated depth]"; const result = {}; for (const [key, entry] of Object.entries(value)) result[key] = this.sanitizeForLogging(entry, depth + 1, seen); return result; } return String(value); } normalizeEventPayload(_type, payload) { if (payload && typeof payload === "object" && "event" in payload) { const { event, ...rest } = payload; const cleaned = Object.keys(rest).length === 0 ? event : { event, ...rest }; return this.sanitizeForLogging(cleaned); } return this.sanitizeForLogging(payload); } normalizeMessageContent(content) { if (typeof content === "string") return content; if (content && typeof content === "object" && "text" in content) { const maybeText = content.text; if (typeof maybeText === "string") return maybeText; } if (content === null || content === void 0) return ""; if (typeof content === "object") try { return JSON.stringify(this.sanitizeForLogging(content)); } catch (_unused5) { return ""; } return String(content); } normalizeToolCalls(raw) { if (!Array.isArray(raw)) return []; return raw.map((entry) => { if (!entry || typeof entry !== "object") return null; const call = entry; const fn = call.function; const functionName = typeof (fn === null || fn === void 0 ? void 0 : fn.name) === "string" ? fn.name : typeof call.toolName === "string" ? call.toolName : void 0; const args = fn && "arguments" in fn ? fn.arguments : call.arguments; const normalized = { id: typeof call.id === "string" ? call.id : void 0, toolName: typeof call.toolName === "string" ? call.toolName : functionName, status: typeof call.status === "string" ? call.status : void 0 }; if (functionName) normalized.function = { name: functionName, arguments: this.sanitizeForLogging(args) }; return normalized; }).filter((call) => Boolean(call)); } normalizeAgentMessage(message) { if (!message || typeof message !== "object") return null; const raw = message; const role = typeof raw.role === "string" ? raw.role : "unknown"; const contentText = this.normalizeMessageContent(raw.content); const toolCalls = this.normalizeToolCalls(raw.toolCalls); return { id: typeof raw.id === "string" ? raw.id : void 0, role, contentText, contentRaw: raw.content !== void 0 ? this.sanitizeForLogging(raw.content) : void 0, toolCalls }; } normalizeAgentMessages(messages) { if (!Array.isArray(messages)) return null; return messages.map((message) => this.normalizeAgentMessage(message)).filter((msg) => msg !== null); } normalizeContextStore(context) { if (!context || typeof context !== "object") return {}; const normalized = {}; for (const [key, entry] of Object.entries(context)) if (entry && typeof entry === "object" && "value" in entry) { const candidate = entry; normalized[key] = { description: typeof candidate.description === "string" && candidate.description.trim().length > 0 ? candidate.description : void 0, value: candidate.value }; } else normalized[key] = { value: entry }; return normalized; } getSelectedMenu() { const found = this.menuItems.find((item) => item.key === this.selectedMenu); return found !== null && found !== void 0 ? found : this.menuItems[0]; } renderCoreWarningBanner() { if (this._core) return lit.nothing; return lit.html`
${this.renderIcon("AlertTriangle")}
CopilotKit core not attached

Pass a live CopilotKitCore instance to <cpk-web-inspector> or expose it on window.__COPILOTKIT_CORE__ for auto-attach.

`; } getCoreStatusSummary() { var _this$runtimeStatus, _this$lastCoreError; if (!this._core) return { label: "Core not attached", tone: "border border-amber-200 bg-amber-50 text-amber-800", description: "Pass a CopilotKitCore instance to or enable auto-attach." }; const status = (_this$runtimeStatus = this.runtimeStatus) !== null && _this$runtimeStatus !== void 0 ? _this$runtimeStatus : _copilotkitnext_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected; const lastErrorMessage = (_this$lastCoreError = this.lastCoreError) === null || _this$lastCoreError === void 0 ? void 0 : _this$lastCoreError.message; if (status === _copilotkitnext_core.CopilotKitCoreRuntimeConnectionStatus.Error) return { label: "Runtime error", tone: "border border-rose-200 bg-rose-50 text-rose-700", description: lastErrorMessage !== null && lastErrorMessage !== void 0 ? lastErrorMessage : "CopilotKit runtime reported an error." }; if (status === _copilotkitnext_core.CopilotKitCoreRuntimeConnectionStatus.Connecting) return { label: "Connecting", tone: "border border-amber-200 bg-amber-50 text-amber-800", description: "Waiting for CopilotKit runtime to finish connecting." }; if (status === _copilotkitnext_core.CopilotKitCoreRuntimeConnectionStatus.Connected) return { label: "Connected", tone: "border border-emerald-200 bg-emerald-50 text-emerald-700", description: "Live runtime connection established." }; return { label: "Disconnected", tone: "border border-gray-200 bg-gray-50 text-gray-700", description: lastErrorMessage !== null && lastErrorMessage !== void 0 ? lastErrorMessage : "Waiting for CopilotKit runtime to connect." }; } renderMainContent() { if (this.selectedMenu === "ag-ui-events") return this.renderEventsTable(); if (this.selectedMenu === "agents") return this.renderAgentsView(); if (this.selectedMenu === "frontend-tools") return this.renderToolsView(); if (this.selectedMenu === "agent-context") return this.renderContextView(); return lit.nothing; } renderEventsTable() { const events = this.getEventsForSelectedContext(); const filteredEvents = this.filterEvents(events); const selectedLabel = this.selectedContext === "all-agents" ? "all agents" : `agent ${this.selectedContext}`; if (events.length === 0) return lit.html`
${this.renderIcon("Zap")}

No events yet

Trigger an agent run to see live activity.

`; if (filteredEvents.length === 0) return lit.html`
${this.renderIcon("Filter")}

No events match the current filters.

`; return lit.html`
Showing ${filteredEvents.length} of ${events.length}${this.selectedContext === "all-agents" ? "" : ` for ${selectedLabel}`}
${filteredEvents.map((event, index) => { const rowBg = index % 2 === 0 ? "bg-white" : "bg-gray-50/50"; const badgeClasses = this.getEventBadgeClasses(event.type); const extractedEvent = this.extractEventFromPayload(event.payload); const inlineEvent = this.stringifyPayload(extractedEvent, false) || "—"; const prettyEvent = this.stringifyPayload(extractedEvent, true) || inlineEvent; const isExpanded = this.expandedRows.has(event.id); return lit.html` this.toggleRowExpansion(event.id)} > `; })}
Agent Time Event Type AG-UI Event
${event.agentId} ${new Date(event.timestamp).toLocaleTimeString()} ${event.type} ${isExpanded ? lit.html`
${prettyEvent}
` : inlineEvent}
`; } handleEventFilterInput(event) { var _target$value; const target = event.target; this.eventFilterText = (_target$value = target === null || target === void 0 ? void 0 : target.value) !== null && _target$value !== void 0 ? _target$value : ""; this.requestUpdate(); } handleEventTypeChange(event) { const target = event.target; const value = target === null || target === void 0 ? void 0 : target.value; if (!value) return; this.eventTypeFilter = value; this.requestUpdate(); } resetEventFilters() { this.eventFilterText = ""; this.eventTypeFilter = "all"; this.requestUpdate(); } exportEvents(events) { try { const payload = JSON.stringify(events, null, 2); const blob = new Blob([payload], { type: "application/json" }); const url = URL.createObjectURL(blob); const anchor = document.createElement("a"); anchor.href = url; anchor.download = `copilotkit-events-${Date.now()}.json`; anchor.click(); URL.revokeObjectURL(url); } catch (error) { console.error("Failed to export events", error); } } renderAgentsView() { if (this.selectedContext === "all-agents") return lit.html`
${this.renderIcon("Bot")}

No agent selected

Select an agent from the dropdown above to view details.

`; const agentId = this.selectedContext; const status = this.getAgentStatus(agentId); const stats = this.getAgentStats(agentId); const state = this.getLatestStateForAgent(agentId); const messages = this.getLatestMessagesForAgent(agentId); return lit.html`
${this.renderIcon("Bot")}

${agentId}

${status.charAt(0).toUpperCase() + status.slice(1)}
${stats.lastActivity ? lit.html`Last activity: ${new Date(stats.lastActivity).toLocaleTimeString()}` : lit.nothing}
Messages
${stats.messages}
Tool Calls
${stats.toolCalls}
Errors
${stats.errors}

Current State

${this.hasRenderableState(state) ? lit.html`
${this.formatStateForDisplay(state)}
` : lit.html`
${this.renderIcon("Database")} State is empty
`}

Current Messages

${messages && messages.length > 0 ? lit.html` ${messages.map((msg) => { var _msg$contentText, _msg$toolCalls; const role = msg.role || "unknown"; const roleColors = { user: "bg-blue-100 text-blue-800", assistant: "bg-green-100 text-green-800", system: "bg-gray-100 text-gray-800", tool: "bg-amber-100 text-amber-800", unknown: "bg-gray-100 text-gray-600" }; const rawContent = (_msg$contentText = msg.contentText) !== null && _msg$contentText !== void 0 ? _msg$contentText : ""; const toolCalls = (_msg$toolCalls = msg.toolCalls) !== null && _msg$toolCalls !== void 0 ? _msg$toolCalls : []; const hasContent = rawContent.trim().length > 0; const contentFallback = toolCalls.length > 0 ? "Invoked tool call" : "—"; return lit.html` `; })}
Role Content
${role} ${hasContent ? lit.html`
${rawContent}
` : lit.html`
${contentFallback}
`} ${role === "assistant" && toolCalls.length > 0 ? this.renderToolCallDetails(toolCalls) : lit.nothing}
` : lit.html`
${this.renderIcon("MessageSquare")} No messages available
`}
`; } renderContextDropdown() { var _filteredOptions$find, _filteredOptions$find2; const filteredOptions = this.selectedMenu === "agents" ? this.contextOptions.filter((opt) => opt.key !== "all-agents") : this.contextOptions; const selectedLabel = (_filteredOptions$find = (_filteredOptions$find2 = filteredOptions.find((opt) => opt.key === this.selectedContext)) === null || _filteredOptions$find2 === void 0 ? void 0 : _filteredOptions$find2.label) !== null && _filteredOptions$find !== void 0 ? _filteredOptions$find : ""; return lit.html`
${this.contextMenuOpen ? lit.html`
${filteredOptions.map((option) => lit.html` `)}
` : lit.nothing}
`; } handleMenuSelect(key) { if (!this.menuItems.some((item) => item.key === key)) return; this.selectedMenu = key; if (key === "agents" && this.selectedContext === "all-agents") { const agentOptions = this.contextOptions.filter((opt) => opt.key !== "all-agents"); if (agentOptions.length > 0) { const defaultAgent = agentOptions.find((opt) => opt.key === "default"); this.selectedContext = defaultAgent ? defaultAgent.key : agentOptions[0].key; } } this.contextMenuOpen = false; this.persistState(); this.requestUpdate(); } handleContextDropdownToggle(event) { event.preventDefault(); event.stopPropagation(); this.contextMenuOpen = !this.contextMenuOpen; this.requestUpdate(); } handleContextOptionSelect(key) { if (!this.contextOptions.some((option) => option.key === key)) return; if (this.selectedContext !== key) { this.selectedContext = key; this.expandedRows.clear(); } this.contextMenuOpen = false; this.persistState(); this.requestUpdate(); } renderToolsView() { if (!this._core) return lit.html`
No core instance available
`; this.refreshToolsSnapshot(); const allTools = this.cachedTools; if (allTools.length === 0) return lit.html`
${this.renderIcon("Hammer")}

No tools available

Tools will appear here once agents are configured with tool handlers or renderers.

`; return lit.html`
${(this.selectedContext === "all-agents" ? allTools : allTools.filter((tool) => !tool.agentId || tool.agentId === this.selectedContext)).map((tool) => this.renderToolCard(tool))}
`; } extractToolsFromAgents() { var _this$_core$tools; if (!this._core) return []; const tools = []; for (const coreTool of (_this$_core$tools = this._core.tools) !== null && _this$_core$tools !== void 0 ? _this$_core$tools : []) { var _coreTool$agentId; tools.push({ agentId: (_coreTool$agentId = coreTool.agentId) !== null && _coreTool$agentId !== void 0 ? _coreTool$agentId : "", name: coreTool.name, description: coreTool.description, parameters: coreTool.parameters, type: "handler" }); } for (const [agentId, agent] of Object.entries(this._core.agents)) { if (!agent) continue; const handlers = agent.toolHandlers; if (handlers && typeof handlers === "object") { for (const [toolName, handler] of Object.entries(handlers)) if (handler && typeof handler === "object") { var _handlerObj$tool, _handlerObj$parameter, _handlerObj$tool2; const handlerObj = handler; tools.push({ agentId, name: toolName, description: typeof handlerObj.description === "string" && handlerObj.description || ((_handlerObj$tool = handlerObj.tool) === null || _handlerObj$tool === void 0 ? void 0 : _handlerObj$tool.description), parameters: (_handlerObj$parameter = handlerObj.parameters) !== null && _handlerObj$parameter !== void 0 ? _handlerObj$parameter : (_handlerObj$tool2 = handlerObj.tool) === null || _handlerObj$tool2 === void 0 ? void 0 : _handlerObj$tool2.parameters, type: "handler" }); } } const renderers = agent.toolRenderers; if (renderers && typeof renderers === "object") { for (const [toolName, renderer] of Object.entries(renderers)) if (!tools.some((t) => t.agentId === agentId && t.name === toolName)) { if (renderer && typeof renderer === "object") { var _rendererObj$tool, _rendererObj$paramete, _rendererObj$tool2; const rendererObj = renderer; tools.push({ agentId, name: toolName, description: typeof rendererObj.description === "string" && rendererObj.description || ((_rendererObj$tool = rendererObj.tool) === null || _rendererObj$tool === void 0 ? void 0 : _rendererObj$tool.description), parameters: (_rendererObj$paramete = rendererObj.parameters) !== null && _rendererObj$paramete !== void 0 ? _rendererObj$paramete : (_rendererObj$tool2 = rendererObj.tool) === null || _rendererObj$tool2 === void 0 ? void 0 : _rendererObj$tool2.parameters, type: "renderer" }); } } } } return tools.sort((a, b) => { const agentCompare = a.agentId.localeCompare(b.agentId); if (agentCompare !== 0) return agentCompare; return a.name.localeCompare(b.name); }); } renderToolCard(tool) { const isExpanded = this.expandedTools.has(`${tool.agentId}:${tool.name}`); const schema = this.extractSchemaInfo(tool.parameters); return lit.html`
${isExpanded ? lit.html`
${schema.properties.length > 0 ? lit.html`
Parameters
${schema.properties.map((prop) => lit.html`
${prop.name}
${prop.required ? lit.html`required` : lit.html`optional`} ${prop.type ? lit.html`${prop.type}` : lit.nothing}
${prop.description ? lit.html`

${prop.description}

` : lit.nothing} ${prop.defaultValue !== void 0 ? lit.html`
Default: ${JSON.stringify(prop.defaultValue)}
` : lit.nothing} ${prop.enum && prop.enum.length > 0 ? lit.html`
Allowed values:
${prop.enum.map((val) => lit.html` ${JSON.stringify(val)} `)}
` : lit.nothing}
`)}
` : lit.html`
No parameters defined
`}
` : lit.nothing}
`; } extractSchemaInfo(parameters) { const result = { properties: [] }; if (!parameters || typeof parameters !== "object") return result; const zodDef = parameters._def; if (zodDef && typeof zodDef === "object") { if (zodDef.typeName === "ZodObject") { const rawShape = zodDef.shape; const shape = typeof rawShape === "function" ? rawShape() : rawShape; if (!shape || typeof shape !== "object") return result; const requiredKeys = /* @__PURE__ */ new Set(); if (zodDef.unknownKeys === "strict" || !zodDef.catchall) Object.keys(shape || {}).forEach((key) => { const candidate = shape[key]; if ((candidate === null || candidate === void 0 ? void 0 : candidate._def) && !this.isZodOptional(candidate)) requiredKeys.add(key); }); for (const [key, value] of Object.entries(shape || {})) { const fieldInfo = this.extractZodFieldInfo(value); result.properties.push({ name: key, type: fieldInfo.type, description: fieldInfo.description, required: requiredKeys.has(key), defaultValue: fieldInfo.defaultValue, enum: fieldInfo.enum }); } } } else if (parameters.type === "object" && parameters.properties) { const props = parameters.properties; const required = new Set(Array.isArray(parameters.required) ? parameters.required : []); for (const [key, value] of Object.entries(props !== null && props !== void 0 ? props : {})) { const prop = value; result.properties.push({ name: key, type: prop.type, description: typeof prop.description === "string" ? prop.description : void 0, required: required.has(key), defaultValue: prop.default, enum: Array.isArray(prop.enum) ? prop.enum : void 0 }); } } return result; } isZodOptional(zodSchema) { const schema = zodSchema; if (!(schema === null || schema === void 0 ? void 0 : schema._def)) return false; const def = schema._def; if (def.typeName === "ZodOptional" || def.typeName === "ZodNullable") return true; if (def.defaultValue !== void 0) return true; return false; } extractZodFieldInfo(zodSchema) { const info = {}; const schema = zodSchema; if (!(schema === null || schema === void 0 ? void 0 : schema._def)) return info; let currentSchema = schema; let def = currentSchema._def; while (def.typeName === "ZodOptional" || def.typeName === "ZodNullable" || def.typeName === "ZodDefault") { var _ref2; if (def.typeName === "ZodDefault" && def.defaultValue !== void 0) info.defaultValue = typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue; currentSchema = (_ref2 = def.innerType) !== null && _ref2 !== void 0 ? _ref2 : currentSchema; if (!(currentSchema === null || currentSchema === void 0 ? void 0 : currentSchema._def)) break; def = currentSchema._def; } info.description = typeof def.description === "string" ? def.description : void 0; const typeName = typeof def.typeName === "string" ? def.typeName : void 0; info.type = typeName ? { ZodString: "string", ZodNumber: "number", ZodBoolean: "boolean", ZodArray: "array", ZodObject: "object", ZodEnum: "enum", ZodLiteral: "literal", ZodUnion: "union", ZodAny: "any", ZodUnknown: "unknown" }[typeName] || typeName.replace("Zod", "").toLowerCase() : void 0; if (typeName === "ZodEnum" && Array.isArray(def.values)) info.enum = def.values; else if (typeName === "ZodLiteral" && def.value !== void 0) info.enum = [def.value]; return info; } toggleToolExpansion(toolId) { if (this.expandedTools.has(toolId)) this.expandedTools.delete(toolId); else this.expandedTools.add(toolId); this.requestUpdate(); } renderContextView() { const contextEntries = Object.entries(this.contextStore); if (contextEntries.length === 0) return lit.html`
${this.renderIcon("FileText")}

No context available

Context will appear here once added to CopilotKit.

`; return lit.html`
${contextEntries.map(([id, context]) => this.renderContextCard(id, context))}
`; } renderContextCard(id, context) { var _context$description; const isExpanded = this.expandedContextItems.has(id); const valuePreview = this.getContextValuePreview(context.value); const hasValue = context.value !== void 0 && context.value !== null; return lit.html`
${isExpanded ? lit.html`
ID
${id}
${hasValue ? lit.html`
Value
${this.formatContextValue(context.value)}
` : lit.html`
No value available
`}
` : lit.nothing}
`; } getContextValuePreview(value) { if (value === void 0 || value === null) return "—"; if (typeof value === "string") return value.length > 50 ? `${value.substring(0, 50)}...` : value; if (typeof value === "number" || typeof value === "boolean") return String(value); if (Array.isArray(value)) return `Array(${value.length})`; if (typeof value === "object") { const keys = Object.keys(value); return `Object with ${keys.length} key${keys.length !== 1 ? "s" : ""}`; } if (typeof value === "function") return "Function"; return String(value); } formatContextValue(value) { if (value === void 0) return "undefined"; if (value === null) return "null"; if (typeof value === "function") return value.toString(); try { return JSON.stringify(value, null, 2); } catch (_unused6) { return String(value); } } async copyContextValue(value, contextId) { var _navigator$clipboard; if (typeof navigator === "undefined" || !((_navigator$clipboard = navigator.clipboard) === null || _navigator$clipboard === void 0 ? void 0 : _navigator$clipboard.writeText)) { console.warn("Clipboard API is not available in this environment."); return; } const serialized = this.formatContextValue(value); try { await navigator.clipboard.writeText(serialized); this.copiedContextItems.add(contextId); this.requestUpdate(); setTimeout(() => { this.copiedContextItems.delete(contextId); this.requestUpdate(); }, 1500); } catch (error) { console.error("Failed to copy context value:", error); } } toggleContextExpansion(contextId) { if (this.expandedContextItems.has(contextId)) this.expandedContextItems.delete(contextId); else this.expandedContextItems.add(contextId); this.requestUpdate(); } toggleRowExpansion(eventId) { const selection = window.getSelection(); if (selection && selection.toString().length > 0) return; if (this.expandedRows.has(eventId)) this.expandedRows.delete(eventId); else this.expandedRows.add(eventId); this.requestUpdate(); } renderAnnouncementPanel() { if (!this.isOpen) return lit.nothing; this.ensureAnnouncementLoading(); if (!this.hasUnseenAnnouncement) return lit.nothing; if (!this.announcementLoaded && !this.announcementMarkdown) return lit.html`
${this.renderIcon("Megaphone")} Loading latest announcement…
`; if (this.announcementLoadError) return lit.html`
${this.renderIcon("Megaphone")} Announcement unavailable

We couldn’t load the latest notice. Please try opening the inspector again.

`; if (!this.announcementMarkdown) return lit.nothing; const content = this.announcementHtml ? (0, lit_directives_unsafe_html_js.unsafeHTML)(this.announcementHtml) : lit.html`
${this.announcementMarkdown}
`; return lit.html`
${this.renderIcon("Megaphone")} Announcement
${content}
`; } ensureAnnouncementLoading() { if (this.announcementPromise || typeof window === "undefined" || typeof fetch === "undefined") return; this.announcementPromise = this.fetchAnnouncement(); } renderAnnouncementPreview() { if (!this.hasUnseenAnnouncement || !this.showAnnouncementPreview || !this.announcementPreviewText) return lit.nothing; return lit.html`
this.handleAnnouncementPreviewClick()} > ${this.announcementPreviewText}
`; } handleAnnouncementPreviewClick() { this.showAnnouncementPreview = false; this.openInspector(); } async fetchAnnouncement() { try { const response = await fetch(ANNOUNCEMENT_URL, { cache: "no-cache" }); if (!response.ok) throw new Error(`Failed to load announcement (${response.status})`); const data = await response.json(); const timestamp = typeof (data === null || data === void 0 ? void 0 : data.timestamp) === "string" ? data.timestamp : null; const previewText = typeof (data === null || data === void 0 ? void 0 : data.previewText) === "string" ? data.previewText : null; const markdown = typeof (data === null || data === void 0 ? void 0 : data.announcement) === "string" ? data.announcement : null; if (!timestamp || !markdown) throw new Error("Malformed announcement payload"); const storedTimestamp = this.loadStoredAnnouncementTimestamp(); this.announcementTimestamp = timestamp; this.announcementPreviewText = previewText !== null && previewText !== void 0 ? previewText : ""; this.announcementMarkdown = markdown; this.hasUnseenAnnouncement = (!storedTimestamp || storedTimestamp !== timestamp) && !!this.announcementPreviewText; this.showAnnouncementPreview = this.hasUnseenAnnouncement; this.announcementHtml = await this.convertMarkdownToHtml(markdown); this.announcementLoaded = true; this.requestUpdate(); } catch (error) { this.announcementLoadError = error; this.announcementLoaded = true; this.requestUpdate(); } } async convertMarkdownToHtml(markdown) { const renderer = new marked.marked.Renderer(); renderer.link = (href, title, text) => { return `${text}`; }; return marked.marked.parse(markdown, { renderer }); } appendRefParam(href) { try { const url = new URL(href, typeof window !== "undefined" ? window.location.href : "https://copilotkit.ai"); if (!url.searchParams.has("ref")) url.searchParams.append("ref", "cpk-inspector"); return url.toString(); } catch (_unused7) { return href; } } escapeHtmlAttr(value) { return value.replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """).replace(/'/g, "'"); } loadStoredAnnouncementTimestamp() { if (typeof window === "undefined" || !window.localStorage) return null; try { const raw = window.localStorage.getItem(ANNOUNCEMENT_STORAGE_KEY); if (!raw) return null; const parsed = JSON.parse(raw); if (parsed && typeof parsed.timestamp === "string") return parsed.timestamp; return null; } catch (_unused8) {} return null; } persistAnnouncementTimestamp(timestamp) { if (typeof window === "undefined" || !window.localStorage) return; try { const payload = JSON.stringify({ timestamp }); window.localStorage.setItem(ANNOUNCEMENT_STORAGE_KEY, payload); } catch (_unused9) {} } markAnnouncementSeen() { this.hasUnseenAnnouncement = false; this.showAnnouncementPreview = false; if (!this.announcementTimestamp) { if (this.announcementPromise && !this.announcementLoaded) this.announcementPromise.then(() => this.markAnnouncementSeen()).catch(() => void 0); this.requestUpdate(); return; } this.persistAnnouncementTimestamp(this.announcementTimestamp); this.requestUpdate(); } }; WebInspectorElement.properties = { core: { attribute: false }, autoAttachCore: { type: Boolean, attribute: "auto-attach-core" } }; WebInspectorElement.styles = [(0, lit.unsafeCSS)(generated_default), lit.css` :host { position: fixed; top: 0; left: 0; z-index: 2147483646; display: block; will-change: transform; } :host([data-transitioning="true"]) { transition: transform 300ms ease; } .console-button { transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1), opacity 160ms ease; } .console-button[data-dragging="true"] { transition: opacity 160ms ease; } .inspector-window[data-transitioning="true"] { transition: width 300ms ease, height 300ms ease; } .inspector-window[data-docked="true"] { border-radius: 0 !important; box-shadow: none !important; } .resize-handle { touch-action: none; user-select: none; } .dock-resize-handle { position: absolute; top: 0; right: 0; width: 10px; height: 100%; cursor: ew-resize; touch-action: none; z-index: 50; background: transparent; } .tooltip-target { position: relative; } .tooltip-target::after { content: attr(data-tooltip); position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%) translateY(-4px); white-space: nowrap; background: rgba(17, 24, 39, 0.95); color: white; padding: 4px 8px; border-radius: 6px; font-size: 10px; line-height: 1.2; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15); opacity: 0; pointer-events: none; transition: opacity 120ms ease, transform 120ms ease; z-index: 4000; } .tooltip-target:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); } .announcement-preview { position: absolute; top: 50%; transform: translateY(-50%); min-width: 300px; max-width: 300px; background: white; color: #111827; font-size: 13px; line-height: 1.4; border-radius: 12px; box-shadow: 0 12px 28px rgba(15, 23, 42, 0.22); padding: 10px 12px; display: inline-flex; align-items: flex-start; gap: 8px; z-index: 4500; animation: fade-slide-in 160ms ease; border: 1px solid rgba(148, 163, 184, 0.35); white-space: normal; word-break: break-word; text-align: left; } .announcement-preview[data-side="left"] { right: 100%; margin-right: 10px; } .announcement-preview[data-side="right"] { left: 100%; margin-left: 10px; } .announcement-preview__arrow { position: absolute; width: 10px; height: 10px; background: white; border: 1px solid rgba(148, 163, 184, 0.35); transform: rotate(45deg); top: 50%; margin-top: -5px; z-index: -1; } .announcement-preview[data-side="left"] .announcement-preview__arrow { right: -5px; box-shadow: 6px -6px 10px rgba(15, 23, 42, 0.12); } .announcement-preview[data-side="right"] .announcement-preview__arrow { left: -5px; box-shadow: -6px 6px 10px rgba(15, 23, 42, 0.12); } .announcement-dismiss { color: #6b7280; font-size: 12px; padding: 2px 8px; border-radius: 8px; border: 1px solid rgba(148, 163, 184, 0.5); background: rgba(248, 250, 252, 0.9); transition: background 120ms ease, color 120ms ease; } .announcement-dismiss:hover { background: rgba(241, 245, 249, 1); color: #111827; } .announcement-content { color: #111827; font-size: 14px; line-height: 1.6; } .announcement-content h1, .announcement-content h2, .announcement-content h3 { font-weight: 700; margin: 0.4rem 0 0.2rem; } .announcement-content h1 { font-size: 1.1rem; } .announcement-content h2 { font-size: 1rem; } .announcement-content h3 { font-size: 0.95rem; } .announcement-content p { margin: 0.25rem 0; } .announcement-content ul { list-style: disc; padding-left: 1.25rem; margin: 0.3rem 0; } .announcement-content ol { list-style: decimal; padding-left: 1.25rem; margin: 0.3rem 0; } .announcement-content a { color: #0f766e; text-decoration: underline; } `]; function defineWebInspector() { if (!customElements.get(WEB_INSPECTOR_TAG)) customElements.define(WEB_INSPECTOR_TAG, WebInspectorElement); } defineWebInspector(); //#endregion exports.WEB_INSPECTOR_TAG = WEB_INSPECTOR_TAG; exports.WebInspectorElement = WebInspectorElement; exports.defineWebInspector = defineWebInspector; }); //# sourceMappingURL=index.umd.js.map