@thinkingos/vsl-sdk 0.2.0 → 0.3.1

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.mjs CHANGED
@@ -591,6 +591,8 @@ function objectsEqual(a, b) {
591
591
  return computeContentHash(a) === computeContentHash(b) && computeCoordHash(a) === computeCoordHash(b);
592
592
  }
593
593
  function tuple2Equal(a, b) {
594
+ if (a === null || a === void 0) return b === null || b === void 0;
595
+ if (b === null || b === void 0) return false;
594
596
  return a[0] === b[0] && a[1] === b[1];
595
597
  }
596
598
  function stringArrayEqual(a, b) {
@@ -727,6 +729,25 @@ var VslSnapshotSession = class {
727
729
  constructor(store = createCacheStore()) {
728
730
  this.store = store;
729
731
  }
732
+ /**
733
+ * Сбрасывает состояние сессии (URL, viewport, документ, версия).
734
+ * Следующий вызов snapshot() вернёт полный документ (как первый вызов).
735
+ */
736
+ clear() {
737
+ this.store.clear();
738
+ this.lastUrl = null;
739
+ this.lastViewport = null;
740
+ this.lastDocument = null;
741
+ this.version = 0;
742
+ }
743
+ /** Возвращает последний полный документ (не diff). */
744
+ getLastDocument() {
745
+ return this.lastDocument;
746
+ }
747
+ /** Текущая версия документа (инкрементируется при каждом diff). */
748
+ getVersion() {
749
+ return this.version;
750
+ }
730
751
  /**
731
752
  * Строит VSL из DOM поддерева root (extractDomTree → segmentTree →
732
753
  * buildVslDocument) и возвращает полный документ либо дифф (см. шапку).
@@ -735,6 +756,15 @@ var VslSnapshotSession = class {
735
756
  const elements = segmentTree(extractDomTree(root));
736
757
  return this.commit(elements, this.buildOptions(root, input), input);
737
758
  }
759
+ /**
760
+ * Вариант snapshot() для pre-extracted elements (MCP сервер, Node.js контекст).
761
+ * Принимает ExtractedElement[] напрямую (без DOM Element), проходит тот же
762
+ * pipeline: segmentTree → buildVslDocument → cache/diff.
763
+ */
764
+ snapshotFromElements(extractedElements, input) {
765
+ const elements = segmentTree(extractedElements);
766
+ return this.commit(elements, this.buildOptionsFromInput(input), input);
767
+ }
738
768
  /**
739
769
  * Vision-вариант конвейера (T1.5.5): segmentTree → enrichWithVision (Level 5
740
770
  * fallback — аннотация t + vf/vf_meta на элементах ДО сборки) → buildVslDocument
@@ -748,6 +778,16 @@ var VslSnapshotSession = class {
748
778
  const snapshot = this.commit(elements, this.buildOptions(root, input), input);
749
779
  return { snapshot, fragments: visionResult.fragments };
750
780
  }
781
+ /**
782
+ * Vision-вариант для pre-extracted elements (MCP сервер, Node.js контекст).
783
+ * Полный pipeline: segmentTree → enrichWithVision → buildVslDocument → cache/diff.
784
+ */
785
+ async snapshotWithVisionFromElements(extractedElements, input, vision) {
786
+ const elements = segmentTree(extractedElements);
787
+ const visionResult = await enrichWithVision(elements, vision);
788
+ const snapshot = this.commit(elements, this.buildOptionsFromInput(input), input);
789
+ return { snapshot, fragments: visionResult.fragments };
790
+ }
751
791
  /** BuildOptions из input + портативный title (логика бывшего snapshot()). */
752
792
  buildOptions(root, input) {
753
793
  const options = {
@@ -759,6 +799,20 @@ var VslSnapshotSession = class {
759
799
  if (input.background !== void 0) options.background = input.background;
760
800
  return options;
761
801
  }
802
+ /**
803
+ * BuildOptions из input без DOM Element (для snapshotFromElements).
804
+ * Title берётся только из input (нет фолбэка на root.ownerDocument.title).
805
+ */
806
+ buildOptionsFromInput(input) {
807
+ const options = {
808
+ viewport: { width: input.viewport.width, height: input.viewport.height },
809
+ url: input.url
810
+ };
811
+ if (input.title !== void 0) options.title = input.title;
812
+ if (input.timestamp !== void 0) options.timestamp = input.timestamp;
813
+ if (input.background !== void 0) options.background = input.background;
814
+ return options;
815
+ }
762
816
  /** Сборка документа + кэш/дифф (логика бывшего snapshot(), см. шапку модуля). */
763
817
  commit(elements, options, input) {
764
818
  const nextDocument = buildVslDocument(elements, options);