@voltagent/internal 0.0.6 → 0.0.8

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,5 +1,11 @@
1
1
  import { SetRequired, EmptyObject, Merge } from 'type-fest';
2
2
 
3
+ /**
4
+ * This type is used to allow any type and bypass restrictions used in
5
+ * typechecking and linting. Provides a CLEAR warning this is NOT the desired
6
+ * behavior and is a dangerous practice.
7
+ */
8
+ type DangerouslyAllowAny = any;
3
9
  /**
4
10
  * A plain object is an object that has no special properties or methods,
5
11
  * and just has properties that are strings, numbers, or symbols.
@@ -23,55 +29,12 @@ type AnySyncFunction = (...args: unknown[]) => unknown;
23
29
  type AnyFunction = AnyAsyncFunction | AnySyncFunction;
24
30
 
25
31
  /**
26
- * Log function signatures
27
- */
28
- interface LogFn {
29
- (msg: string, context?: object): void;
30
- }
31
- /**
32
- * Minimal logger interface for VoltAgent
33
- * This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
34
- */
35
- interface Logger {
36
- /**
37
- * Log at trace level - most detailed level
38
- */
39
- trace: LogFn;
40
- /**
41
- * Log at debug level - detailed information for debugging
42
- */
43
- debug: LogFn;
44
- /**
45
- * Log at info level - general informational messages
46
- */
47
- info: LogFn;
48
- /**
49
- * Log at warn level - warning messages
50
- */
51
- warn: LogFn;
52
- /**
53
- * Log at error level - error messages
54
- */
55
- error: LogFn;
56
- /**
57
- * Log at fatal level - fatal error messages
58
- */
59
- fatal: LogFn;
60
- /**
61
- * Create a child logger with additional context
62
- * @param bindings - Additional context to bind to the child logger
63
- */
64
- child(bindings: Record<string, any>): Logger;
65
- }
66
-
67
- /**
68
- * Deep clone an object using JSON serialization with fallback to shallow clone
32
+ * Deep clone an object
69
33
  *
70
34
  * @param obj - The object to clone
71
- * @param logger - Optional logger for warnings
72
- * @returns A deep copy of the object, or shallow copy if JSON serialization fails
35
+ * @returns A deep copy of the object (fallback to shallow clone for failures)
73
36
  */
74
- declare function deepClone<T>(obj: T, logger?: Logger): T;
37
+ declare function deepClone<T>(obj: T): T;
75
38
  /**
76
39
  * Check if an object has a key
77
40
  *
@@ -147,4 +110,18 @@ type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
147
110
  */
148
111
  declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
149
112
 
