@posthog/ai 7.3.2 → 7.4.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.
@@ -1,7 +1,8 @@
1
1
  import 'buffer';
2
2
  import * as uuid from 'uuid';
3
+ import '@posthog/core';
3
4
 
4
- var version = "7.3.2";
5
+ var version = "7.4.1";
5
6
 
6
7
  // Type guards for safer type checking
7
8
 
@@ -225,6 +226,64 @@ function mapKeys(fields, mapper, map) {
225
226
  return mapped;
226
227
  }
227
228
 
229
+ //#region src/load/validation.ts
230
+ /**
231
+ * Sentinel key used to mark escaped user objects during serialization.
232
+ *
233
+ * When a plain object contains 'lc' key (which could be confused with LC objects),
234
+ * we wrap it as `{"__lc_escaped__": {...original...}}`.
235
+ */
236
+ const LC_ESCAPED_KEY = "__lc_escaped__";
237
+ /**
238
+ * Check if an object needs escaping to prevent confusion with LC objects.
239
+ *
240
+ * An object needs escaping if:
241
+ * 1. It has an `'lc'` key (could be confused with LC serialization format)
242
+ * 2. It has only the escape key (would be mistaken for an escaped object)
243
+ */
244
+ function needsEscaping(obj) {
245
+ return "lc" in obj || Object.keys(obj).length === 1 && LC_ESCAPED_KEY in obj;
246
+ }
247
+ /**
248
+ * Wrap an object in the escape marker.
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * {"key": "value"} // becomes {"__lc_escaped__": {"key": "value"}}
253
+ * ```
254
+ */
255
+ function escapeObject(obj) {
256
+ return { [LC_ESCAPED_KEY]: obj };
257
+ }
258
+ /**
259
+ * Check if an object looks like a Serializable instance (duck typing).
260
+ */
261
+ function isSerializableLike(obj) {
262
+ return obj !== null && typeof obj === "object" && "lc_serializable" in obj && typeof obj.toJSON === "function";
263
+ }
264
+ /**
265
+ * Escape a value if it needs escaping (contains `lc` key).
266
+ *
267
+ * This is a simpler version of `serializeValue` that doesn't handle Serializable
268
+ * objects - it's meant to be called on kwargs values that have already been
269
+ * processed by `toJSON()`.
270
+ *
271
+ * @param value - The value to potentially escape.
272
+ * @returns The value with any `lc`-containing objects wrapped in escape markers.
273
+ */
274
+ function escapeIfNeeded(value) {
275
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
276
+ if (isSerializableLike(value)) return value;
277
+ const record = value;
278
+ if (needsEscaping(record)) return escapeObject(record);
279
+ const result = {};
280
+ for (const [key, val] of Object.entries(record)) result[key] = escapeIfNeeded(val);
281
+ return result;
282
+ }
283
+ if (Array.isArray(value)) return value.map((item) => escapeIfNeeded(item));
284
+ return value;
285
+ }
286
+
228
287
  //#region src/load/serializable.ts
229
288
  var serializable_exports = {};
230
289
  __export(serializable_exports, {
@@ -346,11 +405,15 @@ var Serializable = class Serializable {
346
405
  }
347
406
  if (last in read && read[last] !== void 0) write[last] = write[last] || read[last];
348
407
  });
408
+ const escapedKwargs = {};
409
+ for (const [key, value] of Object.entries(kwargs)) escapedKwargs[key] = escapeIfNeeded(value);
410
+ const kwargsWithSecrets = Object.keys(secrets).length ? replaceSecrets(escapedKwargs, secrets) : escapedKwargs;
411
+ const processedKwargs = mapKeys(kwargsWithSecrets, keyToJson, aliases);
349
412
  return {
350
413
  lc: 1,
351
414
  type: "constructor",
352
415
  id: this.lc_id,
353
- kwargs: mapKeys(Object.keys(secrets).length ? replaceSecrets(kwargs, secrets) : kwargs, keyToJson, aliases)
416
+ kwargs: processedKwargs
354
417
  };
355
418
  }
356
419
  toJSONNotImplemented() {