@copilotkit/web-inspector 1.56.5 → 1.57.0-canary.1778078321

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -1,16 +1,24 @@
1
1
  import { LitElement, css, html, nothing, unsafeCSS } from "lit";
2
+ import type { TemplateResult } from "lit";
3
+ import { marked } from "marked";
2
4
  import { styleMap } from "lit/directives/style-map.js";
3
5
  import tailwindStyles from "./styles/generated.css";
4
6
  import inspectorLogoUrl from "./assets/inspector-logo.svg";
5
7
  import inspectorLogoIconUrl from "./assets/inspector-logo-icon.svg";
6
8
  import { unsafeHTML } from "lit/directives/unsafe-html.js";
7
- import { marked } from "marked";
8
9
  import { icons } from "lucide";
10
+ import type { CopilotKitCore } from "@copilotkit/core";
9
11
  import {
10
- CopilotKitCore,
11
12
  CopilotKitCoreRuntimeConnectionStatus,
12
- type CopilotKitCoreSubscriber,
13
- type CopilotKitCoreErrorCode,
13
+ ɵselectThreads,
14
+ ɵselectThreadsError,
15
+ ɵcreateThreadStore,
16
+ } from "@copilotkit/core";
17
+ import type {
18
+ CopilotKitCoreSubscriber,
19
+ CopilotKitCoreErrorCode,
20
+ ɵThreadStore,
21
+ ɵThread,
14
22
  } from "@copilotkit/core";
15
23
  import type { AbstractAgent, AgentSubscriber } from "@ag-ui/client";
