@copilotkit/web-inspector 1.57.1 → 1.57.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4,6 +4,7 @@ const require_inspector_logo = require('./assets/inspector-logo.cjs');
4
4
  const require_inspector_logo_icon = require('./assets/inspector-logo-icon.cjs');
5
5
  const require_context_helpers = require('./lib/context-helpers.cjs');
6
6
  const require_persistence = require('./lib/persistence.cjs');
7
+ const require_telemetry = require('./lib/telemetry.cjs');
7
8
  let lit = require("lit");
8
9
  let marked = require("marked");
9
10
  let lit_directives_style_map_js = require("lit/directives/style-map.js");
@@ -1870,11 +1871,15 @@ var WebInspectorElement = class extends lit.LitElement {
1870
1871
  this.announcementHtml = null;
1871
1872
  this.announcementTimestamp = null;
1872
1873
  this.announcementPreviewText = null;
1874
+ this.announcementCtaLabel = null;
1873
1875
  this.hasUnseenAnnouncement = false;
1874
1876
  this.announcementLoaded = false;
1875
1877
  this.announcementPromise = null;
1876
1878
  this.showAnnouncementPreview = true;
1877
1879
  this.announcementExpanded = false;
1880
+ this.viewedBannerTimestamps = /* @__PURE__ */ new Set();
1881
+ this.pendingBannerViewed = null;
1882
+ this.clickedBannerIds = /* @__PURE__ */ new Set();
1878
1883
  this.contextState = {
1879
1884
  button: {
1880
1885
  position: {
@@ -2122,12 +2127,16 @@ var WebInspectorElement = class extends lit.LitElement {
2122
2127
  }
2123
2128
  };
2124
2129
  this.handleDismissAnnouncement = () => {
2130
+ this.trackBannerClickedOnce({ cta: "dismiss" });
2125
2131
  this.markAnnouncementSeen();
2126
2132
  };
2127
2133
  this.copyResetTimeouts = /* @__PURE__ */ new WeakMap();
2128
2134
  this.handleAnnouncementContentClick = (event) => {
2129
2135
  const button = (event.target instanceof HTMLElement ? event.target : null)?.closest(".announcement-code__copy");
2130
- if (!(button instanceof HTMLButtonElement)) return;
2136
+ if (!(button instanceof HTMLButtonElement)) {
2137
+ this.trackBannerClickedOnce({ cta: "body" });
2138
+ return;
2139
+ }
2131
2140
  event.preventDefault();
2132
2141
  event.stopPropagation();
2133
2142
  const encoded = button.getAttribute("data-copy") ?? "";
@@ -2277,8 +2286,14 @@ var WebInspectorElement = class extends lit.LitElement {
2277
2286
  this.coreSubscriber = {
2278
2287
  onRuntimeConnectionStatusChanged: ({ status }) => {
2279
2288
  this.runtimeStatus = status;
2280
- if (status === "connected") for (const agentId of this._ownedThreadStores.keys()) this.refreshOwnedThreadStore(agentId);
2281
- else {
2289
+ if (status === "connected") {
2290
+ if (!core.telemetryDisabled) {
2291
+ require_telemetry.ensureTelemetryDistinctId();
2292
+ require_telemetry.maybeShowDisclosure();
2293
+ }
2294
+ this.flushPendingBannerViewed();
2295
+ for (const agentId of this._ownedThreadStores.keys()) this.refreshOwnedThreadStore(agentId);
2296
+ } else {
2282
2297
  this._threadsByAgent.clear();
2283
2298
  this._threads = [];
2284
2299
  }
@@ -3267,6 +3282,11 @@ ${argsString}</pre
3267
3282
  color: #010507;
3268
3283
  font-weight: 600;
3269
3284
  }
3285
+ .cpk-tab-icon {
3286
+ display: inline-flex;
3287
+ flex-shrink: 0;
3288
+ align-items: center;
3289
+ }
3270
3290
  .cpk-tab-active .cpk-tab-icon {
3271
3291
  color: #757cf2;
3272
3292
  }
@@ -3639,6 +3659,15 @@ ${argsString}</pre
3639
3659
  <div class="min-w-[160px] max-w-xs">${agentSelector}</div>
3640
3660
  <div class="flex items-center gap-1">
3641
3661
  ${this.renderDockControls()}
3662
+ <button
3663
+ class="flex h-8 w-8 items-center justify-center rounded-md transition hover:bg-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-gray-400 ${this.selectedMenu === "settings" ? "bg-gray-100 text-gray-700" : "text-gray-400 hover:text-gray-600"}"
3664
+ type="button"
3665
+ aria-label="Settings"
3666
+ aria-pressed=${this.selectedMenu === "settings"}
3667
+ @click=${() => this.handleMenuSelect(this.selectedMenu === "settings" ? "ag-ui-events" : "settings")}
3668
+ >
3669
+ ${this.renderIcon("Settings")}
3670
+ </button>
3642
3671
  <button
3643
3672
  class="flex h-8 w-8 items-center justify-center rounded-md text-gray-400 transition hover:bg-gray-100 hover:text-gray-600 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-gray-400"
3644
3673
  type="button"
@@ -4195,8 +4224,52 @@ ${argsString}</pre
4195
4224
  if (this.selectedMenu === "frontend-tools") return this.renderToolsView();
4196
4225
  if (this.selectedMenu === "agent-context") return this.renderContextView();
4197
4226
  if (this.selectedMenu === "threads") return this.renderThreadsView();
4227
+ if (this.selectedMenu === "settings") return this.renderSettingsPanel();
4198
4228
  return lit.nothing;
4199
4229
  }
4230
+ renderSettingsPanel() {
4231
+ const optedOut = this.core?.telemetryDisabled ?? false;
4232
+ return lit.html`
4233
+ <div class="flex h-full flex-col overflow-hidden">
4234
+ <div class="overflow-auto p-4">
4235
+ <div class="space-y-3">
4236
+ <h2 class="text-sm font-semibold text-slate-900">Settings</h2>
4237
+
4238
+ <div class="space-y-2">
4239
+ <h3 class="text-sm text-slate-500">Privacy</h3>
4240
+ <div class="rounded-lg border border-slate-200 bg-white p-4 space-y-3">
4241
+ <p class="text-sm text-gray-600 flex items-start gap-2">
4242
+ <span>${optedOut ? "❌" : "✅"}</span>
4243
+ <span>
4244
+ ${optedOut ? "You have disabled anonymous interaction data collection." : "CopilotKit is currently collecting anonymous interaction data from the inspector so we know which features people use. We never collect message content, agent state, prompts, or completions."}
4245
+ </span>
4246
+ </p>
4247
+ <a
4248
+ class="inline-flex items-center gap-1 text-sm text-slate-700 underline hover:text-slate-900"
4249
+ href=${require_telemetry.TELEMETRY_DOCS_URL}
4250
+ target="_blank"
4251
+ rel="noopener"
4252
+ >Learn more →</a>
4253
+ </div>
4254
+ </div>
4255
+ </div>
4256
+ </div>
4257
+ </div>
4258
+ `;
4259
+ }
4260
+ trackBannerClickedOnce(opts) {
4261
+ if (this.core?.telemetryDisabled) return;
4262
+ const id = this.announcementTimestamp;
4263
+ if (!id) return;
4264
+ const key = `${id}:${opts.cta}`;
4265
+ if (this.clickedBannerIds.has(key)) return;
4266
+ this.clickedBannerIds.add(key);
4267
+ require_telemetry.trackBannerClicked({
4268
+ banner_id: id,
4269
+ cta: opts.cta,
4270
+ cta_label: this.announcementCtaLabel ?? void 0
4271
+ });
4272
+ }
4200
4273
  renderThreadsView() {
4201
4274
  const displayThreads = this.selectedContext === "all-agents" ? this._threads : this._threadsByAgent.get(this.selectedContext) ?? [];
4202
4275
  let threadsErrorMessage = null;
@@ -4768,7 +4841,7 @@ ${prettyEvent}</pre
4768
4841
  `;
4769
4842
  }
4770
4843
  handleMenuSelect(key) {
4771
- if (!this.menuItems.some((item) => item.key === key)) return;
4844
+ if (key !== "settings" && !this.menuItems.some((item) => item.key === key)) return;
4772
4845
  const previousMenu = this.selectedMenu;
4773
4846
  this.selectedMenu = key;
4774
4847
  if (key === "agents" && this.selectedContext === "all-agents") {
@@ -4787,7 +4860,10 @@ ${prettyEvent}</pre
4787
4860
  if (previousMenu === "agents" && key !== "agents") {
4788
4861
  if (this.contextOptions.filter((opt) => opt.key !== "all-agents").length > 1) this.selectedContext = "all-agents";
4789
4862
  }
4790
- if (key === "threads") this.autoSelectLatestThread();
4863
+ if (key === "threads") {
4864
+ if (this.selectedMenu !== "threads" && !this.core?.telemetryDisabled) require_telemetry.trackThreadsTabClicked();
4865
+ this.autoSelectLatestThread();
4866
+ }
4791
4867
  if (key === "ag-ui-events" || key === "agents") requestAnimationFrame(() => {
4792
4868
  const scroller = this.shadowRoot?.getElementById("cpk-main-scroll");
4793
4869
  if (scroller) scroller.scrollTop = 0;
@@ -5326,6 +5402,15 @@ ${prettyEvent}</pre
5326
5402
  </button>
5327
5403
  </div>`;
5328
5404
  }
5405
+ flushPendingBannerViewed() {
5406
+ if (!this.pendingBannerViewed || this.core?.telemetryDisabled) {
5407
+ this.pendingBannerViewed = null;
5408
+ return;
5409
+ }
5410
+ if (this.runtimeStatus !== "connected") return;
5411
+ require_telemetry.trackBannerViewed(this.pendingBannerViewed);
5412
+ this.pendingBannerViewed = null;
5413
+ }
5329
5414
  ensureAnnouncementLoading() {
5330
5415
  if (this.announcementPromise || typeof window === "undefined" || typeof fetch === "undefined") return;
5331
5416
  this.announcementPromise = this.fetchAnnouncement();
@@ -5354,14 +5439,24 @@ ${prettyEvent}</pre
5354
5439
  const timestamp = typeof data?.timestamp === "string" ? data.timestamp : null;
5355
5440
  const previewText = typeof data?.previewText === "string" ? data.previewText : null;
5356
5441
  const markdown = typeof data?.announcement === "string" ? data.announcement : null;
5442
+ const ctaLabel = typeof data?.cta_label === "string" ? data.cta_label : null;
5357
5443
  if (!timestamp || !markdown) throw new Error("Malformed announcement payload");
5358
5444
  const storedTimestamp = this.loadStoredAnnouncementTimestamp();
5359
5445
  this.announcementTimestamp = timestamp;
5360
5446
  this.announcementPreviewText = previewText ?? "";
5447
+ this.announcementCtaLabel = ctaLabel;
5361
5448
  this.hasUnseenAnnouncement = (!storedTimestamp || storedTimestamp !== timestamp) && !!this.announcementPreviewText;
5362
5449
  this.showAnnouncementPreview = this.hasUnseenAnnouncement;
5363
5450
  this.announcementHtml = await this.convertMarkdownToHtml(markdown);
5364
5451
  this.announcementLoaded = true;
5452
+ if (this.hasUnseenAnnouncement && !this.viewedBannerTimestamps.has(timestamp)) {
5453
+ this.viewedBannerTimestamps.add(timestamp);
5454
+ this.pendingBannerViewed = {
5455
+ banner_id: timestamp,
5456
+ cta_label: ctaLabel ?? void 0
5457
+ };
5458
+ this.flushPendingBannerViewed();
5459
+ }
5365
5460
  this.requestUpdate();
5366
5461
  } catch (error) {
5367
5462
  console.warn("[CopilotKit Inspector] Failed to load announcement", error);
@@ -5401,6 +5496,10 @@ ${prettyEvent}</pre
5401
5496
  try {
5402
5497
  const url = new URL(href, typeof window !== "undefined" ? window.location.href : "https://copilotkit.ai");
5403
5498
  if (!url.searchParams.has("ref")) url.searchParams.append("ref", "cpk-inspector");
5499
+ if (!url.searchParams.has("posthog_distinct_id") && !this.core?.telemetryDisabled) {
5500
+ const distinctId = require_telemetry.getTelemetryDistinctIdForUrl();
5501
+ if (distinctId) url.searchParams.append("posthog_distinct_id", distinctId);
5502
+ }
5404
5503
  return url.toString();
5405
5504
  } catch {
5406
5505
  return href;