@copilotkit/web-inspector 1.61.0 → 1.61.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -189,17 +189,45 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
189
189
  });
190
190
  }
191
191
 
192
+ //#endregion
193
+ //#region package.json
194
+ var version = "1.61.2";
195
+
192
196
  //#endregion
193
197
  //#region src/lib/telemetry.ts
194
198
  const TELEMETRY_EVENTS = {
195
199
  bannerViewed: "oss.inspector.banner_viewed",
196
200
  bannerClicked: "oss.inspector.banner_clicked",
197
- threadsTabClicked: "oss.inspector.threads_tab_clicked"
201
+ threadsTabClicked: "oss.inspector.threads_tab_clicked",
202
+ threadsLockedViewed: "oss.inspector.threads_locked_viewed",
203
+ threadsIntelligenceSignupClicked: "oss.inspector.threads_intelligence_signup_clicked",
204
+ threadsTalkToEngineerClicked: "oss.inspector.threads_talk_to_engineer_clicked",
205
+ talkToEngineerClicked: "oss.inspector.talk_to_engineer_clicked",
206
+ threadsEmptyEnabledViewed: "oss.inspector.threads_empty_enabled_viewed",
207
+ threadsEnabledViewed: "oss.inspector.threads_enabled_viewed"
198
208
  };
199
209
  const TELEMETRY_INGEST_URL = "https://telemetry.copilotkit.ai/ingest";
200
210
  const TELEMETRY_DOCS_URL = "https://docs.copilotkit.ai/telemetry";
201
211
  const PACKAGE_NAME = "@copilotkit/web-inspector";
212
+ const PACKAGE_VERSION = version;
202
213
  const FETCH_TIMEOUT_MS = 3e3;
214
+ function isThreadsTelemetryEvent(event) {
215
+ return event === TELEMETRY_EVENTS.threadsTabClicked || event === TELEMETRY_EVENTS.threadsLockedViewed || event === TELEMETRY_EVENTS.threadsIntelligenceSignupClicked || event === TELEMETRY_EVENTS.threadsTalkToEngineerClicked || event === TELEMETRY_EVENTS.talkToEngineerClicked || event === TELEMETRY_EVENTS.threadsEmptyEnabledViewed || event === TELEMETRY_EVENTS.threadsEnabledViewed;
216
+ }
217
+ function getRuntimeUrlType(runtimeUrl) {
218
+ if (!runtimeUrl) return "missing";
219
+ if (runtimeUrl.startsWith("/") && !runtimeUrl.startsWith("//")) return "relative";
220
+ try {
221
+ const baseHref = typeof window !== "undefined" ? window.location.href : "https://copilotkit.ai";
222
+ const url = new URL(runtimeUrl, baseHref);
223
+ const baseUrl = new URL(baseHref);
224
+ const hostname = url.hostname.toLowerCase();
225
+ if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]") return "localhost";
226
+ return url.origin === baseUrl.origin ? "same_origin" : "remote";
227
+ } catch (_unused) {
228
+ return "invalid";
229
+ }
230
+ }
203
231
  /**
204
232
  * Fire-and-forget telemetry send. Returns synchronously; the network
205
233
  * call is dispatched in the background and any failure is swallowed.
@@ -209,16 +237,32 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
209
237
  * inspector's mount lifecycle instead.
210
238
  */
211
239
  function track(event, properties = {}) {
240
+ if (isTelemetryOptedOut()) return;
212
241
  const distinctId = getOrCreateTelemetryDistinctId();
213
- postBestEffort(TELEMETRY_INGEST_URL, JSON.stringify({
214
- event,
215
- properties: {
216
- ...properties,
217
- distinct_id: distinctId
218
- },
219
- package: { name: PACKAGE_NAME },
220
- ts: Math.floor(Date.now() / 1e3)
221
- }), distinctId);
242
+ const threadsProperties = isThreadsTelemetryEvent(event) ? {
243
+ package_name: PACKAGE_NAME,
244
+ package_version: PACKAGE_VERSION,
245
+ inspector_distinct_id: distinctId
246
+ } : {};
247
+ let body;
248
+ try {
249
+ body = JSON.stringify({
250
+ event,
251
+ properties: {
252
+ ...properties,
253
+ ...threadsProperties,
254
+ distinct_id: distinctId
255
+ },
256
+ package: {
257
+ name: PACKAGE_NAME,
258
+ ...isThreadsTelemetryEvent(event) ? { version: PACKAGE_VERSION } : {}
259
+ },
260
+ ts: Math.floor(Date.now() / 1e3)
261
+ });
262
+ } catch (_unused2) {
263
+ return;
264
+ }
265
+ postBestEffort(TELEMETRY_INGEST_URL, body, distinctId);
222
266
  }