16
24
  import type {
@@ -33,18 +41,23 @@ import {
33
41
  import {
34
42
  loadInspectorState,
35
43
  saveInspectorState,
36
- type PersistedState,
37
44
  isValidAnchor,
38
45
  isValidPosition,
39
46
  isValidSize,
40
47
  isValidDockMode,
41
48
  } from "./lib/persistence";
49
+ import type { PersistedState } from "./lib/persistence";
42
50
 
43
51
  export const WEB_INSPECTOR_TAG = "cpk-web-inspector" as const;
44
52
 
45
53
  type LucideIconName = keyof typeof icons;
46
54
 
47
- type MenuKey = "ag-ui-events" | "agents" | "frontend-tools" | "agent-context";
55
+ type MenuKey =
56
+ | "ag-ui-events"
57
+ | "agents"
58
+ | "frontend-tools"
59
+ | "agent-context"
60
+ | "threads";
48
61
 
49
62
  type MenuItem = {
50
63
  key: MenuKey;
@@ -61,7 +74,7 @@ const INSPECTOR_STORAGE_KEY = "cpk:inspector:state";
61
74
  const ANNOUNCEMENT_STORAGE_KEY = "cpk:inspector:announcements";
62
75
  const ANNOUNCEMENT_URL = "https://cdn.copilotkit.ai/announcements.json";
63
76
  const DEFAULT_BUTTON_SIZE: Size = { width: 48, height: 48 };
64
- const DEFAULT_WINDOW_SIZE: Size = { width: 840, height: 560 };
77
+ const DEFAULT_WINDOW_SIZE: Size = { width: 840, height: 700 };
65
78
  const DOCKED_LEFT_WIDTH = 500; // Sensible width for left dock with collapsed sidebar
66
79
  const MAX_AGENT_EVENTS = 200;
67
80
  const MAX_TOTAL_EVENTS = 500;
@@ -87,7 +100,9 @@ type InspectorAgentEventType =
87
100
  | "REASONING_MESSAGE_CONTENT"
88
101
  | "REASONING_MESSAGE_END"
89
102
  | "REASONING_END"
90
- | "REASONING_ENCRYPTED_VALUE";
103
+ | "REASONING_ENCRYPTED_VALUE"
104
+ | "ACTIVITY_SNAPSHOT"
105
+ | "ACTIVITY_DELTA";
91
106
 
92
107
  const AGENT_EVENT_TYPES: readonly InspectorAgentEventType[] = [
93
108
  "RUN_STARTED",
@@ -111,49 +126,2206 @@ const AGENT_EVENT_TYPES: readonly InspectorAgentEventType[] = [
111
126
  "REASONING_MESSAGE_END",
112
127
  "REASONING_END",
113
128
  "REASONING_ENCRYPTED_VALUE",
129
+ "ACTIVITY_SNAPSHOT",
130
+ "ACTIVITY_DELTA",
114
131
  ] as const;
115
132
 
116
- type SanitizedValue =
117
- | string
118
- | number
119
- | boolean
120
- | null
121
- | SanitizedValue[]
122
- | { [key: string]: SanitizedValue };
133
+ type SanitizedValue =
134
+ | string
135
+ | number
136
+ | boolean
137
+ | null
138
+ | SanitizedValue[]
139
+ | { [key: string]: SanitizedValue };
140
+
141
+ type InspectorToolCall = {
142
+ id?: string;
143
+ function?: {
144
+ name?: string;
145
+ arguments?: SanitizedValue | string;
146
+ };
147
+ toolName?: string;
148
+ status?: string;
149
+ };
150
+
151
+ type InspectorMessage = {
152
+ id?: string;
153
+ role: string;
154
+ contentText: string;
155
+ contentRaw?: SanitizedValue;
156
+ toolCalls: InspectorToolCall[];
157
+ /** Populated for role="activity" messages (Generative UI). */
158
+ activityType?: string;
159
+ };
160
+
161
+ type InspectorToolDefinition = {
162
+ agentId: string;
163
+ name: string;
164
+ description?: string;
165
+ parameters?: unknown;
166
+ type: "handler" | "renderer";
167
+ };
168
+
169
+ type InspectorEvent = {
170
+ id: string;
171
+ agentId: string;
172
+ type: InspectorAgentEventType;
173
+ timestamp: number;
174
+ payload: SanitizedValue;
175
+ };
176
+
177
+ // ─── Thread details types ────────────────────────────────────────────────────
178
+
179
+ interface ApiThreadMessage {
180
+ id: string;
181
+ role: string;
182
+ content?: string;
183
+ toolCalls?: Array<{ id: string; name: string; args: string }>;
184
+ toolCallId?: string;
185
+ /** Present when role === "activity" (Generative UI output). */
186
+ activityType?: string;
187
+ }
188
+
189
+ interface ConversationUser {
190
+ id: string;
191
+ type: "user";
192
+ content: string;
193
+ createdAt: string;
194
+ }
195
+
196
+ interface ConversationAssistant {
197
+ id: string;
198
+ type: "assistant";
199
+ content: string;
200
+ createdAt: string;
201
+ }
202
+
203
+ interface ConversationToolCall {
204
+ id: string;
205
+ type: "tool_call";
206
+ toolName: string;
207
+ toolCallId: string;
208
+ arguments: Record<string, unknown>;
209
+ result: Record<string, unknown> | null;
210
+ createdAt: string;
211
+ groupId?: string;
212
+ }
213
+
214
+ interface ConversationReasoning {
215
+ id: string;
216
+ type: "reasoning";
217
+ duration: string;
218
+ createdAt: string;
219
+ }
220
+
221
+ interface ConversationStateUpdate {
222
+ id: string;
223
+ type: "state_update";
224
+ createdAt: string;
225
+ }
226
+
227
+ interface ConversationAgentResponded {
228
+ id: string;
229
+ type: "agent_responded";
230
+ createdAt: string;
231
+ }
232
+
233
+ interface ConversationGenerativeUIItem {
234
+ id: string;
235
+ type: "generative-ui";
236
+ activityType: string;
237
+ createdAt: string;
238
+ }
239
+
240
+ interface ToolCallGroup {
241
+ type: "tool_call_group";
242
+ id: string;
243
+ items: ConversationToolCall[];
244
+ }
245
+
246
+ type ConversationItem =
247
+ | ConversationUser
248
+ | ConversationAssistant
249
+ | ConversationToolCall
250
+ | ConversationReasoning
251
+ | ConversationStateUpdate
252
+ | ConversationAgentResponded
253
+ | ConversationGenerativeUIItem;
254
+
255
+ type RenderItem = ConversationItem | ToolCallGroup;
256
+
257
+ interface ApiAgentEvent {
258
+ type: string;
259
+ timestamp: string | number;
260
+ payload: Record<string, unknown>;
261
+ }
262
+
263
+ type ThreadDetailsTab = "conversation" | "agent-state" | "ag-ui-events";
264
+
265
+ // ─── JSON syntax highlighter ─────────────────────────────────────────────────
266
+ // Inline-styled so shadow DOM encapsulation preserves colors when the output
267
+ // is injected via unsafeHTML. Only for structured data — never raw user HTML.
268
+
269
+ function escapeHtml(s: string): string {
270
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
271
+ }
272
+
273
+ // Memoize highlight output by payload reference. Tab switches cause Lit to
274
+ // re-render the active panel from scratch, and the JSON.stringify + regex
275
+ // pass below is by far the most expensive thing in the events / state
276
+ // panels (potentially MB of agent state). Caching by object reference
277
+ // turns subsequent renders of an unchanged event list into near-zero JS work.
278
+ const highlightedJsonCache = new WeakMap<object, string>();
279
+
280
+ function highlightedJson(obj: unknown): string {
281
+ if (typeof obj === "object" && obj !== null) {
282
+ const cached = highlightedJsonCache.get(obj);
283
+ if (cached !== undefined) return cached;
284
+ }
285
+ const colors = {
286
+ key: "#5558B2",
287
+ str: "#189370",
288
+ num: "#996300",
289
+ bool: "#c0333a",
290
+ nil: "#838389",
291
+ };
292
+ const json = JSON.stringify(obj, null, 2);
293
+ if (!json) return "";
294
+ const parts: string[] = [];
295
+ let lastIndex = 0;
296
+ const re =
297
+ /("(?:\\u[a-fA-F0-9]{4}|\\[^u]|[^\\"])*"(?:\s*:)?|\b(?:true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?)/g;
298
+ let match: RegExpExecArray | null;
299
+ while ((match = re.exec(json)) !== null) {
300
+ parts.push(escapeHtml(json.slice(lastIndex, match.index)));
301
+ const m = match[0];
302
+ let color = colors.num;
303
+ if (m.startsWith('"')) {
304
+ color = m.trimEnd().endsWith(":") ? colors.key : colors.str;
305
+ } else if (m === "true" || m === "false") {
306
+ color = colors.bool;
307
+ } else if (m === "null") {
308
+ color = colors.nil;
309
+ }
310
+ parts.push(`<span style="color:${color}">${escapeHtml(m)}</span>`);
311
+ lastIndex = match.index + m.length;
312
+ }
313
+ parts.push(escapeHtml(json.slice(lastIndex)));
314
+ const result = parts.join("");
315
+ if (typeof obj === "object" && obj !== null) {
316
+ highlightedJsonCache.set(obj, result);
317
+ }
318
+ return result;
319
+ }
320
+
321
+ function eventColors(type: string): { bg: string; fg: string } {
322
+ if (type.startsWith("TEXT_MESSAGE")) return { bg: "#EEE6FE", fg: "#57575B" };
323
+ if (type.startsWith("TOOL_CALL"))
324
+ return { bg: "rgba(133,236,206,0.15)", fg: "#189370" };
325
+ if (type.startsWith("STATE"))
326
+ return { bg: "rgba(190,194,255,0.102)", fg: "#5558B2" };
327
+ if (type.startsWith("RUN_") || type.startsWith("STEP_"))
328
+ return { bg: "rgba(255,172,77,0.2)", fg: "#996300" };
329
+ if (type === "ERROR") return { bg: "rgba(250,95,103,0.13)", fg: "#c0333a" };
330
+ return { bg: "#F7F7F9", fg: "#838389" };
331
+ }
332
+
333
+ function formatTimestamp(ts: string | number): string {
334
+ const date = typeof ts === "number" ? new Date(ts) : new Date(ts);
335
+ if (Number.isNaN(date.getTime())) return "";
336
+ const ms = date.getMilliseconds().toString().padStart(3, "0");
337
+ return (
338
+ date.toLocaleTimeString("en-US", {
339
+ hour: "2-digit",
340
+ minute: "2-digit",
341
+ second: "2-digit",
342
+ hour12: false,
343
+ }) +
344
+ "." +
345
+ ms
346
+ );
347
+ }
348
+
349
+ // ─── cpk-thread-list ────────────────────────────────────────────────────────
350
+
351
+ class CpkThreadList extends LitElement {
352
+ static properties = {
353
+ threads: { attribute: false },
354
+ selectedThreadId: { attribute: false },
355
+ errorMessage: { attribute: false },
356
+ _query: { state: true },
357
+ };
358
+ threads: ɵThread[] = [];
359
+ selectedThreadId: string | null = null;
360
+ /**
361
+ * Non-null when the underlying thread store reported a load error
362
+ * (REST list rejection, Phoenix subscribe failure, retry exhaustion).
363
+ * Surfaced inline so users see a real error state instead of stale or
364
+ * empty data with no indication of what went wrong.
365
+ */
366
+ errorMessage: string | null = null;
367
+ private _query = "";
368
+
369
+ static styles = css`
370
+ @import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600&family=Spline+Sans+Mono:wght@400;500&display=swap");
371
+
372
+ :host {
373
+ display: flex;
374
+ flex-direction: column;
375
+ height: 100%;
376
+ overflow: hidden;
377
+ }
378
+
379
+ .cpk-tl {
380
+ font-family: "Plus Jakarta Sans", sans-serif;
381
+ display: flex;
382
+ flex-direction: column;
383
+ height: 100%;
384
+ overflow: hidden;
385
+ background: #f7f7f9;
386
+ }
387
+
388
+ /* ── Search ── */
389
+ .cpk-tl__search {
390
+ padding: 10px 12px;
391
+ border-bottom: 1px solid #dbdbe5;
392
+ flex-shrink: 0;
393
+ }
394
+
395
+ .cpk-tl__search-input {
396
+ width: 100%;
397
+ box-sizing: border-box;
398
+ font-family: "Plus Jakarta Sans", sans-serif;
399
+ font-size: 12px;
400
+ padding: 7px 10px;
401
+ border-radius: 6px;
402
+ border: 1px solid #dbdbe5;
403
+ background: #ffffff;
404
+ color: #010507;
405
+ outline: none;
406
+ transition: border-color 0.15s;
407
+ }
408
+
409
+ .cpk-tl__search-input:focus {
410
+ border-color: #bec2ff;
411
+ }
412
+
413
+ /* ── List ── */
414
+ .cpk-tl__list {
415
+ flex: 1;
416
+ overflow-y: auto;
417
+ }
418
+
419
+ /* ── Thread item ── */
420
+ .cpk-tl__item {
421
+ padding: 11px 13px;
422
+ cursor: pointer;
423
+ border-bottom: 1px solid #e9e9ef;
424
+ border-left: 3px solid transparent;
425
+ transition: background 0.1s;
426
+ }
427
+
428
+ .cpk-tl__item:hover {
429
+ background: #ffffff;
430
+ }
431
+
432
+ .cpk-tl__item--active {
433
+ background: #bec2ff1a;
434
+ border-left-color: #bec2ff;
435
+ }
436
+
437
+ .cpk-tl__item--active:hover {
438
+ background: #bec2ff33;
439
+ }
440
+
441
+ .cpk-tl__row1 {
442
+ display: flex;
443
+ align-items: center;
444
+ gap: 8px;
445
+ margin-bottom: 3px;
446
+ }
447
+
448
+ .cpk-tl__name {
449
+ font-size: 12px;
450
+ font-weight: 500;
451
+ color: #010507;
452
+ flex: 1;
453
+ overflow: hidden;
454
+ text-overflow: ellipsis;
455
+ white-space: nowrap;
456
+ }
457
+
458
+ .cpk-tl__name--unnamed {
459
+ color: #838389;
460
+ font-style: italic;
461
+ font-weight: 400;
462
+ }
463
+
464
+ .cpk-tl__time {
465
+ font-family: "Spline Sans Mono", monospace;
466
+ font-size: 10px;
467
+ color: #838389;
468
+ flex-shrink: 0;
469
+ }
470
+
471
+ .cpk-tl__meta {
472
+ display: flex;
473
+ gap: 6px;
474
+ align-items: center;
475
+ flex-wrap: wrap;
476
+ }
477
+
478
+ .cpk-tl__pill {
479
+ font-family: "Spline Sans Mono", monospace;
480
+ font-size: 9px;
481
+ padding: 1px 7px;
482
+ border-radius: 4px;
483
+ text-transform: uppercase;
484
+ font-weight: 500;
485
+ white-space: nowrap;
486
+ background: #eee6fe;
487
+ color: #57575b;
488
+ }
489
+
490
+ /* ── Empty state ── */
491
+ .cpk-tl__empty {
492
+ padding: 32px 16px;
493
+ text-align: center;
494
+ color: #838389;
495
+ font-size: 12px;
496
+ display: flex;
497
+ flex-direction: column;
498
+ align-items: center;
499
+ gap: 8px;
500
+ }
501
+
502
+ .cpk-tl__empty-icon {
503
+ color: #c0c0c8;
504
+ }
505
+ `;
506
+
507
+ private relativeTime(dateStr: string): string {
508
+ const date = new Date(dateStr);
509
+ const diffMs = Date.now() - date.getTime();
510
+ const diffSec = Math.floor(diffMs / 1000);
511
+ if (diffSec < 60) return `${diffSec}s ago`;
512
+ const diffMin = Math.floor(diffSec / 60);
513
+ if (diffMin < 60) return `${diffMin}m ago`;
514
+ const diffH = Math.floor(diffMin / 60);
515
+ if (diffH < 24) return `${diffH}h ago`;
516
+ const diffD = Math.floor(diffH / 24);
517
+ return `${diffD}d ago`;
518
+ }
519
+
520
+ private get filtered(): ɵThread[] {
521
+ const q = this._query.toLowerCase();
522
+ if (!q) return this.threads;
523
+ return this.threads.filter(
524
+ (t) =>
525
+ (t.name?.toLowerCase().includes(q) ?? false) ||
526
+ t.agentId.toLowerCase().includes(q) ||
527
+ t.id.toLowerCase().includes(q),
528
+ );
529
+ }
530
+
531
+ private onThreadClick(threadId: string): void {
532
+ this.dispatchEvent(
533
+ new CustomEvent("threadSelected", {
534
+ detail: threadId,
535
+ bubbles: true,
536
+ composed: true,
537
+ }),
538
+ );
539
+ }
540
+
541
+ private onSearchInput = (event: Event): void => {
542
+ this._query = (event.target as HTMLInputElement).value;
543
+ };
544
+
545
+ render() {
546
+ const filtered = this.filtered;
547
+ return html`
548
+ <div class="cpk-tl">
549
+ <!-- Search -->
550
+ <div class="cpk-tl__search">
551
+ <input
552
+ type="text"
553
+ placeholder="Search threads…"
554
+ .value=${this._query}
555
+ @input=${this.onSearchInput}
556
+ class="cpk-tl__search-input"
557
+ />
558
+ </div>
559
+
560
+ <!-- Thread list -->
561
+ <div class="cpk-tl__list">
562
+ ${filtered.map(
563
+ (thread) => html`
564
+ <div
565
+ class="cpk-tl__item ${
566
+ this.selectedThreadId === thread.id
567
+ ? "cpk-tl__item--active"
568
+ : ""
569
+ }"
570
+ @click=${() => this.onThreadClick(thread.id)}
571
+ >
572
+ <div class="cpk-tl__row1">
573
+ <span
574
+ class="cpk-tl__name ${
575
+ !thread.name ? "cpk-tl__name--unnamed" : ""
576
+ }"
577
+ >${thread.name ?? "Untitled"}</span
578
+ >
579
+ <span class="cpk-tl__time"
580
+ >${this.relativeTime(thread.updatedAt)}</span
581
+ >
582
+ </div>
583
+ <div class="cpk-tl__meta">
584
+ <span class="cpk-tl__pill">${thread.agentId}</span>
585
+ </div>
586
+ </div>
587
+ `,
588
+ )}
589
+ ${
590
+ filtered.length === 0
591
+ ? html`
592
+ <div class="cpk-tl__empty">
593
+ ${
594
+ this.errorMessage
595
+ ? html`
596
+ <svg
597
+ width="24"
598
+ height="24"
599
+ viewBox="0 0 24 24"
600
+ fill="none"
601
+ stroke="currentColor"
602
+ stroke-width="1.5"
603
+ stroke-linecap="round"
604
+ stroke-linejoin="round"
605
+ class="cpk-tl__empty-icon"
606
+ >
607
+ <circle cx="12" cy="12" r="10" />
608
+ <line x1="12" y1="8" x2="12" y2="12" />
609
+ <line x1="12" y1="16" x2="12.01" y2="16" />
610
+ </svg>
611
+ <div>
612
+ Failed to load threads
613
+ <div style="font-size:11px;margin-top:4px;color:#c0333a;">
614
+ ${this.errorMessage}
615
+ </div>
616
+ </div>
617
+ `
618
+ : this.threads.length === 0
619
+ ? html`
620
+ <svg
621
+ width="24"
622
+ height="24"
623
+ viewBox="0 0 24 24"
624
+ fill="none"
625
+ stroke="currentColor"
626
+ stroke-width="1.5"
627
+ stroke-linecap="round"
628
+ stroke-linejoin="round"
629
+ class="cpk-tl__empty-icon"
630
+ >
631
+ <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
632
+ </svg>
633
+ No threads yet
634
+ `
635
+ : html`
636
+ No threads match your search.
637
+ `
638
+ }
639
+ </div>
640
+ `
641
+ : nothing
642
+ }
643
+ </div>
644
+ </div>
645
+ `;
646
+ }
647
+ }
648
+
649
+ // ─── cpk-thread-details ──────────────────────────────────────────────────────
650
+ // Renders the selected thread's conversation, agent state, and AG-UI events.
651
+ // Conversation comes from the runtime's `/threads/:id/messages` endpoint
652
+ // (always thread-accurate). Agent state and AG-UI events accept live inputs
653
+ // (`agentStateInput`, `agentEventsInput`) from the parent inspector's ongoing
654
+ // agent subscriptions; when those are absent we fall back to the per-thread
655
+ // fetched data via `/threads/:id/{events,state}`.
656
+
657
+ // Exported (with the underscore-prefixed name signalling internal/test-only)
658
+ // so unit tests can pin down the per-panel template-cache invariants without
659
+ // reaching through `customElements`. Production consumers continue to use the
660
+ // `cpk-thread-details` custom element registered below.
661
+ export class ɵCpkThreadDetails extends LitElement {
662
+ static properties = {
663
+ threadId: { attribute: false },
664
+ thread: { attribute: false },
665
+ runtimeUrl: { attribute: false },
666
+ headers: { attribute: false },
667
+ agentStateInput: { attribute: false },
668
+ agentEventsInput: { attribute: false },
669
+ liveMessageVersion: { attribute: false },
670
+ _tab: { state: true },
671
+ _conversation: { state: true },
672
+ _fetchedEvents: { state: true },
673
+ _fetchedState: { state: true },
674
+ _loadingMessages: { state: true },
675
+ _loadingEvents: { state: true },
676
+ _loadingState: { state: true },
677
+ _messagesError: { state: true },
678
+ _eventsError: { state: true },
679
+ _stateError: { state: true },
680
+ _expandedTools: { state: true },
681
+ _expandedMessages: { state: true },
682
+ _showDetailPanel: { state: true },
683
+ _detailPanelWidth: { state: true },
684
+ _eventsNotAvailable: { state: true },
685
+ _stateNotAvailable: { state: true },
686
+ _panelInitializing: { state: true },
687
+ _activatedTabs: { state: true },
688
+ };
689
+
690
+ threadId: string | null = null;
691
+ thread: ɵThread | null = null;
692
+ runtimeUrl = "";
693
+ headers: Record<string, string> = {};
694
+ agentStateInput: Record<string, unknown> | null = null;
695
+ agentEventsInput: ApiAgentEvent[] = [];
696
+ /**
697
+ * Monotonic per-thread counter the parent inspector ticks every time the
698
+ * agent currently running on this thread emits a message change. When this
699
+ * prop changes for the same `threadId`, we re-fetch `/threads/:id/messages`
700
+ * so the conversation view reflects live streaming output.
701
+ */
702
+ liveMessageVersion = 0;
703
+
704
+ private _tab: ThreadDetailsTab = "conversation";
705
+ private _conversation: ConversationItem[] = [];
706
+ private _fetchedEvents: ApiAgentEvent[] | null = null;
707
+ private _fetchedState: Record<string, unknown> | null = null;
708
+ private _loadingMessages = false;
709
+ private _loadingEvents = false;
710
+ private _loadingState = false;
711
+ private _messagesError: string | null = null;
712
+ private _eventsError: string | null = null;
713
+ private _stateError: string | null = null;
714
+ private _expandedTools = new Set<string>();
715
+ private _expandedMessages = new Set<string>();
716
+ private _showDetailPanel = false;
717
+ private _detailPanelWidth = 250;
718
+ /** True when the /events endpoint returned 501 — don't fall back to live data. */
719
+ private _eventsNotAvailable = false;
720
+ /** True when the /state endpoint returned 501 — don't fall back to live data. */
721
+ private _stateNotAvailable = false;
722
+ /**
723
+ * Briefly true after a tab switch so the active-tab highlight + a generic
724
+ * "Loading…" placeholder paint before the heavy per-tab render runs. Without
725
+ * this, large event/conversation lists block the next paint and the user
726
+ * sees the click as unresponsive for seconds.
727
+ */
728
+ private _panelInitializing = false;
729
+ /**
730
+ * Tabs that have been opened at least once for the current thread. Once a
731
+ * tab is activated, its rendered DOM stays mounted (we hide inactive tabs
732
+ * via display:none) so flipping back to it is just a CSS swap rather than
733
+ * tearing down and rebuilding the entire panel from scratch. Without this,
734
+ * switching back to AG-UI Events on a thread with hundreds of events
735
+ * triggers a multi-second DOM-creation pass each time.
736
+ *
737
+ * Reset to {"conversation"} when the selected thread changes.
738
+ */
739
+ private _activatedTabs: Set<ThreadDetailsTab> = new Set(["conversation"]);
740
+ /**
741
+ * Memoized per-panel templates keyed by the inputs they render from.
742
+ * When the underlying data hasn't changed (same `_conversation` /
743
+ * `_fetchedState` / events array reference, plus expand-state for the
744
+ * conversation panel), we return the previously built TemplateResult.
745
+ * Lit then sees "same template, same values" and skips the diff entirely,
746
+ * so re-rendering on tab switch is near-zero work even when the panel
747
+ * content is large. The key is an opaque tuple compared element-wise by
748
+ * reference; if any element flips, the cache misses and rebuilds.
749
+ */
750
+ private _panelTplCache: Map<
751
+ ThreadDetailsTab,
752
+ { key: readonly unknown[]; tpl: TemplateResult }
753
+ > = new Map();
754
+ /**
755
+ * Tracks whether we've fetched events for the current thread yet. Events
756
+ * fetch lazily on first sub-tab click so a large response's JSON.parse
757
+ * doesn't block the main thread when the user only ever cares about the
758
+ * conversation.
759
+ */
760
+ private _eventsFetched = false;
761
+ /**
762
+ * Tracks whether we've fetched state for the current thread yet. Same
763
+ * lazy-load reasoning as `_eventsFetched`.
764
+ */
765
+ private _stateFetched = false;
766
+ private _lastFetchedThreadId: string | null = null;
767
+ private _lastSeenLiveMessageVersion = 0;
768
+ private _messagesAbort: AbortController | null = null;
769
+ private _eventsAbort: AbortController | null = null;
770
+ private _stateAbort: AbortController | null = null;
771
+ private _dividerResizing = false;
772
+ private _dividerPointerId = -1;
773
+ private _dividerStartX = 0;
774
+ private _dividerStartWidth = 0;
775
+
776
+ static readonly COLLAPSE_THRESHOLD = 800;
777
+ private static readonly TAB_LIST: ReadonlyArray<{
778
+ id: ThreadDetailsTab;
779
+ label: string;
780
+ }> = [
781
+ { id: "conversation", label: "Conversation" },
782
+ { id: "agent-state", label: "Agent State" },
783
+ { id: "ag-ui-events", label: "AG-UI Events" },
784
+ ];
785
+
786
+ private renderTabContent(id: ThreadDetailsTab): TemplateResult {
787
+ if (id === "conversation") return this.renderConversation();
788
+ if (id === "agent-state") return this.renderState();
789
+ return this.renderEvents();
790
+ }
791
+
792
+ private activateTab(id: ThreadDetailsTab): void {
793
+ if (this._tab === id) return;
794
+ const isFirstActivation = !this._activatedTabs.has(id);
795
+ this._tab = id;
796
+ if (isFirstActivation) {
797
+ // First time opening this tab: paint a "Loading…" overlay for one
798
+ // frame so the tab highlight + spinner appear before the heavy
799
+ // per-tab render runs (events list, state JSON). The rAF batches
800
+ // mounting the panel into `_activatedTabs` and clearing the spinner
801
+ // into a single subsequent paint. Subsequent activations are pure
802
+ // CSS toggles via display:none on the already-mounted panel — no
803
+ // re-render required.
804
+ this._panelInitializing = true;
805
+ requestAnimationFrame(() => {
806
+ this._activatedTabs = new Set([...this._activatedTabs, id]);
807
+ this._panelInitializing = false;
808
+ });
809
+ }
810
+ this.maybeFetchTabData(id);
811
+ }
812
+
813
+ private maybeFetchTabData(id: ThreadDetailsTab): void {
814
+ // Lazy-trigger the events / state fetches so their (potentially huge)
815
+ // JSON.parse only blocks the main thread after the user has shown
816
+ // intent to view that sub-tab. Without lazy-load, the eager fetch runs
817
+ // as soon as the thread opens and a single large response can stall
818
+ // the entire panel for seconds — including making the tab buttons
819
+ // themselves feel unresponsive.
820
+ if (!this.threadId) return;
821
+ if (id === "ag-ui-events" && !this._eventsFetched) {
822
+ this._eventsFetched = true;
823
+ void this.fetchEvents(this.threadId);
824
+ } else if (id === "agent-state" && !this._stateFetched) {
825
+ this._stateFetched = true;
826
+ void this.fetchState(this.threadId);
827
+ }
828
+ }
829
+
830
+ static styles = css`
831
+ @import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600&family=Spline+Sans+Mono:wght@400;500&display=swap");
832
+
833
+ /* ── Root ────────────────────────────────────────────────────────── */
834
+ :host {
835
+ display: flex;
836
+ flex-direction: row;
837
+ overflow: hidden;
838
+ }
839
+
840
+ .cpk-td {
841
+ font-family: "Plus Jakarta Sans", sans-serif;
842
+ font-size: 13px;
843
+ display: flex;
844
+ flex-direction: row;
845
+ width: 100%;
846
+ height: 100%;
847
+ overflow: hidden;
848
+ background: #ffffff;
849
+ }
850
+
851
+ /* ── Left area ───────────────────────────────────────────────────── */
852
+ .cpk-td__left {
853
+ flex: 1;
854
+ min-width: 0;
855
+ display: flex;
856
+ flex-direction: column;
857
+ overflow: hidden;
858
+ }
859
+
860
+ /* ── Tab bar header ──────────────────────────────────────────────── */
861
+ .cpk-td__tabs-header {
862
+ /* No top/right padding so tabs and toggle sit flush against the
863
+ top and right edges of the inspector. */
864
+ padding: 0 0 0 12px;
865
+ border-bottom: 1px solid #dbdbe5;
866
+ flex-shrink: 0;
867
+ display: flex;
868
+ align-items: stretch;
869
+ }
870
+
871
+ .cpk-td__tab-group {
872
+ display: flex;
873
+ gap: 0;
874
+ margin-bottom: -1px;
875
+ /* Allow the tab list to shrink rather than pushing the panel-toggle
876
+ button past the right edge of the inspector when horizontal space
877
+ gets tight (the drawer being open eats noticeably into width). */
878
+ min-width: 0;
879
+ flex-shrink: 1;
880
+ overflow: hidden;
881
+ }
882
+
883
+ .cpk-td__tab {
884
+ font-family: "Plus Jakarta Sans", sans-serif;
885
+ font-size: 11px;
886
+ font-weight: 500;
887
+ padding: 10px 12px;
888
+ border: none;
889
+ border-bottom: 2px solid transparent;
890
+ cursor: pointer;
891
+ background: transparent;
892
+ color: #838389;
893
+ transition:
894
+ color 0.12s,
895
+ border-color 0.12s;
896
+ white-space: nowrap;
897
+ }
898
+
899
+ .cpk-td__tab:hover {
900
+ color: #010507;
901
+ }
902
+
903
+ .cpk-td__tab--active {
904
+ color: #010507;
905
+ border-bottom-color: #bec2ff;
906
+ }
907
+
908
+ /* Toggle is a separate control, not a tab — so it does NOT use the
909
+ tabs' bottom-border active indicator. Instead, a subtle filled
910
+ state communicates "the drawer is open," and a vertical separator
911
+ on the left visually divorces it from the tab group. */
912
+ .cpk-td__panel-toggle {
913
+ margin-left: auto;
914
+ align-self: stretch;
915
+ display: flex;
916
+ align-items: center;
917
+ justify-content: center;
918
+ padding: 0 12px;
919
+ border: none;
920
+ border-left: 1px solid #dbdbe5;
921
+ background: transparent;
922
+ color: #838389;
923
+ cursor: pointer;
924
+ flex-shrink: 0;
925
+ transition:
926
+ color 0.12s,
927
+ background 0.12s;
928
+ }
929
+ .cpk-td__panel-toggle:hover {
930
+ color: #010507;
931
+ background: #f4f4f9;
932
+ }
933
+ .cpk-td__panel-toggle--active {
934
+ color: #5558b2;
935
+ background: #eee6fe;
936
+ }
937
+ .cpk-td__panel-toggle--active:hover {
938
+ background: #e4d8fc;
939
+ }
940
+
941
+ /* ── Scrollable content ──────────────────────────────────────────── */
942
+ .cpk-td__content {
943
+ flex: 1;
944
+ overflow-y: auto;
945
+ padding: 16px;
946
+ display: flex;
947
+ flex-direction: column;
948
+ gap: 8px;
949
+ }
950
+
951
+ /* Pin direct children so expanded tool bodies don't get flex-shrunk. */
952
+ .cpk-td__content > * {
953
+ flex-shrink: 0;
954
+ }
955
+
956
+ /*
957
+ * Each tab's content is wrapped in this panel so the keep-mounted
958
+ * inactive panels can be hidden via display:none without disturbing
959
+ * the gap between visible siblings. The flex column + gap gives each
960
+ * conversation item / event row breathing room (the cpk-td__content
961
+ * rule above no longer reaches them now that they are nested inside
962
+ * the per-panel wrapper).
963
+ */
964
+ .cpk-td__panel {
965
+ display: flex;
966
+ flex-direction: column;
967
+ gap: 12px;
968
+ }
969
+ .cpk-td__panel > * {
970
+ flex-shrink: 0;
971
+ }
972
+
973
+ /* ── Empty state ─────────────────────────────────────────────────── */
974
+ .cpk-td__empty-state {
975
+ flex: 1;
976
+ display: flex;
977
+ flex-direction: column;
978
+ align-items: center;
979
+ justify-content: center;
980
+ gap: 8px;
981
+ color: #838389;
982
+ font-size: 13px;
983
+ padding: 40px 0;
984
+ }
985
+
986
+ .cpk-td__empty-hint {
987
+ font-size: 11px;
988
+ color: #838389;
989
+ text-align: center;
990
+ max-width: 220px;
991
+ line-height: 1.5;
992
+ }
993
+
994
+ /* ── Status messages ─────────────────────────────────────────────── */
995
+ .cpk-td__status {
996
+ padding: 16px;
997
+ font-size: 12px;
998
+ color: #838389;
999
+ text-align: center;
1000
+ }
1001
+
1002
+ .cpk-td__status--error {
1003
+ color: #c0333a;
1004
+ }
1005
+
1006
+ /* ── Conversation bubbles ────────────────────────────────────────── */
1007
+ .cpk-td__bubble {
1008
+ display: flex;
1009
+ margin-bottom: 2px;
1010
+ }
1011
+
1012
+ .cpk-td__bubble--user {
1013
+ justify-content: flex-end;
1014
+ }
1015
+
1016
+ .cpk-td__bubble--assistant {
1017
+ justify-content: flex-start;
1018
+ }
1019
+
1020
+ .cpk-td__bubble-inner {
1021
+ padding: 9px 14px;
1022
+ max-width: 75%;
1023
+ font-size: 13px;
1024
+ line-height: 1.55;
1025
+ }
1026
+
1027
+ .cpk-td__bubble-inner--user {
1028
+ background: #eee6fe;
1029
+ color: #57575b;
1030
+ border-radius: 10px 10px 3px 10px;
1031
+ }
1032
+
1033
+ .cpk-td__show-more {
1034
+ display: inline-block;
1035
+ margin-top: 4px;
1036
+ font-size: 11px;
1037
+ font-weight: 500;
1038
+ color: #57575b;
1039
+ cursor: pointer;
1040
+ text-decoration: underline;
1041
+ text-underline-offset: 2px;
1042
+ }
1043
+
1044
+ .cpk-td__bubble-inner--assistant {
1045
+ background: #f7f7f9;
1046
+ color: #010507;
1047
+ border-radius: 10px 10px 10px 3px;
1048
+ border: 1px solid #e9e9ef;
1049
+ }
1050
+
1051
+ /* ── Tool call blocks ────────────────────────────────────────────── */
1052
+ .cpk-td__tool-block {
1053
+ border: 1px solid #e9e9ef;
1054
+ border-radius: 6px;
1055
+ overflow: hidden;
1056
+ }
1057
+
1058
+ .cpk-td__tool-header {
1059
+ display: flex;
1060
+ align-items: center;
1061
+ gap: 6px;
1062
+ padding: 6px 10px;
1063
+ background: rgba(133, 236, 206, 0.15);
1064
+ cursor: pointer;
1065
+ font-size: 11px;
1066
+ user-select: none;
1067
+ }
1068
+
1069
+ .cpk-td__tool-header:hover {
1070
+ background: rgba(133, 236, 206, 0.22);
1071
+ }
1072
+
1073
+ .cpk-td__tool-name {
1074
+ font-family: "Spline Sans Mono", monospace;
1075
+ font-size: 10px;
1076
+ font-weight: 500;
1077
+ color: #189370;
1078
+ text-transform: uppercase;
1079
+ flex: 1;
1080
+ }
1081
+
1082
+ .cpk-td__tool-status {
1083
+ font-family: "Spline Sans Mono", monospace;
1084
+ font-size: 9px;
1085
+ text-transform: uppercase;
1086
+ color: #189370;
1087
+ }
1088
+
1089
+ .cpk-td__tool-status--pending {
1090
+ color: #996300;
1091
+ }
1092
+
1093
+ .cpk-td__tool-chevron {
1094
+ color: #838389;
1095
+ font-size: 10px;
1096
+ }
1097
+
1098
+ .cpk-td__tool-body {
1099
+ padding: 8px 10px;
1100
+ border-top: 1px solid #e9e9ef;
1101
+ background: #ffffff;
1102
+ }
1103
+
1104
+ .cpk-td__tool-section-label {
1105
+ font-family: "Spline Sans Mono", monospace;
1106
+ font-size: 9px;
1107
+ font-weight: 500;
1108
+ color: #838389;
1109
+ text-transform: uppercase;
1110
+ margin-bottom: 4px;
1111
+ letter-spacing: 0.3px;
1112
+ }
1113
+
1114
+ .cpk-td__tool-pre {
1115
+ margin: 0;
1116
+ font-family: "Spline Sans Mono", monospace;
1117
+ font-size: 10px;
1118
+ background: #f7f7f9;
1119
+ padding: 6px 8px;
1120
+ border-radius: 4px;
1121
+ overflow-x: auto;
1122
+ white-space: pre-wrap;
1123
+ word-break: break-all;
1124
+ color: #010507;
1125
+ line-height: 1.6;
1126
+ }
1127
+
1128
+ /* ── Tool call group ─────────────────────────────────────────────── */
1129
+ .cpk-td__tool-group {
1130
+ border: 1px solid #e9e9ef;
1131
+ border-radius: 6px;
1132
+ overflow: hidden;
1133
+ }
1134
+
1135
+ .cpk-td__tool-group-header {
1136
+ padding: 5px 10px;
1137
+ background: rgba(133, 236, 206, 0.15);
1138
+ font-family: "Spline Sans Mono", monospace;
1139
+ font-size: 10px;
1140
+ color: #189370;
1141
+ text-transform: uppercase;
1142
+ font-weight: 500;
1143
+ border-bottom: 1px solid #e9e9ef;
1144
+ }
1145
+
1146
+ .cpk-td__tool-group .cpk-td__tool-block {
1147
+ border: none;
1148
+ border-bottom: 1px solid #e9e9ef;
1149
+ border-radius: 0;
1150
+ }
1151
+
1152
+ .cpk-td__tool-group .cpk-td__tool-block:last-child {
1153
+ border-bottom: none;
1154
+ }
1155
+
1156
+ /* ── Inline chips (reasoning / state update) ─────────────────────── */
1157
+ .cpk-td__inline-chip {
1158
+ display: flex;
1159
+ align-items: center;
1160
+ gap: 8px;
1161
+ padding: 5px 0;
1162
+ color: #838389;
1163
+ font-family: "Spline Sans Mono", monospace;
1164
+ font-size: 9px;
1165
+ text-transform: uppercase;
1166
+ }
1167
+
1168
+ .cpk-td__inline-chip::before,
1169
+ .cpk-td__inline-chip::after {
1170
+ content: "";
1171
+ flex: 1;
1172
+ height: 1px;
1173
+ background: #e9e9ef;
1174
+ }
1175
+
1176
+ /* ── Generative UI ──────────────────────────────────────────────── */
1177
+ @keyframes cpk-genui-enter {
1178
+ from {
1179
+ opacity: 0;
1180
+ transform: translateY(8px);
1181
+ }
1182
+ to {
1183
+ opacity: 1;
1184
+ transform: translateY(0);
1185
+ }
1186
+ }
1187
+
1188
+ .cpk-td__genui {
1189
+ display: flex;
1190
+ flex-direction: column;
1191
+ gap: 6px;
1192
+ padding: 4px 16px 8px;
1193
+ animation: cpk-genui-enter 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
1194
+ }
1195
+
1196
+ .cpk-td__genui-badge {
1197
+ display: inline-flex;
1198
+ align-items: center;
1199
+ gap: 4px;
1200
+ padding: 2px 8px;
1201
+ border-radius: 4px;
1202
+ background: #eee6fe;
1203
+ color: #57575b;
1204
+ font-size: 10px;
1205
+ font-weight: 600;
1206
+ align-self: flex-start;
1207
+ }
1208
+
1209
+ .cpk-td__genui-card {
1210
+ overflow: hidden;
1211
+ border-radius: 12px;
1212
+ border: 1px solid #e2e8f0;
1213
+ background: #fff;
1214
+ box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.08);
1215
+ }
1216
+
1217
+ .cpk-td__genui-placeholder {
1218
+ padding: 8px 12px;
1219
+ border-radius: 8px;
1220
+ border: 1px solid #ede9fe;
1221
+ background: #f5f3ff;
1222
+ color: #7c3aed;
1223
+ font-size: 11px;
1224
+ }
1225
+
1226
+ /* ── AG-UI Events ────────────────────────────────────────────────── */
1227
+ .cpk-td__event {
1228
+ flex-shrink: 0;
1229
+ border: 1px solid #e9e9ef;
1230
+ border-radius: 6px;
1231
+ overflow: hidden;
1232
+ /*
1233
+ * content-visibility: auto lets the browser skip layout + paint for
1234
+ * off-screen events while keeping them in the DOM (so scroll size
1235
+ * stays correct). Without this, switching back to AG-UI Events on a
1236
+ * thread with hundreds of events triggers a full layout pass over
1237
+ * every event row, which on Martha's intelligence-backed example
1238
+ * shows up as a multi-second freeze each time the panel becomes
1239
+ * visible. The intrinsic-size hint avoids the visible jump as the
1240
+ * browser swaps in real heights when items scroll into view.
1241
+ */
1242
+ content-visibility: auto;
1243
+ contain-intrinsic-size: 0 80px;
1244
+ }
1245
+
1246
+ .cpk-td__event-header {
1247
+ display: flex;
1248
+ justify-content: space-between;
1249
+ align-items: center;
1250
+ padding: 5px 10px;
1251
+ }
1252
+
1253
+ .cpk-td__event-type {
1254
+ font-family: "Spline Sans Mono", monospace;
1255
+ font-size: 9px;
1256
+ font-weight: 500;
1257
+ text-transform: uppercase;
1258
+ }
1259
+
1260
+ .cpk-td__event-time {
1261
+ font-family: "Spline Sans Mono", monospace;
1262
+ font-size: 9px;
1263
+ color: #838389;
1264
+ }
1265
+
1266
+ .cpk-td__event-payload {
1267
+ margin: 0;
1268
+ font-family: "Spline Sans Mono", monospace;
1269
+ font-size: 10px;
1270
+ line-height: 1.6;
1271
+ white-space: pre-wrap;
1272
+ word-break: break-all;
1273
+ color: #57575b;
1274
+ padding: 8px 10px;
1275
+ border-top: 1px solid #e9e9ef;
1276
+ }
1277
+
1278
+ /* ── JSON block (agent state) ────────────────────────────────────── */
1279
+ .cpk-td__json-block {
1280
+ margin: 0;
1281
+ font-family: "Spline Sans Mono", monospace;
1282
+ font-size: 11px;
1283
+ line-height: 1.8;
1284
+ white-space: pre-wrap;
1285
+ word-break: break-all;
1286
+ color: #57575b;
1287
+ }
1288
+
1289
+ /* ── Resize divider ──────────────────────────────────────────────── */
1290
+ /* Floats over the drawer's left edge so the toggle and the drawer
1291
+ touch directly without a 4px flex-gap between them. The hit zone
1292
+ is wider than its visual hint to make it easy to grab. */
1293
+ .cpk-td__detail-divider {
1294
+ position: absolute;
1295
+ top: 0;
1296
+ bottom: 0;
1297
+ left: -3px;
1298
+ width: 7px;
1299
+ cursor: col-resize;
1300
+ background: transparent;
1301
+ z-index: 5;
1302
+ }
1303
+
1304
+ .cpk-td__detail-divider:hover {
1305
+ background: rgba(190, 194, 255, 0.3);
1306
+ }
1307
+
1308
+ /* ── Right detail panel ──────────────────────────────────────────── */
1309
+ .cpk-td__detail {
1310
+ flex-shrink: 0;
1311
+ overflow: hidden;
1312
+ background: #f7f7f9;
1313
+ display: flex;
1314
+ flex-direction: column;
1315
+ gap: 0;
1316
+ padding: 0;
1317
+ box-sizing: border-box;
1318
+ position: relative;
1319
+ /* Slide open/closed via width + padding transition. When closed,
1320
+ width and padding are 0 so the drawer fully collapses. */
1321
+ transition:
1322
+ width 220ms cubic-bezier(0.4, 0, 0.2, 1),
1323
+ padding 220ms cubic-bezier(0.4, 0, 0.2, 1);
1324
+ }
1325
+
1326
+ .cpk-td__detail[data-open="true"] {
1327
+ overflow-y: auto;
1328
+ padding: 16px;
1329
+ }
1330
+
1331
+ .cpk-tdp__section-title {
1332
+ font-family: "Spline Sans Mono", monospace;
1333
+ font-size: 10px;
1334
+ font-weight: 500;
1335
+ color: #838389;
1336
+ text-transform: uppercase;
1337
+ letter-spacing: 0.6px;
1338
+ margin-bottom: 8px;
1339
+ }
1340
+
1341
+ .cpk-tdp__divider {
1342
+ height: 1px;
1343
+ background: #dbdbe5;
1344
+ margin: 14px 0;
1345
+ }
1346
+
1347
+ .cpk-tdp__row {
1348
+ display: flex;
1349
+ justify-content: space-between;
1350
+ align-items: flex-start;
1351
+ padding: 3px 0;
1352
+ gap: 8px;
1353
+ }
1354
+
1355
+ .cpk-tdp__label {
1356
+ color: #838389;
1357
+ font-size: 11px;
1358
+ white-space: nowrap;
1359
+ flex-shrink: 0;
1360
+ }
1361
+
1362
+ .cpk-tdp__value {
1363
+ color: #010507;
1364
+ font-family: "Spline Sans Mono", monospace;
1365
+ font-size: 11px;
1366
+ text-align: right;
1367
+ min-width: 0;
1368
+ }
1369
+
1370
+ .cpk-tdp__value--truncate {
1371
+ overflow: hidden;
1372
+ text-overflow: ellipsis;
1373
+ white-space: nowrap;
1374
+ max-width: 130px;
1375
+ }
1376
+
1377
+ .cpk-tdp__value--wrap {
1378
+ white-space: normal;
1379
+ word-break: break-all;
1380
+ text-align: right;
1381
+ }
1382
+ `;
1383
+
1384
+ updated(_changed: Map<string, unknown>): void {
1385
+ if (this.threadId !== this._lastFetchedThreadId) {
1386
+ this._lastFetchedThreadId = this.threadId;
1387
+ this._lastSeenLiveMessageVersion = this.liveMessageVersion;
1388
+ this._tab = "conversation";
1389
+ this._activatedTabs = new Set(["conversation"]);
1390
+ this._panelTplCache = new Map();
1391
+ this._expandedTools = new Set();
1392
+ this._expandedMessages = new Set();
1393
+ this._messagesAbort?.abort();
1394
+ this._messagesAbort = null;
1395
+ this._eventsAbort?.abort();
1396
+ this._eventsAbort = null;
1397
+ this._stateAbort?.abort();
1398
+ this._stateAbort = null;
1399
+ // Reset cleared so the next click into events/state triggers a fresh
1400
+ // fetch. Eagerly clear `_fetchedEvents` / `_fetchedState` so the empty
1401
+ // state doesn't briefly show last thread's data.
1402
+ this._eventsFetched = false;
1403
+ this._stateFetched = false;
1404
+ this._fetchedEvents = null;
1405
+ this._fetchedState = null;
1406
+
1407
+ if (this.threadId) {
1408
+ // Conversation is the default tab and shows immediately on thread
1409
+ // open, so fetch eagerly. Events and state are only visible once the
1410
+ // user clicks their sub-tab; deferring those fetches prevents a long
1411
+ // JSON.parse of a large events payload from blocking the main thread
1412
+ // before the user has even shown intent to view them.
1413
+ void this.fetchMessages(this.threadId);
1414
+ } else {
1415
+ this._conversation = [];
1416
+ }
1417
+ } else if (
1418
+ this.threadId &&
1419
+ this.liveMessageVersion !== this._lastSeenLiveMessageVersion
1420
+ ) {
1421
+ // Same thread, but the parent inspector signalled new agent-emitted
1422
+ // messages on this thread (via `liveMessageVersion`). Re-fetch the
1423
+ // canonical conversation from the runtime so streaming output flows
1424
+ // into the view without us reimplementing AG-UI → ConversationItem
1425
+ // mapping in the parent. `silent: true` so the loading-state indicator
1426
+ // doesn't flash between every streaming chunk and we keep the
1427
+ // last-good view on transient fetch errors.
1428
+ this._lastSeenLiveMessageVersion = this.liveMessageVersion;
1429
+ this._messagesAbort?.abort();
1430
+ this._messagesAbort = null;
1431
+ void this.fetchMessages(this.threadId, true);
1432
+ }
1433
+ }
1434
+
1435
+ /**
1436
+ * Fetch the canonical conversation for `threadId` from the runtime.
1437
+ *
1438
+ * `silent` is true for live re-fetches triggered by `liveMessageVersion`
1439
+ * bumps during streaming. In that mode we never toggle the loading state
1440
+ * (which would flash "Loading messages…" between every message) and we
1441
+ * keep the previous conversation on transient errors instead of blanking
1442
+ * it. Initial threadId-change fetches use the default (`silent=false`)
1443
+ * so users see an explicit loading indicator on first load.
1444
+ */
1445
+ private async fetchMessages(
1446
+ threadId: string,
1447
+ silent: boolean = false,
1448
+ ): Promise<void> {
1449
+ if (!this.runtimeUrl) {
1450
+ if (!silent) this._conversation = [];
1451
+ return;
1452
+ }
1453
+ const controller = new AbortController();
1454
+ this._messagesAbort = controller;
1455
+ if (!silent) {
1456
+ this._loadingMessages = true;
1457
+ this._messagesError = null;
1458
+ }
1459
+ try {
1460
+ const res = await fetch(
1461
+ `${this.runtimeUrl}/threads/${encodeURIComponent(threadId)}/messages`,
1462
+ { headers: { ...this.headers }, signal: controller.signal },
1463
+ );
1464
+ if (controller.signal.aborted || this.threadId !== threadId) return;
1465
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
1466
+ const data = (await res.json()) as { messages: ApiThreadMessage[] };
1467
+ if (controller.signal.aborted || this.threadId !== threadId) return;
1468
+ this._conversation = this.mapMessages(data.messages);
1469
+ } catch (err) {
1470
+ if (err instanceof Error && err.name === "AbortError") return;
1471
+ if (!silent) {
1472
+ this._messagesError =
1473
+ err instanceof Error ? err.message : "Failed to load messages";
1474
+ this._conversation = [];
1475
+ }
1476
+ // Silent mode: keep last-good conversation, don't surface the error.
1477
+ // The next successful live re-fetch will recover automatically.
1478
+ } finally {
1479
+ if (!silent && !controller.signal.aborted) {
1480
+ this._loadingMessages = false;
1481
+ }
1482
+ }
1483
+ }
1484
+
1485
+ private async fetchEvents(threadId: string): Promise<void> {
1486
+ this._eventsNotAvailable = false;
1487
+ if (!this.runtimeUrl) {
1488
+ this._fetchedEvents = null;
1489
+ return;
1490
+ }
1491
+ const controller = new AbortController();
1492
+ this._eventsAbort = controller;
1493
+ this._loadingEvents = true;
1494
+ this._eventsError = null;
1495
+ try {
1496
+ const res = await fetch(
1497
+ `${this.runtimeUrl}/threads/${encodeURIComponent(threadId)}/events`,
1498
+ { headers: { ...this.headers }, signal: controller.signal },
1499
+ );
1500
+ // Drop results if a newer fetch superseded this one (thread switched
1501
+ // mid-flight). Without this, switching A→B can leave thread B's view
1502
+ // showing thread A's events when A's request resolves last.
1503
+ if (controller.signal.aborted || this.threadId !== threadId) return;
1504
+ if (res.status === 501) {
1505
+ // Endpoint not supported on this runtime (e.g. Intelligence platform).
1506
+ // Mark unavailable so we don't misleadingly fall back to the parent's
1507
+ // live agent events — those are agent-keyed, not thread-keyed, and
1508
+ // would render identical across every thread on the same agent.
1509
+ this._eventsNotAvailable = true;
1510
+ this._fetchedEvents = null;
1511
+ return;
1512
+ }
1513
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
1514
+ const data = (await res.json()) as {
1515
+ events: Array<Record<string, unknown>>;
1516
+ };
1517
+ if (controller.signal.aborted || this.threadId !== threadId) return;
1518
+ this._fetchedEvents = this.mapApiEvents(data.events);
1519
+ } catch (err) {
1520
+ if (err instanceof Error && err.name === "AbortError") return;
1521
+ if (this.threadId !== threadId) return;
1522
+ this._eventsError =
1523
+ err instanceof Error ? err.message : "Failed to load events";
1524
+ this._fetchedEvents = [];
1525
+ } finally {
1526
+ if (!controller.signal.aborted && this.threadId === threadId) {
1527
+ this._loadingEvents = false;
1528
+ }
1529
+ }
1530
+ }
1531
+
1532
+ private async fetchState(threadId: string): Promise<void> {
1533
+ this._stateNotAvailable = false;
1534
+ if (!this.runtimeUrl) {
1535
+ this._fetchedState = null;
1536
+ return;
1537
+ }
1538
+ const controller = new AbortController();
1539
+ this._stateAbort = controller;
1540
+ this._loadingState = true;
1541
+ this._stateError = null;
1542
+ try {
1543
+ const res = await fetch(
1544
+ `${this.runtimeUrl}/threads/${encodeURIComponent(threadId)}/state`,
1545
+ { headers: { ...this.headers }, signal: controller.signal },
1546
+ );
1547
+ if (controller.signal.aborted || this.threadId !== threadId) return;
1548
+ if (res.status === 501) {
1549
+ this._stateNotAvailable = true;
1550
+ this._fetchedState = null;
1551
+ return;
1552
+ }
1553
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
1554
+ const data = (await res.json()) as {
1555
+ state: Record<string, unknown> | null;
1556
+ };
1557
+ if (controller.signal.aborted || this.threadId !== threadId) return;
1558
+ this._fetchedState = data.state ?? null;
1559
+ } catch (err) {
1560
+ if (err instanceof Error && err.name === "AbortError") return;
1561
+ if (this.threadId !== threadId) return;
1562
+ this._stateError =
1563
+ err instanceof Error ? err.message : "Failed to load state";
1564
+ this._fetchedState = null;
1565
+ } finally {
1566
+ if (!controller.signal.aborted && this.threadId === threadId) {
1567
+ this._loadingState = false;
1568
+ }
1569
+ }
1570
+ }
1571
+
1572
+ private mapMessages(messages: ApiThreadMessage[]): ConversationItem[] {
1573
+ const items: ConversationItem[] = [];
1574
+ const toolCallMap = new Map<string, ConversationToolCall>();
1575
+ for (const msg of messages) {
1576
+ if (msg.role === "user" && msg.content) {
1577
+ items.push({
1578
+ id: msg.id,
1579
+ type: "user",
1580
+ content: msg.content,
1581
+ createdAt: "",
1582
+ });
1583
+ } else if (msg.role === "assistant") {
1584
+ if (msg.toolCalls?.length) {
1585
+ for (const tc of msg.toolCalls) {
1586
+ let args: Record<string, unknown> = {};
1587
+ try {
1588
+ args = JSON.parse(tc.args) as Record<string, unknown>;
1589
+ } catch (err) {
1590
+ // Inspector is a debugging surface — surface malformed payloads
1591
+ // instead of silently substituting `{}`. The sentinel lets the
1592
+ // renderer flag "raw arguments — failed to parse" if/when it
1593
+ // grows that branch; the console.error gives anyone with the
1594
+ // devtools open immediate visibility into the offending blob.
1595
+ console.error(
1596
+ "[CopilotKit Inspector] Failed to parse tool-call arguments",
1597
+ { toolCallId: tc.id, raw: tc.args, error: err },
1598
+ );
1599
+ args = { __parseError: true, __raw: tc.args };
1600
+ }
1601
+ const item: ConversationToolCall = {
1602
+ id: tc.id,
1603
+ type: "tool_call",
1604
+ toolName: tc.name,
1605
+ toolCallId: tc.id,
1606
+ arguments: args,
1607
+ result: null,
1608
+ createdAt: "",
1609
+ };
1610
+ toolCallMap.set(tc.id, item);
1611
+ items.push(item);
1612
+ }
1613
+ }
1614
+ if (msg.content) {
1615
+ items.push({
1616
+ id: msg.id,
1617
+ type: "assistant",
1618
+ content: msg.content,
1619
+ createdAt: "",
1620
+ });
1621
+ }
1622
+ } else if (msg.role === "activity") {
1623
+ items.push({
1624
+ id: msg.id,
1625
+ type: "generative-ui",
1626
+ activityType: msg.activityType ?? "unknown",
1627
+ createdAt: "",
1628
+ });
1629
+ } else if (msg.role === "tool" && msg.toolCallId) {
1630
+ const tc = toolCallMap.get(msg.toolCallId);
1631
+ if (tc) {
1632
+ try {
1633
+ tc.result = JSON.parse(msg.content ?? "{}") as Record<
1634
+ string,
1635
+ unknown
1636
+ >;
1637
+ } catch (err) {
1638
+ // See the comment on the assistant tool-call args parse above —
1639
+ // same rationale, same sentinel shape so the renderer can treat
1640
+ // both consistently.
1641
+ console.error(
1642
+ "[CopilotKit Inspector] Failed to parse tool-call result content",
1643
+ { toolCallId: msg.toolCallId, raw: msg.content, error: err },
1644
+ );
1645
+ tc.result = { __parseError: true, __raw: msg.content ?? null };
1646
+ }
1647
+ }
1648
+ }
1649
+ }
1650
+ return items;
1651
+ }
1652
+
1653
+ private mapApiEvents(
1654
+ events: Array<Record<string, unknown>>,
1655
+ ): ApiAgentEvent[] {
1656
+ return events.map((event) => {
1657
+ const { type, timestamp, ...rest } = event;
1658
+ return {
1659
+ type: typeof type === "string" ? type : "UNKNOWN",
1660
+ timestamp:
1661
+ typeof timestamp === "string" || typeof timestamp === "number"
1662
+ ? timestamp
1663
+ : Date.now(),
1664
+ payload: rest,
1665
+ };
1666
+ });
1667
+ }
1668
+
1669
+ private get renderItems(): RenderItem[] {
1670
+ const items = this._conversation;
1671
+ const result: RenderItem[] = [];
1672
+ const seen = new Set<string>();
1673
+ for (const item of items) {
1674
+ if (item.type === "agent_responded") continue;
1675
+ if (item.type !== "tool_call" || !item.groupId) {
1676
+ result.push(item);
1677
+ continue;
1678
+ }
1679
+ if (seen.has(item.groupId)) continue;
1680
+ seen.add(item.groupId);
1681
+ const group: ToolCallGroup = {
1682
+ type: "tool_call_group",
1683
+ id: item.groupId,
1684
+ items: items.filter(
1685
+ (i): i is ConversationToolCall =>
1686
+ i.type === "tool_call" && i.groupId === item.groupId,
1687
+ ),
1688
+ };
1689
+ result.push(group);
1690
+ }
1691
+ return result;
1692
+ }
1693
+
1694
+ private get activityCounts(): {
1695
+ messages: number;
1696
+ toolCalls: number;
1697
+ generativeUi: number;
1698
+ } {
1699
+ let messages = 0;
1700
+ let toolCalls = 0;
1701
+ let generativeUi = 0;
1702
+ for (const item of this._conversation) {
1703
+ if (item.type === "user" || item.type === "assistant") messages++;
1704
+ if (item.type === "tool_call") toolCalls++;
1705
+ if (item.type === "generative-ui") generativeUi++;
1706
+ }
1707
+ return { messages, toolCalls, generativeUi };
1708
+ }
1709
+
1710
+ private get duration(): string {
1711
+ const t = this.thread;
1712
+ if (!t?.createdAt || !t?.updatedAt) return "—";
1713
+ const ms =
1714
+ new Date(t.updatedAt).getTime() - new Date(t.createdAt).getTime();
1715
+ if (ms < 0) return "—";
1716
+ if (ms < 1000) return `${ms}ms`;
1717
+ const s = Math.floor(ms / 1000);
1718
+ if (s < 60) return `${s}s`;
1719
+ const m = Math.floor(s / 60);
1720
+ const rs = s % 60;
1721
+ return `${m}m ${rs}s`;
1722
+ }
1723
+
1724
+ private toggleToolExpand(id: string): void {
1725
+ const next = new Set(this._expandedTools);
1726
+ if (next.has(id)) next.delete(id);
1727
+ else next.add(id);
1728
+ this._expandedTools = next;
1729
+ }
1730
+
1731
+ private toggleMessageExpand(id: string): void {
1732
+ const next = new Set(this._expandedMessages);
1733
+ if (next.has(id)) next.delete(id);
1734
+ else next.add(id);
1735
+ this._expandedMessages = next;
1736
+ }
1737
+
1738
+ private get activeEvents(): ApiAgentEvent[] {
1739
+ // When the endpoint explicitly returned 501 we report no events rather
1740
+ // than leaking the parent's agent-keyed live events across historical
1741
+ // threads (those would render identically for every thread on the same
1742
+ // agent and mislead the reader).
1743
+ if (this._eventsNotAvailable) return [];
1744
+ return this._fetchedEvents ?? this.agentEventsInput ?? [];
1745
+ }
1746
+
1747
+ private get activeState(): Record<string, unknown> | null {
1748
+ if (this._stateNotAvailable) return null;
1749
+ return this._fetchedState ?? this.agentStateInput ?? null;
1750
+ }
1751
+
1752
+ private hasRenderableState(): boolean {
1753
+ const s = this.activeState;
1754
+ return !!s && typeof s === "object" && Object.keys(s).length > 0;
1755
+ }
1756
+
1757
+ private shortId(id: string | null | undefined): string {
1758
+ if (!id) return "—";
1759
+ return id.length > 20 ? id.slice(0, 8) + "…" : id;
1760
+ }
1761
+
1762
+ private fmtTime(dateStr: string | null | undefined): string {
1763
+ if (!dateStr) return "—";
1764
+ const d = new Date(dateStr);
1765
+ if (Number.isNaN(d.getTime())) return "—";
1766
+ return d.toLocaleTimeString("en-US", {
1767
+ hour: "2-digit",
1768
+ minute: "2-digit",
1769
+ second: "2-digit",
1770
+ hour12: false,
1771
+ });
1772
+ }
1773
+
1774
+ private onDetailDividerDown = (event: PointerEvent): void => {
1775
+ this._dividerResizing = true;
1776
+ this._dividerPointerId = event.pointerId;
1777
+ this._dividerStartX = event.clientX;
1778
+ this._dividerStartWidth = this._detailPanelWidth;
1779
+ (event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
1780
+ event.preventDefault();
1781
+ };
1782
+
1783
+ private onDetailDividerMove = (event: PointerEvent): void => {
1784
+ if (!this._dividerResizing || this._dividerPointerId !== event.pointerId)
1785
+ return;
1786
+ const delta = this._dividerStartX - event.clientX;
1787
+ this._detailPanelWidth = Math.max(
1788
+ 160,
1789
+ Math.min(400, this._dividerStartWidth + delta),
1790
+ );
1791
+ };
1792
+
1793
+ private onDetailDividerUp = (event: PointerEvent): void => {
1794
+ if (this._dividerPointerId !== event.pointerId) return;
1795
+ const target = event.currentTarget as HTMLElement;
1796
+ if (target.hasPointerCapture(this._dividerPointerId)) {
1797
+ target.releasePointerCapture(this._dividerPointerId);
1798
+ }
1799
+ this._dividerResizing = false;
1800
+ };
1801
+
1802
+ render() {
1803
+ return html`
1804
+ <div class="cpk-td">
1805
+ <!-- ── Left area: tabs + content ─────────────────────────────────── -->
1806
+ <div class="cpk-td__left">
1807
+ <!-- Tab bar -->
1808
+ <div class="cpk-td__tabs-header">
1809
+ <div class="cpk-td__tab-group" role="tablist">
1810
+ ${ɵCpkThreadDetails.TAB_LIST.map(
1811
+ (tab) => html`
1812
+ <button
1813
+ role="tab"
1814
+ class="cpk-td__tab ${
1815
+ this._tab === tab.id ? "cpk-td__tab--active" : ""
1816
+ }"
1817
+ @click=${() => this.activateTab(tab.id)}
1818
+ >
1819
+ ${tab.label}
1820
+ </button>
1821
+ `,
1822
+ )}
1823
+ </div>
1824
+ ${this.renderPanelToggle()}
1825
+ </div>
1826
+
1827
+ <!-- Scrollable content -->
1828
+ <div class="cpk-td__content">
1829
+ ${
1830
+ this._panelInitializing
1831
+ ? html`
1832
+ <div class="cpk-td__status">Loading…</div>
1833
+ `
1834
+ : nothing
1835
+ }
1836
+ ${ɵCpkThreadDetails.TAB_LIST.map((tab) =>
1837
+ this._activatedTabs.has(tab.id)
1838
+ ? html`<div
1839
+ class="cpk-td__panel"
1840
+ style=${
1841
+ this._tab === tab.id && !this._panelInitializing
1842
+ ? ""
1843
+ : "display:none"
1844
+ }
1845
+ >
1846
+ ${this.renderTabContent(tab.id)}
1847
+ </div>`
1848
+ : nothing,
1849
+ )}
1850
+ </div>
1851
+ </div>
1852
+
1853
+ <!--
1854
+ Drawer always rendered so width animates between 0 and its
1855
+ target. Divider lives INSIDE the drawer and is absolutely
1856
+ positioned over its left edge so the toggle (rightmost of the
1857
+ tab row) and the drawer touch with no flex-gap between them.
1858
+ -->
1859
+ <div
1860
+ class="cpk-td__detail"
1861
+ data-open=${this._showDetailPanel ? "true" : "false"}
1862
+ style="width:${this._showDetailPanel ? this._detailPanelWidth : 0}px"
1863
+ aria-hidden=${this._showDetailPanel ? "false" : "true"}
1864
+ >
1865
+ ${
1866
+ this._showDetailPanel
1867
+ ? html`
1868
+ <div
1869
+ class="cpk-td__detail-divider"
1870
+ @pointerdown=${this.onDetailDividerDown}
1871
+ @pointermove=${this.onDetailDividerMove}
1872
+ @pointerup=${this.onDetailDividerUp}
1873
+ @pointercancel=${this.onDetailDividerUp}
1874
+ ></div>
1875
+ `
1876
+ : nothing
1877
+ }
1878
+ ${this.renderDetailPanel()}
1879
+ </div>
1880
+ </div>
1881
+ `;
1882
+ }
1883
+
1884
+ private renderConversation() {
1885
+ if (this._loadingMessages) {
1886
+ return html`
1887
+ <div class="cpk-td__status">Loading messages…</div>
1888
+ `;
1889
+ }
1890
+ if (this._messagesError) {
1891
+ return html`<div class="cpk-td__status cpk-td__status--error">
1892
+ ${this._messagesError}
1893
+ </div>`;
1894
+ }
1895
+ if (this._conversation.length === 0) {
1896
+ return html`
1897
+ <div class="cpk-td__empty-state">
1898
+ <svg
1899
+ width="28"
1900
+ height="28"
1901
+ viewBox="0 0 24 24"
1902
+ fill="none"
1903
+ stroke="currentColor"
1904
+ stroke-width="1.5"
1905
+ stroke-linecap="round"
1906
+ stroke-linejoin="round"
1907
+ >
1908
+ <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
1909
+ </svg>
1910
+ <span>No messages yet</span>
1911
+ </div>
1912
+ `;
1913
+ }
1914
+ // Expand state is part of the cache key because clicking a tool-call
1915
+ // header or the "Show more" button on a long message replaces
1916
+ // `_expandedTools` / `_expandedMessages` without touching
1917
+ // `_conversation` — without those keys the cache returns the
1918
+ // pre-toggle template and the disclosure appears broken.
1919
+ return this.cachedPanelTpl(
1920
+ "conversation",
1921
+ [this._conversation, this._expandedTools, this._expandedMessages],
1922
+ () => {
1923
+ const items = this.renderItems;
1924
+ return html`${items.map((item) => this.renderRenderItem(item))}`;
1925
+ },
1926
+ );
1927
+ }
1928
+
1929
+ /**
1930
+ * Memoize the rendered TemplateResult for `slot` keyed by tuple
1931
+ * element-wise reference equality. The hot path for tab switches: when
1932
+ * the underlying data hasn't changed, return the previously built
1933
+ * TemplateResult so Lit's diff short-circuits. Each panel's `key` is
1934
+ * the tuple of inputs the template reads — pass everything the template
1935
+ * depends on, or the cache will return stale output when those inputs
1936
+ * change without the listed key flipping.
1937
+ */
1938
+ private cachedPanelTpl(
1939
+ slot: ThreadDetailsTab,
1940
+ key: readonly unknown[],
1941
+ build: () => TemplateResult,
1942
+ ): TemplateResult {
1943
+ const cached = this._panelTplCache.get(slot);
1944
+ if (
1945
+ cached &&
1946
+ cached.key.length === key.length &&
1947
+ cached.key.every((v, i) => v === key[i])
1948
+ ) {
1949
+ return cached.tpl;
1950
+ }
1951
+ const tpl = build();
1952
+ this._panelTplCache.set(slot, { key, tpl });
1953
+ return tpl;
1954
+ }
1955
+
1956
+ private renderRenderItem(item: RenderItem) {
1957
+ switch (item.type) {
1958
+ case "user":
1959
+ case "assistant":
1960
+ return this.renderBubble(item);
1961
+ case "tool_call":
1962
+ return this.renderToolBlock(item);
1963
+ case "tool_call_group":
1964
+ return this.renderToolGroup(item);
1965
+ case "reasoning":
1966
+ return html`<div class="cpk-td__inline-chip">
1967
+ <span>Reasoned for ${item.duration}</span>
1968
+ </div>`;
1969
+ case "state_update":
1970
+ return html`
1971
+ <div class="cpk-td__inline-chip">
1972
+ <span>Updated agent state</span>
1973
+ </div>
1974
+ `;
1975
+ case "generative-ui":
1976
+ return this.renderGenerativeUI(item);
1977
+ case "agent_responded":
1978
+ return nothing;
1979
+ }
1980
+ }
1981
+
1982
+ private renderBubble(item: ConversationUser | ConversationAssistant) {
1983
+ const isUser = item.type === "user";
1984
+ const threshold = ɵCpkThreadDetails.COLLAPSE_THRESHOLD;
1985
+ const expanded = this._expandedMessages.has(item.id);
1986
+ const tooLong = item.content.length > threshold;
1987
+ const shown =
1988
+ tooLong && !expanded
1989
+ ? item.content.slice(0, threshold) + "…"
1990
+ : item.content;
1991
+ return html`
1992
+ <div
1993
+ class="cpk-td__bubble ${
1994
+ isUser ? "cpk-td__bubble--user" : "cpk-td__bubble--assistant"
1995
+ }"
1996
+ >
1997
+ <div
1998
+ class="cpk-td__bubble-inner ${
1999
+ isUser
2000
+ ? "cpk-td__bubble-inner--user"
2001
+ : "cpk-td__bubble-inner--assistant"
2002
+ }"
2003
+ >
2004
+ ${shown}
2005
+ ${
2006
+ tooLong
2007
+ ? html`<span
2008
+ class="cpk-td__show-more"
2009
+ @click=${() => this.toggleMessageExpand(item.id)}
2010
+ >${expanded ? "Show less" : "Show more"}</span
2011
+ >`
2012
+ : nothing
2013
+ }
2014
+ </div>
2015
+ </div>
2016
+ `;
2017
+ }
2018
+
2019
+ private renderToolBlock(item: ConversationToolCall) {
2020
+ const expanded = this._expandedTools.has(item.id);
2021
+ return html`
2022
+ <div class="cpk-td__tool-block">
2023
+ <div
2024
+ class="cpk-td__tool-header"
2025
+ @click=${() => this.toggleToolExpand(item.id)}
2026
+ >
2027
+ <svg width="10" height="10" viewBox="0 0 10 10" fill="none">
2028
+ <path
2029
+ d="M1 9C1 9 2 7 5 7C8 7 9 9 9 9M5 1C5 1 7 2.5 7 4.5C7 6.5 5 7 5 7C5 7 3 6.5 3 4.5C3 2.5 5 1 5 1Z"
2030
+ stroke="#189370"
2031
+ stroke-width="1.2"
2032
+ stroke-linecap="round"
2033
+ stroke-linejoin="round"
2034
+ />
2035
+ </svg>
2036
+ <span class="cpk-td__tool-name">${item.toolName}</span>
2037
+ ${
2038
+ item.result || Object.keys(item.arguments).length > 0
2039
+ ? html`
2040
+ <span class="cpk-td__tool-status">DONE</span>
2041
+ `
2042
+ : html`
2043
+ <span class="cpk-td__tool-status cpk-td__tool-status--pending">PENDING</span>
2044
+ `
2045
+ }
2046
+ <span class="cpk-td__tool-chevron">${expanded ? "▾" : "▸"}</span>
2047
+ </div>
2048
+ ${
2049
+ expanded
2050
+ ? html`
2051
+ <div class="cpk-td__tool-body">
2052
+ <div class="cpk-td__tool-section-label">Arguments</div>
2053
+ <pre class="cpk-td__tool-pre">
2054
+ ${unsafeHTML(highlightedJson(item.arguments))}</pre
2055
+ >
2056
+ ${
2057
+ item.result
2058
+ ? html`
2059
+ <div
2060
+ class="cpk-td__tool-section-label"
2061
+ style="margin-top:8px"
2062
+ >
2063
+ Result
2064
+ </div>
2065
+ <pre class="cpk-td__tool-pre">
2066
+ ${unsafeHTML(highlightedJson(item.result))}</pre
2067
+ >
2068
+ `
2069
+ : nothing
2070
+ }
2071
+ </div>
2072
+ `
2073
+ : nothing
2074
+ }
2075
+ </div>
2076
+ `;
2077
+ }
2078
+
2079
+ private renderToolGroup(group: ToolCallGroup) {
2080
+ return html`
2081
+ <div class="cpk-td__tool-group">
2082
+ <div class="cpk-td__tool-group-header">
2083
+ ${group.items.length} tool call${group.items.length !== 1 ? "s" : ""}
2084
+ </div>
2085
+ ${group.items.map((tc) => this.renderToolBlock(tc))}
2086
+ </div>
2087
+ `;
2088
+ }
2089
+
2090
+ private renderGenerativeUI(item: ConversationGenerativeUIItem) {
2091
+ return html`
2092
+ <div class="cpk-td__genui">
2093
+ <div class="cpk-td__genui-badge">
2094
+ <svg width="9" height="9" viewBox="0 0 24 24" fill="currentColor">
2095
+ <path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z" />
2096
+ </svg>
2097
+ Generative UI
2098
+ </div>
2099
+ <div class="cpk-td__genui-placeholder">
2100
+ ${item.activityType} — rendered in chat
2101
+ </div>
2102
+ </div>
2103
+ `;
2104
+ }
2105
+
2106
+ private renderState() {
2107
+ if (this._loadingState) {
2108
+ return html`
2109
+ <div class="cpk-td__status">Loading state…</div>
2110
+ `;
2111
+ }
2112
+ if (this._stateError) {
2113
+ return html`<div class="cpk-td__status cpk-td__status--error">
2114
+ ${this._stateError}
2115
+ </div>`;
2116
+ }
2117
+ if (this._stateNotAvailable) {
2118
+ return html`
2119
+ <div class="cpk-td__empty-state">
2120
+ <svg
2121
+ width="28"
2122
+ height="28"
2123
+ viewBox="0 0 24 24"
2124
+ fill="none"
2125
+ stroke="currentColor"
2126
+ stroke-width="1.5"
2127
+ stroke-linecap="round"
2128
+ stroke-linejoin="round"
2129
+ >
2130
+ <ellipse cx="12" cy="5" rx="9" ry="3" />
2131
+ <path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3" />
2132
+ <path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5" />
2133
+ </svg>
2134
+ <span>State history not available</span>
2135
+ <span class="cpk-td__empty-hint"
2136
+ >This runtime doesn't yet expose per-thread agent state. Available when
2137
+ running against the in-memory runner.</span
2138
+ >
2139
+ </div>
2140
+ `;
2141
+ }
2142
+ if (!this.hasRenderableState()) {
2143
+ return html`
2144
+ <div class="cpk-td__empty-state">
2145
+ <svg
2146
+ width="28"
2147
+ height="28"
2148
+ viewBox="0 0 24 24"
2149
+ fill="none"
2150
+ stroke="currentColor"
2151
+ stroke-width="1.5"
2152
+ stroke-linecap="round"
2153
+ stroke-linejoin="round"
2154
+ >
2155
+ <ellipse cx="12" cy="5" rx="9" ry="3" />
2156
+ <path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3" />
2157
+ <path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5" />
2158
+ </svg>
2159
+ <span>No state captured</span>
2160
+ <span class="cpk-td__empty-hint"
2161
+ >Emitted live from STATE_SNAPSHOT events.</span
2162
+ >
2163
+ </div>
2164
+ `;
2165
+ }
2166
+ const stateValue = this.activeState;
2167
+ return this.cachedPanelTpl("agent-state", [stateValue], () => {
2168
+ return html`<pre class="cpk-td__json-block">
2169
+ ${unsafeHTML(highlightedJson(stateValue))}</pre
2170
+ >`;
2171
+ });
2172
+ }
2173
+
2174
+ private renderEvents() {
2175
+ if (this._loadingEvents) {
2176
+ return html`
2177
+ <div class="cpk-td__status">Loading events…</div>
2178
+ `;
2179
+ }
2180
+ if (this._eventsError) {
2181
+ return html`<div class="cpk-td__status cpk-td__status--error">
2182
+ ${this._eventsError}
2183
+ </div>`;
2184
+ }
2185
+ if (this._eventsNotAvailable) {
2186
+ return html`
2187
+ <div class="cpk-td__empty-state">
2188
+ <span>Event history not available</span>
2189
+ <span class="cpk-td__empty-hint"
2190
+ >This runtime doesn't yet expose per-thread AG-UI events. Available when
2191
+ running against the in-memory runner.</span
2192
+ >
2193
+ </div>
2194
+ `;
2195
+ }
2196
+ const events = this.activeEvents;
2197
+ if (events.length === 0) {
2198
+ return html`
2199
+ <div class="cpk-td__empty-state">
2200
+ <span>No events captured</span>
2201
+ <span class="cpk-td__empty-hint"
2202
+ >Events are recorded live. Run the agent to see them here.</span
2203
+ >
2204
+ </div>
2205
+ `;
2206
+ }
2207
+ return this.cachedPanelTpl("ag-ui-events", [events], () => {
2208
+ return html`${events.map((event) => {
2209
+ const { bg, fg } = eventColors(event.type);
2210
+ return html`
2211
+ <div class="cpk-td__event">
2212
+ <div class="cpk-td__event-header" style="background:${bg}">
2213
+ <span class="cpk-td__event-type" style="color:${fg}"
2214
+ >${event.type}</span
2215
+ >
2216
+ <span class="cpk-td__event-time"
2217
+ >${formatTimestamp(event.timestamp)}</span
2218
+ >
2219
+ </div>
2220
+ <pre class="cpk-td__event-payload">
2221
+ ${unsafeHTML(highlightedJson(event.payload))}</pre
2222
+ >
2223
+ </div>
2224
+ `;
2225
+ })}`;
2226
+ });
2227
+ }
2228
+
2229
+ private renderPanelToggle() {
2230
+ return html`
2231
+ <button
2232
+ class="cpk-td__panel-toggle ${
2233
+ this._showDetailPanel ? "cpk-td__panel-toggle--active" : ""
2234
+ }"
2235
+ @click=${() => {
2236
+ this._showDetailPanel = !this._showDetailPanel;
2237
+ }}
2238
+ title="Toggle thread details"
2239
+ type="button"
2240
+ >
2241
+ <svg
2242
+ width="14"
2243
+ height="14"
2244
+ viewBox="0 0 24 24"
2245
+ fill="none"
2246
+ stroke="currentColor"
2247
+ stroke-width="2"
2248
+ stroke-linecap="round"
2249
+ stroke-linejoin="round"
2250
+ >
2251
+ <rect x="3" y="3" width="18" height="18" rx="2" />
2252
+ <line x1="15" y1="3" x2="15" y2="21" />
2253
+ </svg>
2254
+ </button>
2255
+ `;
2256
+ }
2257
+
2258
+ private renderDetailPanel() {
2259
+ const counts = this.activityCounts;
2260
+ return html`
2261
+ <!-- Thread -->
2262
+ <div class="cpk-tdp__section-title">Thread</div>
2263
+ <div class="cpk-tdp__row">
2264
+ <span class="cpk-tdp__label">ID</span>
2265
+ <span class="cpk-tdp__value cpk-tdp__value--wrap"
2266
+ >${this.shortId(this.thread?.id)}</span
2267
+ >
2268
+ </div>
2269
+ <div class="cpk-tdp__row">
2270
+ <span class="cpk-tdp__label">Name</span>
2271
+ <span class="cpk-tdp__value">${this.thread?.name ?? "—"}</span>
2272
+ </div>
2273
+ <div class="cpk-tdp__row">
2274
+ <span class="cpk-tdp__label">Agent</span>
2275
+ <span class="cpk-tdp__value cpk-tdp__value--truncate"
2276
+ >${this.thread?.agentId ?? "—"}</span
2277
+ >
2278
+ </div>
2279
+ <div class="cpk-tdp__row">
2280
+ <span class="cpk-tdp__label">Created by</span>
2281
+ <span class="cpk-tdp__value cpk-tdp__value--truncate"
2282
+ >${this.thread?.createdById ?? "—"}</span
2283
+ >
2284
+ </div>
123
2285
 
124
- type InspectorToolCall = {
125
- id?: string;
126
- function?: {
127
- name?: string;
128
- arguments?: SanitizedValue | string;
129
- };
130
- toolName?: string;
131
- status?: string;
132
- };
2286
+ <div class="cpk-tdp__divider"></div>
133
2287
 
134
- type InspectorMessage = {
135
- id?: string;
136
- role: string;
137
- contentText: string;
138
- contentRaw?: SanitizedValue;
139
- toolCalls: InspectorToolCall[];
140
- };
2288
+ <!-- Timestamps -->
2289
+ <div class="cpk-tdp__section-title">Timestamps</div>
2290
+ <div class="cpk-tdp__row">
2291
+ <span class="cpk-tdp__label">Created</span>
2292
+ <span class="cpk-tdp__value">${this.fmtTime(this.thread?.createdAt)}</span>
2293
+ </div>
2294
+ <div class="cpk-tdp__row">
2295
+ <span class="cpk-tdp__label">Updated</span>
2296
+ <span class="cpk-tdp__value">${this.fmtTime(this.thread?.updatedAt)}</span>
2297
+ </div>
2298
+ <div class="cpk-tdp__row">
2299
+ <span class="cpk-tdp__label">Duration</span>
2300
+ <span class="cpk-tdp__value">${this.duration}</span>
2301
+ </div>
141
2302
 
142
- type InspectorToolDefinition = {
143
- agentId: string;
144
- name: string;
145
- description?: string;
146
- parameters?: unknown;
147
- type: "handler" | "renderer";
148
- };
2303
+ <div class="cpk-tdp__divider"></div>
149
2304
 
150
- type InspectorEvent = {
151
- id: string;
152
- agentId: string;
153
- type: InspectorAgentEventType;
154
- timestamp: number;
155
- payload: SanitizedValue;
156
- };
2305
+ <!-- Activity -->
2306
+ <div class="cpk-tdp__section-title">Activity</div>
2307
+ <div class="cpk-tdp__row">
2308
+ <span class="cpk-tdp__label">Messages</span>
2309
+ <span class="cpk-tdp__value">${counts.messages}</span>
2310
+ </div>
2311
+ <div class="cpk-tdp__row">
2312
+ <span class="cpk-tdp__label">Tool calls</span>
2313
+ <span class="cpk-tdp__value">${counts.toolCalls}</span>
2314
+ </div>
2315
+ <div class="cpk-tdp__row">
2316
+ <span class="cpk-tdp__label">AG-UI events</span>
2317
+ <span class="cpk-tdp__value">${this.activeEvents.length}</span>
2318
+ </div>
2319
+ `;
2320
+ }
2321
+ }
2322
+
2323
+ if (!customElements.get("cpk-thread-list")) {
2324
+ customElements.define("cpk-thread-list", CpkThreadList);
2325
+ }
2326
+ if (!customElements.get("cpk-thread-details")) {
2327
+ customElements.define("cpk-thread-details", ɵCpkThreadDetails);
2328
+ }
157
2329
 
158
2330
  export class WebInspectorElement extends LitElement {
159
2331
  static properties = {
@@ -173,6 +2345,12 @@ export class WebInspectorElement extends LitElement {
173
2345
  private agentSubscriptions: Map<string, () => void> = new Map();
174
2346
  private agentEvents: Map<string, InspectorEvent[]> = new Map();
175
2347
  private agentMessages: Map<string, InspectorMessage[]> = new Map();
2348
+ // Per-thread monotonic version that ticks every time an agent currently
2349
+ // running on that thread emits a message change. `cpk-thread-details`
2350
+ // watches this prop and re-fetches `/threads/:id/messages` when it changes,
2351
+ // which is how live updates flow into the conversation view without
2352
+ // duplicating the runtime's message-shape conversion in the inspector.
2353
+ private liveMessageVersion: Map<string, number> = new Map();
176
2354
  private agentStates: Map<string, SanitizedValue> = new Map();
177
2355
  private flattenedEvents: InspectorEvent[] = [];
178
2356
  private eventCounter = 0;
@@ -190,6 +2368,22 @@ export class WebInspectorElement extends LitElement {
190
2368
  private draggedDuringInteraction = false;
191
2369
  private ignoreNextButtonClick = false;
192
2370
  private selectedMenu: MenuKey = "ag-ui-events";
2371
+ private selectedThreadId: string | null = null;
2372
+ private threadListWidth = 290;
2373
+ private threadDividerResizing = false;
2374
+ private threadDividerPointerId = -1;
2375
+ private threadDividerStartX = 0;
2376
+ private threadDividerStartWidth = 0;
2377
+ private _threads: ɵThread[] = [];
2378
+ private _threadStoreSubscriptions: Map<string, () => void> = new Map();
2379
+ private _threadsByAgent: Map<string, ɵThread[]> = new Map();
2380
+ // Error from each agent's thread store (REST list rejection, Phoenix
2381
+ // subscribe failure, retry exhaustion). When non-empty for the active
2382
+ // selection, the threads view renders an error state instead of stale
2383
+ // data with no indication.
2384
+ private _threadsErrorByAgent: Map<string, Error> = new Map();
2385
+ // Thread stores created and owned by the inspector (keyed by agentId)
2386
+ private _ownedThreadStores: Map<string, ɵThreadStore> = new Map();
193
2387
  private contextMenuOpen = false;
194
2388
  private dockMode: DockMode = "floating";
195
2389
  private previousBodyMargins: { left: string; bottom: string } | null = null;
@@ -203,16 +2397,22 @@ export class WebInspectorElement extends LitElement {
203
2397
  private toolSignature = "";
204
2398
  private eventFilterText = "";
205
2399
  private eventTypeFilter: InspectorAgentEventType | "all" = "all";
2400
+ // Column widths for the AG-UI events table (agent, time, event-type; last col is auto)
2401
+ private evtColWidths = [100, 80, 150];
2402
+ private _evtColResize: {
2403
+ col: number;
2404
+ startX: number;
2405
+ startW: number;
2406
+ } | null = null;
206
2407
 
207
- private announcementMarkdown: string | null = null;
208
2408
  private announcementHtml: string | null = null;
209
2409
  private announcementTimestamp: string | null = null;
210
2410
  private announcementPreviewText: string | null = null;
211
2411
  private hasUnseenAnnouncement = false;
212
2412
  private announcementLoaded = false;
213
- private announcementLoadError: unknown = null;
214
2413
  private announcementPromise: Promise<void> | null = null;
215
2414
  private showAnnouncementPreview = true;
2415
+ private announcementExpanded = false;
216
2416
 
217
2417
  get core(): CopilotKitCore | null {
218
2418
  return this._core;
@@ -259,12 +2459,140 @@ export class WebInspectorElement extends LitElement {
259
2459
  private resizeInitialSize: { width: number; height: number } | null = null;
260
2460
  private isResizing = false;
261
2461
 
262
- private readonly menuItems: MenuItem[] = [
263
- { key: "ag-ui-events", label: "AG-UI Events", icon: "Zap" },
264
- { key: "agents", label: "Agent", icon: "Bot" },
265
- { key: "frontend-tools", label: "Frontend Tools", icon: "Hammer" },
266
- { key: "agent-context", label: "Context", icon: "FileText" },
267
- ];
2462
+ private readonly customTabIcons: Record<string, string> = {
2463
+ threads: `<svg class="h-3.5 w-3.5" width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M9.04167 15C8.29167 15 7.65972 14.7431 7.14583 14.2292C6.63194 13.7153 6.375 13.0972 6.375 12.375C6.375 11.3194 6.80208 10.3646 7.65625 9.51042C8.51042 8.65625 9.57639 8.125 10.8542 7.91667C10.8125 7.41667 10.6875 7.03819 10.4792 6.78125C10.2708 6.52431 9.98611 6.39583 9.625 6.39583C9.20833 6.39583 8.75694 6.56944 8.27083 6.91667C7.78472 7.26389 7.20833 7.83333 6.54167 8.625C5.45833 9.91667 4.66319 10.7569 4.15625 11.1458C3.64931 11.5347 3.10417 11.7292 2.52083 11.7292C1.8125 11.7292 1.21528 11.4653 0.729167 10.9375C0.243056 10.4097 0 9.77083 0 9.02083C0 8.27083 0.163194 7.50347 0.489583 6.71875C0.815972 5.93403 1.36806 4.99306 2.14583 3.89583C2.40972 3.53472 2.60417 3.22917 2.72917 2.97917C2.85417 2.72917 2.91667 2.52778 2.91667 2.375C2.91667 2.27778 2.89931 2.20486 2.86458 2.15625C2.82986 2.10764 2.77778 2.08333 2.70833 2.08333C2.56944 2.08333 2.39583 2.17014 2.1875 2.34375C1.97917 2.51736 1.73611 2.78472 1.45833 3.14583L0 1.66667C0.444444 1.125 0.895833 0.711806 1.35417 0.427083C1.8125 0.142361 2.26389 0 2.70833 0C3.34722 0 3.88889 0.222222 4.33333 0.666667C4.77778 1.11111 5 1.66667 5 2.33333C5 2.73611 4.89583 3.18056 4.6875 3.66667C4.47917 4.15278 4.13194 4.73611 3.64583 5.41667C3.11806 6.16667 2.72569 6.82639 2.46875 7.39583C2.21181 7.96528 2.08333 8.46528 2.08333 8.89583C2.08333 9.13194 2.12153 9.31597 2.19792 9.44792C2.27431 9.57986 2.38194 9.64583 2.52083 9.64583C2.65972 9.64583 2.78125 9.60764 2.88542 9.53125C2.98958 9.45486 3.18056 9.27083 3.45833 8.97917C3.63889 8.78472 3.85417 8.54514 4.10417 8.26042C4.35417 7.97569 4.65972 7.625 5.02083 7.20833C5.89583 6.16667 6.6875 5.42361 7.39583 4.97917C8.10417 4.53472 8.84722 4.3125 9.625 4.3125C10.5556 4.3125 11.3194 4.625 11.9167 5.25C12.5139 5.875 12.8542 6.72917 12.9375 7.8125H15V9.89583H12.9375C12.8264 11.4514 12.4201 12.691 11.7188 13.6146C11.0174 14.5382 10.125 15 9.04167 15ZM9.08333 12.9167C9.52778 12.9167 9.90278 12.6632 10.2083 12.1562C10.5139 11.6493 10.7222 10.9444 10.8333 10.0417C10.1944 10.1944 9.63889 10.4965 9.16667 10.9479C8.69444 11.3993 8.45833 11.8472 8.45833 12.2917C8.45833 12.4861 8.51389 12.6389 8.625 12.75C8.73611 12.8611 8.88889 12.9167 9.08333 12.9167Z" fill="currentColor"/></svg>`,
2464
+ };
2465
+
2466
+ private get menuItems(): MenuItem[] {
2467
+ const hasFrontendTools = (this._core?.tools?.length ?? 0) > 0;
2468
+ return [
2469
+ {
2470
+ key: "ag-ui-events",
2471
+ label: "AG-UI Events",
2472
+ icon: "Zap" as LucideIconName,
2473
+ },
2474
+ { key: "agents", label: "Agent", icon: "Bot" as LucideIconName },
2475
+ ...(hasFrontendTools
2476
+ ? [
2477
+ {
2478
+ key: "frontend-tools" as const,
2479
+ label: "Frontend Tools",
2480
+ icon: "Hammer" as LucideIconName,
2481
+ },
2482
+ ]
2483
+ : []),
2484
+ {
2485
+ key: "agent-context",
2486
+ label: "Context",
2487
+ icon: "FileText" as LucideIconName,
2488
+ },
2489
+ {
2490
+ key: "threads",
2491
+ label: "Threads",
2492
+ icon: "MessageSquare" as LucideIconName,
2493
+ },
2494
+ ];
2495
+ }
2496
+
2497
+ private subscribeToThreadStore(agentId: string, store: ɵThreadStore): void {
2498
+ if (this._threadStoreSubscriptions.has(agentId)) return;
2499
+ const threadsSub = store.select(ɵselectThreads).subscribe((threads) => {
2500
+ this._threadsByAgent.set(agentId, threads as ɵThread[]);
2501
+ this._threads = Array.from(this._threadsByAgent.values()).flat();
2502
+ this.autoSelectLatestThread();
2503
+ this.requestUpdate();
2504
+ });
2505
+ const errorSub = store.select(ɵselectThreadsError).subscribe((error) => {
2506
+ if (error) {
2507
+ this._threadsErrorByAgent.set(agentId, error);
2508
+ } else {
2509
+ this._threadsErrorByAgent.delete(agentId);
2510
+ }
2511
+ this.requestUpdate();
2512
+ });
2513
+ this._threadStoreSubscriptions.set(agentId, () => {
2514
+ threadsSub.unsubscribe();
2515
+ errorSub.unsubscribe();
2516
+ });
2517
+ // Populate immediately from current state
2518
+ const initialState = store.getState();
2519
+ this._threadsByAgent.set(agentId, ɵselectThreads(initialState));
2520
+ const initialError = ɵselectThreadsError(initialState);
2521
+ if (initialError) {
2522
+ this._threadsErrorByAgent.set(agentId, initialError);
2523
+ } else {
2524
+ this._threadsErrorByAgent.delete(agentId);
2525
+ }
2526
+ this._threads = Array.from(this._threadsByAgent.values()).flat();
2527
+ this.autoSelectLatestThread();
2528
+ }
2529
+
2530
+ private autoSelectLatestThread(): void {
2531
+ if (this._threads.length === 0) return;
2532
+ const stillValid =
2533
+ this.selectedThreadId != null &&
2534
+ this._threads.some((t) => t.id === this.selectedThreadId);
2535
+ if (!stillValid) {
2536
+ // Threads are sorted most-recently-updated first
2537
+ this.selectedThreadId = this._threads[0]!.id;
2538
+ }
2539
+ }
2540
+
2541
+ private teardownThreadStoreSubscriptions(): void {
2542
+ for (const unsub of this._threadStoreSubscriptions.values()) {
2543
+ unsub();
2544
+ }
2545
+ this._threadStoreSubscriptions.clear();
2546
+ this._threadsByAgent.clear();
2547
+ this._threadsErrorByAgent.clear();
2548
+ this._threads = [];
2549
+ }
2550
+
2551
+ private ensureOwnedThreadStore(agentId: string): void {
2552
+ if (this._ownedThreadStores.has(agentId)) return;
2553
+ // Don't overwrite a store already registered by useThreads() or another external caller
2554
+ if (this.core?.getThreadStore(agentId)) return;
2555
+ const core = this.core;
2556
+ if (!core?.runtimeUrl) return;
2557
+
2558
+ const store = ɵcreateThreadStore({ fetch: globalThis.fetch });
2559
+ store.start();
2560
+ store.setContext({
2561
+ runtimeUrl: core.runtimeUrl,
2562
+ headers: {},
2563
+ agentId,
2564
+ });
2565
+ this._ownedThreadStores.set(agentId, store);
2566
+ // Subscribe directly so threads render even before the registry callback
2567
+ // fires (some published-core code paths land on the subscriber after
2568
+ // registerThreadStore returns).
2569
+ this.subscribeToThreadStore(agentId, store);
2570
+ core.registerThreadStore(agentId, store);
2571
+ }
2572
+
2573
+ private refreshOwnedThreadStore(agentId: string): void {
2574
+ const store = this._ownedThreadStores.get(agentId);
2575
+ if (!store) return;
2576
+ // refresh() re-fetches without resetting threads to [] first, so the list
2577
+ // stays visible while new data loads and survives transient fetch failures.
2578
+ store.refresh();
2579
+ }
2580
+
2581
+ private removeOwnedThreadStore(agentId: string): void {
2582
+ const store = this._ownedThreadStores.get(agentId);
2583
+ if (!store) return;
2584
+ store.stop();
2585
+ this.core?.unregisterThreadStore(agentId);
2586
+ this._ownedThreadStores.delete(agentId);
2587
+ }
2588
+
2589
+ private teardownOwnedThreadStores(): void {
2590
+ for (const [agentId, store] of this._ownedThreadStores) {
2591
+ store.stop();
2592
+ this.core?.unregisterThreadStore(agentId);
2593
+ }
2594
+ this._ownedThreadStores.clear();
2595
+ }
268
2596
 
269
2597
  private attachToCore(core: CopilotKitCore): void {
270
2598
  this.runtimeStatus = core.runtimeConnectionStatus;
@@ -274,6 +2602,15 @@ export class WebInspectorElement extends LitElement {
274
2602
  this.coreSubscriber = {
275
2603
  onRuntimeConnectionStatusChanged: ({ status }) => {
276
2604
  this.runtimeStatus = status;
2605
+ if (status === "connected") {
2606
+ for (const agentId of this._ownedThreadStores.keys()) {
2607
+ this.refreshOwnedThreadStore(agentId);
2608
+ }
2609
+ } else {
2610
+ // Clear stale thread data immediately when the server goes away
2611
+ this._threadsByAgent.clear();
2612
+ this._threads = [];
2613
+ }
277
2614
  this.requestUpdate();
278
2615
  },
279
2616
  onPropertiesChanged: ({ properties }) => {
@@ -287,23 +2624,39 @@ export class WebInspectorElement extends LitElement {
287
2624
  onAgentsChanged: ({ agents }) => {
288
2625
  this.processAgentsChanged(agents);
289
2626
  },
290
- onAgentRunStarted: ({ agent }) => {
291
- // Per-thread clones are not in the agent registry, so
292
- // onAgentsChanged never fires for them. Subscribe here so
293
- // the inspector captures their AG-UI events.
294
- if (agent?.agentId) {
295
- this.subscribeToAgent(agent);
296
- }
297
- },
298
2627
  onContextChanged: ({ context }) => {
299
2628
  this.contextStore = this.normalizeContextStore(context);
300
2629
  this.requestUpdate();
301
2630
  },
2631
+ onThreadStoreRegistered: ({ agentId, store }) => {
2632
+ this.subscribeToThreadStore(agentId, store);
2633
+ this.requestUpdate();
2634
+ },
2635
+ onThreadStoreUnregistered: ({ agentId }) => {
2636
+ const unsub = this._threadStoreSubscriptions.get(agentId);
2637
+ if (unsub) {
2638
+ unsub();
2639
+ this._threadStoreSubscriptions.delete(agentId);
2640
+ }
2641
+ this._threadsByAgent.delete(agentId);
2642
+ this._threadsErrorByAgent.delete(agentId);
2643
+ this._threads = Array.from(this._threadsByAgent.values()).flat();
2644
+ this.requestUpdate();
2645
+ },
302
2646
  } satisfies CopilotKitCoreSubscriber;
303
2647
 
304
2648
  this.coreUnsubscribe = core.subscribe(this.coreSubscriber).unsubscribe;
305
2649
  this.processAgentsChanged(core.agents);
306
2650
 
2651
+ // Subscribe to any already-registered thread stores. `getThreadStores` was
2652
+ // added in the same release as this inspector; guard so consumers still on
2653
+ // an older @copilotkit/core don't throw when assigning `inspector.core`.
2654
+ const threadStores =
2655
+ typeof core.getThreadStores === "function" ? core.getThreadStores() : {};
2656
+ for (const [agentId, store] of Object.entries(threadStores)) {
2657
+ this.subscribeToThreadStore(agentId, store);
2658
+ }
2659
+
307
2660
  // Initialize context from core
308
2661
  if (core.context) {
309
2662
  this.contextStore = this.normalizeContextStore(core.context);
@@ -322,6 +2675,8 @@ export class WebInspectorElement extends LitElement {
322
2675
  this.cachedTools = [];
323
2676
  this.toolSignature = "";
324
2677
  this.teardownAgentSubscriptions();
2678
+ this.teardownThreadStoreSubscriptions();
2679
+ this.teardownOwnedThreadStores();
325
2680
  }
326
2681
 
327
2682
  private teardownAgentSubscriptions(): void {
@@ -347,6 +2702,7 @@ export class WebInspectorElement extends LitElement {
347
2702
  }
348
2703
  seenAgentIds.add(agent.agentId);
349
2704
  this.subscribeToAgent(agent);
2705
+ this.ensureOwnedThreadStore(agent.agentId);
350
2706
  }
351
2707
 
352
2708
  for (const agentId of Array.from(this.agentSubscriptions.keys())) {
@@ -355,6 +2711,10 @@ export class WebInspectorElement extends LitElement {
355
2711
  this.agentEvents.delete(agentId);
356
2712
  this.agentMessages.delete(agentId);
357
2713
  this.agentStates.delete(agentId);
2714
+ // Do NOT remove owned thread stores here — they are independent of
2715
+ // whether the agent appears in core.agents (published cores discover
2716
+ // agents asynchronously so agents may be empty on first fire). Stores
2717
+ // are torn down in teardownOwnedThreadStores() when the core detaches.
358
2718
  }
359
2719
  }
360
2720
 
@@ -436,6 +2796,7 @@ export class WebInspectorElement extends LitElement {
436
2796
  },
437
2797
  onRunFinishedEvent: ({ event, result }) => {
438
2798
  this.recordAgentEvent(agentId, "RUN_FINISHED", { event, result });
2799
+ this.refreshOwnedThreadStore(agentId);
439
2800
  },
440
2801
  onRunErrorEvent: ({ event }) => {
441
2802
  this.recordAgentEvent(agentId, "RUN_ERROR", event);
@@ -529,6 +2890,14 @@ export class WebInspectorElement extends LitElement {
529
2890
  onReasoningEncryptedValueEvent: ({ event }) => {
530
2891
  this.recordAgentEvent(agentId, "REASONING_ENCRYPTED_VALUE", event);
531
2892
  },
2893
+ onActivitySnapshotEvent: ({ event }) => {
2894
+ this.recordAgentEvent(agentId, "ACTIVITY_SNAPSHOT", event);
2895
+ this.syncAgentMessages(agent);
2896
+ },
2897
+ onActivityDeltaEvent: ({ event }) => {
2898
+ this.recordAgentEvent(agentId, "ACTIVITY_DELTA", event);
2899
+ this.syncAgentMessages(agent);
2900
+ },
532
2901
  };
533
2902
 
534
2903
  const { unsubscribe } = agent.subscribe(subscriber);
@@ -549,6 +2918,32 @@ export class WebInspectorElement extends LitElement {
549
2918
  }
550
2919
  }
551
2920
 
2921
+ private mapMessagesToConversation(
2922
+ messages: InspectorMessage[] | null,
2923
+ ): { id: string; type: string; content: string; createdAt: string }[] | null {
2924
+ if (!messages) return null;
2925
+ return messages
2926
+ .filter(
2927
+ (m) =>
2928
+ m.role === "user" || m.role === "assistant" || m.role === "activity",
2929
+ )
2930
+ .map((m, i) => ({
2931
+ id: m.id ?? `msg-${i}`,
2932
+ type:
2933
+ m.role === "user"
2934
+ ? "user"
2935
+ : m.role === "activity"
2936
+ ? "generative-ui"
2937
+ : "assistant",
2938
+ // For activity messages, store the activityType as a label so the
2939
+ // renderer has something meaningful to display.
2940
+ // TODO: render activity payload once available.
2941
+ content:
2942
+ m.role === "activity" ? (m.activityType ?? "unknown") : m.contentText,
2943
+ createdAt: "",
2944
+ }));
2945
+ }
2946
+
552
2947
  private recordAgentEvent(
553
2948
  agentId: string,
554
2949
  type: InspectorAgentEventType,
@@ -594,6 +2989,19 @@ export class WebInspectorElement extends LitElement {
594
2989
  this.agentMessages.delete(agent.agentId);
595
2990
  }
596
2991
 
2992
+ // Bump the live-message version for whichever thread this agent is
2993
+ // currently running on. cpk-thread-details watches this for the
2994
+ // selected thread and re-fetches `/threads/:id/messages` when it ticks,
2995
+ // so the conversation view stays in sync with the streaming agent
2996
+ // without the parent re-implementing AG-UI → ConversationItem mapping.
2997
+ const runThreadId = (agent as { threadId?: string }).threadId;
2998
+ if (runThreadId) {
2999
+ this.liveMessageVersion.set(
3000
+ runThreadId,
3001
+ (this.liveMessageVersion.get(runThreadId) ?? 0) + 1,
3002
+ );
3003
+ }
3004
+
597
3005
  this.requestUpdate();
598
3006
  } catch (error) {
599
3007
  console.error(
@@ -648,14 +3056,25 @@ export class WebInspectorElement extends LitElement {
648
3056
  if (pendingContext) {
649
3057
  const isPendingAvailable =
650
3058
  pendingContext === "all-agents" || agentIds.has(pendingContext);
651
- if (isPendingAvailable) {
3059
+ // Only restore a specific-agent selection when there is exactly one
3060
+ // agent registered. With multiple agents, fall back to "all-agents" so
3061
+ // events from any agent are visible regardless of what was persisted.
3062
+ const shouldRestore =
3063
+ isPendingAvailable &&
3064
+ (pendingContext === "all-agents" || agentIds.size === 1);
3065
+ if (shouldRestore) {
652
3066
  if (this.selectedContext !== pendingContext) {
653
3067
  this.selectedContext = pendingContext;
654
3068
  this.expandedRows.clear();
655
3069
  }
656
3070
  this.pendingSelectedContext = null;
657
3071
  } else if (agentIds.size > 0) {
658
- // Agents are loaded but the pending selection no longer exists
3072
+ // Persisted selection is unavailable or inappropriate for multiple
3073
+ // agents — reset to "all-agents" so nothing is silently filtered.
3074
+ if (this.selectedContext !== "all-agents") {
3075
+ this.selectedContext = "all-agents";
3076
+ this.expandedRows.clear();
3077
+ }
659
3078
  this.pendingSelectedContext = null;
660
3079
  }
661
3080
  }
@@ -665,15 +3084,13 @@ export class WebInspectorElement extends LitElement {
665
3084
  );
666
3085
 
667
3086
  if (!hasSelectedContext && this.pendingSelectedContext === null) {
668
- // Auto-select "default" agent if it exists, otherwise first agent, otherwise "all-agents"
3087
+ // When there is exactly one agent, auto-select it so the view is
3088
+ // immediately focused. When multiple agents are registered (e.g. "default"
3089
+ // + "openai"), keep "all-agents" so events from any agent are visible.
669
3090
  let nextSelected: string = "all-agents";
670
3091
 
671
- if (agentIds.has("default")) {
672
- nextSelected = "default";
673
- } else if (agentIds.size > 0) {
674
- nextSelected = Array.from(agentIds).sort((a, b) =>
675
- a.localeCompare(b),
676
- )[0]!;
3092
+ if (agentIds.size === 1) {
3093
+ nextSelected = Array.from(agentIds)[0]!;
677
3094
  }
678
3095
 
679
3096
  if (this.selectedContext !== nextSelected) {
@@ -1003,6 +3420,7 @@ ${argsString}</pre
1003
3420
  z-index: 2147483646;
1004
3421
  display: block;
1005
3422
  will-change: transform;
3423
+ font-family: "Plus Jakarta Sans", system-ui, sans-serif;
1006
3424
  }
1007
3425
 
1008
3426
  :host([data-transitioning="true"]) {
@@ -1058,13 +3476,14 @@ ${argsString}</pre
1058
3476
  left: 50%;
1059
3477
  transform: translateX(-50%) translateY(-4px);
1060
3478
  white-space: nowrap;
1061
- background: rgba(17, 24, 39, 0.95);
3479
+ background: rgba(1, 5, 7, 0.95);
1062
3480
  color: white;
1063
3481
  padding: 4px 8px;
1064
3482
  border-radius: 6px;
1065
3483
  font-size: 10px;
3484
+ font-family: "Plus Jakarta Sans", system-ui, sans-serif;
1066
3485
  line-height: 1.2;
1067
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
3486
+ box-shadow: 0 4px 10px rgba(1, 5, 7, 0.18);
1068
3487
  opacity: 0;
1069
3488
  pointer-events: none;
1070
3489
  transition:
@@ -1085,116 +3504,599 @@ ${argsString}</pre
1085
3504
  min-width: 300px;
1086
3505
  max-width: 300px;
1087
3506
  background: white;
1088
- color: #111827;
3507
+ color: #010507;
1089
3508
  font-size: 13px;
3509
+ font-family: "Plus Jakarta Sans", system-ui, sans-serif;
1090
3510
  line-height: 1.4;
1091
3511
  border-radius: 12px;
1092
- box-shadow: 0 12px 28px rgba(15, 23, 42, 0.22);
3512
+ box-shadow: 0 12px 28px rgba(1, 5, 7, 0.12);
1093
3513
  padding: 10px 12px;
1094
3514
  display: inline-flex;
1095
3515
  align-items: flex-start;
1096
3516
  gap: 8px;
1097
3517
  z-index: 4500;
1098
3518
  animation: fade-slide-in 160ms ease;
1099
- border: 1px solid rgba(148, 163, 184, 0.35);
3519
+ border: 1px solid rgba(219, 219, 229, 0.4);
1100
3520
  white-space: normal;
1101
3521
  word-break: break-word;
1102
3522
  text-align: left;
1103
3523
  }
1104
3524
 
1105
- .announcement-preview[data-side="left"] {
1106
- right: 100%;
1107
- margin-right: 10px;
3525
+ .announcement-preview[data-side="left"] {
3526
+ right: 100%;
3527
+ margin-right: 10px;
3528
+ }
3529
+
3530
+ .announcement-preview[data-side="right"] {
3531
+ left: 100%;
3532
+ margin-left: 10px;
3533
+ }
3534
+
3535
+ .announcement-preview__arrow {
3536
+ position: absolute;
3537
+ width: 10px;
3538
+ height: 10px;
3539
+ background: white;
3540
+ border: 1px solid rgba(219, 219, 229, 0.4);
3541
+ transform: rotate(45deg);
3542
+ top: 50%;
3543
+ margin-top: -5px;
3544
+ z-index: -1;
3545
+ }
3546
+
3547
+ .announcement-preview[data-side="left"] .announcement-preview__arrow {
3548
+ right: -5px;
3549
+ box-shadow: 6px -6px 10px rgba(1, 5, 7, 0.08);
3550
+ }
3551
+
3552
+ .announcement-preview[data-side="right"] .announcement-preview__arrow {
3553
+ left: -5px;
3554
+ box-shadow: -6px 6px 10px rgba(1, 5, 7, 0.08);
3555
+ }
3556
+
3557
+ .announcement-dismiss {
3558
+ background: none;
3559
+ border: none;
3560
+ cursor: pointer;
3561
+ color: #838389;
3562
+ width: 28px;
3563
+ height: 28px;
3564
+ display: flex;
3565
+ align-items: center;
3566
+ justify-content: center;
3567
+ border-radius: 6px;
3568
+ padding: 0;
3569
+ transition:
3570
+ background 120ms ease,
3571
+ color 120ms ease;
3572
+ }
3573
+
3574
+ .announcement-dismiss:hover {
3575
+ background: rgba(0, 0, 0, 0.06);
3576
+ color: #010507;
3577
+ }
3578
+
3579
+ /* ── Agent tab section cards ─────────────────────────────────────── */
3580
+ .cpk-section-card {
3581
+ border-radius: 8px;
3582
+ background: #ffffff;
3583
+ overflow: hidden;
3584
+ }
3585
+
3586
+ /* ── Agent icon bubble ───────────────────────────────────────────── */
3587
+ .cpk-agent-icon {
3588
+ background-color: #f0f0f4 !important;
3589
+ color: #57575b !important;
3590
+ }
3591
+
3592
+ /* ── Agent stat cards ────────────────────────────────────────────── */
3593
+ .cpk-stat-card {
3594
+ background-color: #ffffff !important;
3595
+ border: 1px solid #dbdbe5 !important;
3596
+ }
3597
+ button.cpk-stat-card:hover {
3598
+ background-color: #f7f7f9 !important;
3599
+ }
3600
+
3601
+ /* ── Circle chevron (Frontend Tools + Context) ──────────────────── */
3602
+ .cpk-chevron-circle {
3603
+ display: inline-flex;
3604
+ align-items: center;
3605
+ justify-content: center;
3606
+ width: 24px;
3607
+ height: 24px;
3608
+ border-radius: 50%;
3609
+ background-color: #f0f0f4;
3610
+ color: #838389;
3611
+ flex-shrink: 0;
3612
+ transition: transform 0.2s;
3613
+ }
3614
+ .cpk-chevron-circle svg {
3615
+ width: 14px !important;
3616
+ height: 14px !important;
3617
+ }
3618
+ .cpk-chevron-circle--open {
3619
+ transform: rotate(180deg);
3620
+ }
3621
+
3622
+ /* ── Inline copy button ─────────────────────────────────────────── */
3623
+ .cpk-copy-btn {
3624
+ font-size: 10px;
3625
+ font-weight: 500;
3626
+ color: #57575b;
3627
+ background: #ffffff;
3628
+ border: 1px solid #dbdbe5;
3629
+ cursor: pointer;
3630
+ padding: 2px 8px;
3631
+ border-radius: 4px;
3632
+ flex-shrink: 0;
3633
+ transition:
3634
+ background-color 0.15s,
3635
+ border-color 0.15s;
3636
+ }
3637
+ .cpk-copy-btn:hover {
3638
+ background-color: #f0f0f4;
3639
+ border-color: #afafb7;
3640
+ }
3641
+
3642
+ .cpk-section-header {
3643
+ background: #e8edf5;
3644
+ border-bottom: 1px solid rgba(0, 0, 0, 0.08);
3645
+ padding: 10px 16px;
3646
+ }
3647
+ .cpk-section-header h4 {
3648
+ font-size: 11px;
3649
+ font-weight: 600;
3650
+ color: #181c1f;
3651
+ margin: 0;
3652
+ }
3653
+
3654
+ /* Inputs/selects inside the lavender header need an explicit white bg */
3655
+ .cpk-section-header input,
3656
+ .cpk-section-header select {
3657
+ background-color: #ffffff !important;
3658
+ box-shadow: none !important;
3659
+ }
3660
+ .cpk-section-header select {
3661
+ padding-right: 24px !important;
3662
+ }
3663
+ /* Events table column headers */
3664
+ table thead th {
3665
+ font-weight: 600 !important;
3666
+ }
3667
+
3668
+ .announcement-content {
3669
+ color: #1f2230;
3670
+ font-size: 13px;
3671
+ font-family: "Plus Jakarta Sans", system-ui, sans-serif;
3672
+ line-height: 1.55;
3673
+ }
3674
+
3675
+ .announcement-content h1,
3676
+ .announcement-content h2,
3677
+ .announcement-content h3 {
3678
+ color: #010507;
3679
+ font-weight: 700;
3680
+ line-height: 1.3;
3681
+ margin: 0.9rem 0 0.4rem;
3682
+ }
3683
+ .announcement-content > h1:first-child,
3684
+ .announcement-content > h2:first-child,
3685
+ .announcement-content > h3:first-child {
3686
+ margin-top: 0;
3687
+ }
3688
+
3689
+ .announcement-content h1 {
3690
+ font-size: 1.15rem;
3691
+ letter-spacing: -0.01em;
3692
+ }
3693
+ .announcement-content h2 {
3694
+ font-size: 1rem;
3695
+ }
3696
+ .announcement-content h3 {
3697
+ font-size: 0.9rem;
3698
+ text-transform: none;
3699
+ }
3700
+
3701
+ .announcement-content p {
3702
+ margin: 0.45rem 0;
3703
+ }
3704
+
3705
+ .announcement-content strong {
3706
+ color: #010507;
3707
+ font-weight: 700;
3708
+ }
3709
+
3710
+ .announcement-content ul {
3711
+ list-style: disc;
3712
+ padding-left: 1.25rem;
3713
+ margin: 0.45rem 0;
3714
+ }
3715
+
3716
+ .announcement-content ol {
3717
+ list-style: decimal;
3718
+ padding-left: 1.25rem;
3719
+ margin: 0.45rem 0;
3720
+ }
3721
+
3722
+ .announcement-content li + li {
3723
+ margin-top: 0.15rem;
3724
+ }
3725
+
3726
+ .announcement-content a {
3727
+ color: #757cf2;
3728
+ text-decoration: underline;
3729
+ }
3730
+
3731
+ .announcement-content :not(pre) > code {
3732
+ background: #f3f3f7;
3733
+ border: 1px solid #e4e4ec;
3734
+ border-radius: 4px;
3735
+ padding: 1px 5px;
3736
+ font-size: 0.85em;
3737
+ color: #4a3a8a;
3738
+ }
3739
+
3740
+ .announcement-code {
3741
+ position: relative;
3742
+ margin: 0.6rem 0;
3743
+ }
3744
+
3745
+ .announcement-code pre {
3746
+ background: #0f1117;
3747
+ color: #e6e8f2;
3748
+ border-radius: 8px;
3749
+ padding: 10px 12px;
3750
+ overflow-x: auto;
3751
+ font-size: 12px;
3752
+ line-height: 1.5;
3753
+ white-space: pre;
3754
+ }
3755
+
3756
+ .announcement-code pre code::after {
3757
+ content: "";
3758
+ display: inline-block;
3759
+ width: 80px;
3760
+ }
3761
+
3762
+ .announcement-code__copy-shield {
3763
+ position: absolute;
3764
+ top: 4px;
3765
+ right: 4px;
3766
+ padding: 4px 4px 4px 24px;
3767
+ border-top-right-radius: 8px;
3768
+ background: linear-gradient(
3769
+ to right,
3770
+ rgba(15, 17, 23, 0) 0%,
3771
+ rgba(15, 17, 23, 0.95) 40%,
3772
+ #0f1117 100%
3773
+ );
3774
+ pointer-events: none;
3775
+ }
3776
+
3777
+ .announcement-code pre code {
3778
+ background: transparent;
3779
+ border: none;
3780
+ padding: 0;
3781
+ color: inherit;
3782
+ font-size: inherit;
3783
+ }
3784
+
3785
+ .announcement-code pre::-webkit-scrollbar {
3786
+ height: 6px;
3787
+ }
3788
+ .announcement-code pre::-webkit-scrollbar-track {
3789
+ background: transparent;
3790
+ }
3791
+ .announcement-code pre::-webkit-scrollbar-thumb {
3792
+ background: rgba(255, 255, 255, 0.2);
3793
+ border-radius: 3px;
3794
+ }
3795
+
3796
+ .announcement-code__copy {
3797
+ position: relative;
3798
+ pointer-events: auto;
3799
+ padding: 3px 8px;
3800
+ font-family: "Plus Jakarta Sans", system-ui, sans-serif;
3801
+ font-size: 11px;
3802
+ font-weight: 600;
3803
+ color: #e6e8f2;
3804
+ background: #1f222d;
3805
+ border: 1px solid rgba(255, 255, 255, 0.15);
3806
+ border-radius: 5px;
3807
+ cursor: pointer;
3808
+ transition:
3809
+ background 0.12s ease,
3810
+ color 0.12s ease;
3811
+ }
3812
+ .announcement-code__copy:hover {
3813
+ background: #2a2e3c;
3814
+ }
3815
+ .announcement-code__copy[data-copied="true"] {
3816
+ background: #eee6fe;
3817
+ color: #6430ab;
3818
+ border-color: transparent;
3819
+ }
3820
+
3821
+ .announcement-body {
3822
+ position: relative;
3823
+ overflow: hidden;
3824
+ transition: max-height 0.25s ease;
3825
+ }
3826
+ .announcement-body--collapsed {
3827
+ max-height: 72px;
3828
+ }
3829
+ .announcement-body--expanded {
3830
+ max-height: 2000px;
3831
+ }
3832
+ .announcement-fade {
3833
+ position: absolute;
3834
+ bottom: 0;
3835
+ left: 0;
3836
+ right: 0;
3837
+ height: 48px;
3838
+ background: linear-gradient(to bottom, transparent, #ffffff);
3839
+ pointer-events: none;
3840
+ }
3841
+ .announcement-toggle {
3842
+ display: block;
3843
+ width: 100%;
3844
+ margin-top: 6px;
3845
+ padding: 0;
3846
+ background: none;
3847
+ border: none;
3848
+ font-family: "Plus Jakarta Sans", system-ui, sans-serif;
3849
+ font-size: 12px;
3850
+ font-weight: 500;
3851
+ color: #757cf2;
3852
+ cursor: pointer;
3853
+ text-align: center;
3854
+ }
3855
+ .announcement-toggle:hover {
3856
+ color: #6430ab;
1108
3857
  }
1109
3858
 
1110
- .announcement-preview[data-side="right"] {
1111
- left: 100%;
1112
- margin-left: 10px;
3859
+ /* ── Brand typography ────────────────────────────────────────── */
3860
+ /* Override Tailwind font-mono stack → Spline Sans Mono */
3861
+ .font-mono,
3862
+ pre,
3863
+ code {
3864
+ font-family: "Spline Sans Mono", ui-monospace, "Cascadia Code", monospace;
1113
3865
  }
1114
3866
 
1115
- .announcement-preview__arrow {
1116
- position: absolute;
1117
- width: 10px;
1118
- height: 10px;
1119
- background: white;
1120
- border: 1px solid rgba(148, 163, 184, 0.35);
1121
- transform: rotate(45deg);
1122
- top: 50%;
1123
- margin-top: -5px;
1124
- z-index: -1;
3867
+ /* ── Floating button ─────────────────────────────────────────── */
3868
+ .console-button {
3869
+ background-color: rgba(1, 5, 7, 0.95) !important;
3870
+ border-color: rgba(190, 194, 255, 0.25) !important;
3871
+ box-shadow:
3872
+ 0 0 0 1px rgba(190, 194, 255, 0.15),
3873
+ 0 4px 14px rgba(1, 5, 7, 0.28) !important;
3874
+ }
3875
+ .console-button:hover {
3876
+ background-color: rgba(1, 5, 7, 1) !important;
3877
+ border-color: rgba(190, 194, 255, 0.45) !important;
3878
+ }
3879
+ .console-button:focus-visible {
3880
+ outline-color: #bec2ff !important;
1125
3881
  }
1126
3882
 
1127
- .announcement-preview[data-side="left"] .announcement-preview__arrow {
1128
- right: -5px;
1129
- box-shadow: 6px -6px 10px rgba(15, 23, 42, 0.12);
3883
+ /* ── Inspector window ────────────────────────────────────────── */
3884
+ .inspector-window {
3885
+ border-color: #dbdbe5 !important;
3886
+ box-shadow:
3887
+ 0 8px 32px rgba(1, 5, 7, 0.1),
3888
+ 0 2px 8px rgba(1, 5, 7, 0.06) !important;
1130
3889
  }
1131
3890
 
1132
- .announcement-preview[data-side="right"] .announcement-preview__arrow {
1133
- left: -5px;
1134
- box-shadow: -6px 6px 10px rgba(15, 23, 42, 0.12);
3891
+ /* ── Header drag area ────────────────────────────────────────── */
3892
+ .drag-handle {
3893
+ border-bottom-color: #dbdbe5 !important;
3894
+ /* Subtle pale lavender gradient — brand "light, spacious" surface */
3895
+ background: linear-gradient(180deg, #f4f4fd 0%, #ffffff 100%) !important;
1135
3896
  }
1136
3897
 
1137
- .announcement-dismiss {
1138
- color: #6b7280;
1139
- font-size: 12px;
1140
- padding: 2px 8px;
1141
- border-radius: 8px;
1142
- border: 1px solid rgba(148, 163, 184, 0.5);
1143
- background: rgba(248, 250, 252, 0.9);
1144
- transition:
1145
- background 120ms ease,
1146
- color 120ms ease;
3898
+ /* Tab strip row: soft off-white, separated from content */
3899
+ .drag-handle > div:last-child {
3900
+ border-top-color: #e2e2ea !important;
3901
+ background-color: #fafafc !important;
1147
3902
  }
1148
3903
 
1149
- .announcement-dismiss:hover {
1150
- background: rgba(241, 245, 249, 1);
1151
- color: #111827;
3904
+ /* ── Tab buttons ─────────────────────────────────────────────── */
3905
+ /*
3906
+ * Named classes owned by this component — no Tailwind conflict.
3907
+ * Active: brand surface/surfaceContainerActive (lilac tint) +
3908
+ * border/borderActionEnabled underline.
3909
+ * Dark fill is for primary action buttons only, not nav tabs.
3910
+ */
3911
+ .cpk-tab-active {
3912
+ background-color: rgba(190, 194, 255, 0.18);
3913
+ color: #010507;
3914
+ font-weight: 600;
3915
+ }
3916
+ .cpk-tab-active .cpk-tab-icon {
3917
+ color: #757cf2;
3918
+ }
3919
+ .cpk-tab-inactive {
3920
+ background-color: transparent;
3921
+ color: #2b2b2b;
3922
+ }
3923
+ .cpk-tab-inactive .cpk-tab-icon {
3924
+ color: #838389;
3925
+ }
3926
+ .cpk-tab-inactive:hover {
3927
+ background-color: rgba(190, 194, 255, 0.08);
3928
+ color: #010507;
3929
+ cursor: pointer;
3930
+ }
3931
+ .cpk-tab-active {
3932
+ cursor: pointer;
1152
3933
  }
1153
3934
 
1154
- .announcement-content {
1155
- color: #111827;
1156
- font-size: 14px;
1157
- line-height: 1.6;
3935
+ /* ── Header control buttons (dock, close) — first row only ───── */
3936
+ .drag-handle > div:first-child button {
3937
+ color: #838389 !important;
3938
+ }
3939
+ .drag-handle > div:first-child button:hover {
3940
+ background-color: #f0f0f4 !important;
3941
+ color: #57575b !important;
3942
+ }
3943
+ .drag-handle > div:first-child button:focus-visible {
3944
+ outline-color: #bec2ff !important;
1158
3945
  }
1159
3946
 
1160
- .announcement-content h1,
1161
- .announcement-content h2,
1162
- .announcement-content h3 {
1163
- font-weight: 700;
1164
- margin: 0.4rem 0 0.2rem;
3947
+ /* ── Agent/context dropdown ──────────────────────────────────── */
3948
+ [data-context-dropdown-root="true"] > button {
3949
+ border-color: #dbdbe5 !important;
3950
+ color: #010507 !important;
3951
+ }
3952
+ [data-context-dropdown-root="true"] > button:hover {
3953
+ border-color: #bec2ff !important;
3954
+ background-color: #f7f7f9 !important;
3955
+ }
3956
+ [data-context-dropdown-root="true"] > button > span:last-child {
3957
+ color: #838389 !important;
3958
+ }
3959
+ [data-context-dropdown-root="true"] > div {
3960
+ border-color: #dbdbe5 !important;
3961
+ box-shadow: 0 4px 12px rgba(1, 5, 7, 0.08) !important;
3962
+ }
3963
+ [data-context-dropdown-root="true"] > div button:hover,
3964
+ [data-context-dropdown-root="true"] > div button:focus {
3965
+ background-color: #f7f7f9 !important;
1165
3966
  }
1166
3967
 
1167
- .announcement-content h1 {
1168
- font-size: 1.1rem;
3968
+ /* ── Status bar (bottom chrome) ──────────────────────────────── */
3969
+ .inspector-window > div > div:last-child {
3970
+ border-top-color: #dbdbe5 !important;
3971
+ background-color: #f7f7f9 !important;
1169
3972
  }
1170
3973
 
1171
- .announcement-content h2 {
1172
- font-size: 1rem;
3974
+ /* ── Resize handle ───────────────────────────────────────────── */
3975
+ .resize-handle {
3976
+ color: #838389 !important;
3977
+ }
3978
+ .resize-handle:hover {
3979
+ color: #57575b !important;
1173
3980
  }
1174
3981
 
1175
- .announcement-content h3 {
1176
- font-size: 0.95rem;
3982
+ /* ── AG-UI Events tab ────────────────────────────────────────── */
3983
+ /* Row hover: replace blue tint with brand lilac */
3984
+ tr:hover td {
3985
+ background-color: rgba(190, 194, 255, 0.08) !important;
3986
+ }
3987
+ /* Reset/dark action button */
3988
+ button[class*="bg-gray-900"] {
3989
+ background-color: #010507 !important;
3990
+ }
3991
+ button[class*="bg-gray-800"] {
3992
+ background-color: #2b2b2b !important;
3993
+ }
3994
+ /* Copy "copied" state: generic green → brand mint */
3995
+ button[class*="bg-green-100"] {
3996
+ background-color: rgba(133, 236, 206, 0.2) !important;
3997
+ color: #189370 !important;
1177
3998
  }
1178
3999
 
1179
- .announcement-content p {
1180
- margin: 0.25rem 0;
4000
+ /* ── Agents tab ──────────────────────────────────────────────── */
4001
+ /* Agent icon bubble: blue → lilac */
4002
+ span[class*="bg-blue-100"]:not([class*="text-blue-800"]) {
4003
+ background-color: rgba(190, 194, 255, 0.15) !important;
4004
+ }
4005
+ span[class*="text-blue-600"] {
4006
+ color: #757cf2 !important;
4007
+ }
4008
+ /* Running badge: emerald → mint */
4009
+ span[class*="bg-emerald-50"] {
4010
+ background-color: rgba(133, 236, 206, 0.15) !important;
4011
+ }
4012
+ span[class*="text-emerald-700"] {
4013
+ color: #189370 !important;
4014
+ }
4015
+ /* Running status dot */
4016
+ span[class*="bg-emerald-500"] {
4017
+ background-color: #85ecce !important;
4018
+ }
4019
+ /* Idle dot */
4020
+ span[class*="bg-gray-400"] {
4021
+ background-color: #afafb7 !important;
4022
+ }
4023
+ /* User role badge (blue → lilac) */
4024
+ span[class*="bg-blue-100"][class*="text-blue-800"] {
4025
+ background-color: rgba(190, 194, 255, 0.22) !important;
4026
+ border: 1px solid rgba(190, 194, 255, 0.45) !important;
4027
+ color: #57575b !important;
4028
+ }
4029
+ /* Assistant role badge (green → mint) */
4030
+ span[class*="bg-green-100"][class*="text-green-800"] {
4031
+ background-color: rgba(133, 236, 206, 0.18) !important;
4032
+ border: 1px solid rgba(133, 236, 206, 0.4) !important;
4033
+ color: #189370 !important;
4034
+ }
4035
+ /* Tool role badge (amber → orange brand) */
4036
+ span[class*="bg-amber-100"][class*="text-amber-800"] {
4037
+ background-color: rgba(255, 172, 77, 0.15) !important;
4038
+ color: #57575b !important;
1181
4039
  }
1182
4040
 
1183
- .announcement-content ul {
1184
- list-style: disc;
1185
- padding-left: 1.25rem;
1186
- margin: 0.3rem 0;
4041
+ /* ── Frontend Tools tab ──────────────────────────────────────── */
4042
+ /* Handler badge (blue → lilac) */
4043
+ span[class*="bg-blue-50"][class*="text-blue-700"] {
4044
+ background-color: rgba(190, 194, 255, 0.12) !important;
4045
+ border-color: rgba(190, 194, 255, 0.3) !important;
4046
+ color: #010507 !important;
4047
+ }
4048
+ /* Renderer badge (purple → lilac-adjacent) */
4049
+ span[class*="bg-purple-50"][class*="text-purple-700"] {
4050
+ background-color: rgba(190, 194, 255, 0.12) !important;
4051
+ border-color: rgba(190, 194, 255, 0.3) !important;
4052
+ color: #57575b !important;
4053
+ }
4054
+ /* Required badge (rose → brand red) */
4055
+ span[class*="bg-rose-50"][class*="text-rose-700"] {
4056
+ background-color: rgba(250, 95, 103, 0.1) !important;
4057
+ border-color: rgba(250, 95, 103, 0.25) !important;
4058
+ color: #fa5f67 !important;
4059
+ }
4060
+ /* Code/default value blocks */
4061
+ code[class*="bg-gray-100"],
4062
+ span[class*="bg-gray-100"] {
4063
+ background-color: #f0f0f4 !important;
1187
4064
  }
1188
4065
 
1189
- .announcement-content ol {
1190
- list-style: decimal;
1191
- padding-left: 1.25rem;
1192
- margin: 0.3rem 0;
4066
+ /* ── Connected status bar: match threads header mint (#5BE4BB) ──── */
4067
+ /* Outer strip bg + top border + text when connected badge is present */
4068
+ .inspector-window
4069
+ > div
4070
+ > div:last-child
4071
+ > div:last-child:has(div[class*="bg-emerald-50"]) {
4072
+ background-color: rgba(91, 228, 187, 0.08) !important;
4073
+ border-top-color: rgba(91, 228, 187, 0.3) !important;
4074
+ color: #189370 !important;
4075
+ }
4076
+ /* Inner badge — slightly more opaque on the mint bg */
4077
+ div[class*="bg-emerald-50"][class*="border-emerald-200"] {
4078
+ background-color: rgba(91, 228, 187, 0.12) !important;
4079
+ border-color: rgba(91, 228, 187, 0.4) !important;
4080
+ color: #189370 !important;
4081
+ }
4082
+ /* Icon bubble inside connected badge → mint tint */
4083
+ div[class*="bg-emerald-50"] span[class*="bg-white"] {
4084
+ background-color: rgba(91, 228, 187, 0.3) !important;
1193
4085
  }
1194
4086
 
1195
- .announcement-content a {
1196
- color: #0f766e;
1197
- text-decoration: underline;
4087
+ /* ── Announcement panel ──────────────────────────────────────── */
4088
+ div[class*="border-slate-200"][class*="bg-white"] {
4089
+ border-color: #dbdbe5 !important;
4090
+ }
4091
+ /* Announcement icon bubble: black → brand light lavender + lilac icon */
4092
+ span[class*="bg-slate-900"],
4093
+ div[class*="bg-slate-900"] {
4094
+ background-color: #eee6fe !important;
4095
+ color: #757cf2 !important;
4096
+ }
4097
+ span[class*="text-slate-800"],
4098
+ div[class*="text-slate-800"] {
4099
+ color: #010507 !important;
1198
4100
  }
1199
4101
  `,
1200
4102
  ];
@@ -1202,6 +4104,7 @@ ${argsString}</pre
1202
4104
  connectedCallback(): void {
1203
4105
  super.connectedCallback();
1204
4106
  if (typeof window !== "undefined") {
4107
+ this.ensureBrandFonts();
1205
4108
  window.addEventListener("resize", this.handleResize);
1206
4109
  window.addEventListener(
1207
4110
  "pointerdown",
@@ -1215,6 +4118,17 @@ ${argsString}</pre
1215
4118
  }
1216
4119
  }
1217
4120
 
4121
+ private ensureBrandFonts(): void {
4122
+ const FONT_LINK_ID = "cpk-inspector-brand-fonts";
4123
+ if (document.getElementById(FONT_LINK_ID)) return;
4124
+ const link = document.createElement("link");
4125
+ link.id = FONT_LINK_ID;
4126
+ link.rel = "stylesheet";
4127
+ link.href =
4128
+ "https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600&family=Spline+Sans+Mono:wght@600&display=swap";
4129
+ document.head.appendChild(link);
4130
+ }
4131
+
1218
4132
  disconnectedCallback(): void {
1219
4133
  super.disconnectedCallback();
1220
4134
  if (typeof window !== "undefined") {
@@ -1309,7 +4223,7 @@ ${argsString}</pre
1309
4223
  "focus-visible:outline",
1310
4224
  "focus-visible:outline-2",
1311
4225
  "focus-visible:outline-offset-2",
1312
- "focus-visible:outline-rose-500",
4226
+ "focus-visible:outline-[#BEC2FF]",
1313
4227
  "touch-none",
1314
4228
  "select-none",
1315
4229
  this.isDragging ? "cursor-grabbing" : "cursor-grab",
@@ -1442,9 +4356,7 @@ ${argsString}</pre
1442
4356
  const isSelected = this.selectedMenu === key;
1443
4357
  const tabClasses = [
1444
4358
  "inline-flex items-center gap-2 rounded-md px-3 py-2 transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-gray-300",
1445
- isSelected
1446
- ? "bg-gray-900 text-white shadow-sm"
1447
- : "text-gray-600 hover:bg-gray-100 hover:text-gray-900",
4359
+ isSelected ? "cpk-tab-active" : "cpk-tab-inactive",
1448
4360
  ].join(" ");
1449
4361
 
1450
4362
  return html`
@@ -1454,10 +4366,12 @@ ${argsString}</pre
1454
4366
  aria-pressed=${isSelected}
1455
4367
  @click=${() => this.handleMenuSelect(key)}
1456
4368
  >
1457
- <span
1458
- class="text-gray-400 ${isSelected ? "text-white" : ""}"
1459
- >
1460
- ${this.renderIcon(icon)}
4369
+ <span class="cpk-tab-icon">
4370
+ ${
4371
+ key in this.customTabIcons
4372
+ ? unsafeHTML(this.customTabIcons[key])
4373
+ : this.renderIcon(icon)
4374
+ }
1461
4375
  </span>
1462
4376
  <span>${label}</span>
1463
4377
  </button>
@@ -1466,8 +4380,8 @@ ${argsString}</pre
1466
4380
  </div>
1467
4381
  </div>
1468
4382
  <div class="flex flex-1 flex-col overflow-hidden">
1469
- <div class="flex-1 overflow-auto">
1470
- ${this.renderAnnouncementPanel()}
4383
+ <div id="cpk-main-scroll" class="flex-1 overflow-auto">
4384
+ ${this.renderAnnouncementBanner()}
1471
4385
  ${this.renderCoreWarningBanner()} ${this.renderMainContent()}
1472
4386
  <slot></slot>
1473
4387
  </div>
@@ -2531,6 +5445,8 @@ ${argsString}</pre
2531
5445
  ? this.sanitizeForLogging(raw.content)
2532
5446
  : undefined,
2533
5447
  toolCalls,
5448
+ activityType:
5449
+ typeof raw.activityType === "string" ? raw.activityType : undefined,
2534
5450
  };
2535
5451
  }
2536
5452
 
@@ -2587,11 +5503,6 @@ ${argsString}</pre
2587
5503
  private expandedContextItems: Set<string> = new Set();
2588
5504
  private copiedContextItems: Set<string> = new Set();
2589
5505
 
2590
- private getSelectedMenu(): MenuItem {
2591
- const found = this.menuItems.find((item) => item.key === this.selectedMenu);
2592
- return found ?? this.menuItems[0]!;
2593
- }
2594
-
2595
5506
  private renderCoreWarningBanner() {
2596
5507
  if (this._core) {
2597
5508
  return nothing;
@@ -2686,9 +5597,156 @@ ${argsString}</pre
2686
5597
  return this.renderContextView();
2687
5598
  }
2688
5599
 
5600
+ if (this.selectedMenu === "threads") {
5601
+ return this.renderThreadsView();
5602
+ }
5603
+
2689
5604
  return nothing;
2690
5605
  }
2691
5606
 
5607
+ private handleThreadDividerPointerDown = (event: PointerEvent) => {
5608
+ this.threadDividerResizing = true;
5609
+ this.threadDividerPointerId = event.pointerId;
5610
+ this.threadDividerStartX = event.clientX;
5611
+ this.threadDividerStartWidth = this.threadListWidth;
5612
+ (event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
5613
+ event.preventDefault();
5614
+ };
5615
+
5616
+ private handleThreadDividerPointerMove = (event: PointerEvent) => {
5617
+ if (
5618
+ !this.threadDividerResizing ||
5619
+ this.threadDividerPointerId !== event.pointerId
5620
+ )
5621
+ return;
5622
+ const delta = event.clientX - this.threadDividerStartX;
5623
+ this.threadListWidth = Math.max(
5624
+ 180,
5625
+ Math.min(480, this.threadDividerStartWidth + delta),
5626
+ );
5627
+ this.requestUpdate();
5628
+ };
5629
+
5630
+ private handleThreadDividerPointerUp = (event: PointerEvent) => {
5631
+ if (this.threadDividerPointerId !== event.pointerId) return;
5632
+ const target = event.currentTarget as HTMLElement;
5633
+ if (target.hasPointerCapture(this.threadDividerPointerId)) {
5634
+ target.releasePointerCapture(this.threadDividerPointerId);
5635
+ }
5636
+ this.threadDividerResizing = false;
5637
+ };
5638
+
5639
+ private renderThreadsView() {
5640
+ const displayThreads =
5641
+ this.selectedContext === "all-agents"
5642
+ ? this._threads
5643
+ : (this._threadsByAgent.get(this.selectedContext) ?? []);
5644
+
5645
+ // Surface a thread-store load error inline. For "all-agents" we report
5646
+ // the first error encountered across all agents (good enough for a
5647
+ // debugging surface — the per-agent context filter narrows down the
5648
+ // culprit). For a specific agent we use that agent's error directly.
5649
+ let threadsErrorMessage: string | null = null;
5650
+ if (this.selectedContext === "all-agents") {
5651
+ const firstError = this._threadsErrorByAgent.values().next().value;
5652
+ threadsErrorMessage = firstError?.message ?? null;
5653
+ } else {
5654
+ threadsErrorMessage =
5655
+ this._threadsErrorByAgent.get(this.selectedContext)?.message ?? null;
5656
+ }
5657
+
5658
+ const selectedThread =
5659
+ this.selectedThreadId != null
5660
+ ? (displayThreads.find((t) => t.id === this.selectedThreadId) ?? null)
5661
+ : null;
5662
+
5663
+ return html`
5664
+ <div style="display:flex;height:100%;overflow:hidden;">
5665
+ <!-- Left sidebar: thread list -->
5666
+ <div
5667
+ style="width:${this.threadListWidth}px;flex-shrink:0;overflow:hidden;display:flex;flex-direction:column;border-right:1px solid #DBDBE5;"
5668
+ >
5669
+ <cpk-thread-list
5670
+ style="height:100%;"
5671
+ .threads=${displayThreads}
5672
+ .selectedThreadId=${this.selectedThreadId}
5673
+ .errorMessage=${threadsErrorMessage}
5674
+ @threadSelected=${(e: CustomEvent<string>) => {
5675
+ this.selectedThreadId = e.detail;
5676
+ this.requestUpdate();
5677
+ }}
5678
+ ></cpk-thread-list>
5679
+ </div>
5680
+
5681
+ <!-- Resize divider -->
5682
+ <div
5683
+ style="width:4px;flex-shrink:0;cursor:col-resize;background:transparent;position:relative;z-index:1;"
5684
+ @pointerdown=${this.handleThreadDividerPointerDown}
5685
+ @pointermove=${this.handleThreadDividerPointerMove}
5686
+ @pointerup=${this.handleThreadDividerPointerUp}
5687
+ @pointercancel=${this.handleThreadDividerPointerUp}
5688
+ ></div>
5689
+
5690
+ <!-- Center + right: thread details or empty state -->
5691
+ <div style="flex:1;min-width:0;overflow:hidden;display:flex;">
5692
+ ${
5693
+ this.selectedThreadId
5694
+ ? html`<cpk-thread-details
5695
+ style="flex:1;min-width:0;"
5696
+ .threadId=${this.selectedThreadId}
5697
+ .thread=${selectedThread}
5698
+ .runtimeUrl=${this._core?.runtimeUrl ?? ""}
5699
+ .headers=${this._core?.headers ?? {}}
5700
+ .liveMessageVersion=${
5701
+ this.selectedThreadId
5702
+ ? (this.liveMessageVersion.get(this.selectedThreadId) ??
5703
+ 0)
5704
+ : 0
5705
+ }
5706
+ .agentStateInput=${
5707
+ selectedThread
5708
+ ? this.getLatestStateForAgent(selectedThread.agentId)
5709
+ : null
5710
+ }
5711
+ .agentEventsInput=${
5712
+ selectedThread
5713
+ ? (this.agentEvents.get(selectedThread.agentId) ?? [])
5714
+ : []
5715
+ }
5716
+ ></cpk-thread-details>`
5717
+ : html`
5718
+ <div
5719
+ style="
5720
+ flex: 1;
5721
+ display: flex;
5722
+ flex-direction: column;
5723
+ align-items: center;
5724
+ justify-content: center;
5725
+ gap: 8px;
5726
+ color: #838389;
5727
+ "
5728
+ >
5729
+ <svg
5730
+ width="32"
5731
+ height="32"
5732
+ viewBox="0 0 24 24"
5733
+ fill="none"
5734
+ stroke="#c0c0c8"
5735
+ stroke-width="1.5"
5736
+ stroke-linecap="round"
5737
+ stroke-linejoin="round"
5738
+ >
5739
+ <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
5740
+ </svg>
5741
+ <span style="font-size: 13px">${displayThreads.length === 0 ? "No threads yet" : "Select a thread to inspect"}</span>
5742
+ </div>
5743
+ `
5744
+ }
5745
+ </div>
5746
+ </div>
5747
+ `;
5748
+ }
5749
+
2692
5750
  private renderEventsTable() {
2693
5751
  const events = this.getEventsForSelectedContext();
2694
5752
  const filteredEvents = this.filterEvents(events);
@@ -2700,19 +5758,15 @@ ${argsString}</pre
2700
5758
  if (events.length === 0) {
2701
5759
  return html`
2702
5760
  <div
2703
- class="flex h-full items-center justify-center px-4 py-8 text-center"
5761
+ class="flex h-full flex-col items-center justify-center gap-2 px-4 py-10 text-center"
2704
5762
  >
2705
- <div class="max-w-md">
2706
- <div
2707
- class="mb-3 flex justify-center text-gray-300 [&>svg]:!h-8 [&>svg]:!w-8"
2708
- >
2709
- ${this.renderIcon("Zap")}
2710
- </div>
2711
- <p class="text-sm text-gray-600">No events yet</p>
2712
- <p class="mt-2 text-xs text-gray-500">
2713
- Trigger an agent run to see live activity.
2714
- </p>
5763
+ <div class="text-gray-300 [&>svg]:!h-8 [&>svg]:!w-8">
5764
+ ${this.renderIcon("Zap")}
2715
5765
  </div>
5766
+ <span class="text-sm text-gray-600">No events yet</span>
5767
+ <span class="max-w-[240px] text-xs leading-snug text-gray-400"
5768
+ >Events are recorded live. Run the agent to see them here.</span
5769
+ >
2716
5770
  </div>
2717
5771
  `;
2718
5772
  }
@@ -2823,23 +5877,30 @@ ${argsString}</pre
2823
5877
  </div>
2824
5878
  <div class="relative h-full w-full overflow-y-auto overflow-x-hidden">
2825
5879
  <table class="w-full table-fixed border-collapse text-xs box-border">
5880
+ <colgroup>
5881
+ <col style="width:${this.evtColWidths[0]}px">
5882
+ <col style="width:${this.evtColWidths[1]}px">
5883
+ <col style="width:${this.evtColWidths[2]}px">
5884
+ <col>
5885
+ </colgroup>
2826
5886
  <thead class="sticky top-0 z-10">
2827
5887
  <tr class="bg-white">
5888
+ ${["Agent", "Time", "Event Type"].map(
5889
+ (label, col) => html`
2828
5890
  <th
2829
5891
  class="border-b border-gray-200 bg-white px-3 py-2 text-left font-medium text-gray-900"
5892
+ style="position:relative;overflow:hidden;"
2830
5893
  >
2831
- Agent
2832
- </th>
2833
- <th
2834
- class="border-b border-gray-200 bg-white px-3 py-2 text-left font-medium text-gray-900"
2835
- >
2836
- Time
2837
- </th>
2838
- <th
2839
- class="border-b border-gray-200 bg-white px-3 py-2 text-left font-medium text-gray-900"
2840
- >
2841
- Event Type
2842
- </th>
5894
+ ${label}
5895
+ <div
5896
+ style="position:absolute;top:0;right:0;width:5px;height:100%;cursor:col-resize;user-select:none;background:transparent;"
5897
+ @pointerdown=${(e: PointerEvent) => this._onEvtColResizeStart(e, col)}
5898
+ @pointermove=${(e: PointerEvent) => this._onEvtColResizeMove(e)}
5899
+ @pointerup=${() => this._onEvtColResizeEnd()}
5900
+ @pointercancel=${() => this._onEvtColResizeEnd()}
5901
+ ></div>
5902
+ </th>`,
5903
+ )}
2843
5904
  <th
2844
5905
  class="border-b border-gray-200 bg-white px-3 py-2 text-left font-medium text-gray-900"
2845
5906
  >
@@ -2954,6 +6015,30 @@ ${prettyEvent}</pre
2954
6015
  this.requestUpdate();
2955
6016
  }
2956
6017
 
6018
+ private _onEvtColResizeStart(e: PointerEvent, col: number): void {
6019
+ e.preventDefault();
6020
+ e.stopPropagation();
6021
+ (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
6022
+ this._evtColResize = {
6023
+ col,
6024
+ startX: e.clientX,
6025
+ startW: this.evtColWidths[col] ?? 0,
6026
+ };
6027
+ }
6028
+
6029
+ private _onEvtColResizeMove(e: PointerEvent): void {
6030
+ if (!this._evtColResize) return;
6031
+ const { col, startX, startW } = this._evtColResize;
6032
+ this.evtColWidths = this.evtColWidths.map((w, i) =>
6033
+ i === col ? Math.max(40, startW + (e.clientX - startX)) : w,
6034
+ );
6035
+ this.requestUpdate();
6036
+ }
6037
+
6038
+ private _onEvtColResizeEnd(): void {
6039
+ this._evtColResize = null;
6040
+ }
6041
+
2957
6042
  private handleClearEvents = (): void => {
2958
6043
  if (this.selectedContext === "all-agents") {
2959
6044
  this.agentEvents.clear();
@@ -3026,7 +6111,7 @@ ${prettyEvent}</pre
3026
6111
  <div class="flex items-start justify-between mb-4">
3027
6112
  <div class="flex items-center gap-3">
3028
6113
  <div
3029
- class="flex h-10 w-10 items-center justify-center rounded-lg bg-blue-100 text-blue-600"
6114
+ class="flex h-10 w-10 items-center justify-center rounded-lg bg-blue-100 text-blue-600 cpk-agent-icon"
3030
6115
  >
3031
6116
  ${this.renderIcon("Bot")}
3032
6117
  </div>
@@ -3062,7 +6147,7 @@ ${prettyEvent}</pre
3062
6147
  <div class="grid grid-cols-2 gap-4 md:grid-cols-4">
3063
6148
  <button
3064
6149
  type="button"
3065
- class="rounded-md bg-gray-50 px-3 py-2 text-left transition hover:bg-gray-100 cursor-pointer overflow-hidden"
6150
+ class="rounded-md bg-gray-50 px-3 py-2 text-left transition hover:bg-gray-100 cursor-pointer overflow-hidden cpk-stat-card"
3066
6151
  @click=${() => this.handleMenuSelect("ag-ui-events")}
3067
6152
  title="View all events in AG-UI Events"
3068
6153
  >
@@ -3073,7 +6158,9 @@ ${prettyEvent}</pre
3073
6158
  ${stats.totalEvents}
3074
6159
  </div>
3075
6160
  </button>
3076
- <div class="rounded-md bg-gray-50 px-3 py-2 overflow-hidden">
6161
+ <div
6162
+ class="rounded-md bg-gray-50 px-3 py-2 overflow-hidden cpk-stat-card"
6163
+ >
3077
6164
  <div class="truncate whitespace-nowrap text-xs text-gray-600">
3078
6165
  Messages
3079
6166
  </div>
@@ -3081,7 +6168,9 @@ ${prettyEvent}</pre
3081
6168
  ${stats.messages}
3082
6169
  </div>
3083
6170
  </div>
3084
- <div class="rounded-md bg-gray-50 px-3 py-2 overflow-hidden">
6171
+ <div
6172
+ class="rounded-md bg-gray-50 px-3 py-2 overflow-hidden cpk-stat-card"
6173
+ >
3085
6174
  <div class="truncate whitespace-nowrap text-xs text-gray-600">
3086
6175
  Tool Calls
3087
6176
  </div>
@@ -3089,7 +6178,9 @@ ${prettyEvent}</pre
3089
6178
  ${stats.toolCalls}
3090
6179
  </div>
3091
6180
  </div>
3092
- <div class="rounded-md bg-gray-50 px-3 py-2 overflow-hidden">
6181
+ <div
6182
+ class="rounded-md bg-gray-50 px-3 py-2 overflow-hidden cpk-stat-card"
6183
+ >
3093
6184
  <div class="truncate whitespace-nowrap text-xs text-gray-600">
3094
6185
  Errors
3095
6186
  </div>
@@ -3101,9 +6192,9 @@ ${prettyEvent}</pre
3101
6192
  </div>
3102
6193
 
3103
6194
  <!-- Current State Section -->
3104
- <div class="rounded-lg border border-gray-200 bg-white">
3105
- <div class="border-b border-gray-200 px-4 py-3">
3106
- <h4 class="text-sm font-semibold text-gray-900">Current State</h4>
6195
+ <div class="cpk-section-card">
6196
+ <div class="cpk-section-header">
6197
+ <h4>Current State</h4>
3107
6198
  </div>
3108
6199
  <div class="overflow-auto p-4">
3109
6200
  ${
@@ -3115,7 +6206,7 @@ ${prettyEvent}</pre
3115
6206
  `
3116
6207
  : html`
3117
6208
  <div
3118
- class="flex h-40 items-center justify-center text-xs text-gray-500"
6209
+ class="flex h-12 items-center justify-center text-xs text-gray-500"
3119
6210
  >
3120
6211
  <div class="flex items-center gap-2 text-gray-500">
3121
6212
  <span class="text-lg text-gray-400"
@@ -3130,32 +6221,20 @@ ${prettyEvent}</pre
3130
6221
  </div>
3131
6222
 
3132
6223
  <!-- Current Messages Section -->
3133
- <div class="rounded-lg border border-gray-200 bg-white">
3134
- <div class="border-b border-gray-200 px-4 py-3">
3135
- <h4 class="text-sm font-semibold text-gray-900">
3136
- Current Messages
3137
- </h4>
6224
+ <div class="cpk-section-card">
6225
+ <div class="cpk-section-header">
6226
+ <h4>Current Messages</h4>
3138
6227
  </div>
3139
6228
  <div class="overflow-auto">
3140
6229
  ${
3141
6230
  messages && messages.length > 0
3142
6231
  ? html`
3143
- <table class="w-full text-xs">
3144
- <thead class="bg-gray-50">
3145
- <tr>
3146
- <th
3147
- class="px-4 py-2 text-left font-medium text-gray-700"
3148
- >
3149
- Role
3150
- </th>
3151
- <th
3152
- class="px-4 py-2 text-left font-medium text-gray-700"
3153
- >
3154
- Content
3155
- </th>
3156
- </tr>
3157
- </thead>
3158
- <tbody class="divide-y divide-gray-200">
6232
+ <div class="w-full text-xs">
6233
+ <div class="flex bg-gray-50">
6234
+ <div class="w-40 shrink-0 px-4 py-2 font-medium text-gray-700">Role</div>
6235
+ <div class="flex-1 px-4 py-2 font-medium text-gray-700">Content</div>
6236
+ </div>
6237
+ <div class="divide-y divide-gray-200">
3159
6238
  ${messages.map((msg) => {
3160
6239
  const role = msg.role || "unknown";
3161
6240
  const roleColors: Record<string, string> = {
@@ -3173,27 +6252,23 @@ ${prettyEvent}</pre
3173
6252
  toolCalls.length > 0 ? "Invoked tool call" : "—";
3174
6253
 
3175
6254
  return html`
3176
- <tr>
3177
- <td class="px-4 py-2 align-top">
6255
+ <div class="flex items-start">
6256
+ <div class="w-40 shrink-0 px-4 py-2">
3178
6257
  <span
3179
- class="inline-flex rounded px-2 py-0.5 text-[10px] font-medium ${
3180
- roleColors[role] || roleColors.unknown
3181
- }"
6258
+ class="inline-flex rounded px-2 py-0.5 text-[10px] font-medium ${roleColors[role] || roleColors.unknown}"
3182
6259
  >
3183
6260
  ${role}
3184
6261
  </span>
3185
- </td>
3186
- <td class="px-4 py-2">
6262
+ </div>
6263
+ <div class="flex-1 px-4 py-2">
3187
6264
  ${
3188
6265
  hasContent
3189
6266
  ? html`<div
3190
- class="max-w-2xl whitespace-pre-wrap break-words text-gray-700"
6267
+ class="whitespace-pre-line break-words text-gray-700"
3191
6268
  >
3192
6269
  ${rawContent}
3193
6270
  </div>`
3194
- : html`<div
3195
- class="text-xs italic text-gray-400"
3196
- >
6271
+ : html`<div class="italic text-gray-400">
3197
6272
  ${contentFallback}
3198
6273
  </div>`
3199
6274
  }
@@ -3202,16 +6277,16 @@ ${prettyEvent}</pre
3202
6277
  ? this.renderToolCallDetails(toolCalls)
3203
6278
  : nothing
3204
6279
  }
3205
- </td>
3206
- </tr>
6280
+ </div>
6281
+ </div>
3207
6282
  `;
3208
6283
  })}
3209
- </tbody>
3210
- </table>
6284
+ </div>
6285
+ </div>
3211
6286
  `
3212
6287
  : html`
3213
6288
  <div
3214
- class="flex h-40 items-center justify-center text-xs text-gray-500"
6289
+ class="flex h-12 items-center justify-center text-xs text-gray-500"
3215
6290
  >
3216
6291
  <div class="flex items-center gap-2 text-gray-500">
3217
6292
  <span class="text-lg text-gray-400"
@@ -3300,22 +6375,51 @@ ${prettyEvent}</pre
3300
6375
  return;
3301
6376
  }
3302
6377
 
6378
+ const previousMenu = this.selectedMenu;
3303
6379
  this.selectedMenu = key;
3304
6380
 
3305
- // If switching to agents view and "all-agents" is selected, switch to default or first agent
6381
+ // If switching to agents view and "all-agents" is selected, switch to the most recently active agent
3306
6382
  if (key === "agents" && this.selectedContext === "all-agents") {
3307
6383
  const agentOptions = this.contextOptions.filter(
3308
6384
  (opt) => opt.key !== "all-agents",
3309
6385
  );
3310
6386
  if (agentOptions.length > 0) {
3311
- // Try to find "default" agent first
3312
- const defaultAgent = agentOptions.find((opt) => opt.key === "default");
3313
- this.selectedContext = defaultAgent
3314
- ? defaultAgent.key
6387
+ // Pick the agent with the most recent activity; fall back to first
6388
+ const mostRecent = agentOptions.reduce<{
6389
+ key: string;
6390
+ ts: number;
6391
+ } | null>((best, opt) => {
6392
+ const ts = this.getAgentStats(opt.key).lastActivity ?? -1;
6393
+ return best === null || ts > best.ts ? { key: opt.key, ts } : best;
6394
+ }, null);
6395
+ this.selectedContext = mostRecent
6396
+ ? mostRecent.key
3315
6397
  : agentOptions[0]!.key;
3316
6398
  }
3317
6399
  }
3318
6400
 
6401
+ // If leaving the agents view with multiple agents registered, restore
6402
+ // "all-agents" so the Events tab isn't silently filtered to one agent.
6403
+ if (previousMenu === "agents" && key !== "agents") {
6404
+ const agentCount = this.contextOptions.filter(
6405
+ (opt) => opt.key !== "all-agents",
6406
+ ).length;
6407
+ if (agentCount > 1) {
6408
+ this.selectedContext = "all-agents";
6409
+ }
6410
+ }
6411
+
6412
+ if (key === "threads") {
6413
+ this.autoSelectLatestThread();
6414
+ }
6415
+
6416
+ if (key === "ag-ui-events" || key === "agents") {
6417
+ requestAnimationFrame(() => {
6418
+ const scroller = this.shadowRoot?.getElementById("cpk-main-scroll");
6419
+ if (scroller) scroller.scrollTop = 0;
6420
+ });
6421
+ }
6422
+
3319
6423
  this.contextMenuOpen = false;
3320
6424
  this.persistState();
3321
6425
  this.requestUpdate();
@@ -3948,9 +7052,19 @@ ${prettyEvent}</pre
3948
7052
  <div class="mb-3">
3949
7053
  <h5 class="mb-1 text-xs font-semibold text-gray-700">ID</h5>
3950
7054
  <code
3951
- class="block rounded bg-white border border-gray-200 px-2 py-1 text-[10px] font-mono text-gray-600"
7055
+ class="font-mono text-xs font-medium text-gray-800 flex-1 truncate min-w-0"
3952
7056
  >${id}</code
3953
7057
  >
7058
+ <button
7059
+ type="button"
7060
+ class="cpk-copy-btn"
7061
+ @click=${(e: Event) => {
7062
+ e.stopPropagation();
7063
+ void this.copyContextValue(id, `${id}:id`);
7064
+ }}
7065
+ >
7066
+ ${this.copiedContextItems.has(`${id}:id`) ? "✓" : "Copy"}
7067
+ </button>
3954
7068
  </div>
3955
7069
  ${
3956
7070
  hasValue
@@ -3960,8 +7074,8 @@ ${prettyEvent}</pre
3960
7074
  Value
3961
7075
  </h5>
3962
7076
  <button
3963
- class="flex items-center gap-1 rounded-md border border-gray-200 bg-white px-2 py-1 text-[10px] font-medium text-gray-700 transition hover:bg-gray-50"
3964
7077
  type="button"
7078
+ class="cpk-copy-btn"
3965
7079
  @click=${(e: Event) => {
3966
7080
  e.stopPropagation();
3967
7081
  void this.copyContextValue(context.value, id);
@@ -3974,15 +7088,6 @@ ${prettyEvent}</pre
3974
7088
  }
3975
7089
  </button>
3976
7090
  </div>
3977
- <div
3978
- class="rounded-md border border-gray-200 bg-white p-3"
3979
- >
3980
- <pre
3981
- class="overflow-auto text-xs text-gray-800 max-h-96"
3982
- ><code>${this.formatContextValue(
3983
- context.value,
3984
- )}</code></pre>
3985
- </div>
3986
7091
  `
3987
7092
  : html`
3988
7093
  <div class="flex items-center justify-center py-4 text-xs text-gray-500">
@@ -4004,7 +7109,7 @@ ${prettyEvent}</pre
4004
7109
  }
4005
7110
 
4006
7111
  if (typeof value === "string") {
4007
- return value.length > 50 ? `${value.substring(0, 50)}...` : value;
7112
+ return value.length > 50 ? `${value.slice(0, 50)}...` : value;
4008
7113
  }
4009
7114
 
4010
7115
  if (typeof value === "number" || typeof value === "boolean") {
@@ -4112,70 +7217,34 @@ ${prettyEvent}</pre
4112
7217
  this.requestUpdate();
4113
7218
  }
4114
7219
 
4115
- private renderAnnouncementPanel() {
4116
- if (!this.isOpen) {
4117
- return nothing;
4118
- }
4119
-
4120
- // Ensure loading is triggered even if we mounted in an already-open state
4121
- this.ensureAnnouncementLoading();
4122
-
7220
+ private renderAnnouncementBanner() {
4123
7221
  if (!this.hasUnseenAnnouncement) {
4124
7222
  return nothing;
4125
7223
  }
4126
7224
 
4127
- if (!this.announcementLoaded && !this.announcementMarkdown) {
4128
- return html`<div
4129
- class="mx-4 my-3 rounded-xl border border-slate-200 bg-white px-4 py-3 text-sm text-slate-800 shadow-[0_12px_30px_rgba(15,23,42,0.12)]"
4130
- >
4131
- <div class="flex items-center gap-2 font-semibold">
4132
- <span
4133
- class="inline-flex h-6 w-6 items-center justify-center rounded-md bg-slate-900 text-white shadow-sm"
4134
- >
4135
- ${this.renderIcon("Megaphone")}
4136
- </span>
4137
- <span>Loading latest announcement…</span>
4138
- </div>
4139
- </div>`;
4140
- }
4141
-
4142
- if (this.announcementLoadError) {
7225
+ if (!this.announcementLoaded && !this.announcementHtml) {
4143
7226
  return html`<div
4144
- class="mx-4 my-3 rounded-xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-900 shadow-[0_12px_30px_rgba(15,23,42,0.12)]"
7227
+ class="flex items-center gap-2 px-4 py-3 text-sm font-semibold text-slate-800"
4145
7228
  >
4146
- <div class="flex items-center gap-2 font-semibold">
4147
- <span
4148
- class="inline-flex h-6 w-6 items-center justify-center rounded-md bg-rose-600 text-white shadow-sm"
4149
- >
4150
- ${this.renderIcon("Megaphone")}
4151
- </span>
4152
- <span>Announcement unavailable</span>
4153
- </div>
4154
- <p class="mt-2 text-xs text-rose-800">
4155
- We couldn’t load the latest notice. Please try opening the inspector
4156
- again.
4157
- </p>
7229
+ <span
7230
+ class="inline-flex h-6 w-6 items-center justify-center rounded-md bg-slate-900 text-white shadow-sm"
7231
+ >
7232
+ ${this.renderIcon("Megaphone")}
7233
+ </span>
7234
+ <span>Loading latest announcement…</span>
4158
7235
  </div>`;
4159
7236
  }
4160
7237
 
4161
- if (!this.announcementMarkdown) {
7238
+ if (!this.announcementHtml) {
4162
7239
  return nothing;
4163
7240
  }
4164
7241
 
4165
- const content = this.announcementHtml
4166
- ? unsafeHTML(this.announcementHtml)
4167
- : html`<pre class="whitespace-pre-wrap text-sm text-gray-900">
4168
- ${this.announcementMarkdown}</pre
4169
- >`;
4170
-
4171
- return html`<div
4172
- class="mx-4 my-3 rounded-xl border border-slate-200 bg-white px-4 py-4 shadow-[0_12px_30px_rgba(15,23,42,0.12)]"
4173
- >
7242
+ return html`<div class="mx-4 mt-3 mb-3 rounded-xl border border-slate-200 bg-white px-4 py-3">
4174
7243
  <div
4175
- class="mb-3 flex items-center gap-2 text-sm font-semibold text-slate-900"
7244
+ class="mb-2 flex items-center gap-2 text-xs font-semibold text-slate-900"
4176
7245
  >
4177
7246
  <span
4178
- class="inline-flex h-7 w-7 items-center justify-center rounded-md bg-slate-900 text-white shadow-sm"
7247
+ class="inline-flex h-5 w-5 items-center justify-center rounded-md bg-slate-900 text-white shadow-sm"
4179
7248
  >
4180
7249
  ${this.renderIcon("Megaphone")}
4181
7250
  </span>
@@ -4186,12 +7255,34 @@ ${this.announcementMarkdown}</pre
4186
7255
  @click=${this.handleDismissAnnouncement}
4187
7256
  aria-label="Dismiss announcement"
4188
7257
  >
4189
- Dismiss
7258
+ ${this.renderIcon("X")}
4190
7259
  </button>
4191
7260
  </div>
4192
- <div class="announcement-content text-sm leading-relaxed text-gray-900">
4193
- ${content}
7261
+ <div class="announcement-body ${this.announcementExpanded ? "announcement-body--expanded" : "announcement-body--collapsed"}">
7262
+ <div
7263
+ class="announcement-content"
7264
+ @click=${this.handleAnnouncementContentClick}
7265
+ >
7266
+ ${unsafeHTML(this.announcementHtml)}
7267
+ </div>
7268
+ ${
7269
+ !this.announcementExpanded
7270
+ ? html`
7271
+ <div class="announcement-fade"></div>
7272
+ `
7273
+ : nothing
7274
+ }
4194
7275
  </div>
7276
+ <button
7277
+ class="announcement-toggle"
7278
+ type="button"
7279
+ @click=${() => {
7280
+ this.announcementExpanded = !this.announcementExpanded;
7281
+ this.requestUpdate();
7282
+ }}
7283
+ >
7284
+ ${this.announcementExpanded ? "Show less ↑" : "Show more ↓"}
7285
+ </button>
4195
7286
  </div>`;
4196
7287
  }
4197
7288
 
@@ -4266,7 +7357,6 @@ ${this.announcementMarkdown}</pre
4266
7357
 
4267
7358
  this.announcementTimestamp = timestamp;
4268
7359
  this.announcementPreviewText = previewText ?? "";
4269
- this.announcementMarkdown = markdown;
4270
7360
  this.hasUnseenAnnouncement =
4271
7361
  (!storedTimestamp || storedTimestamp !== timestamp) &&
4272
7362
  !!this.announcementPreviewText;
@@ -4276,7 +7366,11 @@ ${this.announcementMarkdown}</pre
4276
7366
 
4277
7367
  this.requestUpdate();
4278
7368
  } catch (error) {
4279
- this.announcementLoadError = error;
7369
+ // Swallowing here would hide non-network failures (malformed JSON, the
7370
+ // explicit "Malformed announcement payload" throw above, exceptions
7371
+ // from `convertMarkdownToHtml`). At minimum, surface in the console so
7372
+ // a stale announcement is debuggable.
7373
+ console.warn("[CopilotKit Inspector] Failed to load announcement", error);
4280
7374
  this.announcementLoaded = true;
4281
7375
  this.requestUpdate();
4282
7376
  }
@@ -4291,9 +7385,76 @@ ${this.announcementMarkdown}</pre
4291
7385
  const titleAttr = title ? ` title="${this.escapeHtmlAttr(title)}"` : "";
4292
7386
  return `<a href="${safeHref}" target="_blank" rel="noopener"${titleAttr}>${text}</a>`;
4293
7387
  };
4294
- return marked.parse(markdown, { renderer });
7388
+ renderer.code = (code, lang) => {
7389
+ const safeLang = (lang ?? "").replace(/[^a-z0-9-]/gi, "");
7390
+ const langClass = safeLang ? ` class="language-${safeLang}"` : "";
7391
+ const escaped = escapeHtml(code);
7392
+ const encoded = this.encodeBase64(code);
7393
+ return `<div class="announcement-code"><pre><code${langClass}>${escaped}</code></pre><div class="announcement-code__copy-shield"><button type="button" class="announcement-code__copy" data-copy="${encoded}" aria-label="Copy code">Copy</button></div></div>`;
7394
+ };
7395
+ return marked.parse(markdown, { renderer, async: false });
7396
+ }
7397
+
7398
+ private copyResetTimeouts = new WeakMap<HTMLButtonElement, number>();
7399
+
7400
+ private encodeBase64(value: string): string {
7401
+ if (typeof window === "undefined" || typeof window.btoa !== "function") {
7402
+ return "";
7403
+ }
7404
+ // btoa only accepts Latin-1; round-trip via TextEncoder to keep full UTF-8.
7405
+ const bytes = new TextEncoder().encode(value);
7406
+ let binary = "";
7407
+ for (const b of bytes) binary += String.fromCharCode(b);
7408
+ return window.btoa(binary);
7409
+ }
7410
+
7411
+ private decodeBase64(value: string): string {
7412
+ if (typeof window === "undefined" || typeof window.atob !== "function") {
7413
+ return "";
7414
+ }
7415
+ const decoded = window.atob(value);
7416
+ const bytes = new Uint8Array(decoded.length);
7417
+ for (let i = 0; i < decoded.length; i++) bytes[i] = decoded.charCodeAt(i);
7418
+ return new TextDecoder().decode(bytes);
4295
7419
  }
4296
7420
 
7421
+ private handleAnnouncementContentClick = (event: Event): void => {
7422
+ const target = event.target instanceof HTMLElement ? event.target : null;
7423
+ const button = target?.closest(".announcement-code__copy");
7424
+ if (!(button instanceof HTMLButtonElement)) {
7425
+ return;
7426
+ }
7427
+ event.preventDefault();
7428
+ event.stopPropagation();
7429
+ const encoded = button.getAttribute("data-copy") ?? "";
7430
+ const code = this.decodeBase64(encoded);
7431
+ if (!code) {
7432
+ return;
7433
+ }
7434
+ const showCopied = () => {
7435
+ const existing = this.copyResetTimeouts.get(button);
7436
+ if (existing !== undefined) {
7437
+ window.clearTimeout(existing);
7438
+ }
7439
+ button.setAttribute("data-copied", "true");
7440
+ button.setAttribute("aria-label", "Code copied");
7441
+ button.textContent = "Copied";
7442
+ const id = window.setTimeout(() => {
7443
+ button.removeAttribute("data-copied");
7444
+ button.setAttribute("aria-label", "Copy code");
7445
+ button.textContent = "Copy";
7446
+ this.copyResetTimeouts.delete(button);
7447
+ }, 1500);
7448
+ this.copyResetTimeouts.set(button, id);
7449
+ };
7450
+ if (typeof navigator !== "undefined" && navigator.clipboard?.writeText) {
7451
+ navigator.clipboard.writeText(code).then(showCopied, () => {
7452
+ // ignore — clipboard may be unavailable (insecure context, denied
7453
+ // permission, focus loss); button silently stays in idle state.
7454
+ });
7455
+ }
7456
+ };
7457
+
4297
7458
  private appendRefParam(href: string): string {
4298
7459
  try {
4299
7460
  const url = new URL(
@@ -4312,12 +7473,7 @@ ${this.announcementMarkdown}</pre
4312
7473
  }
4313
7474
 
4314
7475
  private escapeHtmlAttr(value: string): string {
4315
- return value
4316
- .replace(/&/g, "&amp;")
4317
- .replace(/</g, "&lt;")
4318
- .replace(/>/g, "&gt;")
4319
- .replace(/"/g, "&quot;")
4320
- .replace(/'/g, "&#39;");
7476
+ return escapeHtml(value).replace(/"/g, "&quot;").replace(/'/g, "&#39;");
4321
7477
  }
4322
7478
 
4323
7479
  private loadStoredAnnouncementTimestamp(): string | null {