@copilotkit/web-inspector 1.77.1 → 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
@@ -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
@@ -16196,6 +16275,7 @@ function defineWebInspector(registry = globalThis.customElements) {
16196
16275
  defineElementOnce(registry, THREAD_INSPECTOR_TAG, CpkThreadInspector);
16197
16276
  defineElementOnce(registry, "cpk-thread-details", ɵCpkThreadDetails);
16198
16277
  defineElementOnce(registry, "cpk-memory-list", CpkMemoryList);
16278
+ defineElementOnce(registry, JSON_BLOCK_TAG, CpkJsonBlock);
16199
16279
  defineElementOnce(registry, WEB_INSPECTOR_TAG, WebInspectorElement);
16200
16280
  }
16201
16281
  /**
@@ -16218,6 +16298,7 @@ exports.WEB_INSPECTOR_TAG = WEB_INSPECTOR_TAG;
16218
16298
  exports.WebInspectorElement = WebInspectorElement;
16219
16299
  exports.configureWebInspectorElement = configureWebInspectorElement;
16220
16300
  exports.defineWebInspector = defineWebInspector;
16301
+ exports.setInspectorJsonRenderer = setInspectorJsonRenderer;
16221
16302
  exports.ɵCpkThreadDetails = ɵCpkThreadDetails;
16222
16303
  exports.ɵbuildCapabilityRows = buildCapabilityRows;
16223
16304
  exports.ɵmaxRecallScore = maxRecallScore;