@voltagent/internal 0.0.1 → 0.0.3
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/main/index.d.mts +77 -1
- package/dist/main/index.d.ts +77 -1
- package/dist/main/index.js +80 -2
- package/dist/main/index.js.map +1 -1
- package/dist/main/index.mjs +73 -1
- package/dist/main/index.mjs.map +1 -1
- package/dist/types/index.d.mts +29 -0
- package/dist/types/index.d.ts +29 -0
- package/dist/utils/index.d.mts +77 -0
- package/dist/utils/index.d.ts +77 -0
- package/dist/utils/index.js +185 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +155 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +11 -4
package/dist/main/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SetRequired, EmptyObject } from 'type-fest';
|
|
2
|
+
|
|
1
3
|
interface DevLoggerOptions {
|
|
2
4
|
dev: boolean | (() => boolean);
|
|
3
5
|
}
|
|
@@ -129,4 +131,78 @@ declare function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T>
|
|
|
129
131
|
*/
|
|
130
132
|
declare function convertResponseStreamToArray(response: Response): Promise<string[]>;
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
/**
|
|
135
|
+
* A plain object is an object that has no special properties or methods,
|
|
136
|
+
* and just has properties that are strings, numbers, or symbols.
|
|
137
|
+
*/
|
|
138
|
+
type PlainObject = Record<string | number | symbol, unknown>;
|
|
139
|
+
/**
|
|
140
|
+
* A nil value is a value that is not defined or is undefined.
|
|
141
|
+
*/
|
|
142
|
+
type Nil = null | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* A type that represents any async function.
|
|
145
|
+
*/
|
|
146
|
+
type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
147
|
+
/**
|
|
148
|
+
* A type that represents any synchronous function.
|
|
149
|
+
*/
|
|
150
|
+
type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
151
|
+
/**
|
|
152
|
+
* A type that represents any function.
|
|
153
|
+
*/
|
|
154
|
+
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
158
|
+
*
|
|
159
|
+
* @param obj - The object to clone
|
|
160
|
+
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
161
|
+
*/
|
|
162
|
+
declare function deepClone<T>(obj: T): T;
|
|
163
|
+
/**
|
|
164
|
+
* Check if an object has a key
|
|
165
|
+
*
|
|
166
|
+
* @param obj - The object to check
|
|
167
|
+
* @param key - The key to check
|
|
168
|
+
* @returns True if the object has the key, false otherwise
|
|
169
|
+
*/
|
|
170
|
+
declare function hasKey<T extends PlainObject, K extends string>(obj: T, key: K): obj is T & SetRequired<T, K>;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Check if a value is nil
|
|
174
|
+
*
|
|
175
|
+
* @param obj - The value to check
|
|
176
|
+
* @returns True if the value is nil, false otherwise
|
|
177
|
+
*/
|
|
178
|
+
declare function isNil(obj: unknown): obj is Nil;
|
|
179
|
+
/**
|
|
180
|
+
* Check if an object is a JS object
|
|
181
|
+
*
|
|
182
|
+
* @param obj - The object to check
|
|
183
|
+
* @returns True if the object is a JS object}
|
|
184
|
+
*/
|
|
185
|
+
declare function isObject<T extends object>(obj: unknown): obj is T;
|
|
186
|
+
/**
|
|
187
|
+
* Check if a value is a function
|
|
188
|
+
*
|
|
189
|
+
* @param obj - The value to check
|
|
190
|
+
* @returns True if the value is a function, false otherwise
|
|
191
|
+
*/
|
|
192
|
+
declare function isFunction<T extends AnyFunction>(obj: unknown): obj is T;
|
|
193
|
+
/**
|
|
194
|
+
* Check if an object is a plain object (i.e. a JS object but not including arrays or functions)
|
|
195
|
+
*
|
|
196
|
+
* @param obj - The object to check
|
|
197
|
+
* @returns True if the object is a plain object, false otherwise.
|
|
198
|
+
*/
|
|
199
|
+
declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
200
|
+
/**
|
|
201
|
+
* Check if an object is an empty object
|
|
202
|
+
*
|
|
203
|
+
* @param obj - The object to check
|
|
204
|
+
* @returns True if the object is an empty object, false otherwise
|
|
205
|
+
*/
|
|
206
|
+
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
207
|
+
|
|
208
|
+
export { type DevLoggerOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createDevLogger, deepClone, _default as devLogger, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
|
package/dist/main/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SetRequired, EmptyObject } from 'type-fest';
|
|
2
|
+
|
|
1
3
|
interface DevLoggerOptions {
|
|
2
4
|
dev: boolean | (() => boolean);
|
|
3
5
|
}
|
|
@@ -129,4 +131,78 @@ declare function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T>
|
|
|
129
131
|
*/
|
|
130
132
|
declare function convertResponseStreamToArray(response: Response): Promise<string[]>;
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
/**
|
|
135
|
+
* A plain object is an object that has no special properties or methods,
|
|
136
|
+
* and just has properties that are strings, numbers, or symbols.
|
|
137
|
+
*/
|
|
138
|
+
type PlainObject = Record<string | number | symbol, unknown>;
|
|
139
|
+
/**
|
|
140
|
+
* A nil value is a value that is not defined or is undefined.
|
|
141
|
+
*/
|
|
142
|
+
type Nil = null | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* A type that represents any async function.
|
|
145
|
+
*/
|
|
146
|
+
type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
147
|
+
/**
|
|
148
|
+
* A type that represents any synchronous function.
|
|
149
|
+
*/
|
|
150
|
+
type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
151
|
+
/**
|
|
152
|
+
* A type that represents any function.
|
|
153
|
+
*/
|
|
154
|
+
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
158
|
+
*
|
|
159
|
+
* @param obj - The object to clone
|
|
160
|
+
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
161
|
+
*/
|
|
162
|
+
declare function deepClone<T>(obj: T): T;
|
|
163
|
+
/**
|
|
164
|
+
* Check if an object has a key
|
|
165
|
+
*
|
|
166
|
+
* @param obj - The object to check
|
|
167
|
+
* @param key - The key to check
|
|
168
|
+
* @returns True if the object has the key, false otherwise
|
|
169
|
+
*/
|
|
170
|
+
declare function hasKey<T extends PlainObject, K extends string>(obj: T, key: K): obj is T & SetRequired<T, K>;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Check if a value is nil
|
|
174
|
+
*
|
|
175
|
+
* @param obj - The value to check
|
|
176
|
+
* @returns True if the value is nil, false otherwise
|
|
177
|
+
*/
|
|
178
|
+
declare function isNil(obj: unknown): obj is Nil;
|
|
179
|
+
/**
|
|
180
|
+
* Check if an object is a JS object
|
|
181
|
+
*
|
|
182
|
+
* @param obj - The object to check
|
|
183
|
+
* @returns True if the object is a JS object}
|
|
184
|
+
*/
|
|
185
|
+
declare function isObject<T extends object>(obj: unknown): obj is T;
|
|
186
|
+
/**
|
|
187
|
+
* Check if a value is a function
|
|
188
|
+
*
|
|
189
|
+
* @param obj - The value to check
|
|
190
|
+
* @returns True if the value is a function, false otherwise
|
|
191
|
+
*/
|
|
192
|
+
declare function isFunction<T extends AnyFunction>(obj: unknown): obj is T;
|
|
193
|
+
/**
|
|
194
|
+
* Check if an object is a plain object (i.e. a JS object but not including arrays or functions)
|
|
195
|
+
*
|
|
196
|
+
* @param obj - The object to check
|
|
197
|
+
* @returns True if the object is a plain object, false otherwise.
|
|
198
|
+
*/
|
|
199
|
+
declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
200
|
+
/**
|
|
201
|
+
* Check if an object is an empty object
|
|
202
|
+
*
|
|
203
|
+
* @param obj - The object to check
|
|
204
|
+
* @returns True if the object is an empty object, false otherwise
|
|
205
|
+
*/
|
|
206
|
+
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
207
|
+
|
|
208
|
+
export { type DevLoggerOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createDevLogger, deepClone, _default as devLogger, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
|
package/dist/main/index.js
CHANGED
|
@@ -2,8 +2,22 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
8
|
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
7
21
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
22
|
var __export = (target, all) => {
|
|
9
23
|
for (var name in all)
|
|
@@ -64,7 +78,14 @@ __export(index_exports, {
|
|
|
64
78
|
convertReadableStreamToArray: () => convertReadableStreamToArray,
|
|
65
79
|
convertResponseStreamToArray: () => convertResponseStreamToArray,
|
|
66
80
|
createDevLogger: () => createDevLogger,
|
|
67
|
-
|
|
81
|
+
deepClone: () => deepClone,
|
|
82
|
+
devLogger: () => logger_default,
|
|
83
|
+
hasKey: () => hasKey,
|
|
84
|
+
isEmptyObject: () => isEmptyObject,
|
|
85
|
+
isFunction: () => isFunction,
|
|
86
|
+
isNil: () => isNil,
|
|
87
|
+
isObject: () => isObject,
|
|
88
|
+
isPlainObject: () => isPlainObject
|
|
68
89
|
});
|
|
69
90
|
module.exports = __toCommonJS(index_exports);
|
|
70
91
|
|
|
@@ -214,6 +235,56 @@ function convertResponseStreamToArray(response) {
|
|
|
214
235
|
});
|
|
215
236
|
}
|
|
216
237
|
__name(convertResponseStreamToArray, "convertResponseStreamToArray");
|
|
238
|
+
|
|
239
|
+
// src/utils/lang.ts
|
|
240
|
+
function isNil(obj) {
|
|
241
|
+
return obj === null || obj === void 0;
|
|
242
|
+
}
|
|
243
|
+
__name(isNil, "isNil");
|
|
244
|
+
function isObject(obj) {
|
|
245
|
+
return (typeof obj === "object" || typeof obj === "function") && !isNil(obj);
|
|
246
|
+
}
|
|
247
|
+
__name(isObject, "isObject");
|
|
248
|
+
function isFunction(obj) {
|
|
249
|
+
return typeof obj === "function";
|
|
250
|
+
}
|
|
251
|
+
__name(isFunction, "isFunction");
|
|
252
|
+
function isPlainObject(obj) {
|
|
253
|
+
if (!isObject(obj)) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
257
|
+
return prototype === Object.prototype || prototype === null;
|
|
258
|
+
}
|
|
259
|
+
__name(isPlainObject, "isPlainObject");
|
|
260
|
+
function isEmptyObject(obj) {
|
|
261
|
+
if (!isObject(obj)) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
__name(isEmptyObject, "isEmptyObject");
|
|
270
|
+
|
|
271
|
+
// src/utils/objects.ts
|
|
272
|
+
function deepClone(obj) {
|
|
273
|
+
try {
|
|
274
|
+
return JSON.parse(JSON.stringify(obj));
|
|
275
|
+
} catch (error) {
|
|
276
|
+
logger_default.warn("Failed to deep clone object, using shallow clone:", error);
|
|
277
|
+
if (obj === null || typeof obj !== "object") {
|
|
278
|
+
return obj;
|
|
279
|
+
}
|
|
280
|
+
return __spreadValues({}, obj);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
__name(deepClone, "deepClone");
|
|
284
|
+
function hasKey(obj, key) {
|
|
285
|
+
return isObject(obj) && key in obj;
|
|
286
|
+
}
|
|
287
|
+
__name(hasKey, "hasKey");
|
|
217
288
|
// Annotate the CommonJS export names for ESM import in node:
|
|
218
289
|
0 && (module.exports = {
|
|
219
290
|
convertArrayToAsyncIterable,
|
|
@@ -222,6 +293,13 @@ __name(convertResponseStreamToArray, "convertResponseStreamToArray");
|
|
|
222
293
|
convertReadableStreamToArray,
|
|
223
294
|
convertResponseStreamToArray,
|
|
224
295
|
createDevLogger,
|
|
225
|
-
|
|
296
|
+
deepClone,
|
|
297
|
+
devLogger,
|
|
298
|
+
hasKey,
|
|
299
|
+
isEmptyObject,
|
|
300
|
+
isFunction,
|
|
301
|
+
isNil,
|
|
302
|
+
isObject,
|
|
303
|
+
isPlainObject
|
|
226
304
|
});
|
|
227
305
|
//# sourceMappingURL=index.js.map
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/dev/logger.ts","../../src/test/conversions.ts"],"sourcesContent":["export * from \"./dev\";\nexport * from \"./test\";\n","export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n return process.env.NODE_ENV === \"development\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\n","/**\n * Convert a readable stream to an array\n * @param stream - The readable stream to convert\n * @returns The array of values\n */\nexport async function convertReadableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> {\n const reader = stream.getReader();\n const result: T[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n result.push(value);\n }\n\n return result;\n}\n\n/**\n * Convert an array to an async iterable\n * @param values - The array to convert\n * @returns The async iterable\n */\nexport function convertArrayToAsyncIterable<T>(values: T[]): AsyncIterable<T> {\n return {\n async *[Symbol.asyncIterator]() {\n for (const value of values) {\n yield value;\n }\n },\n };\n}\n\n/**\n * Convert an async iterable to an array\n * @param iterable - The async iterable to convert\n * @returns The array of values\n */\nexport async function convertAsyncIterableToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {\n const result: T[] = [];\n for await (const item of iterable) {\n result.push(item);\n }\n return result;\n}\n\n/**\n * Convert an array to a readable stream\n * @param values - The array to convert\n * @returns The readable stream\n */\nexport function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T> {\n return new ReadableStream({\n start(controller) {\n try {\n for (const value of values) {\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n },\n });\n}\n\n/**\n * Convert a response stream to an array\n * @param response - The response to convert\n * @returns The array of values\n */\nexport async function convertResponseStreamToArray(response: Response): Promise<string[]> {\n // biome-ignore lint/style/noNonNullAssertion: ignore this\n return convertReadableStreamToArray(response.body!.pipeThrough(new TextDecoderStream()));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYO,SAAS,gBAAgB,SAA4B;AAC1D,QAAM,QACJ,QAAO,mCAAS,SAAQ,aAAa,QAAQ,MAAM,MAAG;AAd1D;AAc6D,oDAAS,QAAT,YAAgB,aAAa;AAAA;AAEx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AA,IACnB;AAEA,WAAO;AAAA,EACT;AAAA;AAXsB;AAkBf,SAAS,4BAA+B,QAA+B;AAC5E,SAAO;AAAA,IACL,CAAQ,OAAO,aAAa,IAAI;AAAA;AAC9B,mBAAW,SAAS,QAAQ;AAC1B,gBAAM;AAAA,QACR;AAAA,MACF;AAAA;AAAA,EACF;AACF;AARgB;AAehB,SAAsB,4BAA+B,UAA0C;AAAA;AAC7F,UAAM,SAAc,CAAC;AACrB;AAAA,iCAAyB,WAAzB,0EAAmC;AAAxB,cAAM,OAAjB;AACE,eAAO,KAAK,IAAI;AAAA,MAClB;AAAA,aAFA,MAxCF;AAwCE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,WAAO;AAAA,EACT;AAAA;AANsB;AAaf,SAAS,6BAAgC,QAAgC;AAC9E,SAAO,IAAI,eAAe;AAAA,IACxB,MAAM,YAAY;AAChB,UAAI;AACF,mBAAW,SAAS,QAAQ;AAC1B,qBAAW,QAAQ,KAAK;AAAA,QAC1B;AAAA,MACF,UAAE;AACA,mBAAW,MAAM;AAAA,MACnB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAZgB;AAmBhB,SAAsB,6BAA6B,UAAuC;AAAA;AAExF,WAAO,6BAA6B,SAAS,KAAM,YAAY,IAAI,kBAAkB,CAAC,CAAC;AAAA,EACzF;AAAA;AAHsB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/dev/logger.ts","../../src/test/conversions.ts","../../src/utils/lang.ts","../../src/utils/objects.ts"],"sourcesContent":["export * from \"./dev\";\nexport * from \"./test\";\nexport * from \"./utils\";\n","export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n return process.env.NODE_ENV === \"development\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\n","/**\n * Convert a readable stream to an array\n * @param stream - The readable stream to convert\n * @returns The array of values\n */\nexport async function convertReadableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> {\n const reader = stream.getReader();\n const result: T[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n result.push(value);\n }\n\n return result;\n}\n\n/**\n * Convert an array to an async iterable\n * @param values - The array to convert\n * @returns The async iterable\n */\nexport function convertArrayToAsyncIterable<T>(values: T[]): AsyncIterable<T> {\n return {\n async *[Symbol.asyncIterator]() {\n for (const value of values) {\n yield value;\n }\n },\n };\n}\n\n/**\n * Convert an async iterable to an array\n * @param iterable - The async iterable to convert\n * @returns The array of values\n */\nexport async function convertAsyncIterableToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {\n const result: T[] = [];\n for await (const item of iterable) {\n result.push(item);\n }\n return result;\n}\n\n/**\n * Convert an array to a readable stream\n * @param values - The array to convert\n * @returns The readable stream\n */\nexport function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T> {\n return new ReadableStream({\n start(controller) {\n try {\n for (const value of values) {\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n },\n });\n}\n\n/**\n * Convert a response stream to an array\n * @param response - The response to convert\n * @returns The array of values\n */\nexport async function convertResponseStreamToArray(response: Response): Promise<string[]> {\n // biome-ignore lint/style/noNonNullAssertion: ignore this\n return convertReadableStreamToArray(response.body!.pipeThrough(new TextDecoderStream()));\n}\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 { devLogger } from \"../dev\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n devLogger.warn(\"Failed to deep clone object, using shallow clone:\", error);\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYO,SAAS,gBAAgB,SAA4B;AAC1D,QAAM,QACJ,QAAO,mCAAS,SAAQ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S,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;;;AC3CT,SAAS,UAAa,KAAW;AACtC,MAAI;AACF,WAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AAAA,EACvC,SAAS,OAAO;AACd,mBAAU,KAAK,qDAAqD,KAAK;AAEzE,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,mBAAK;AAAA,EACd;AACF;AAXgB;AAoBT,SAAS,OACd,KACA,KAC8B;AAC9B,SAAO,SAAS,GAAG,KAAK,OAAO;AACjC;AALgB;","names":[]}
|
package/dist/main/index.mjs
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
2
5
|
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __spreadValues = (a, b) => {
|
|
8
|
+
for (var prop in b || (b = {}))
|
|
9
|
+
if (__hasOwnProp.call(b, prop))
|
|
10
|
+
__defNormalProp(a, prop, b[prop]);
|
|
11
|
+
if (__getOwnPropSymbols)
|
|
12
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
+
if (__propIsEnum.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
}
|
|
16
|
+
return a;
|
|
17
|
+
};
|
|
3
18
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
19
|
var __async = (__this, __arguments, generator) => {
|
|
5
20
|
return new Promise((resolve, reject) => {
|
|
@@ -184,6 +199,56 @@ function convertResponseStreamToArray(response) {
|
|
|
184
199
|
});
|
|
185
200
|
}
|
|
186
201
|
__name(convertResponseStreamToArray, "convertResponseStreamToArray");
|
|
202
|
+
|
|
203
|
+
// src/utils/lang.ts
|
|
204
|
+
function isNil(obj) {
|
|
205
|
+
return obj === null || obj === void 0;
|
|
206
|
+
}
|
|
207
|
+
__name(isNil, "isNil");
|
|
208
|
+
function isObject(obj) {
|
|
209
|
+
return (typeof obj === "object" || typeof obj === "function") && !isNil(obj);
|
|
210
|
+
}
|
|
211
|
+
__name(isObject, "isObject");
|
|
212
|
+
function isFunction(obj) {
|
|
213
|
+
return typeof obj === "function";
|
|
214
|
+
}
|
|
215
|
+
__name(isFunction, "isFunction");
|
|
216
|
+
function isPlainObject(obj) {
|
|
217
|
+
if (!isObject(obj)) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
221
|
+
return prototype === Object.prototype || prototype === null;
|
|
222
|
+
}
|
|
223
|
+
__name(isPlainObject, "isPlainObject");
|
|
224
|
+
function isEmptyObject(obj) {
|
|
225
|
+
if (!isObject(obj)) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
__name(isEmptyObject, "isEmptyObject");
|
|
234
|
+
|
|
235
|
+
// src/utils/objects.ts
|
|
236
|
+
function deepClone(obj) {
|
|
237
|
+
try {
|
|
238
|
+
return JSON.parse(JSON.stringify(obj));
|
|
239
|
+
} catch (error) {
|
|
240
|
+
logger_default.warn("Failed to deep clone object, using shallow clone:", error);
|
|
241
|
+
if (obj === null || typeof obj !== "object") {
|
|
242
|
+
return obj;
|
|
243
|
+
}
|
|
244
|
+
return __spreadValues({}, obj);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
__name(deepClone, "deepClone");
|
|
248
|
+
function hasKey(obj, key) {
|
|
249
|
+
return isObject(obj) && key in obj;
|
|
250
|
+
}
|
|
251
|
+
__name(hasKey, "hasKey");
|
|
187
252
|
export {
|
|
188
253
|
convertArrayToAsyncIterable,
|
|
189
254
|
convertArrayToReadableStream,
|
|
@@ -191,6 +256,13 @@ export {
|
|
|
191
256
|
convertReadableStreamToArray,
|
|
192
257
|
convertResponseStreamToArray,
|
|
193
258
|
createDevLogger,
|
|
194
|
-
|
|
259
|
+
deepClone,
|
|
260
|
+
logger_default as devLogger,
|
|
261
|
+
hasKey,
|
|
262
|
+
isEmptyObject,
|
|
263
|
+
isFunction,
|
|
264
|
+
isNil,
|
|
265
|
+
isObject,
|
|
266
|
+
isPlainObject
|
|
195
267
|
};
|
|
196
268
|
//# sourceMappingURL=index.mjs.map
|
package/dist/main/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/dev/logger.ts","../../src/test/conversions.ts"],"sourcesContent":["export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n return process.env.NODE_ENV === \"development\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\n","/**\n * Convert a readable stream to an array\n * @param stream - The readable stream to convert\n * @returns The array of values\n */\nexport async function convertReadableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> {\n const reader = stream.getReader();\n const result: T[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n result.push(value);\n }\n\n return result;\n}\n\n/**\n * Convert an array to an async iterable\n * @param values - The array to convert\n * @returns The async iterable\n */\nexport function convertArrayToAsyncIterable<T>(values: T[]): AsyncIterable<T> {\n return {\n async *[Symbol.asyncIterator]() {\n for (const value of values) {\n yield value;\n }\n },\n };\n}\n\n/**\n * Convert an async iterable to an array\n * @param iterable - The async iterable to convert\n * @returns The array of values\n */\nexport async function convertAsyncIterableToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {\n const result: T[] = [];\n for await (const item of iterable) {\n result.push(item);\n }\n return result;\n}\n\n/**\n * Convert an array to a readable stream\n * @param values - The array to convert\n * @returns The readable stream\n */\nexport function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T> {\n return new ReadableStream({\n start(controller) {\n try {\n for (const value of values) {\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n },\n });\n}\n\n/**\n * Convert a response stream to an array\n * @param response - The response to convert\n * @returns The array of values\n */\nexport async function convertResponseStreamToArray(response: Response): Promise<string[]> {\n // biome-ignore lint/style/noNonNullAssertion: ignore this\n return convertReadableStreamToArray(response.body!.pipeThrough(new TextDecoderStream()));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYO,SAAS,gBAAgB,SAA4B;AAC1D,QAAM,QACJ,QAAO,mCAAS,SAAQ,aAAa,QAAQ,MAAM,MAAG;AAd1D;AAc6D,oDAAS,QAAT,YAAgB,aAAa;AAAA;AAExF,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcL,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,gBAAQ,KAAK,gBAAgB,MAAM,GAAG,SAAS,GAAG,IAAI;AAAA,MACxD;AAAA,IACF,GAJM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkBN,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,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AAA,aAFA,MAxCF;AAwCE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,WAAO;AAAA,EACT;AAAA;AANsB;AAaf,SAAS,6BAAgC,QAAgC;AAC9E,SAAO,IAAI,eAAe;AAAA,IACxB,MAAM,YAAY;AAChB,UAAI;AACF,mBAAW,SAAS,QAAQ;AAC1B,qBAAW,QAAQ,KAAK;AAAA,QAC1B;AAAA,MACF,UAAE;AACA,mBAAW,MAAM;AAAA,MACnB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAZgB;AAmBhB,SAAsB,6BAA6B,UAAuC;AAAA;AAExF,WAAO,6BAA6B,SAAS,KAAM,YAAY,IAAI,kBAAkB,CAAC,CAAC;AAAA,EACzF;AAAA;AAHsB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/dev/logger.ts","../../src/test/conversions.ts","../../src/utils/lang.ts","../../src/utils/objects.ts"],"sourcesContent":["export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n return process.env.NODE_ENV === \"development\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\n","/**\n * Convert a readable stream to an array\n * @param stream - The readable stream to convert\n * @returns The array of values\n */\nexport async function convertReadableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> {\n const reader = stream.getReader();\n const result: T[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n result.push(value);\n }\n\n return result;\n}\n\n/**\n * Convert an array to an async iterable\n * @param values - The array to convert\n * @returns The async iterable\n */\nexport function convertArrayToAsyncIterable<T>(values: T[]): AsyncIterable<T> {\n return {\n async *[Symbol.asyncIterator]() {\n for (const value of values) {\n yield value;\n }\n },\n };\n}\n\n/**\n * Convert an async iterable to an array\n * @param iterable - The async iterable to convert\n * @returns The array of values\n */\nexport async function convertAsyncIterableToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {\n const result: T[] = [];\n for await (const item of iterable) {\n result.push(item);\n }\n return result;\n}\n\n/**\n * Convert an array to a readable stream\n * @param values - The array to convert\n * @returns The readable stream\n */\nexport function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T> {\n return new ReadableStream({\n start(controller) {\n try {\n for (const value of values) {\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n },\n });\n}\n\n/**\n * Convert a response stream to an array\n * @param response - The response to convert\n * @returns The array of values\n */\nexport async function convertResponseStreamToArray(response: Response): Promise<string[]> {\n // biome-ignore lint/style/noNonNullAssertion: ignore this\n return convertReadableStreamToArray(response.body!.pipeThrough(new TextDecoderStream()));\n}\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 { devLogger } from \"../dev\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n devLogger.warn(\"Failed to deep clone object, using shallow clone:\", error);\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYO,SAAS,gBAAgB,SAA4B;AAC1D,QAAM,QACJ,QAAO,mCAAS,SAAQ,aAAa,QAAQ,MAAM,MAAG;AAd1D;AAc6D,oDAAS,QAAT,YAAgB,aAAa;AAAA;AAExF,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcL,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,gBAAQ,KAAK,gBAAgB,MAAM,GAAG,SAAS,GAAG,IAAI;AAAA,MACxD;AAAA,IACF,GAJM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkBN,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,gBAAQ,KAAK,gBAAgB,MAAM,GAAG,SAAS,GAAG,IAAI;AAAA,MACxD;AAAA,IACF,GAJM;AAAA;AAAA;AAA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AACA,WAAO,mBAAK;AAAA,EACd;AACF;AAXgB;AAoBT,SAAS,OACd,KACA,KAC8B;AAC9B,SAAO,SAAS,GAAG,KAAK,OAAO;AACjC;AALgB;","names":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This type is used to allow any type and bypass restrictions used in
|
|
3
|
+
* typechecking and linting. Provides a CLEAR warning this is NOT the desired
|
|
4
|
+
* behavior and is a dangerous practice.
|
|
5
|
+
*/
|
|
6
|
+
type DangerouslyAllowAny = any;
|
|
7
|
+
/**
|
|
8
|
+
* A plain object is an object that has no special properties or methods,
|
|
9
|
+
* and just has properties that are strings, numbers, or symbols.
|
|
10
|
+
*/
|
|
11
|
+
type PlainObject = Record<string | number | symbol, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* A nil value is a value that is not defined or is undefined.
|
|
14
|
+
*/
|
|
15
|
+
type Nil = null | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* A type that represents any async function.
|
|
18
|
+
*/
|
|
19
|
+
type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* A type that represents any synchronous function.
|
|
22
|
+
*/
|
|
23
|
+
type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
24
|
+
/**
|
|
25
|
+
* A type that represents any function.
|
|
26
|
+
*/
|
|
27
|
+
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
28
|
+
|
|
29
|
+
export type { AnyAsyncFunction, AnyFunction, AnySyncFunction, DangerouslyAllowAny, Nil, PlainObject };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This type is used to allow any type and bypass restrictions used in
|
|
3
|
+
* typechecking and linting. Provides a CLEAR warning this is NOT the desired
|
|
4
|
+
* behavior and is a dangerous practice.
|
|
5
|
+
*/
|
|
6
|
+
type DangerouslyAllowAny = any;
|
|
7
|
+
/**
|
|
8
|
+
* A plain object is an object that has no special properties or methods,
|
|
9
|
+
* and just has properties that are strings, numbers, or symbols.
|
|
10
|
+
*/
|
|
11
|
+
type PlainObject = Record<string | number | symbol, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* A nil value is a value that is not defined or is undefined.
|
|
14
|
+
*/
|
|
15
|
+
type Nil = null | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* A type that represents any async function.
|
|
18
|
+
*/
|
|
19
|
+
type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* A type that represents any synchronous function.
|
|
22
|
+
*/
|
|
23
|
+
type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
24
|
+
/**
|
|
25
|
+
* A type that represents any function.
|
|
26
|
+
*/
|
|
27
|
+
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
28
|
+
|
|
29
|
+
export type { AnyAsyncFunction, AnyFunction, AnySyncFunction, DangerouslyAllowAny, Nil, PlainObject };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { SetRequired, EmptyObject } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A plain object is an object that has no special properties or methods,
|
|
5
|
+
* and just has properties that are strings, numbers, or symbols.
|
|
6
|
+
*/
|
|
7
|
+
type PlainObject = Record<string | number | symbol, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* A nil value is a value that is not defined or is undefined.
|
|
10
|
+
*/
|
|
11
|
+
type Nil = null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* A type that represents any async function.
|
|
14
|
+
*/
|
|
15
|
+
type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* A type that represents any synchronous function.
|
|
18
|
+
*/
|
|
19
|
+
type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
20
|
+
/**
|
|
21
|
+
* A type that represents any function.
|
|
22
|
+
*/
|
|
23
|
+
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
27
|
+
*
|
|
28
|
+
* @param obj - The object to clone
|
|
29
|
+
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
30
|
+
*/
|
|
31
|
+
declare function deepClone<T>(obj: T): T;
|
|
32
|
+
/**
|
|
33
|
+
* Check if an object has a key
|
|
34
|
+
*
|
|
35
|
+
* @param obj - The object to check
|
|
36
|
+
* @param key - The key to check
|
|
37
|
+
* @returns True if the object has the key, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
declare function hasKey<T extends PlainObject, K extends string>(obj: T, key: K): obj is T & SetRequired<T, K>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if a value is nil
|
|
43
|
+
*
|
|
44
|
+
* @param obj - The value to check
|
|
45
|
+
* @returns True if the value is nil, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
declare function isNil(obj: unknown): obj is Nil;
|
|
48
|
+
/**
|
|
49
|
+
* Check if an object is a JS object
|
|
50
|
+
*
|
|
51
|
+
* @param obj - The object to check
|
|
52
|
+
* @returns True if the object is a JS object}
|
|
53
|
+
*/
|
|
54
|
+
declare function isObject<T extends object>(obj: unknown): obj is T;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a value is a function
|
|
57
|
+
*
|
|
58
|
+
* @param obj - The value to check
|
|
59
|
+
* @returns True if the value is a function, false otherwise
|
|
60
|
+
*/
|
|
61
|
+
declare function isFunction<T extends AnyFunction>(obj: unknown): obj is T;
|
|
62
|
+
/**
|
|
63
|
+
* Check if an object is a plain object (i.e. a JS object but not including arrays or functions)
|
|
64
|
+
*
|
|
65
|
+
* @param obj - The object to check
|
|
66
|
+
* @returns True if the object is a plain object, false otherwise.
|
|
67
|
+
*/
|
|
68
|
+
declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
69
|
+
/**
|
|
70
|
+
* Check if an object is an empty object
|
|
71
|
+
*
|
|
72
|
+
* @param obj - The object to check
|
|
73
|
+
* @returns True if the object is an empty object, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
76
|
+
|
|
77
|
+
export { deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { SetRequired, EmptyObject } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A plain object is an object that has no special properties or methods,
|
|
5
|
+
* and just has properties that are strings, numbers, or symbols.
|
|
6
|
+
*/
|
|
7
|
+
type PlainObject = Record<string | number | symbol, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* A nil value is a value that is not defined or is undefined.
|
|
10
|
+
*/
|
|
11
|
+
type Nil = null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* A type that represents any async function.
|
|
14
|
+
*/
|
|
15
|
+
type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* A type that represents any synchronous function.
|
|
18
|
+
*/
|
|
19
|
+
type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
20
|
+
/**
|
|
21
|
+
* A type that represents any function.
|
|
22
|
+
*/
|
|
23
|
+
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
27
|
+
*
|
|
28
|
+
* @param obj - The object to clone
|
|
29
|
+
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
30
|
+
*/
|
|
31
|
+
declare function deepClone<T>(obj: T): T;
|
|
32
|
+
/**
|
|
33
|
+
* Check if an object has a key
|
|
34
|
+
*
|
|
35
|
+
* @param obj - The object to check
|
|
36
|
+
* @param key - The key to check
|
|
37
|
+
* @returns True if the object has the key, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
declare function hasKey<T extends PlainObject, K extends string>(obj: T, key: K): obj is T & SetRequired<T, K>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if a value is nil
|
|
43
|
+
*
|
|
44
|
+
* @param obj - The value to check
|
|
45
|
+
* @returns True if the value is nil, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
declare function isNil(obj: unknown): obj is Nil;
|
|
48
|
+
/**
|
|
49
|
+
* Check if an object is a JS object
|
|
50
|
+
*
|
|
51
|
+
* @param obj - The object to check
|
|
52
|
+
* @returns True if the object is a JS object}
|
|
53
|
+
*/
|
|
54
|
+
declare function isObject<T extends object>(obj: unknown): obj is T;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a value is a function
|
|
57
|
+
*
|
|
58
|
+
* @param obj - The value to check
|
|
59
|
+
* @returns True if the value is a function, false otherwise
|
|
60
|
+
*/
|
|
61
|
+
declare function isFunction<T extends AnyFunction>(obj: unknown): obj is T;
|
|
62
|
+
/**
|
|
63
|
+
* Check if an object is a plain object (i.e. a JS object but not including arrays or functions)
|
|
64
|
+
*
|
|
65
|
+
* @param obj - The object to check
|
|
66
|
+
* @returns True if the object is a plain object, false otherwise.
|
|
67
|
+
*/
|
|
68
|
+
declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
69
|
+
/**
|
|
70
|
+
* Check if an object is an empty object
|
|
71
|
+
*
|
|
72
|
+
* @param obj - The object to check
|
|
73
|
+
* @returns True if the object is an empty object, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
76
|
+
|
|
77
|
+
export { deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
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
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
21
|
+
var __export = (target, all) => {
|
|
22
|
+
for (var name in all)
|
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
+
};
|
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
+
for (let key of __getOwnPropNames(from))
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
|
+
|
|
35
|
+
// src/utils/index.ts
|
|
36
|
+
var index_exports = {};
|
|
37
|
+
__export(index_exports, {
|
|
38
|
+
deepClone: () => deepClone,
|
|
39
|
+
hasKey: () => hasKey,
|
|
40
|
+
isEmptyObject: () => isEmptyObject,
|
|
41
|
+
isFunction: () => isFunction,
|
|
42
|
+
isNil: () => isNil,
|
|
43
|
+
isObject: () => isObject,
|
|
44
|
+
isPlainObject: () => isPlainObject
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(index_exports);
|
|
47
|
+
|
|
48
|
+
// src/dev/logger.ts
|
|
49
|
+
function createDevLogger(options) {
|
|
50
|
+
const isDev = typeof (options == null ? void 0 : options.dev) === "function" ? options.dev : () => {
|
|
51
|
+
var _a;
|
|
52
|
+
return (_a = options == null ? void 0 : options.dev) != null ? _a : isDevNodeEnv();
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
/**
|
|
56
|
+
* Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* devLogger.info("Hello, world!");
|
|
61
|
+
*
|
|
62
|
+
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @param message - The message to log.
|
|
66
|
+
* @param args - The arguments to log.
|
|
67
|
+
*/
|
|
68
|
+
info: /* @__PURE__ */ __name((message, ...args) => {
|
|
69
|
+
if (isDev()) {
|
|
70
|
+
console.info(formatLogPrefix("INFO"), message, ...args);
|
|
71
|
+
}
|
|
72
|
+
}, "info"),
|
|
73
|
+
/**
|
|
74
|
+
* Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* devLogger.warn("Hello, world!");
|
|
79
|
+
*
|
|
80
|
+
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @param message - The message to log.
|
|
84
|
+
* @param args - The arguments to log.
|
|
85
|
+
*/
|
|
86
|
+
warn: /* @__PURE__ */ __name((message, ...args) => {
|
|
87
|
+
if (isDev()) {
|
|
88
|
+
console.warn(formatLogPrefix("WARN"), message, ...args);
|
|
89
|
+
}
|
|
90
|
+
}, "warn"),
|
|
91
|
+
/**
|
|
92
|
+
* Log a warning message to the console if the environment is development.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* devLogger.error("Hello, world!");
|
|
97
|
+
*
|
|
98
|
+
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @param message - The message to log.
|
|
102
|
+
* @param args - The arguments to log.
|
|
103
|
+
*/
|
|
104
|
+
error: /* @__PURE__ */ __name((message, ...args) => {
|
|
105
|
+
if (isDev()) {
|
|
106
|
+
console.error(formatLogPrefix("ERROR"), message, ...args);
|
|
107
|
+
}
|
|
108
|
+
}, "error")
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
__name(createDevLogger, "createDevLogger");
|
|
112
|
+
var logger_default = createDevLogger();
|
|
113
|
+
function isDevNodeEnv() {
|
|
114
|
+
return process.env.NODE_ENV === "development";
|
|
115
|
+
}
|
|
116
|
+
__name(isDevNodeEnv, "isDevNodeEnv");
|
|
117
|
+
function formatLogPrefix(level) {
|
|
118
|
+
return `[VoltAgent] [${timestamp()}] ${level}: `;
|
|
119
|
+
}
|
|
120
|
+
__name(formatLogPrefix, "formatLogPrefix");
|
|
121
|
+
function timestamp() {
|
|
122
|
+
return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, -1);
|
|
123
|
+
}
|
|
124
|
+
__name(timestamp, "timestamp");
|
|
125
|
+
|
|
126
|
+
// src/utils/lang.ts
|
|
127
|
+
function isNil(obj) {
|
|
128
|
+
return obj === null || obj === void 0;
|
|
129
|
+
}
|
|
130
|
+
__name(isNil, "isNil");
|
|
131
|
+
function isObject(obj) {
|
|
132
|
+
return (typeof obj === "object" || typeof obj === "function") && !isNil(obj);
|
|
133
|
+
}
|
|
134
|
+
__name(isObject, "isObject");
|
|
135
|
+
function isFunction(obj) {
|
|
136
|
+
return typeof obj === "function";
|
|
137
|
+
}
|
|
138
|
+
__name(isFunction, "isFunction");
|
|
139
|
+
function isPlainObject(obj) {
|
|
140
|
+
if (!isObject(obj)) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
144
|
+
return prototype === Object.prototype || prototype === null;
|
|
145
|
+
}
|
|
146
|
+
__name(isPlainObject, "isPlainObject");
|
|
147
|
+
function isEmptyObject(obj) {
|
|
148
|
+
if (!isObject(obj)) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
__name(isEmptyObject, "isEmptyObject");
|
|
157
|
+
|
|
158
|
+
// src/utils/objects.ts
|
|
159
|
+
function deepClone(obj) {
|
|
160
|
+
try {
|
|
161
|
+
return JSON.parse(JSON.stringify(obj));
|
|
162
|
+
} catch (error) {
|
|
163
|
+
logger_default.warn("Failed to deep clone object, using shallow clone:", error);
|
|
164
|
+
if (obj === null || typeof obj !== "object") {
|
|
165
|
+
return obj;
|
|
166
|
+
}
|
|
167
|
+
return __spreadValues({}, obj);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
__name(deepClone, "deepClone");
|
|
171
|
+
function hasKey(obj, key) {
|
|
172
|
+
return isObject(obj) && key in obj;
|
|
173
|
+
}
|
|
174
|
+
__name(hasKey, "hasKey");
|
|
175
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
176
|
+
0 && (module.exports = {
|
|
177
|
+
deepClone,
|
|
178
|
+
hasKey,
|
|
179
|
+
isEmptyObject,
|
|
180
|
+
isFunction,
|
|
181
|
+
isNil,
|
|
182
|
+
isObject,
|
|
183
|
+
isPlainObject
|
|
184
|
+
});
|
|
185
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts","../../src/dev/logger.ts","../../src/utils/lang.ts","../../src/utils/objects.ts"],"sourcesContent":["export { deepClone, hasKey } from \"./objects\";\nexport { isNil, isObject, isEmptyObject, isFunction, isPlainObject } from \"./lang\";\n","export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n return process.env.NODE_ENV === \"development\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\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 { devLogger } from \"../dev\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n devLogger.warn(\"Failed to deep clone object, using shallow clone:\", error);\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYO,SAAS,gBAAgB,SAA4B;AAC1D,QAAM,QACJ,QAAO,mCAAS,SAAQ,aAAa,QAAQ,MAAM,MAAG;AAd1D;AAc6D,oDAAS,QAAT,YAAgB,aAAa;AAAA;AAExF,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcL,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,gBAAQ,KAAK,gBAAgB,MAAM,GAAG,SAAS,GAAG,IAAI;AAAA,MACxD;AAAA,IACF,GAJM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkBN,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,gBAAQ,KAAK,gBAAgB,MAAM,GAAG,SAAS,GAAG,IAAI;AAAA,MACxD;AAAA,IACF,GAJM;AAAA;AAAA;AAAA;AAAA;AAAA;AA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M,KAAK,UAAU,GAAG,CAAC;AAAA,EACvC,SAAS,OAAO;AACd,mBAAU,KAAK,qDAAqD,KAAK;AAEzE,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,mBAAK;AAAA,EACd;AACF;AAXgB;AAoBT,SAAS,OACd,KACA,KAC8B;AAC9B,SAAO,SAAS,GAAG,KAAK,OAAO;AACjC;AALgB;","names":[]}
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
18
|
+
|
|
19
|
+
// src/dev/logger.ts
|
|
20
|
+
function createDevLogger(options) {
|
|
21
|
+
const isDev = typeof (options == null ? void 0 : options.dev) === "function" ? options.dev : () => {
|
|
22
|
+
var _a;
|
|
23
|
+
return (_a = options == null ? void 0 : options.dev) != null ? _a : isDevNodeEnv();
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
/**
|
|
27
|
+
* Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* devLogger.info("Hello, world!");
|
|
32
|
+
*
|
|
33
|
+
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param message - The message to log.
|
|
37
|
+
* @param args - The arguments to log.
|
|
38
|
+
*/
|
|
39
|
+
info: /* @__PURE__ */ __name((message, ...args) => {
|
|
40
|
+
if (isDev()) {
|
|
41
|
+
console.info(formatLogPrefix("INFO"), message, ...args);
|
|
42
|
+
}
|
|
43
|
+
}, "info"),
|
|
44
|
+
/**
|
|
45
|
+
* Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* devLogger.warn("Hello, world!");
|
|
50
|
+
*
|
|
51
|
+
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param message - The message to log.
|
|
55
|
+
* @param args - The arguments to log.
|
|
56
|
+
*/
|
|
57
|
+
warn: /* @__PURE__ */ __name((message, ...args) => {
|
|
58
|
+
if (isDev()) {
|
|
59
|
+
console.warn(formatLogPrefix("WARN"), message, ...args);
|
|
60
|
+
}
|
|
61
|
+
}, "warn"),
|
|
62
|
+
/**
|
|
63
|
+
* Log a warning message to the console if the environment is development.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* devLogger.error("Hello, world!");
|
|
68
|
+
*
|
|
69
|
+
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @param message - The message to log.
|
|
73
|
+
* @param args - The arguments to log.
|
|
74
|
+
*/
|
|
75
|
+
error: /* @__PURE__ */ __name((message, ...args) => {
|
|
76
|
+
if (isDev()) {
|
|
77
|
+
console.error(formatLogPrefix("ERROR"), message, ...args);
|
|
78
|
+
}
|
|
79
|
+
}, "error")
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
__name(createDevLogger, "createDevLogger");
|
|
83
|
+
var logger_default = createDevLogger();
|
|
84
|
+
function isDevNodeEnv() {
|
|
85
|
+
return process.env.NODE_ENV === "development";
|
|
86
|
+
}
|
|
87
|
+
__name(isDevNodeEnv, "isDevNodeEnv");
|
|
88
|
+
function formatLogPrefix(level) {
|
|
89
|
+
return `[VoltAgent] [${timestamp()}] ${level}: `;
|
|
90
|
+
}
|
|
91
|
+
__name(formatLogPrefix, "formatLogPrefix");
|
|
92
|
+
function timestamp() {
|
|
93
|
+
return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, -1);
|
|
94
|
+
}
|
|
95
|
+
__name(timestamp, "timestamp");
|
|
96
|
+
|
|
97
|
+
// src/utils/lang.ts
|
|
98
|
+
function isNil(obj) {
|
|
99
|
+
return obj === null || obj === void 0;
|
|
100
|
+
}
|
|
101
|
+
__name(isNil, "isNil");
|
|
102
|
+
function isObject(obj) {
|
|
103
|
+
return (typeof obj === "object" || typeof obj === "function") && !isNil(obj);
|
|
104
|
+
}
|
|
105
|
+
__name(isObject, "isObject");
|
|
106
|
+
function isFunction(obj) {
|
|
107
|
+
return typeof obj === "function";
|
|
108
|
+
}
|
|
109
|
+
__name(isFunction, "isFunction");
|
|
110
|
+
function isPlainObject(obj) {
|
|
111
|
+
if (!isObject(obj)) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
115
|
+
return prototype === Object.prototype || prototype === null;
|
|
116
|
+
}
|
|
117
|
+
__name(isPlainObject, "isPlainObject");
|
|
118
|
+
function isEmptyObject(obj) {
|
|
119
|
+
if (!isObject(obj)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
__name(isEmptyObject, "isEmptyObject");
|
|
128
|
+
|
|
129
|
+
// src/utils/objects.ts
|
|
130
|
+
function deepClone(obj) {
|
|
131
|
+
try {
|
|
132
|
+
return JSON.parse(JSON.stringify(obj));
|
|
133
|
+
} catch (error) {
|
|
134
|
+
logger_default.warn("Failed to deep clone object, using shallow clone:", error);
|
|
135
|
+
if (obj === null || typeof obj !== "object") {
|
|
136
|
+
return obj;
|
|
137
|
+
}
|
|
138
|
+
return __spreadValues({}, obj);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
__name(deepClone, "deepClone");
|
|
142
|
+
function hasKey(obj, key) {
|
|
143
|
+
return isObject(obj) && key in obj;
|
|
144
|
+
}
|
|
145
|
+
__name(hasKey, "hasKey");
|
|
146
|
+
export {
|
|
147
|
+
deepClone,
|
|
148
|
+
hasKey,
|
|
149
|
+
isEmptyObject,
|
|
150
|
+
isFunction,
|
|
151
|
+
isNil,
|
|
152
|
+
isObject,
|
|
153
|
+
isPlainObject
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/dev/logger.ts","../../src/utils/lang.ts","../../src/utils/objects.ts"],"sourcesContent":["export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n return process.env.NODE_ENV === \"development\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\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 { devLogger } from \"../dev\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n devLogger.warn(\"Failed to deep clone object, using shallow clone:\", error);\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"],"mappings":";;;;;;;;;;;;;;;;;;;AAYO,SA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B;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;;;AC3CT,SAAS,UAAa,KAAW;AACtC,MAAI;AACF,WAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AAAA,EACvC,SAAS,OAAO;AACd,mBAAU,KAAK,qDAAqD,KAAK;AAEzE,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,mBAAK;AAAA,EACd;AACF;AAXgB;AAoBT,SAAS,OACd,KACA,KAC8B;AAC9B,SAAO,SAAS,GAAG,KAAK,OAAO;AACjC;AALgB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltagent/internal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "VoltAgent internal - an internal set of tools for the VoltAgent packages",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"exports": {
|
|
@@ -18,6 +18,14 @@
|
|
|
18
18
|
"types": "./dist/test/index.d.ts",
|
|
19
19
|
"import": "./dist/test/index.mjs",
|
|
20
20
|
"require": "./dist/test/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./utils": {
|
|
23
|
+
"types": "./dist/utils/index.d.ts",
|
|
24
|
+
"import": "./dist/utils/index.mjs",
|
|
25
|
+
"require": "./dist/utils/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./types": {
|
|
28
|
+
"types": "./dist/types/index.d.ts"
|
|
21
29
|
}
|
|
22
30
|
},
|
|
23
31
|
"main": "dist/main/index.js",
|
|
@@ -28,12 +36,11 @@
|
|
|
28
36
|
"dev/dist/**/*",
|
|
29
37
|
"test/dist/**/*"
|
|
30
38
|
],
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@voltagent/core": "^0.1.31"
|
|
33
|
-
},
|
|
34
39
|
"devDependencies": {
|
|
35
40
|
"@types/node": "^24.0.3",
|
|
41
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
36
42
|
"tsup": "^8.5.0",
|
|
43
|
+
"type-fest": "^4.41.0",
|
|
37
44
|
"typescript": "^5.0.4",
|
|
38
45
|
"vitest": "^3.2.4"
|
|
39
46
|
},
|