150
- export { type AsyncIterableStream, createAsyncIterableStream, deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
113
+ type SafeStringifyOptions = {
114
+ /**
115
+ * The indentation to use for the output.
116
+ */
117
+ indentation?: string | number;
118
+ };
119
+ /**
120
+ * Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.
121
+ * @param input - The object to stringify.
122
+ * @param options.indentation - The indentation to use for the output.
123
+ * @returns The stringified object.
124
+ */
125
+ declare function safeStringify(input: DangerouslyAllowAny, { indentation }?: SafeStringifyOptions): string;
126
+
127
+ export { type AsyncIterableStream, type SafeStringifyOptions, createAsyncIterableStream, deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject, safeStringify };
@@ -1,5 +1,11 @@
1
1
  import { SetRequired, EmptyObject, Merge } from 'type-fest';
2
2
 
3
+ /**
4
+ * This type is used to allow any type and bypass restrictions used in
5
+ * typechecking and linting. Provides a CLEAR warning this is NOT the desired
6
+ * behavior and is a dangerous practice.
7
+ */
8
+ type DangerouslyAllowAny = any;
3
9
  /**
4
10
  * A plain object is an object that has no special properties or methods,
5
11
  * and just has properties that are strings, numbers, or symbols.
@@ -23,55 +29,12 @@ type AnySyncFunction = (...args: unknown[]) => unknown;
23
29
  type AnyFunction = AnyAsyncFunction | AnySyncFunction;
24
30
 
25
31
  /**
26
- * Log function signatures
27
- */
28
- interface LogFn {
29
- (msg: string, context?: object): void;
30
- }
31
- /**
32
- * Minimal logger interface for VoltAgent
33
- * This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
34
- */
35
- interface Logger {
36
- /**
37
- * Log at trace level - most detailed level
38
- */
39
- trace: LogFn;
40
- /**
41
- * Log at debug level - detailed information for debugging
42
- */
43
- debug: LogFn;
44
- /**
45
- * Log at info level - general informational messages
46
- */
47
- info: LogFn;
48
- /**
49
- * Log at warn level - warning messages
50
- */
51
- warn: LogFn;
52
- /**
53
- * Log at error level - error messages
54
- */
55
- error: LogFn;
56
- /**
57
- * Log at fatal level - fatal error messages
58
- */
59
- fatal: LogFn;
60
- /**
61
- * Create a child logger with additional context
62
- * @param bindings - Additional context to bind to the child logger
63
- */
64
- child(bindings: Record<string, any>): Logger;
65
- }
66
-
67
- /**
68
- * Deep clone an object using JSON serialization with fallback to shallow clone
32
+ * Deep clone an object
69
33
  *
70
34
  * @param obj - The object to clone
71
- * @param logger - Optional logger for warnings
72
- * @returns A deep copy of the object, or shallow copy if JSON serialization fails
35
+ * @returns A deep copy of the object (fallback to shallow clone for failures)
73
36
  */
74
- declare function deepClone<T>(obj: T, logger?: Logger): T;
37
+ declare function deepClone<T>(obj: T): T;
75
38
  /**
76
39
  * Check if an object has a key
77
40
  *
@@ -147,4 +110,18 @@ type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
147
110
  */
148
111
  declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
149
112
 
150
- export { type AsyncIterableStream, createAsyncIterableStream, deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
113
+ type SafeStringifyOptions = {
114
+ /**
115
+ * The indentation to use for the output.
116
+ */
117
+ indentation?: string | number;
118
+ };
119
+ /**
120
+ * Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.
121
+ * @param input - The object to stringify.
122
+ * @param options.indentation - The indentation to use for the output.
123
+ * @returns The stringified object.
124
+ */
125
+ declare function safeStringify(input: DangerouslyAllowAny, { indentation }?: SafeStringifyOptions): string;
126
+
127
+ export { type AsyncIterableStream, type SafeStringifyOptions, createAsyncIterableStream, deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject, safeStringify };
@@ -2,21 +2,7 @@
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols)
14
- for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
6
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
21
7
  var __export = (target, all) => {
22
8
  for (var name in all)
@@ -31,26 +17,6 @@ var __copyProps = (to, from, except, desc) => {
31
17
  return to;
32
18
  };
33
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
- var __async = (__this, __arguments, generator) => {
35
- return new Promise((resolve, reject) => {
36
- var fulfilled = (value) => {
37
- try {
38
- step(generator.next(value));
39
- } catch (e) {
40
- reject(e);
41
- }
42
- };
43
- var rejected = (value) => {
44
- try {
45
- step(generator.throw(value));
46
- } catch (e) {
47
- reject(e);
48
- }
49
- };
50
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
51
- step((generator = generator.apply(__this, __arguments)).next());
52
- });
53
- };
54
20
 
55
21
  // src/utils/index.ts
56
22
  var index_exports = {};
@@ -62,7 +28,8 @@ __export(index_exports, {
62
28
  isFunction: () => isFunction,
63
29
  isNil: () => isNil,
64
30
  isObject: () => isObject,
65
- isPlainObject: () => isPlainObject
31
+ isPlainObject: () => isPlainObject,
32
+ safeStringify: () => safeStringify
66
33
  });
67
34
  module.exports = __toCommonJS(index_exports);
68
35
 
@@ -99,17 +66,20 @@ function isEmptyObject(obj) {
99
66
  __name(isEmptyObject, "isEmptyObject");
100
67
 
101
68
  // src/utils/objects.ts
102
- function deepClone(obj, logger) {
69
+ function deepClone(obj) {
103
70
  try {
104
- return JSON.parse(JSON.stringify(obj));
71
+ if (typeof structuredClone === "function") {
72
+ return structuredClone(obj);
73
+ }
74
+ throw new Error("structuredClone is not available");
105
75
  } catch (error) {
106
- if (logger) {
107
- logger.warn("Failed to deep clone object, using shallow clone", { error });
76
+ if (process.env.NODE_ENV !== "production") {
77
+ console.warn("Failed to deep clone object, using shallow clone", { error });
108
78
  }
109
79
  if (obj === null || typeof obj !== "object") {
110
80
  return obj;
111
81
  }
112
- return __spreadValues({}, obj);
82
+ return { ...obj };
113
83
  }
114
84
  }
115
85
  __name(deepClone, "deepClone");
@@ -124,17 +94,48 @@ function createAsyncIterableStream(source) {
124
94
  stream[Symbol.asyncIterator] = () => {
125
95
  const reader = stream.getReader();
126
96
  return {
127
- next() {
128
- return __async(this, null, function* () {
129
- const { done, value } = yield reader.read();
130
- return done ? { done: true, value: void 0 } : { done: false, value };
131
- });
97
+ async next() {
98
+ const { done, value } = await reader.read();
99
+ return done ? { done: true, value: void 0 } : { done: false, value };
132
100
  }
133
101
  };
134
102
  };
135
103
  return stream;
136
104
  }
137
105
  __name(createAsyncIterableStream, "createAsyncIterableStream");
106
+
107
+ // src/utils/safe-stringify.ts
108
+ function safeStringify(input, { indentation } = {}) {
109
+ try {
110
+ const seen = /* @__PURE__ */ new WeakSet();
111
+ return JSON.stringify(input, safeStringifyReplacer(seen), indentation);
112
+ } catch (error) {
113
+ return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : "Unknown error"}`;
114
+ }
115
+ }
116
+ __name(safeStringify, "safeStringify");
117
+ function safeStringifyReplacer(seen) {
118
+ const replacer = /* @__PURE__ */ __name((_key, value) => {
119
+ if (typeof value?.toJSON === "function") {
120
+ value = value.toJSON();
121
+ }
122
+ if (!(value !== null && typeof value === "object")) {
123
+ return value;
124
+ }
125
+ if (seen.has(value)) {
126
+ return "[Circular]";
127
+ }
128
+ seen.add(value);
129
+ const newValue = Array.isArray(value) ? [] : {};
130
+ for (const [key2, value2] of Object.entries(value)) {
131
+ newValue[key2] = replacer(key2, value2);
132
+ }
133
+ seen.delete(value);
134
+ return newValue;
135
+ }, "replacer");
136
+ return replacer;
137
+ }
138
+ __name(safeStringifyReplacer, "safeStringifyReplacer");
138
139
  // Annotate the CommonJS export names for ESM import in node:
139
140
  0 && (module.exports = {
140
141
  createAsyncIterableStream,
@@ -144,6 +145,7 @@ __name(createAsyncIterableStream, "createAsyncIterableStream");
144
145
  isFunction,
145
146
  isNil,
146
147
  isObject,
147
- isPlainObject
148
+ isPlainObject,
149
+ safeStringify
148
150
  });
149
151
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.ts","../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts"],"sourcesContent":["export { deepClone, hasKey } from \"./objects\";\nexport { isNil, isObject, isEmptyObject, isFunction, isPlainObject } from \"./lang\";\nexport type { AsyncIterableStream } from \"./async-iterable-stream\";\nexport { createAsyncIterableStream } from \"./async-iterable-stream\";\n","import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\nimport type { Logger } from \"../logger/types\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @param logger - Optional logger for warnings\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T, logger?: Logger): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n if (logger) {\n logger.warn(\"Failed to deep clone object, using shallow clone\", { error });\n }\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n * console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n * start(controller) {\n * controller.enqueue(\"Hello\");\n * controller.close();\n * },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n const stream = source.pipeThrough(new TransformStream<T, T>());\n\n (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n const reader = stream.getReader();\n return {\n async next(): Promise<IteratorResult<T>> {\n const { done, value } = await reader.read();\n return done ? { done: true, value: undefined } : { done: false, value };\n },\n };\n };\n\n return stream as AsyncIterableStream<T>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,SAAS,MAAM,KAA0B;AAC9C,SAAO,QAAQ,QAAQ,QAAQ;AACjC;AAFgB;AAUT,SAAS,SAA2B,KAAwB;AACjE,UAAQ,OAAO,QAAQ,YAAY,OAAO,QAAQ,eAAe,CAAC,MAAM,GAAG;AAC7E;AAFgB;AAUT,SAAS,WAAkC,KAAwB;AACxE,SAAO,OAAO,QAAQ;AACxB;AAFgB;AAUT,SAAS,cAAqC,KAAwB;AAC3E,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,GAAG;AAC3C,SAAO,cAAc,OAAO,aAAa,cAAc;AACzD;AAPgB;AAeT,SAAS,cAAc,KAAkC;AAC9D,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,oBAAoB,GAAG,EAAE,SAAS,KAAK,OAAO,sBAAsB,GAAG,EAAE,SAAS,GAAG;AAC9F,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAXgB;;;AC1CT,SAAS,UAAa,KAAQ,QAAoB;AACvD,MAAI;AACF,WAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AAAA,EACvC,SAAS,OAAO;AACd,QAAI,QAAQ;AACV,aAAO,KAAK,oDAAoD,EAAE,MAAM,CAAC;AAAA,IAC3E;AAEA,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,mBAAK;AAAA,EACd;AACF;AAbgB;AAsBT,SAAS,OACd,KACA,KAC8B;AAC9B,SAAO,SAAS,GAAG,KAAK,OAAO;AACjC;AALgB;;;ACHT,SAAS,0BAA6B,QAAmD;AAC9F,QAAM,SAAS,OAAO,YAAY,IAAI,gBAAsB,CAAC;AAE7D,EAAC,OAAkC,OAAO,aAAa,IAAI,MAAM;AAC/D,UAAM,SAAS,OAAO,UAAU;AAChC,WAAO;AAAA,MACC,OAAmC;AAAA;AACvC,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,iBAAO,OAAO,EAAE,MAAM,MAAM,OAAO,OAAU,IAAI,EAAE,MAAM,OAAO,MAAM;AAAA,QACxE;AAAA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAdgB;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/index.ts","../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts","../../src/utils/safe-stringify.ts"],"sourcesContent":["export { deepClone, hasKey } from \"./objects\";\nexport { isNil, isObject, isEmptyObject, isFunction, isPlainObject } from \"./lang\";\nexport type { AsyncIterableStream } from \"./async-iterable-stream\";\nexport { createAsyncIterableStream } from \"./async-iterable-stream\";\nexport { safeStringify, type SafeStringifyOptions } from \"./safe-stringify\";\n","import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object (fallback to shallow clone for failures)\n */\nexport function deepClone<T>(obj: T): T {\n try {\n // Use structuredClone if available (Node.js 17+, modern browsers)\n if (typeof structuredClone === \"function\") {\n return structuredClone(obj);\n }\n\n throw new Error(\"structuredClone is not available\");\n } catch (error) {\n // This is only a warning in development mode we don't expect this to happen\n // as we do not support sub-Node versions and structuredClone is available in Node.js 17+\n if (process.env.NODE_ENV !== \"production\") {\n console.warn(\"Failed to deep clone object, using shallow clone\", { error });\n }\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n * console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n * start(controller) {\n * controller.enqueue(\"Hello\");\n * controller.close();\n * },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n const stream = source.pipeThrough(new TransformStream<T, T>());\n\n (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n const reader = stream.getReader();\n return {\n async next(): Promise<IteratorResult<T>> {\n const { done, value } = await reader.read();\n return done ? { done: true, value: undefined } : { done: false, value };\n },\n };\n };\n\n return stream as AsyncIterableStream<T>;\n}\n","import type { DangerouslyAllowAny } from \"../types\";\n\nexport type SafeStringifyOptions = {\n /**\n * The indentation to use for the output.\n */\n indentation?: string | number;\n};\n\n/**\n * Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.\n * @param input - The object to stringify.\n * @param options.indentation - The indentation to use for the output.\n * @returns The stringified object.\n */\nexport function safeStringify(\n input: DangerouslyAllowAny,\n { indentation }: SafeStringifyOptions = {},\n) {\n try {\n const seen = new WeakSet();\n return JSON.stringify(input, safeStringifyReplacer(seen), indentation);\n } catch (error) {\n return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : \"Unknown error\"}`;\n }\n}\n\nfunction safeStringifyReplacer(seen: WeakSet<DangerouslyAllowAny>) {\n const replacer = (_key: string, value: DangerouslyAllowAny) => {\n // Handle objects with a custom `.toJSON()` method.\n if (typeof value?.toJSON === \"function\") {\n // biome-ignore lint/style/noParameterAssign: needed to handle circular references\n value = value.toJSON();\n }\n\n if (!(value !== null && typeof value === \"object\")) {\n return value;\n }\n\n if (seen.has(value)) {\n return \"[Circular]\";\n }\n\n seen.add(value);\n\n const newValue = Array.isArray(value) ? [] : {};\n\n for (const [key2, value2] of Object.entries(value)) {\n // @ts-expect-error - ignore as this is needed to handle circular references\n newValue[key2] = replacer(key2, value2);\n }\n\n seen.delete(value);\n\n return newValue;\n };\n\n return replacer;\n}\n"],"mappings":"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","names":[]}
@@ -1,40 +1,5 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
18
- var __async = (__this, __arguments, generator) => {
19
- return new Promise((resolve, reject) => {
20
- var fulfilled = (value) => {
21
- try {
22
- step(generator.next(value));
23
- } catch (e) {
24
- reject(e);
25
- }
26
- };
27
- var rejected = (value) => {
28
- try {
29
- step(generator.throw(value));
30
- } catch (e) {
31
- reject(e);
32
- }
33
- };
34
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
35
- step((generator = generator.apply(__this, __arguments)).next());
36
- });
37
- };
38
3
 
39
4
  // src/utils/lang.ts
40
5
  function isNil(obj) {
@@ -69,17 +34,20 @@ function isEmptyObject(obj) {
69
34
  __name(isEmptyObject, "isEmptyObject");
70
35
 
71
36
  // src/utils/objects.ts
72
- function deepClone(obj, logger) {
37
+ function deepClone(obj) {
73
38
  try {
74
- return JSON.parse(JSON.stringify(obj));
39
+ if (typeof structuredClone === "function") {
40
+ return structuredClone(obj);
41
+ }
42
+ throw new Error("structuredClone is not available");
75
43
  } catch (error) {
76
- if (logger) {
77
- logger.warn("Failed to deep clone object, using shallow clone", { error });
44
+ if (process.env.NODE_ENV !== "production") {
45
+ console.warn("Failed to deep clone object, using shallow clone", { error });
78
46
  }
79
47
  if (obj === null || typeof obj !== "object") {
80
48
  return obj;
81
49
  }
82
- return __spreadValues({}, obj);
50
+ return { ...obj };
83
51
  }
84
52
  }
85
53
  __name(deepClone, "deepClone");
@@ -94,17 +62,48 @@ function createAsyncIterableStream(source) {
94
62
  stream[Symbol.asyncIterator] = () => {
95
63
  const reader = stream.getReader();
96
64
  return {
97
- next() {
98
- return __async(this, null, function* () {
99
- const { done, value } = yield reader.read();
100
- return done ? { done: true, value: void 0 } : { done: false, value };
101
- });
65
+ async next() {
66
+ const { done, value } = await reader.read();
67
+ return done ? { done: true, value: void 0 } : { done: false, value };
102
68
  }
103
69
  };
104
70
  };
105
71
  return stream;
106
72
  }
107
73
  __name(createAsyncIterableStream, "createAsyncIterableStream");
74
+
75
+ // src/utils/safe-stringify.ts
76
+ function safeStringify(input, { indentation } = {}) {
77
+ try {
78
+ const seen = /* @__PURE__ */ new WeakSet();
79
+ return JSON.stringify(input, safeStringifyReplacer(seen), indentation);
80
+ } catch (error) {
81
+ return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : "Unknown error"}`;
82
+ }
83
+ }
84
+ __name(safeStringify, "safeStringify");
85
+ function safeStringifyReplacer(seen) {
86
+ const replacer = /* @__PURE__ */ __name((_key, value) => {
87
+ if (typeof value?.toJSON === "function") {
88
+ value = value.toJSON();
89
+ }
90
+ if (!(value !== null && typeof value === "object")) {
91
+ return value;
92
+ }
93
+ if (seen.has(value)) {
94
+ return "[Circular]";
95
+ }
96
+ seen.add(value);
97
+ const newValue = Array.isArray(value) ? [] : {};
98
+ for (const [key2, value2] of Object.entries(value)) {
99
+ newValue[key2] = replacer(key2, value2);
100
+ }
101
+ seen.delete(value);
102
+ return newValue;
103
+ }, "replacer");
104
+ return replacer;
105
+ }
106
+ __name(safeStringifyReplacer, "safeStringifyReplacer");
108
107
  export {
109
108
  createAsyncIterableStream,
110
109
  deepClone,
@@ -113,6 +112,7 @@ export {
113
112
  isFunction,
114
113
  isNil,
115
114
  isObject,
116
- isPlainObject
115
+ isPlainObject,
116
+ safeStringify
117
117
  };
118
118
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts"],"sourcesContent":["import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\nimport type { Logger } from \"../logger/types\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @param logger - Optional logger for warnings\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T, logger?: Logger): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n if (logger) {\n logger.warn(\"Failed to deep clone object, using shallow clone\", { error });\n }\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n * console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n * start(controller) {\n * controller.enqueue(\"Hello\");\n * controller.close();\n * },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n const stream = source.pipeThrough(new TransformStream<T, T>());\n\n (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n const reader = stream.getReader();\n return {\n async next(): Promise<IteratorResult<T>> {\n const { done, value } = await reader.read();\n return done ? { done: true, value: undefined } : { done: false, value };\n },\n };\n };\n\n return stream as AsyncIterableStream<T>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASO,SAAS,MAAM,KAA0B;AAC9C,SAAO,QAAQ,QAAQ,QAAQ;AACjC;AAFgB;AAUT,SAAS,SAA2B,KAAwB;AACjE,UAAQ,OAAO,QAAQ,YAAY,OAAO,QAAQ,eAAe,CAAC,MAAM,GAAG;AAC7E;AAFgB;AAUT,SAAS,WAAkC,KAAwB;AACxE,SAAO,OAAO,QAAQ;AACxB;AAFgB;AAUT,SAAS,cAAqC,KAAwB;AAC3E,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,GAAG;AAC3C,SAAO,cAAc,OAAO,aAAa,cAAc;AACzD;AAPgB;AAeT,SAAS,cAAc,KAAkC;AAC9D,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,oBAAoB,GAAG,EAAE,SAAS,KAAK,OAAO,sBAAsB,GAAG,EAAE,SAAS,GAAG;AAC9F,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAXgB;;;AC1CT,SAAS,UAAa,KAAQ,QAAoB;AACvD,MAAI;AACF,WAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AAAA,EACvC,SAAS,OAAO;AACd,QAAI,QAAQ;AACV,aAAO,KAAK,oDAAoD,EAAE,MAAM,CAAC;AAAA,IAC3E;AAEA,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,mBAAK;AAAA,EACd;AACF;AAbgB;AAsBT,SAAS,OACd,KACA,KAC8B;AAC9B,SAAO,SAAS,GAAG,KAAK,OAAO;AACjC;AALgB;;;ACHT,SAAS,0BAA6B,QAAmD;AAC9F,QAAM,SAAS,OAAO,YAAY,IAAI,gBAAsB,CAAC;AAE7D,EAAC,OAAkC,OAAO,aAAa,IAAI,MAAM;AAC/D,UAAM,SAAS,OAAO,UAAU;AAChC,WAAO;AAAA,MACC,OAAmC;AAAA;AACvC,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,iBAAO,OAAO,EAAE,MAAM,MAAM,OAAO,OAAU,IAAI,EAAE,MAAM,OAAO,MAAM;AAAA,QACxE;AAAA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAdgB;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts","../../src/utils/safe-stringify.ts"],"sourcesContent":["import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object (fallback to shallow clone for failures)\n */\nexport function deepClone<T>(obj: T): T {\n try {\n // Use structuredClone if available (Node.js 17+, modern browsers)\n if (typeof structuredClone === \"function\") {\n return structuredClone(obj);\n }\n\n throw new Error(\"structuredClone is not available\");\n } catch (error) {\n // This is only a warning in development mode we don't expect this to happen\n // as we do not support sub-Node versions and structuredClone is available in Node.js 17+\n if (process.env.NODE_ENV !== \"production\") {\n console.warn(\"Failed to deep clone object, using shallow clone\", { error });\n }\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n * console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n * start(controller) {\n * controller.enqueue(\"Hello\");\n * controller.close();\n * },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n const stream = source.pipeThrough(new TransformStream<T, T>());\n\n (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n const reader = stream.getReader();\n return {\n async next(): Promise<IteratorResult<T>> {\n const { done, value } = await reader.read();\n return done ? { done: true, value: undefined } : { done: false, value };\n },\n };\n };\n\n return stream as AsyncIterableStream<T>;\n}\n","import type { DangerouslyAllowAny } from \"../types\";\n\nexport type SafeStringifyOptions = {\n /**\n * The indentation to use for the output.\n */\n indentation?: string | number;\n};\n\n/**\n * Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.\n * @param input - The object to stringify.\n * @param options.indentation - The indentation to use for the output.\n * @returns The stringified object.\n */\nexport function safeStringify(\n input: DangerouslyAllowAny,\n { indentation }: SafeStringifyOptions = {},\n) {\n try {\n const seen = new WeakSet();\n return JSON.stringify(input, safeStringifyReplacer(seen), indentation);\n } catch (error) {\n return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : \"Unknown error\"}`;\n }\n}\n\nfunction safeStringifyReplacer(seen: WeakSet<DangerouslyAllowAny>) {\n const replacer = (_key: string, value: DangerouslyAllowAny) => {\n // Handle objects with a custom `.toJSON()` method.\n if (typeof value?.toJSON === \"function\") {\n // biome-ignore lint/style/noParameterAssign: needed to handle circular references\n value = value.toJSON();\n }\n\n if (!(value !== null && typeof value === \"object\")) {\n return value;\n }\n\n if (seen.has(value)) {\n return \"[Circular]\";\n }\n\n seen.add(value);\n\n const newValue = Array.isArray(value) ? [] : {};\n\n for (const [key2, value2] of Object.entries(value)) {\n // @ts-expect-error - ignore as this is needed to handle circular references\n newValue[key2] = replacer(key2, value2);\n }\n\n seen.delete(value);\n\n return newValue;\n };\n\n return replacer;\n}\n"],"mappings":";;;;AASO,SAAS,MAAM,KAA0B;AAC9C,SAAO,QAAQ,QAAQ,QAAQ;AACjC;AAFgB;AAUT,SAAS,SAA2B,KAAwB;AACjE,UAAQ,OAAO,QAAQ,YAAY,OAAO,QAAQ,eAAe,CAAC,MAAM,GAAG;AAC7E;AAFgB;AAUT,SAAS,WAAkC,KAAwB;AACxE,SAAO,OAAO,QAAQ;AACxB;AAFgB;AAUT,SAAS,cAAqC,KAAwB;AAC3E,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,GAAG;AAC3C,SAAO,cAAc,OAAO,aAAa,cAAc;AACzD;AAPgB;AAeT,SAAS,cAAc,KAAkC;AAC9D,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,oBAAoB,GAAG,EAAE,SAAS,KAAK,OAAO,sBAAsB,GAAG,EAAE,SAAS,GAAG;AAC9F,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAXgB;;;AC5CT,SAAS,UAAa,KAAW;AACtC,MAAI;AAEF,QAAI,OAAO,oBAAoB,YAAY;AACzC,aAAO,gBAAgB,GAAG;AAAA,IAC5B;AAEA,UAAM,IAAI,MAAM,kCAAkC;AAAA,EACpD,SAAS,OAAO;AAGd,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,cAAQ,KAAK,oDAAoD,EAAE,MAAM,CAAC;AAAA,IAC5E;AAEA,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,EAAE,GAAG,IAAI;AAAA,EAClB;AACF;AApBgB;AA6BT,SAAS,OACd,KACA,KAC8B;AAC9B,SAAO,SAAS,GAAG,KAAK,OAAO;AACjC;AALgB;;;ACRT,SAAS,0BAA6B,QAAmD;AAC9F,QAAM,SAAS,OAAO,YAAY,IAAI,gBAAsB,CAAC;AAE7D,EAAC,OAAkC,OAAO,aAAa,IAAI,MAAM;AAC/D,UAAM,SAAS,OAAO,UAAU;AAChC,WAAO;AAAA,MACL,MAAM,OAAmC;AACvC,cAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,eAAO,OAAO,EAAE,MAAM,MAAM,OAAO,OAAU,IAAI,EAAE,MAAM,OAAO,MAAM;AAAA,MACxE;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAdgB;;;AChBT,SAAS,cACd,OACA,EAAE,YAAY,IAA0B,CAAC,GACzC;AACA,MAAI;AACF,UAAM,OAAO,oBAAI,QAAQ;AACzB,WAAO,KAAK,UAAU,OAAO,sBAAsB,IAAI,GAAG,WAAW;AAAA,EACvE,SAAS,OAAO;AACd,WAAO,oDAAoD,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,EACrH;AACF;AAVgB;AAYhB,SAAS,sBAAsB,MAAoC;AACjE,QAAM,WAAW,wBAAC,MAAc,UAA+B;AAE7D,QAAI,OAAO,OAAO,WAAW,YAAY;AAEvC,cAAQ,MAAM,OAAO;AAAA,IACvB;AAEA,QAAI,EAAE,UAAU,QAAQ,OAAO,UAAU,WAAW;AAClD,aAAO;AAAA,IACT;AAEA,QAAI,KAAK,IAAI,KAAK,GAAG;AACnB,aAAO;AAAA,IACT;AAEA,SAAK,IAAI,KAAK;AAEd,UAAM,WAAW,MAAM,QAAQ,KAAK,IAAI,CAAC,IAAI,CAAC;AAE9C,eAAW,CAAC,MAAM,MAAM,KAAK,OAAO,QAAQ,KAAK,GAAG;AAElD,eAAS,IAAI,IAAI,SAAS,MAAM,MAAM;AAAA,IACxC;AAEA,SAAK,OAAO,KAAK;AAEjB,WAAO;AAAA,EACT,GA3BiB;AA6BjB,SAAO;AACT;AA/BS;","names":[]}
package/package.json CHANGED
@@ -1,49 +1,82 @@
1
1
  {
2
2
  "name": "@voltagent/internal",
3
- "version": "0.0.6",
4
3
  "description": "VoltAgent internal - an internal set of tools for the VoltAgent packages",
5
- "license": "MIT",
4
+ "version": "0.0.8",
5
+ "devDependencies": {
6
+ "@types/node": "^24.0.3",
7
+ "@vitest/coverage-v8": "^3.2.4",
8
+ "tsup": "^8.5.0",
9
+ "type-fest": "^4.41.0",
10
+ "typescript": "^5.8.2",
11
+ "vitest": "^3.2.4"
12
+ },
6
13
  "exports": {
7
14
  ".": {
8
- "types": "./dist/main/index.d.ts",
9
- "import": "./dist/main/index.mjs",
10
- "require": "./dist/main/index.js"
15
+ "import": {
16
+ "types": "./dist/main/index.d.mts",
17
+ "default": "./dist/main/index.mjs"
18
+ },
19
+ "require": {
20
+ "types": "./dist/main/index.d.ts",
21
+ "default": "./dist/main/index.js"
22
+ }
11
23
  },
12
24
  "./test": {
13
- "types": "./dist/test/index.d.ts",
14
- "import": "./dist/test/index.mjs",
15
- "require": "./dist/test/index.js"
25
+ "import": {
26
+ "types": "./dist/test/index.d.mts",
27
+ "default": "./dist/test/index.mjs"
28
+ },
29
+ "require": {
30
+ "types": "./dist/test/index.d.ts",
31
+ "default": "./dist/test/index.js"
32
+ }
16
33
  },
17
34
  "./utils": {
18
- "types": "./dist/utils/index.d.ts",
19
- "import": "./dist/utils/index.mjs",
20
- "require": "./dist/utils/index.js"
35
+ "import": {
36
+ "types": "./dist/utils/index.d.mts",
37
+ "default": "./dist/utils/index.mjs"
38
+ },
39
+ "require": {
40
+ "types": "./dist/utils/index.d.ts",
41
+ "default": "./dist/utils/index.js"
42
+ }
21
43
  },
22
44
  "./types": {
23
45
  "types": "./dist/types/index.d.ts"
24
46
  }
25
47
  },
26
- "main": "dist/main/index.js",
27
- "module": "dist/main/index.mjs",
28
- "types": "dist/main/index.d.ts",
29
48
  "files": [
30
49
  "dist/**/*",
31
50
  "dev/dist/**/*",
32
51
  "test/dist/**/*"
33
52
  ],
34
- "devDependencies": {
35
- "@types/node": "^24.0.3",
36
- "@vitest/coverage-v8": "^3.2.4",
37
- "tsup": "^8.5.0",
38
- "type-fest": "^4.41.0",
39
- "typescript": "^5.0.4",
40
- "vitest": "^3.2.4"
53
+ "license": "MIT",
54
+ "main": "dist/main/index.js",
55
+ "module": "dist/main/index.mjs",
56
+ "types": "dist/main/index.d.ts",
57
+ "typesVersions": {
58
+ "*": {
59
+ "*": [
60
+ "dist/main/index.d.ts"
61
+ ],
62
+ "test": [
63
+ "dist/test/index.d.ts"
64
+ ],
65
+ "utils": [
66
+ "dist/utils/index.d.ts"
67
+ ],
68
+ "types": [
69
+ "dist/types/index.d.ts"
70
+ ]
71
+ }
41
72
  },
42
73
  "scripts": {
74
+ "attw": "attw --pack",
43
75
  "build": "tsup",
44
76
  "dev": "tsup --watch",
45
77
  "lint": "biome check .",
46
78
  "lint:fix": "biome check . --write",
79
+ "publint": "publint --strict",
47
80
  "test": "vitest",
48
81
  "test:coverage": "vitest run --coverage"
49
82
  }