@copilotkit/web-inspector 1.77.0 → 1.77.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.cjs CHANGED
@@ -1,6 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_notifications = require('./lib/notifications.cjs');
3
3
  const require_notification_loader = require('./lib/notification-loader.cjs');
4
+ const require_hud_config = require('./lib/hud-config.cjs');
5
+ const require_hud_loader = require('./lib/hud-loader.cjs');
6
+ const require_hud_defaults = require('./lib/hud-defaults.cjs');
4
7
  const require_persistence = require('./lib/persistence.cjs');
5
8
  const require_generated = require('./styles/generated.cjs');
6
9
  const require_notification_article = require('./styles/notification-article.cjs');
@@ -121,9 +124,6 @@ const EVENT_ERROR_GUIDANCE = {
121
124
  const PILL_SUBLINE_LABEL = "Open Inspector for details";
122
125
  const HUD_INSPECTOR_LABEL = "CopilotKit Inspector";
123
126
  const HUD_ANNOUNCEMENT_TITLE_LIMIT = 80;
124
- const HUD_THREADS_LABEL = "Rich Threads";
125
- const HUD_LEARNING_LABEL = "Automatic Learning";
126
- const HUD_LEARN_MORE_LABEL = "Click to learn more";
127
127
  const INSPECTOR_DISMISSAL_MS = {
128
128
  day: 1440 * 60 * 1e3,
129
129
  week: 10080 * 60 * 1e3,
@@ -834,7 +834,86 @@ function coerceJsonValue(value) {
834
834
  return value;
835
835
  }
836
836
  }
837
+ let inspectorJsonRenderer = null;
838
+ let inspectorJsonSlotCount = 0;
839
+ const JSON_BLOCK_TAG = "cpk-json-block";
840
+ /**
841
+ * Replaces the inspector's built-in JSON blocks (tool arguments and results,
842
+ * state, events, and context) with a host renderer. Pass `null` to restore the
843
+ * built-in blocks. Set it before the inspector renders: a block that is
844
+ * already on screen changes at the inspector's next render.
845
+ *
846
+ * @example
847
+ * ```ts
848
+ * setInspectorJsonRenderer((container, value) => {
849
+ * const root = createRoot(container);
850
+ * root.render(<JsonView value={value} />);
851
+ * return () => root.unmount();
852
+ * });
853
+ * ```
854
+ */
855
+ function setInspectorJsonRenderer(renderer) {
856
+ inspectorJsonRenderer = renderer;
857
+ }
858
+ /**
859
+ * Hosts one value drawn by the host renderer. Inside a shadow root, the
860
+ * container lives in the shadow host's light DOM and shows here through a
861
+ * named slot, so the host page's own styles apply to what the renderer draws.
862
+ */
863
+ var CpkJsonBlock = class extends (globalThis.HTMLElement ?? class {}) {
864
+ #value = void 0;
865
+ #hasValue = false;
866
+ #cleanup;
867
+ #container;
868
+ get value() {
869
+ return this.#value;
870
+ }
871
+ set value(next) {
872
+ if (this.#hasValue && Object.is(next, this.#value)) return;
873
+ this.#value = next;
874
+ this.#hasValue = true;
875
+ if (this.isConnected) this.#render();
876
+ }
877
+ connectedCallback() {
878
+ this.style.display = "block";
879
+ this.#render();
880
+ }
881
+ disconnectedCallback() {
882
+ this.#teardown();
883
+ }
884
+ #render() {
885
+ this.#teardown();
886
+ const renderer = inspectorJsonRenderer;
887
+ if (!renderer) return;
888
+ const root = this.getRootNode();
889
+ const container = this.ownerDocument.createElement("div");
890
+ if (root.nodeType === Node.DOCUMENT_FRAGMENT_NODE && "host" in root) {
891
+ inspectorJsonSlotCount += 1;
892
+ const name = `cpk-json-${inspectorJsonSlotCount}`;
893
+ const slot = this.ownerDocument.createElement("slot");
894
+ slot.name = name;
895
+ this.replaceChildren(slot);
896
+ container.slot = name;
897
+ root.host.append(container);
898
+ } else this.replaceChildren(container);
899
+ this.#container = container;
900
+ const cleanup = renderer(container, this.#value);
901
+ this.#cleanup = typeof cleanup === "function" ? cleanup : void 0;
902
+ }
903
+ #teardown() {
904
+ const cleanup = this.#cleanup;
905
+ this.#cleanup = void 0;
906
+ cleanup?.();
907
+ this.#container?.remove();
908
+ this.#container = void 0;
909
+ this.replaceChildren();
910
+ }
911
+ };
837
912
  function renderHighlightedJsonBlock(value, options = {}) {
913
+ if (inspectorJsonRenderer) return lit.html`<cpk-json-block
914
+ .value=${value}
915
+ style=${options.maxHeight ? `overflow:auto;max-height:${options.maxHeight}` : lit.nothing}
916
+ ></cpk-json-block>`;
838
917
  const parsed = coerceJsonValue(value);
839
918
  return lit.html`<pre class="cpk-json-block" style=${(options.maxHeight ? `max-height:${options.maxHeight}` : void 0) || lit.nothing}>
840
919
  ${(0, lit_directives_unsafe_html_js.unsafeHTML)(highlightedJson(parsed))}</pre
@@ -5225,6 +5304,9 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
5225
5304
  this.announcementId = null;
5226
5305
  this.announcementLoaded = false;
5227
5306
  this.announcementPromise = null;
5307
+ this.hudFeed = null;
5308
+ this.hudFeedPromise = null;
5309
+ this.hudContent = require_hud_defaults.HUD_DEFAULT_CONTENT;
5228
5310
  this.newsSignalArmed = false;
5229
5311
  this.pulsingSignal = null;
5230
5312
  this.pendingPulseSignal = null;
@@ -5567,7 +5649,8 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
5567
5649
  control,
5568
5650
  trigger
5569
5651
  }));
5570
- this.hudLandingMenu = row === "threads" ? "threads" : row === "learning" ? "memories" : "home";
5652
+ const destination = this.hudContent[row].destination;
5653
+ this.hudLandingMenu = require_inspector_nav.isInspectorMenuKey(destination) && this.menuItems.some((item) => item.key === destination) ? destination : row === "threads" ? "threads" : "memories";
5571
5654
  this.closeLauncherHud();
5572
5655
  this.openInspector("floating_button");
5573
5656
  };
@@ -8890,6 +8973,8 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
8890
8973
 
8891
8974
  .cpk-launcher-hud__label {
8892
8975
  min-width: 0;
8976
+ /* Remote copy can be one long word; wrap it inside the row. */
8977
+ overflow-wrap: anywhere;
8893
8978
  }
8894
8979
 
8895
8980
  .cpk-launcher-hud__feature-icon {
@@ -9692,7 +9777,8 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
9692
9777
  <div data-inspector-portal-anchor></div>
9693
9778
  ` : this.renderButton();
9694
9779
  }
9695
- willUpdate() {
9780
+ willUpdate(changed) {
9781
+ if (changed.has("notificationContext")) this.refreshHudContent();
9696
9782
  this.evaluateErrorSignals();
9697
9783
  this.reconcileSelectedMenuVisibility();
9698
9784
  if (this.isOpen && this.dockMode === "docked-left") this.setAttribute("data-docked", "true");
@@ -10077,6 +10163,7 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
10077
10163
  renderHudRow(args) {
10078
10164
  if (args.connected) return lit.nothing;
10079
10165
  const detailId = `cpk-hud-detail-${args.id}`;
10166
+ const { label, description } = this.hudContent[args.id];
10080
10167
  return lit.html`
10081
10168
  <li
10082
10169
  class="cpk-launcher-hud__row"
@@ -10090,7 +10177,7 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
10090
10177
  type="button"
10091
10178
  class="cpk-launcher-hud__action"
10092
10179
  data-cpk-hud-action
10093
- aria-label=${`Open ${args.label} in Inspector`}
10180
+ aria-label=${`Open ${label} in Inspector`}
10094
10181
  @click=${(event) => this.handleHudActionClick(event, args.id, "action")}
10095
10182
  @pointerdown=${(event) => event.stopPropagation()}
10096
10183
  >
@@ -10100,13 +10187,13 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
10100
10187
  aria-hidden="true"
10101
10188
  >${this.renderIcon(args.icon)}</span
10102
10189
  >
10103
- <span class="cpk-launcher-hud__label">${args.label}</span>
10190
+ <span class="cpk-launcher-hud__label">${label}</span>
10104
10191
  </button>
10105
10192
  <span
10106
10193
  class="cpk-launcher-hud__tooltip"
10107
10194
  id=${detailId}
10108
10195
  role="tooltip"
10109
- >${HUD_LEARN_MORE_LABEL}</span
10196
+ >${description}</span
10110
10197
  >
10111
10198
  </span>
10112
10199
  <span class="cpk-launcher-hud__controls">
@@ -10114,7 +10201,7 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
10114
10201
  type="button"
10115
10202
  class="cpk-launcher-hud__learn-more"
10116
10203
  data-cpk-hud-learn-more=${args.id}
10117
- aria-label=${`Learn more about ${args.label}`}
10204
+ aria-label=${`Learn more about ${label}`}
10118
10205
  aria-describedby=${detailId}
10119
10206
  @click=${(event) => this.handleHudActionClick(event, args.id, "learn_more")}
10120
10207
  @pointerdown=${(event) => event.stopPropagation()}
@@ -10126,7 +10213,7 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
10126
10213
  class="cpk-launcher-hud__toggle"
10127
10214
  data-cpk-hud-toggle=${args.id}
10128
10215
  data-enabled=${args.connected ? "true" : "false"}
10129
- aria-label=${args.connected ? `${args.label} is enabled` : `Open ${args.label} in Inspector`}
10216
+ aria-label=${args.connected ? `${label} is enabled` : `Open ${label} in Inspector`}
10130
10217
  ?disabled=${args.connected}
10131
10218
  @click=${(event) => this.handleHudActionClick(event, args.id, "toggle")}
10132
10219
  @pointerdown=${(event) => event.stopPropagation()}
@@ -10212,14 +10299,12 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
10212
10299
  >
10213
10300
  ${this.renderHudRow({
10214
10301
  id: "threads",
10215
- label: HUD_THREADS_LABEL,
10216
10302
  icon: "MessageSquare",
10217
10303
  connected: threadsOn,
10218
10304
  introIndex: featureBlockIntroIndex + 1
10219
10305
  })}
10220
10306
  ${this.renderHudRow({
10221
10307
  id: "learning",
10222
- label: HUD_LEARNING_LABEL,
10223
10308
  icon: "Brain",
10224
10309
  connected: learningOn,
10225
10310
  introIndex: featureBlockIntroIndex + (threadsOn ? 1 : 2)
@@ -16056,9 +16141,23 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
16056
16141
  require_telemetry.trackWhatsNewSignalViewed(props);
16057
16142
  }
16058
16143
  }
16144
+ /** Start the development-only remote feeds; neither blocks rendering. */
16059
16145
  ensureAnnouncementLoading() {
16060
- if (this.isInspectorDismissed || !this.notificationContext.development || !this.isConnected || this.announcementPromise || typeof window === "undefined" || typeof fetch === "undefined") return;
16061
- this.announcementPromise = this.fetchAnnouncement();
16146
+ if (this.isInspectorDismissed || !this.notificationContext.development || !this.isConnected || typeof window === "undefined" || typeof fetch === "undefined") return;
16147
+ this.announcementPromise ??= this.fetchAnnouncement();
16148
+ this.hudFeedPromise ??= this.fetchHudFeed();
16149
+ }
16150
+ async fetchHudFeed() {
16151
+ this.hudFeed = await require_hud_loader.loadHudFeed();
16152
+ this.refreshHudContent();
16153
+ this.requestUpdate();
16154
+ }
16155
+ /** Overlay the matching feed rule on the built-in HUD content. */
16156
+ refreshHudContent() {
16157
+ this.hudContent = require_hud_config.resolveHudContent(this.hudFeed, this.notificationContext, {
16158
+ defaults: require_hud_defaults.HUD_DEFAULT_CONTENT,
16159
+ supportedDestinations: require_inspector_nav.INSPECTOR_MENU_KEYS
16160
+ });
16062
16161
  }
16063
16162
  async fetchAnnouncement() {
16064
16163
  try {
@@ -16176,6 +16275,7 @@ function defineWebInspector(registry = globalThis.customElements) {
16176
16275
  defineElementOnce(registry, THREAD_INSPECTOR_TAG, CpkThreadInspector);
16177
16276
  defineElementOnce(registry, "cpk-thread-details", ɵCpkThreadDetails);
16178
16277
  defineElementOnce(registry, "cpk-memory-list", CpkMemoryList);
16278
+ defineElementOnce(registry, JSON_BLOCK_TAG, CpkJsonBlock);
16179
16279
  defineElementOnce(registry, WEB_INSPECTOR_TAG, WebInspectorElement);
16180
16280
  }
16181
16281
  /**
@@ -16198,6 +16298,7 @@ exports.WEB_INSPECTOR_TAG = WEB_INSPECTOR_TAG;
16198
16298
  exports.WebInspectorElement = WebInspectorElement;
16199
16299
  exports.configureWebInspectorElement = configureWebInspectorElement;
16200
16300
  exports.defineWebInspector = defineWebInspector;
16301
+ exports.setInspectorJsonRenderer = setInspectorJsonRenderer;
16201
16302
  exports.ɵCpkThreadDetails = ɵCpkThreadDetails;
16202
16303
  exports.ɵbuildCapabilityRows = buildCapabilityRows;
16203
16304
  exports.ɵmaxRecallScore = maxRecallScore;