223
267
  function trackBannerViewed(props) {
224
268
  track(TELEMETRY_EVENTS.bannerViewed, props);
@@ -226,8 +270,26 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
226
270
  function trackBannerClicked(props) {
227
271
  track(TELEMETRY_EVENTS.bannerClicked, props);
228
272
  }
229
- function trackThreadsTabClicked() {
230
- track(TELEMETRY_EVENTS.threadsTabClicked);
273
+ function trackThreadsTabClicked(props = {}) {
274
+ track(TELEMETRY_EVENTS.threadsTabClicked, props);
275
+ }
276
+ function trackThreadsLockedViewed(props) {
277
+ track(TELEMETRY_EVENTS.threadsLockedViewed, props);
278
+ }
279
+ function trackThreadsIntelligenceSignupClicked(props) {
280
+ track(TELEMETRY_EVENTS.threadsIntelligenceSignupClicked, props);
281
+ }
282
+ function trackThreadsTalkToEngineerClicked(props) {
283
+ track(TELEMETRY_EVENTS.threadsTalkToEngineerClicked, props);
284
+ }
285
+ function trackTalkToEngineerClicked(props) {
286
+ track(TELEMETRY_EVENTS.talkToEngineerClicked, props);
287
+ }
288
+ function trackThreadsEmptyEnabledViewed(props) {
289
+ track(TELEMETRY_EVENTS.threadsEmptyEnabledViewed, props);
290
+ }
291
+ function trackThreadsEnabledViewed(props) {
292
+ track(TELEMETRY_EVENTS.threadsEnabledViewed, props);
231
293
  }
232
294
  /**
233
295
  * Returns the inspector's anonymous distinct-ID for cross-domain
@@ -286,7 +348,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
286
348
  body,
287
349
  signal: controller.signal
288
350
  });
289
- } catch (_unused) {} finally {
351
+ } catch (_unused3) {} finally {
290
352
  clearTimeout(timeoutId);
291
353
  }
292
354
  }
@@ -313,6 +375,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
313
375
  const DOCKED_LEFT_WIDTH = 500;
314
376
  const MAX_AGENT_EVENTS = 200;
315
377
  const MAX_TOTAL_EVENTS = 500;
378
+ const INTELLIGENCE_SIGNUP_URL = "https://go.copilotkit.ai/intelligence-signup";
379
+ const TALK_TO_ENGINEER_URL = "https://www.copilotkit.ai/talk-to-an-engineer";
316
380
  const AGENT_EVENT_TYPES = [
317
381
  "RUN_STARTED",
318
382
  "RUN_FINISHED",
@@ -388,14 +452,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
388
452
  bg: "rgba(190,194,255,0.102)",
389
453
  fg: "#5558B2"
390
454
  };
455
+ if (type === "RUN_ERROR" || type === "ERROR") return {
456
+ bg: "rgba(250,95,103,0.13)",
457
+ fg: "#c0333a"
458
+ };
391
459
  if (type.startsWith("RUN_") || type.startsWith("STEP_")) return {
392
460
  bg: "rgba(255,172,77,0.2)",
393
461
  fg: "#996300"
394
462
  };
395
- if (type === "ERROR") return {
396
- bg: "rgba(250,95,103,0.13)",
397
- fg: "#c0333a"
398
- };
399
463
  return {
400
464
  bg: "#F7F7F9",
401
465
  fg: "#838389"
@@ -687,6 +751,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
687
751
  this.thread = null;
688
752
  this.runtimeUrl = "";
689
753
  this.headers = {};
754
+ this.threadInspectionAvailable = false;
690
755
  this.agentStateInput = null;
691
756
  this.agentEventsInput = [];
692
757
  this.liveMessageVersion = 0;
@@ -809,7 +874,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
809
874
  * so users see an explicit loading indicator on first load.
810
875
  */
811
876
  async fetchMessages(threadId, silent = false) {
812
- if (!this.runtimeUrl) {
877
+ if (!this.runtimeUrl || !this.threadInspectionAvailable) {
813
878
  if (!silent) this._conversation = [];
814
879
  return;
815
880
  }
@@ -820,7 +885,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
820
885
  this._messagesError = null;
821
886
  }
822
887
  try {
823
- const res = await fetch(`${this.runtimeUrl}/threads/${encodeURIComponent(threadId)}/messages`, {
888
+ const res = await fetch(this.getThreadInspectionUrl(threadId, "messages"), {
824
889
  headers: { ...this.headers },
825
890
  signal: controller.signal
826
891
  });
@@ -841,7 +906,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
841
906
  }
842
907
  async fetchEvents(threadId) {
843
908
  this._eventsNotAvailable = false;
844
- if (!this.runtimeUrl) {
909
+ if (!this.runtimeUrl || !this.threadInspectionAvailable) {
845
910
  this._fetchedEvents = null;
846
911
  return;
847
912
  }
@@ -850,7 +915,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
850
915
  this._loadingEvents = true;
851
916
  this._eventsError = null;
852
917
  try {
853
- const res = await fetch(`${this.runtimeUrl}/threads/${encodeURIComponent(threadId)}/events`, {
918
+ const res = await fetch(this.getThreadInspectionUrl(threadId, "events"), {
854
919
  headers: { ...this.headers },
855
920
  signal: controller.signal
856
921
  });
@@ -875,7 +940,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
875
940
  }
876
941
  async fetchState(threadId) {
877
942
  this._stateNotAvailable = false;
878
- if (!this.runtimeUrl) {
943
+ if (!this.runtimeUrl || !this.threadInspectionAvailable) {
879
944
  this._fetchedState = null;
880
945
  return;
881
946
  }
@@ -885,7 +950,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
885
950
  this._stateError = null;
886
951
  try {
887
952
  var _data$state;
888
- const res = await fetch(`${this.runtimeUrl}/threads/${encodeURIComponent(threadId)}/state`, {
953
+ const res = await fetch(this.getThreadInspectionUrl(threadId, "state"), {
889
954
  headers: { ...this.headers },
890
955
  signal: controller.signal
891
956
  });
@@ -908,6 +973,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
908
973
  if (!controller.signal.aborted && this.threadId === threadId) this._loadingState = false;
909
974
  }
910
975
  }
976
+ getThreadInspectionUrl(threadId, resource) {
977
+ return `${this.runtimeUrl.replace(/\/+$/, "")}/threads/${encodeURIComponent(threadId)}/${resource}`;
978
+ }
911
979
  mapMessages(messages) {
912
980
  const items = [];
913
981
  const toolCallMap = /* @__PURE__ */ new Map();
@@ -1503,6 +1571,7 @@ ${(0, lit_directives_unsafe_html_js.unsafeHTML)(highlightedJson(event.payload))}
1503
1571
  thread: { attribute: false },
1504
1572
  runtimeUrl: { attribute: false },
1505
1573
  headers: { attribute: false },
1574
+ threadInspectionAvailable: { attribute: false },
1506
1575
  agentStateInput: { attribute: false },
1507
1576
  agentEventsInput: { attribute: false },
1508
1577
  liveMessageVersion: { attribute: false },
@@ -2165,6 +2234,7 @@ ${(0, lit_directives_unsafe_html_js.unsafeHTML)(highlightedJson(event.payload))}
2165
2234
  this.viewedBannerTimestamps = /* @__PURE__ */ new Set();
2166
2235
  this.pendingBannerViewed = null;
2167
2236
  this.clickedBannerIds = /* @__PURE__ */ new Set();
2237
+ this.viewedThreadsTelemetryStates = /* @__PURE__ */ new Set();
2168
2238
  this.contextState = {
2169
2239
  button: {
2170
2240
  position: {
@@ -2374,6 +2444,30 @@ ${(0, lit_directives_unsafe_html_js.unsafeHTML)(highlightedJson(event.payload))}
2374
2444
  this.expandedTools = /* @__PURE__ */ new Set();
2375
2445
  this.expandedContextItems = /* @__PURE__ */ new Set();
2376
2446
  this.copiedContextItems = /* @__PURE__ */ new Set();
2447
+ this.handleTalkToEngineerClick = () => {
2448
+ var _this$core;
2449
+ if ((_this$core = this.core) === null || _this$core === void 0 ? void 0 : _this$core.telemetryDisabled) return;
2450
+ trackTalkToEngineerClicked(this.getThreadsTelemetryProps({
2451
+ cta: "talk_to_engineer",
2452
+ cta_surface: "threads_header"
2453
+ }, { includeUrlAttribution: true }));
2454
+ };
2455
+ this.handleThreadsIntelligenceSignupClick = () => {
2456
+ var _this$core2;
2457
+ if ((_this$core2 = this.core) === null || _this$core2 === void 0 ? void 0 : _this$core2.telemetryDisabled) return;
2458
+ trackThreadsIntelligenceSignupClicked(this.getThreadsTelemetryProps({
2459
+ cta: "signup",
2460
+ cta_surface: "threads_locked"
2461
+ }, { includeUrlAttribution: true }));
2462
+ };
2463
+ this.handleThreadsTalkToEngineerClick = () => {
2464
+ var _this$core3;
2465
+ if ((_this$core3 = this.core) === null || _this$core3 === void 0 ? void 0 : _this$core3.telemetryDisabled) return;
2466
+ trackThreadsTalkToEngineerClicked(this.getThreadsTelemetryProps({
2467
+ cta: "talk_to_engineer",
2468
+ cta_surface: "threads_locked"
2469
+ }, { includeUrlAttribution: true }));
2470
+ };
2377
2471
  this.handleThreadDividerPointerDown = (event) => {
2378
2472
  this.threadDividerResizing = true;
2379
2473
  this.threadDividerPointerId = event.pointerId;
@@ -2496,7 +2590,38 @@ ${(0, lit_directives_unsafe_html_js.unsafeHTML)(highlightedJson(event.payload))}
2496
2590
  }
2497
2591
  ];
2498
2592
  }
2593
+ getThreadServiceStatus() {
2594
+ var _this$_core$threadEnd;
2595
+ if (!this._core) return "unknown";
2596
+ if (!this._core.threadEndpoints) return "unknown";
2597
+ return ((_this$_core$threadEnd = this._core.threadEndpoints) === null || _this$_core$threadEnd === void 0 ? void 0 : _this$_core$threadEnd.list) === false ? "unavailable" : "available";
2598
+ }
2599
+ areThreadEndpointsAvailable() {
2600
+ return this.getThreadServiceStatus() !== "unavailable";
2601
+ }
2602
+ getThreadsTelemetryProps(extra = {}, options = {}) {
2603
+ var _this$core4, _this$core$licenseSta, _this$core5, _this$core$runtimeMod, _this$core6, _this$core7, _this$core$telemetryD, _this$core8;
2604
+ const distinctId = options.includeUrlAttribution && !((_this$core4 = this.core) === null || _this$core4 === void 0 ? void 0 : _this$core4.telemetryDisabled) ? getTelemetryDistinctIdForUrl() : null;
2605
+ const threadServiceStatus = this.getThreadServiceStatus();
2606
+ return {
2607
+ posthog_distinct_id: distinctId !== null && distinctId !== void 0 ? distinctId : void 0,
2608
+ intelligence_status: threadServiceStatus === "available" ? "intelligence_enabled" : threadServiceStatus === "unavailable" ? "intelligence_not_enabled" : "unknown",
2609
+ thread_service_status: threadServiceStatus,
2610
+ license_status: (_this$core$licenseSta = (_this$core5 = this.core) === null || _this$core5 === void 0 ? void 0 : _this$core5.licenseStatus) !== null && _this$core$licenseSta !== void 0 ? _this$core$licenseSta : void 0,
2611
+ runtime_mode: (_this$core$runtimeMod = (_this$core6 = this.core) === null || _this$core6 === void 0 ? void 0 : _this$core6.runtimeMode) !== null && _this$core$runtimeMod !== void 0 ? _this$core$runtimeMod : void 0,
2612
+ runtime_url_type: getRuntimeUrlType((_this$core7 = this.core) === null || _this$core7 === void 0 ? void 0 : _this$core7.runtimeUrl),
2613
+ telemetry_disabled: (_this$core$telemetryD = (_this$core8 = this.core) === null || _this$core8 === void 0 ? void 0 : _this$core8.telemetryDisabled) !== null && _this$core$telemetryD !== void 0 ? _this$core$telemetryD : false,
2614
+ ...extra
2615
+ };
2616
+ }
2617
+ getIntelligenceSignupUrl() {
2618
+ return this.appendRefParam(INTELLIGENCE_SIGNUP_URL, "cpk-inspector");
2619
+ }
2620
+ getTalkToEngineerUrl() {
2621
+ return this.appendRefParam(TALK_TO_ENGINEER_URL, "cpk-inspector-threads");
2622
+ }
2499
2623
  subscribeToThreadStore(agentId, store) {
2624
+ if (!this.areThreadEndpointsAvailable()) return;
2500
2625
  if (this._threadStoreSubscriptions.has(agentId)) return;
2501
2626
  const threadsSub = store.select(_copilotkit_core.ɵselectThreads).subscribe((threads) => {
2502
2627
  this._threadsByAgent.set(agentId, threads);
@@ -2533,16 +2658,18 @@ ${(0, lit_directives_unsafe_html_js.unsafeHTML)(highlightedJson(event.payload))}
2533
2658
  this._threads = [];
2534
2659
  }
2535
2660
  ensureOwnedThreadStore(agentId) {
2536
- var _this$core;
2661
+ var _this$core9, _core$intelligence;
2537
2662
  if (this._ownedThreadStores.has(agentId)) return;
2538
- if ((_this$core = this.core) === null || _this$core === void 0 ? void 0 : _this$core.getThreadStore(agentId)) return;
2663
+ if ((_this$core9 = this.core) === null || _this$core9 === void 0 ? void 0 : _this$core9.getThreadStore(agentId)) return;
2539
2664
  const core = this.core;
2540
2665
  if (!(core === null || core === void 0 ? void 0 : core.runtimeUrl)) return;
2666
+ if (!this.areThreadEndpointsAvailable()) return;
2541
2667
  const store = (0, _copilotkit_core.ɵcreateThreadStore)({ fetch: globalThis.fetch });
2542
2668
  store.start();
2543
2669
  store.setContext({
2544
2670
  runtimeUrl: core.runtimeUrl,
2545
- headers: {},
2671
+ headers: { ...core.headers },
2672
+ wsUrl: (_core$intelligence = core.intelligence) === null || _core$intelligence === void 0 ? void 0 : _core$intelligence.wsUrl,
2546
2673
  agentId
2547
2674
  });
2548
2675
  this._ownedThreadStores.set(agentId, store);
@@ -2554,19 +2681,32 @@ ${(0, lit_directives_unsafe_html_js.unsafeHTML)(highlightedJson(event.payload))}
2554
2681
  if (!store) return;
2555
2682
  store.refresh();
2556
2683
  }
2684
+ updateOwnedThreadStoreHeaders(headers) {
2685
+ const core = this.core;
2686
+ if (!(core === null || core === void 0 ? void 0 : core.runtimeUrl)) return;
2687
+ for (const [agentId, store] of this._ownedThreadStores) {
2688
+ var _core$intelligence2;
2689
+ store.setContext({
2690
+ runtimeUrl: core.runtimeUrl,
2691
+ headers: { ...headers },
2692
+ wsUrl: (_core$intelligence2 = core.intelligence) === null || _core$intelligence2 === void 0 ? void 0 : _core$intelligence2.wsUrl,
2693
+ agentId
2694
+ });
2695
+ }
2696
+ }
2557
2697
  removeOwnedThreadStore(agentId) {
2558
- var _this$core2;
2698
+ var _this$core10;
2559
2699
  const store = this._ownedThreadStores.get(agentId);
2560
2700
  if (!store) return;
2561
2701
  store.stop();
2562
- (_this$core2 = this.core) === null || _this$core2 === void 0 || _this$core2.unregisterThreadStore(agentId);
2702
+ (_this$core10 = this.core) === null || _this$core10 === void 0 || _this$core10.unregisterThreadStore(agentId);
2563
2703
  this._ownedThreadStores.delete(agentId);
2564
2704
  }
2565
2705
  teardownOwnedThreadStores() {
2566
2706
  for (const [agentId, store] of this._ownedThreadStores) {
2567
- var _this$core3;
2707
+ var _this$core11;
2568
2708
  store.stop();
2569
- (_this$core3 = this.core) === null || _this$core3 === void 0 || _this$core3.unregisterThreadStore(agentId);
2709
+ (_this$core11 = this.core) === null || _this$core11 === void 0 || _this$core11.unregisterThreadStore(agentId);
2570
2710
  }
2571
2711
  this._ownedThreadStores.clear();
2572
2712
  }
@@ -2583,7 +2723,8 @@ ${(0, lit_directives_unsafe_html_js.unsafeHTML)(highlightedJson(event.payload))}
2583
2723
  maybeShowDisclosure();
2584
2724
  }
2585
2725
  this.flushPendingBannerViewed();
2586
- for (const agentId of this._ownedThreadStores.keys()) this.refreshOwnedThreadStore(agentId);
2726
+ if (this.areThreadEndpointsAvailable()) for (const agentId of this._ownedThreadStores.keys()) this.refreshOwnedThreadStore(agentId);
2727
+ else this.teardownOwnedThreadStores();
2587
2728
  } else {
2588
2729
  this._threadsByAgent.clear();
2589
2730
  this._threads = [];
@@ -2594,6 +2735,9 @@ ${(0, lit_directives_unsafe_html_js.unsafeHTML)(highlightedJson(event.payload))}
2594
2735
  this.coreProperties = properties;
2595
2736
  this.requestUpdate();
2596
2737
  },
2738
+ onHeadersChanged: ({ headers }) => {
2739
+ this.updateOwnedThreadStoreHeaders(headers);
2740
+ },
2597
2741
  onError: ({ code, error }) => {
2598
2742
  this.lastCoreError = {
2599
2743
  code,
@@ -2626,6 +2770,13 @@ ${(0, lit_directives_unsafe_html_js.unsafeHTML)(highlightedJson(event.payload))}
2626
2770
  };
2627
2771
  this.coreUnsubscribe = core.subscribe(this.coreSubscriber).unsubscribe;
2628
2772
  this.processAgentsChanged(core.agents);
2773
+ if (core.runtimeConnectionStatus === "connected") {
2774
+ if (!core.telemetryDisabled) {
2775
+ ensureTelemetryDistinctId();
2776
+ maybeShowDisclosure();
2777
+ }
2778
+ this.flushPendingBannerViewed();
2779
+ }
2629
2780
  const threadStores = typeof core.getThreadStores === "function" ? core.getThreadStores() : {};
2630
2781
  for (const [agentId, store] of Object.entries(threadStores)) this.subscribeToThreadStore(agentId, store);
2631
2782
  if (core.context) this.contextStore = this.normalizeContextStore(core.context);
@@ -2715,10 +2866,10 @@ ${(0, lit_directives_unsafe_html_js.unsafeHTML)(highlightedJson(event.payload))}
2715
2866
  onRunStartedEvent: ({ event }) => {
2716
2867
  this.recordAgentEvent(agentId, "RUN_STARTED", event);
2717
2868
  },
2718
- onRunFinishedEvent: ({ event, result }) => {
2869
+ onRunFinishedEvent: (params) => {
2719
2870
  this.recordAgentEvent(agentId, "RUN_FINISHED", {
2720
- event,
2721
- result
2871
+ event: params.event,
2872
+ result: "result" in params ? params.result : void 0
2722
2873
  });
2723
2874
  this.refreshOwnedThreadStore(agentId);
2724
2875
  },
@@ -3055,13 +3206,13 @@ ${argsString}</pre
3055
3206
  }
3056
3207
  getEventBadgeClasses(type) {
3057
3208
  const base = "font-mono text-[10px] font-medium inline-flex items-center rounded-sm px-1.5 py-0.5 border";
3209
+ if (type === "RUN_ERROR") return `${base} bg-rose-50 text-rose-700 border-rose-200`;
3058
3210
  if (type.startsWith("RUN_")) return `${base} bg-blue-50 text-blue-700 border-blue-200`;
3059
3211
  if (type.startsWith("TEXT_MESSAGE")) return `${base} bg-emerald-50 text-emerald-700 border-emerald-200`;
3060
3212
  if (type.startsWith("TOOL_CALL")) return `${base} bg-amber-50 text-amber-700 border-amber-200`;
3061
3213
  if (type.startsWith("REASONING")) return `${base} bg-fuchsia-50 text-fuchsia-700 border-fuchsia-200`;
3062
3214
  if (type.startsWith("STATE")) return `${base} bg-violet-50 text-violet-700 border-violet-200`;
3063
3215
  if (type.startsWith("MESSAGES")) return `${base} bg-sky-50 text-sky-700 border-sky-200`;
3064
- if (type === "RUN_ERROR") return `${base} bg-rose-50 text-rose-700 border-rose-200`;
3065
3216
  return `${base} bg-gray-100 text-gray-600 border-gray-200`;
3066
3217
  }
3067
3218
  stringifyPayload(payload, pretty) {
@@ -3851,8 +4002,8 @@ ${argsString}</pre
3851
4002
  return lit.nothing;
3852
4003
  }
3853
4004
  renderSettingsPanel() {
3854
- var _this$core$telemetryD, _this$core4;
3855
- const optedOut = (_this$core$telemetryD = (_this$core4 = this.core) === null || _this$core4 === void 0 ? void 0 : _this$core4.telemetryDisabled) !== null && _this$core$telemetryD !== void 0 ? _this$core$telemetryD : false;
4005
+ var _this$core$telemetryD2, _this$core12;
4006
+ const optedOut = (_this$core$telemetryD2 = (_this$core12 = this.core) === null || _this$core12 === void 0 ? void 0 : _this$core12.telemetryDisabled) !== null && _this$core$telemetryD2 !== void 0 ? _this$core$telemetryD2 : false;
3856
4007
  return lit.html`
3857
4008
  <div class="flex h-full flex-col overflow-hidden">
3858
4009
  <div class="overflow-auto p-4">
@@ -3882,8 +4033,8 @@ ${argsString}</pre
3882
4033
  `;
3883
4034
  }
3884
4035
  trackBannerClickedOnce(opts) {
3885
- var _this$core5, _this$announcementCta;
3886
- if ((_this$core5 = this.core) === null || _this$core5 === void 0 ? void 0 : _this$core5.telemetryDisabled) return;
4036
+ var _this$core13, _this$announcementCta;
4037
+ if ((_this$core13 = this.core) === null || _this$core13 === void 0 ? void 0 : _this$core13.telemetryDisabled) return;
3887
4038
  const id = this.announcementTimestamp;
3888
4039
  if (!id) return;
3889
4040
  const key = `${id}:${opts.cta}`;
@@ -3895,8 +4046,314 @@ ${argsString}</pre
3895
4046
  cta_label: (_this$announcementCta = this.announcementCtaLabel) !== null && _this$announcementCta !== void 0 ? _this$announcementCta : void 0
3896
4047
  });
3897
4048
  }
4049
+ trackThreadsViewStateOnce(state, threadCount) {
4050
+ var _this$core14;
4051
+ if ((_this$core14 = this.core) === null || _this$core14 === void 0 ? void 0 : _this$core14.telemetryDisabled) return;
4052
+ const key = `${state}:${this.getThreadServiceStatus()}`;
4053
+ if (this.viewedThreadsTelemetryStates.has(key)) return;
4054
+ this.viewedThreadsTelemetryStates.add(key);
4055
+ const props = this.getThreadsTelemetryProps({ thread_count: threadCount });
4056
+ if (state === "locked") trackThreadsLockedViewed(props);
4057
+ else if (state === "empty_enabled") trackThreadsEmptyEnabledViewed(props);
4058
+ else trackThreadsEnabledViewed(props);
4059
+ }
4060
+ renderThreadsLockedBackgroundMockup() {
4061
+ return lit.html`
4062
+ <div
4063
+ aria-hidden="true"
4064
+ style="
4065
+ position: absolute;
4066
+ inset: 0;
4067
+ display: grid;
4068
+ grid-template-columns: minmax(180px, 28%) 1fr;
4069
+ overflow: hidden;
4070
+ opacity: 0.58;
4071
+ pointer-events: none;
4072
+ "
4073
+ >
4074
+ <div
4075
+ style="
4076
+ display: flex;
4077
+ flex-direction: column;
4078
+ gap: 12px;
4079
+ padding: 28px 24px;
4080
+ border-right: 1px solid #dbdbe5;
4081
+ background: #fafafa;
4082
+ "
4083
+ >
4084
+ ${[
4085
+ {
4086
+ width: 74,
4087
+ accent: true
4088
+ },
4089
+ { width: 92 },
4090
+ { width: 68 },
4091
+ { width: 84 },
4092
+ { width: 58 },
4093
+ { width: 76 }
4094
+ ].map((row) => lit.html`
4095
+ <div
4096
+ style="
4097
+ padding: 12px;
4098
+ border-radius: 8px;
4099
+ background: ${row.accent ? "#eee6fe" : "#ffffff"};
4100
+ box-shadow: inset 0 0 0 1px #eeeef4;
4101
+ "
4102
+ >
4103
+ <div
4104
+ style="
4105
+ height: 8px;
4106
+ width: ${row.width}%;
4107
+ border-radius: 99px;
4108
+ background: ${row.accent ? "#a984f5" : "#d7d7df"};
4109
+ "
4110
+ ></div>
4111
+ <div
4112
+ style="
4113
+ height: 6px;
4114
+ width: 88%;
4115
+ margin-top: 10px;
4116
+ border-radius: 99px;
4117
+ background: #e3e3eb;
4118
+ "
4119
+ ></div>
4120
+ <div
4121
+ style="
4122
+ height: 6px;
4123
+ width: 62%;
4124
+ margin-top: 7px;
4125
+ border-radius: 99px;
4126
+ background: #e8e8ef;
4127
+ "
4128
+ ></div>
4129
+ </div>
4130
+ `)}
4131
+ </div>
4132
+ <div
4133
+ style="
4134
+ min-width: 0;
4135
+ padding: 42px 48px;
4136
+ background: #ffffff;
4137
+ "
4138
+ >
4139
+ <div
4140
+ style="
4141
+ height: 10px;
4142
+ width: 180px;
4143
+ border-radius: 99px;
4144
+ background: #d7d7df;
4145
+ "
4146
+ ></div>
4147
+ <div
4148
+ style="
4149
+ height: 8px;
4150
+ width: min(520px, 58%);
4151
+ margin-top: 28px;
4152
+ border-radius: 99px;
4153
+ background: #e3e3eb;
4154
+ "
4155
+ ></div>
4156
+ <div
4157
+ style="
4158
+ height: 8px;
4159
+ width: min(430px, 48%);
4160
+ margin-top: 12px;
4161
+ border-radius: 99px;
4162
+ background: #e8e8ef;
4163
+ "
4164
+ ></div>
4165
+ <div
4166
+ style="
4167
+ display: grid;
4168
+ grid-template-columns: repeat(2, minmax(0, 1fr));
4169
+ gap: 16px;
4170
+ max-width: 620px;
4171
+ margin-top: 30px;
4172
+ "
4173
+ >
4174
+ <div
4175
+ style="
4176
+ height: 116px;
4177
+ border-radius: 8px;
4178
+ background: #f5f5f8;
4179
+ box-shadow: inset 0 0 0 1px #eeeef4;
4180
+ "
4181
+ ></div>
4182
+ <div
4183
+ style="
4184
+ height: 116px;
4185
+ border-radius: 8px;
4186
+ background: #f5f5f8;
4187
+ box-shadow: inset 0 0 0 1px #eeeef4;
4188
+ "
4189
+ ></div>
4190
+ </div>
4191
+ <div
4192
+ style="
4193
+ height: 10px;
4194
+ width: min(680px, 74%);
4195
+ margin-top: 34px;
4196
+ border-radius: 99px;
4197
+ background: #e3e3eb;
4198
+ "
4199
+ ></div>
4200
+ <div
4201
+ style="
4202
+ height: 10px;
4203
+ width: min(560px, 60%);
4204
+ margin-top: 14px;
4205
+ border-radius: 99px;
4206
+ background: #e8e8ef;
4207
+ "
4208
+ ></div>
4209
+ </div>
4210
+ </div>
4211
+ `;
4212
+ }
4213
+ renderThreadsLockedView() {
4214
+ this.trackThreadsViewStateOnce("locked", 0);
4215
+ return lit.html`
4216
+ <div
4217
+ style="
4218
+ position: relative;
4219
+ height: 100%;
4220
+ display: flex;
4221
+ align-items: center;
4222
+ justify-content: center;
4223
+ padding: 32px;
4224
+ overflow: hidden;
4225
+ background: #ffffff;
4226
+ "
4227
+ >
4228
+ ${this.renderThreadsLockedBackgroundMockup()}
4229
+ <div
4230
+ aria-hidden="true"
4231
+ style="
4232
+ position: absolute;
4233
+ inset: 0;
4234
+ pointer-events: none;
4235
+ background:
4236
+ radial-gradient(circle at center, rgba(255,255,255,0.9) 0, rgba(255,255,255,0.78) 24%, rgba(255,255,255,0.34) 48%, rgba(255,255,255,0.56) 100%);
4237
+ "
4238
+ ></div>
4239
+ <div
4240
+ style="
4241
+ position: relative;
4242
+ z-index: 1;
4243
+ max-width: 440px;
4244
+ text-align: center;
4245
+ color: #57575b;
4246
+ "
4247
+ >
4248
+ <div
4249
+ aria-hidden="true"
4250
+ style="
4251
+ margin: 0 auto 18px;
4252
+ display: flex;
4253
+ justify-content: center;
4254
+ "
4255
+ >
4256
+ <div
4257
+ style="
4258
+ display: flex;
4259
+ height: 44px;
4260
+ width: 44px;
4261
+ align-items: center;
4262
+ justify-content: center;
4263
+ border: 1px solid #dfd6fb;
4264
+ border-radius: 8px;
4265
+ background: #eee6fe;
4266
+ color: #57575b;
4267
+ box-shadow: 0 8px 18px rgba(87, 87, 91, 0.14);
4268
+ "
4269
+ >
4270
+ ${this.renderIcon("Lock")}
4271
+ </div>
4272
+ </div>
4273
+ <h2
4274
+ style="
4275
+ margin: 0 0 8px;
4276
+ font-size: 16px;
4277
+ line-height: 1.35;
4278
+ font-weight: 600;
4279
+ color: #010507;
4280
+ "
4281
+ >
4282
+ Enable Intelligence to inspect Threads.
4283
+ </h2>
4284
+ <p
4285
+ style="
4286
+ margin: 0 auto 18px;
4287
+ max-width: 380px;
4288
+ font-size: 13px;
4289
+ line-height: 1.55;
4290
+ color: #57575b;
4291
+ "
4292
+ >
4293
+ Persist conversations and inspect saved thread history from the
4294
+ Inspector.
4295
+ </p>
4296
+ <div
4297
+ style="
4298
+ display: flex;
4299
+ flex-wrap: wrap;
4300
+ justify-content: center;
4301
+ gap: 8px;
4302
+ "
4303
+ >
4304
+ <a
4305
+ href=${this.getTalkToEngineerUrl()}
4306
+ target="_blank"
4307
+ rel="noopener"
4308
+ style="
4309
+ display: inline-flex;
4310
+ min-height: 34px;
4311
+ align-items: center;
4312
+ justify-content: center;
4313
+ gap: 6px;
4314
+ border-radius: 6px;
4315
+ background: #010507;
4316
+ padding: 8px 12px;
4317
+ font-size: 12px;
4318
+ font-weight: 600;
4319
+ color: #ffffff;
4320
+ text-decoration: none;
4321
+ "
4322
+ @click=${this.handleThreadsTalkToEngineerClick}
4323
+ >
4324
+ Talk to an Engineer
4325
+ </a>
4326
+ <a
4327
+ href=${this.getIntelligenceSignupUrl()}
4328
+ target="_blank"
4329
+ rel="noopener"
4330
+ style="
4331
+ display: inline-flex;
4332
+ min-height: 34px;
4333
+ align-items: center;
4334
+ justify-content: center;
4335
+ gap: 6px;
4336
+ border-radius: 6px;
4337
+ border: 1px solid #dbdbe5;
4338
+ background: #ffffff;
4339
+ padding: 8px 12px;
4340
+ font-size: 12px;
4341
+ font-weight: 600;
4342
+ color: #57575b;
4343
+ text-decoration: none;
4344
+ "
4345
+ @click=${this.handleThreadsIntelligenceSignupClick}
4346
+ >
4347
+ Sign up for Intelligence
4348
+ </a>
4349
+ </div>
4350
+ </div>
4351
+ </div>
4352
+ `;
4353
+ }
3898
4354
  renderThreadsView() {
3899
- var _this$_threadsByAgent, _displayThreads$find, _this$_core$runtimeUr, _this$_core2, _this$_core$headers, _this$_core3, _this$liveMessageVers2, _this$agentEvents$get6;
4355
+ var _this$_threadsByAgent, _displayThreads$find, _this$_core$runtimeUr, _this$_core2, _this$_core$headers, _this$_core3, _this$_core4, _this$liveMessageVers2, _this$agentEvents$get6;
4356
+ if (!this.areThreadEndpointsAvailable()) return this.renderThreadsLockedView();
3900
4357
  const displayThreads = this.selectedContext === "all-agents" ? this._threads : (_this$_threadsByAgent = this._threadsByAgent.get(this.selectedContext)) !== null && _this$_threadsByAgent !== void 0 ? _this$_threadsByAgent : [];
3901
4358
  let threadsErrorMessage = null;
3902
4359
  if (this.selectedContext === "all-agents") {
@@ -3908,71 +4365,88 @@ ${argsString}</pre
3908
4365
  threadsErrorMessage = (_this$_threadsErrorBy = (_this$_threadsErrorBy2 = this._threadsErrorByAgent.get(this.selectedContext)) === null || _this$_threadsErrorBy2 === void 0 ? void 0 : _this$_threadsErrorBy2.message) !== null && _this$_threadsErrorBy !== void 0 ? _this$_threadsErrorBy : null;
3909
4366
  }
3910
4367
  const selectedThread = this.selectedThreadId != null ? (_displayThreads$find = displayThreads.find((t) => t.id === this.selectedThreadId)) !== null && _displayThreads$find !== void 0 ? _displayThreads$find : null : null;
4368
+ if (!threadsErrorMessage) this.trackThreadsViewStateOnce(displayThreads.length === 0 ? "empty_enabled" : "enabled", displayThreads.length);
3911
4369
  return lit.html`
3912
- <div style="display:flex;height:100%;overflow:hidden;">
3913
- <!-- Left sidebar: thread list -->
4370
+ <div style="display:flex;height:100%;overflow:hidden;flex-direction:column;">
3914
4371
  <div
3915
- style="width:${this.threadListWidth}px;flex-shrink:0;overflow:hidden;display:flex;flex-direction:column;border-right:1px solid #DBDBE5;"
4372
+ style="display:flex;align-items:center;justify-content:flex-end;border-bottom:1px solid #DBDBE5;background:#ffffff;padding:8px 12px;flex-shrink:0;"
3916
4373
  >
3917
- <cpk-thread-list
3918
- style="height:100%;"
3919
- .threads=${displayThreads}
3920
- .selectedThreadId=${this.selectedThreadId}
3921
- .errorMessage=${threadsErrorMessage}
3922
- @threadSelected=${(e) => {
4374
+ <a
4375
+ href=${this.getTalkToEngineerUrl()}
4376
+ target="_blank"
4377
+ rel="noopener"
4378
+ style="display:inline-flex;align-items:center;gap:6px;border-radius:6px;border:1px solid #dbdbe5;background:#ffffff;padding:7px 10px;font-size:12px;font-weight:600;color:#57575b;text-decoration:none;"
4379
+ @click=${this.handleTalkToEngineerClick}
4380
+ >
4381
+ Talk to an Engineer
4382
+ </a>
4383
+ </div>
4384
+ <div style="display:flex;min-height:0;flex:1;overflow:hidden;">
4385
+ <!-- Left sidebar: thread list -->
4386
+ <div
4387
+ style="width:${this.threadListWidth}px;flex-shrink:0;overflow:hidden;display:flex;flex-direction:column;border-right:1px solid #DBDBE5;"
4388
+ >
4389
+ <cpk-thread-list
4390
+ style="height:100%;"
4391
+ .threads=${displayThreads}
4392
+ .selectedThreadId=${this.selectedThreadId}
4393
+ .errorMessage=${threadsErrorMessage}
4394
+ @threadSelected=${(e) => {
3923
4395
  this.selectedThreadId = e.detail;
3924
4396
  this.requestUpdate();
3925
4397
  }}
3926
- ></cpk-thread-list>
3927
- </div>
3928
-
3929
- <!-- Resize divider -->
3930
- <div
3931
- style="width:4px;flex-shrink:0;cursor:col-resize;background:transparent;position:relative;z-index:1;"
3932
- @pointerdown=${this.handleThreadDividerPointerDown}
3933
- @pointermove=${this.handleThreadDividerPointerMove}
3934
- @pointerup=${this.handleThreadDividerPointerUp}
3935
- @pointercancel=${this.handleThreadDividerPointerUp}
3936
- ></div>
4398
+ ></cpk-thread-list>
4399
+ </div>
3937
4400
 
3938
- <!-- Center + right: thread details or empty state -->
3939
- <div style="flex:1;min-width:0;overflow:hidden;display:flex;">
3940
- ${this.selectedThreadId ? lit.html`<cpk-thread-details
3941
- style="flex:1;min-width:0;"
3942
- .threadId=${this.selectedThreadId}
3943
- .thread=${selectedThread}
3944
- .runtimeUrl=${(_this$_core$runtimeUr = (_this$_core2 = this._core) === null || _this$_core2 === void 0 ? void 0 : _this$_core2.runtimeUrl) !== null && _this$_core$runtimeUr !== void 0 ? _this$_core$runtimeUr : ""}
3945
- .headers=${(_this$_core$headers = (_this$_core3 = this._core) === null || _this$_core3 === void 0 ? void 0 : _this$_core3.headers) !== null && _this$_core$headers !== void 0 ? _this$_core$headers : {}}
3946
- .liveMessageVersion=${this.selectedThreadId ? (_this$liveMessageVers2 = this.liveMessageVersion.get(this.selectedThreadId)) !== null && _this$liveMessageVers2 !== void 0 ? _this$liveMessageVers2 : 0 : 0}
3947
- .agentStateInput=${selectedThread ? this.getLatestStateForAgent(selectedThread.agentId) : null}
3948
- .agentEventsInput=${selectedThread ? (_this$agentEvents$get6 = this.agentEvents.get(selectedThread.agentId)) !== null && _this$agentEvents$get6 !== void 0 ? _this$agentEvents$get6 : [] : []}
3949
- ></cpk-thread-details>` : lit.html`
3950
- <div
3951
- style="
3952
- flex: 1;
3953
- display: flex;
3954
- flex-direction: column;
3955
- align-items: center;
3956
- justify-content: center;
3957
- gap: 8px;
3958
- color: #838389;
3959
- "
3960
- >
3961
- <svg
3962
- width="32"
3963
- height="32"
3964
- viewBox="0 0 24 24"
3965
- fill="none"
3966
- stroke="#c0c0c8"
3967
- stroke-width="1.5"
3968
- stroke-linecap="round"
3969
- stroke-linejoin="round"
4401
+ <!-- Resize divider -->
4402
+ <div
4403
+ style="width:4px;flex-shrink:0;cursor:col-resize;background:transparent;position:relative;z-index:1;"
4404
+ @pointerdown=${this.handleThreadDividerPointerDown}
4405
+ @pointermove=${this.handleThreadDividerPointerMove}
4406
+ @pointerup=${this.handleThreadDividerPointerUp}
4407
+ @pointercancel=${this.handleThreadDividerPointerUp}
4408
+ ></div>
4409
+
4410
+ <!-- Center + right: thread details or empty state -->
4411
+ <div style="flex:1;min-width:0;overflow:hidden;display:flex;">
4412
+ ${selectedThread ? lit.html`<cpk-thread-details
4413
+ style="flex:1;min-width:0;"
4414
+ .threadId=${selectedThread.id}
4415
+ .thread=${selectedThread}
4416
+ .runtimeUrl=${(_this$_core$runtimeUr = (_this$_core2 = this._core) === null || _this$_core2 === void 0 ? void 0 : _this$_core2.runtimeUrl) !== null && _this$_core$runtimeUr !== void 0 ? _this$_core$runtimeUr : ""}
4417
+ .headers=${(_this$_core$headers = (_this$_core3 = this._core) === null || _this$_core3 === void 0 ? void 0 : _this$_core3.headers) !== null && _this$_core$headers !== void 0 ? _this$_core$headers : {}}
4418
+ .threadInspectionAvailable=${((_this$_core4 = this._core) === null || _this$_core4 === void 0 || (_this$_core4 = _this$_core4.threadEndpoints) === null || _this$_core4 === void 0 ? void 0 : _this$_core4.inspect) !== false}
4419
+ .liveMessageVersion=${(_this$liveMessageVers2 = this.liveMessageVersion.get(selectedThread.id)) !== null && _this$liveMessageVers2 !== void 0 ? _this$liveMessageVers2 : 0}
4420
+ .agentStateInput=${this.getLatestStateForAgent(selectedThread.agentId)}
4421
+ .agentEventsInput=${(_this$agentEvents$get6 = this.agentEvents.get(selectedThread.agentId)) !== null && _this$agentEvents$get6 !== void 0 ? _this$agentEvents$get6 : []}
4422
+ ></cpk-thread-details>` : lit.html`
4423
+ <div
4424
+ style="
4425
+ flex: 1;
4426
+ display: flex;
4427
+ flex-direction: column;
4428
+ align-items: center;
4429
+ justify-content: center;
4430
+ gap: 8px;
4431
+ color: #838389;
4432
+ "
3970
4433
  >
3971
- <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
3972
- </svg>
3973
- <span style="font-size: 13px">${displayThreads.length === 0 ? "No threads yet" : "Select a thread to inspect"}</span>
3974
- </div>
3975
- `}
4434
+ <svg
4435
+ width="32"
4436
+ height="32"
4437
+ viewBox="0 0 24 24"
4438
+ fill="none"
4439
+ stroke="#c0c0c8"
4440
+ stroke-width="1.5"
4441
+ stroke-linecap="round"
4442
+ stroke-linejoin="round"
4443
+ >
4444
+ <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
4445
+ </svg>
4446
+ <span style="font-size: 13px">${displayThreads.length === 0 ? "No threads yet" : "Select a thread to inspect"}</span>
4447
+ </div>
4448
+ `}
4449
+ </div>
3976
4450
  </div>
3977
4451
  </div>
3978
4452
  `;
@@ -4500,8 +4974,8 @@ ${prettyEvent}</pre
4500
4974
  if (this.contextOptions.filter((opt) => opt.key !== "all-agents").length > 1) this.selectedContext = "all-agents";
4501
4975
  }
4502
4976
  if (key === "threads") {
4503
- var _this$core6;
4504
- if (this.selectedMenu !== "threads" && !((_this$core6 = this.core) === null || _this$core6 === void 0 ? void 0 : _this$core6.telemetryDisabled)) trackThreadsTabClicked();
4977
+ var _this$core15;
4978
+ if (previousMenu !== "threads" && !((_this$core15 = this.core) === null || _this$core15 === void 0 ? void 0 : _this$core15.telemetryDisabled)) trackThreadsTabClicked(this.getThreadsTelemetryProps());
4505
4979
  this.autoSelectLatestThread();
4506
4980
  }
4507
4981
  if (key === "ag-ui-events" || key === "agents") requestAnimationFrame(() => {
@@ -4934,6 +5408,22 @@ ${prettyEvent}</pre
4934
5408
  ${this.copiedContextItems.has(id) ? "Copied" : "Copy JSON"}
4935
5409
  </button>
4936
5410
  </div>
5411
+ <pre
5412
+ style="
5413
+ margin: 0;
5414
+ max-height: 180px;
5415
+ overflow: auto;
5416
+ white-space: pre-wrap;
5417
+ word-break: break-word;
5418
+ border-radius: 6px;
5419
+ border: 1px solid #eeeef4;
5420
+ background: #f7f7f9;
5421
+ padding: 10px;
5422
+ font-size: 11px;
5423
+ line-height: 1.5;
5424
+ color: #2d2d30;
5425
+ "
5426
+ >${this.formatContextValue(context.value)}</pre>
4937
5427
  ` : lit.html`
4938
5428
  <div class="flex items-center justify-center py-4 text-xs text-gray-500">
4939
5429
  <span>No value available</span>
@@ -5053,8 +5543,8 @@ ${prettyEvent}</pre
5053
5543
  </div>`;
5054
5544
  }
5055
5545
  flushPendingBannerViewed() {
5056
- var _this$core7;
5057
- if (!this.pendingBannerViewed || ((_this$core7 = this.core) === null || _this$core7 === void 0 ? void 0 : _this$core7.telemetryDisabled)) {
5546
+ var _this$core16;
5547
+ if (!this.pendingBannerViewed || ((_this$core16 = this.core) === null || _this$core16 === void 0 ? void 0 : _this$core16.telemetryDisabled)) {
5058
5548
  this.pendingBannerViewed = null;
5059
5549
  return;
5060
5550
  }
@@ -5126,8 +5616,9 @@ ${prettyEvent}</pre
5126
5616
  async convertMarkdownToHtml(markdown) {
5127
5617
  const renderer = new marked.marked.Renderer();
5128
5618
  renderer.link = (href, title, text) => {
5129
- return `<a href="${this.escapeHtmlAttr(this.appendRefParam(href !== null && href !== void 0 ? href : ""))}" target="_blank" rel="noopener"${title ? ` title="${this.escapeHtmlAttr(title)}"` : ""}>${text}</a>`;
5619
+ return `<a href="${this.escapeHtmlAttr(this.isSafeAnnouncementHref(href !== null && href !== void 0 ? href : "") ? this.appendRefParam(href !== null && href !== void 0 ? href : "") : "#")}" target="_blank" rel="noopener"${title ? ` title="${this.escapeHtmlAttr(title)}"` : ""}>${text}</a>`;
5130
5620
  };
5621
+ renderer.html = (html) => escapeHtml(html);
5131
5622
  renderer.code = (code, lang) => {
5132
5623
  const safeLang = (lang !== null && lang !== void 0 ? lang : "").replace(/[^a-z0-9-]/gi, "");
5133
5624
  return `<div class="announcement-code"><pre><code${safeLang ? ` class="language-${safeLang}"` : ""}>${escapeHtml(code)}</code></pre><div class="announcement-code__copy-shield"><button type="button" class="announcement-code__copy" data-copy="${this.encodeBase64(code)}" aria-label="Copy code">Copy</button></div></div>`;
@@ -5137,6 +5628,14 @@ ${prettyEvent}</pre
5137
5628
  async: false
5138
5629
  });
5139
5630
  }
5631
+ isSafeAnnouncementHref(href) {
5632
+ try {
5633
+ const url = new URL(href, typeof window !== "undefined" ? window.location.href : "https://copilotkit.ai");
5634
+ return url.protocol === "http:" || url.protocol === "https:" || url.protocol === "mailto:";
5635
+ } catch (_unused7) {
5636
+ return false;
5637
+ }
5638
+ }
5140
5639
  encodeBase64(value) {
5141
5640
  if (typeof window === "undefined" || typeof window.btoa !== "function") return "";
5142
5641
  const bytes = new TextEncoder().encode(value);
@@ -5151,20 +5650,26 @@ ${prettyEvent}</pre
5151
5650
  for (let i = 0; i < decoded.length; i++) bytes[i] = decoded.charCodeAt(i);
5152
5651
  return new TextDecoder().decode(bytes);
5153
5652
  }
5154
- appendRefParam(href) {
5653
+ appendRefParam(href, ref = "cpk-inspector") {
5155
5654
  try {
5156
- var _this$core8;
5655
+ var _this$core17;
5656
+ const isRootRelative = href.startsWith("/") && !href.startsWith("//");
5157
5657
  const url = new URL(href, typeof window !== "undefined" ? window.location.href : "https://copilotkit.ai");
5158
- if (!url.searchParams.has("ref")) url.searchParams.append("ref", "cpk-inspector");
5159
- if (!url.searchParams.has("posthog_distinct_id") && !((_this$core8 = this.core) === null || _this$core8 === void 0 ? void 0 : _this$core8.telemetryDisabled)) {
5658
+ if (!url.searchParams.has("ref")) url.searchParams.append("ref", ref);
5659
+ if (!url.searchParams.has("posthog_distinct_id") && !((_this$core17 = this.core) === null || _this$core17 === void 0 ? void 0 : _this$core17.telemetryDisabled) && this.isCopilotKitDestination(url)) {
5160
5660
  const distinctId = getTelemetryDistinctIdForUrl();
5161
5661
  if (distinctId) url.searchParams.append("posthog_distinct_id", distinctId);
5162
5662
  }
5663
+ if (isRootRelative) return `${url.pathname}${url.search}${url.hash}`;
5163
5664
  return url.toString();
5164
- } catch (_unused7) {
5665
+ } catch (_unused8) {
5165
5666
  return href;
5166
5667
  }
5167
5668
  }
5669
+ isCopilotKitDestination(url) {
5670
+ const hostname = url.hostname.toLowerCase();
5671
+ return hostname === "copilotkit.ai" || hostname.endsWith(".copilotkit.ai");
5672
+ }
5168
5673
  escapeHtmlAttr(value) {
5169
5674
  return escapeHtml(value).replace(/"/g, "&quot;").replace(/'/g, "&#39;");
5170
5675
  }
@@ -5176,7 +5681,7 @@ ${prettyEvent}</pre
5176
5681
  const parsed = JSON.parse(raw);
5177
5682
  if (parsed && typeof parsed.timestamp === "string") return parsed.timestamp;
5178
5683
  return null;
5179
- } catch (_unused8) {}
5684
+ } catch (_unused9) {}
5180
5685
  return null;
5181
5686
  }
5182
5687
  persistAnnouncementTimestamp(timestamp) {
@@ -5184,7 +5689,7 @@ ${prettyEvent}</pre
5184
5689
  try {
5185
5690
  const payload = JSON.stringify({ timestamp });
5186
5691
  window.localStorage.setItem(ANNOUNCEMENT_STORAGE_KEY, payload);
5187
- } catch (_unused9) {}
5692
+ } catch (_unused10) {}
5188
5693
  }
5189
5694
  markAnnouncementSeen() {
5190
5695
  this.hasUnseenAnnouncement = false;