@ai-matrx/kit 0.13.1 → 0.13.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.js CHANGED
@@ -2795,7 +2795,7 @@ var stop = (s) => {
2795
2795
  };
2796
2796
  var enc = (x) => x.replace(/~/g, "~0").replace(/\//g, "~1");
2797
2797
  var dec = (x) => x.replace(/~1/g, "/").replace(/~0/g, "~");
2798
- function clone(v, path = "", seen = /* @__PURE__ */ new WeakSet()) {
2798
+ function clone(v, path = "", seen = /* @__PURE__ */ new WeakSet(), policy = {}) {
2799
2799
  if (v === null || typeof v === "string" || typeof v === "boolean") return v;
2800
2800
  if (typeof v === "number") {
2801
2801
  if (!Number.isFinite(v))
@@ -2834,15 +2834,48 @@ function clone(v, path = "", seen = /* @__PURE__ */ new WeakSet()) {
2834
2834
  `${path}/${index}`
2835
2835
  );
2836
2836
  }
2837
- const out = Array.isArray(v) ? v.map((x, i) => clone(x, `${path}/${i}`, seen)) : Object.fromEntries(
2838
- Object.entries(v).map(([k, x]) => [
2837
+ const out = Array.isArray(v) ? v.map((x, i) => clone(x, `${path}/${i}`, seen, policy)) : Object.fromEntries(
2838
+ Object.entries(v).filter(([, x]) => !policy.omitUndefinedObjectProperties || x !== void 0).map(([k, x]) => [
2839
2839
  k,
2840
- clone(x, `${path}/${enc(k)}`, seen)
2840
+ clone(x, `${path}/${enc(k)}`, seen, policy)
2841
2841
  ])
2842
2842
  );
2843
2843
  seen.delete(v);
2844
2844
  return out;
2845
2845
  }
2846
+ var maxSurfacePointerSegmentLength = 64;
2847
+ var maxSurfacePointerLength = 192;
2848
+ var truncateSurfacePointer = (value, maxLength) => {
2849
+ const characters = Array.from(value);
2850
+ return characters.length > maxLength ? `${characters.slice(0, maxLength - 1).join("")}\u2026` : value;
2851
+ };
2852
+ function displaySurfacePointer(path) {
2853
+ if (!path) return "/";
2854
+ const safe = path.split("/").slice(1).map((segment) => {
2855
+ const controlSafe = segment.replace(
2856
+ /[\u0000-\u001F\u007F-\u009F]/g,
2857
+ (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`
2858
+ );
2859
+ return truncateSurfacePointer(controlSafe, maxSurfacePointerSegmentLength);
2860
+ }).join("/");
2861
+ const pointer = `/${safe}`;
2862
+ return truncateSurfacePointer(pointer, maxSurfacePointerLength);
2863
+ }
2864
+ function cloneSurfaceValue(value, path) {
2865
+ try {
2866
+ return clone(value, path, /* @__PURE__ */ new WeakSet(), {
2867
+ omitUndefinedObjectProperties: true
2868
+ });
2869
+ } catch (error) {
2870
+ if (error instanceof ContentTransferError)
2871
+ throw new ContentTransferError(
2872
+ error.code,
2873
+ `Surface capture rejected value at ${displaySurfacePointer(error.path)}: ${error.message}`,
2874
+ error.path
2875
+ );
2876
+ throw error;
2877
+ }
2878
+ }
2846
2879
  function normalizeTransferJson(value) {
2847
2880
  return clone(value);
2848
2881
  }
@@ -3756,7 +3789,7 @@ function createSurfaceTransferHandle(options) {
3756
3789
  for (const declaration of declarations) {
3757
3790
  if (Object.hasOwn(scope, declaration.name) && scope[declaration.name] !== void 0) {
3758
3791
  Object.defineProperty(value, declaration.name, {
3759
- value: clone(
3792
+ value: cloneSurfaceValue(
3760
3793
  scope[declaration.name],
3761
3794
  `/${enc(declaration.name)}`
3762
3795
  ),