@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.
- package/dist/anthropic/index.cjs +37 -10
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.mjs +37 -10
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +40 -14
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.mjs +40 -14
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/index.cjs +151 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +151 -74
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +65 -2
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +65 -2
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/openai/index.cjs +48 -33
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.mjs +48 -33
- package/dist/openai/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +63 -14
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.mjs +63 -14
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +11 -10
package/dist/langchain/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require('buffer');
|
|
4
4
|
var uuid = require('uuid');
|
|
5
|
+
require('@posthog/core');
|
|
5
6
|
|
|
6
7
|
function _interopNamespace(e) {
|
|
7
8
|
if (e && e.__esModule) return e;
|
|
@@ -23,7 +24,7 @@ function _interopNamespace(e) {
|
|
|
23
24
|
|
|
24
25
|
var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
|
|
25
26
|
|
|
26
|
-
var version = "7.
|
|
27
|
+
var version = "7.4.1";
|
|
27
28
|
|
|
28
29
|
// Type guards for safer type checking
|
|
29
30
|
|
|
@@ -247,6 +248,64 @@ function mapKeys(fields, mapper, map) {
|
|
|
247
248
|
return mapped;
|
|
248
249
|
}
|
|
249
250
|
|
|
251
|
+
//#region src/load/validation.ts
|
|
252
|
+
/**
|
|
253
|
+
* Sentinel key used to mark escaped user objects during serialization.
|
|
254
|
+
*
|
|
255
|
+
* When a plain object contains 'lc' key (which could be confused with LC objects),
|
|
256
|
+
* we wrap it as `{"__lc_escaped__": {...original...}}`.
|
|
257
|
+
*/
|
|
258
|
+
const LC_ESCAPED_KEY = "__lc_escaped__";
|
|
259
|
+
/**
|
|
260
|
+
* Check if an object needs escaping to prevent confusion with LC objects.
|
|
261
|
+
*
|
|
262
|
+
* An object needs escaping if:
|
|
263
|
+
* 1. It has an `'lc'` key (could be confused with LC serialization format)
|
|
264
|
+
* 2. It has only the escape key (would be mistaken for an escaped object)
|
|
265
|
+
*/
|
|
266
|
+
function needsEscaping(obj) {
|
|
267
|
+
return "lc" in obj || Object.keys(obj).length === 1 && LC_ESCAPED_KEY in obj;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Wrap an object in the escape marker.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```typescript
|
|
274
|
+
* {"key": "value"} // becomes {"__lc_escaped__": {"key": "value"}}
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
function escapeObject(obj) {
|
|
278
|
+
return { [LC_ESCAPED_KEY]: obj };
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Check if an object looks like a Serializable instance (duck typing).
|
|
282
|
+
*/
|
|
283
|
+
function isSerializableLike(obj) {
|
|
284
|
+
return obj !== null && typeof obj === "object" && "lc_serializable" in obj && typeof obj.toJSON === "function";
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Escape a value if it needs escaping (contains `lc` key).
|
|
288
|
+
*
|
|
289
|
+
* This is a simpler version of `serializeValue` that doesn't handle Serializable
|
|
290
|
+
* objects - it's meant to be called on kwargs values that have already been
|
|
291
|
+
* processed by `toJSON()`.
|
|
292
|
+
*
|
|
293
|
+
* @param value - The value to potentially escape.
|
|
294
|
+
* @returns The value with any `lc`-containing objects wrapped in escape markers.
|
|
295
|
+
*/
|
|
296
|
+
function escapeIfNeeded(value) {
|
|
297
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
298
|
+
if (isSerializableLike(value)) return value;
|
|
299
|
+
const record = value;
|
|
300
|
+
if (needsEscaping(record)) return escapeObject(record);
|
|
301
|
+
const result = {};
|
|
302
|
+
for (const [key, val] of Object.entries(record)) result[key] = escapeIfNeeded(val);
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
if (Array.isArray(value)) return value.map((item) => escapeIfNeeded(item));
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
308
|
+
|
|
250
309
|
//#region src/load/serializable.ts
|
|
251
310
|
var serializable_exports = {};
|
|
252
311
|
__export(serializable_exports, {
|
|
@@ -368,11 +427,15 @@ var Serializable = class Serializable {
|
|
|
368
427
|
}
|
|
369
428
|
if (last in read && read[last] !== void 0) write[last] = write[last] || read[last];
|
|
370
429
|
});
|
|
430
|
+
const escapedKwargs = {};
|
|
431
|
+
for (const [key, value] of Object.entries(kwargs)) escapedKwargs[key] = escapeIfNeeded(value);
|
|
432
|
+
const kwargsWithSecrets = Object.keys(secrets).length ? replaceSecrets(escapedKwargs, secrets) : escapedKwargs;
|
|
433
|
+
const processedKwargs = mapKeys(kwargsWithSecrets, keyToJson, aliases);
|
|
371
434
|
return {
|
|
372
435
|
lc: 1,
|
|
373
436
|
type: "constructor",
|
|
374
437
|
id: this.lc_id,
|
|
375
|
-
kwargs:
|
|
438
|
+
kwargs: processedKwargs
|
|
376
439
|
};
|
|
377
440
|
}
|
|
378
441
|
toJSONNotImplemented() {
|