@voltagent/internal 0.0.5 → 0.0.7

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,122 +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
-
39
- // src/dev/logger.ts
40
- function createDevLogger(options) {
41
- const isDev = typeof (options == null ? void 0 : options.dev) === "function" ? options.dev : () => {
42
- var _a;
43
- return (_a = options == null ? void 0 : options.dev) != null ? _a : isDevNodeEnv();
44
- };
45
- return {
46
- /**
47
- * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
48
- *
49
- * @example
50
- * ```typescript
51
- * devLogger.info("Hello, world!");
52
- *
53
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
54
- * ```
55
- *
56
- * @param message - The message to log.
57
- * @param args - The arguments to log.
58
- */
59
- info: /* @__PURE__ */ __name((message, ...args) => {
60
- if (isDev()) {
61
- console.info(formatLogPrefix("INFO"), message, ...args);
62
- }
63
- }, "info"),
64
- /**
65
- * 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".
66
- *
67
- * @example
68
- * ```typescript
69
- * devLogger.warn("Hello, world!");
70
- *
71
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
72
- * ```
73
- *
74
- * @param message - The message to log.
75
- * @param args - The arguments to log.
76
- */
77
- warn: /* @__PURE__ */ __name((message, ...args) => {
78
- if (isDev()) {
79
- console.warn(formatLogPrefix("WARN"), message, ...args);
80
- }
81
- }, "warn"),
82
- /**
83
- * Log a warning message to the console if the environment is development.
84
- *
85
- * @example
86
- * ```typescript
87
- * devLogger.error("Hello, world!");
88
- *
89
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
90
- * ```
91
- *
92
- * @param message - The message to log.
93
- * @param args - The arguments to log.
94
- */
95
- error: /* @__PURE__ */ __name((message, ...args) => {
96
- if (isDev()) {
97
- console.error(formatLogPrefix("ERROR"), message, ...args);
98
- }
99
- }, "error"),
100
- debug: /* @__PURE__ */ __name((_message, ..._args) => {
101
- return;
102
- }, "debug")
103
- };
104
- }
105
- __name(createDevLogger, "createDevLogger");
106
- var logger_default = createDevLogger();
107
- function isDevNodeEnv() {
108
- const nodeEnv = process.env.NODE_ENV;
109
- return nodeEnv !== "production" && nodeEnv !== "test" && nodeEnv !== "ci";
110
- }
111
- __name(isDevNodeEnv, "isDevNodeEnv");
112
- function formatLogPrefix(level) {
113
- return `[VoltAgent] [${timestamp()}] ${level}: `;
114
- }
115
- __name(formatLogPrefix, "formatLogPrefix");
116
- function timestamp() {
117
- return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, -1);
118
- }
119
- __name(timestamp, "timestamp");
120
3
 
121
4
  // src/utils/lang.ts
122
5
  function isNil(obj) {
@@ -151,15 +34,17 @@ function isEmptyObject(obj) {
151
34
  __name(isEmptyObject, "isEmptyObject");
152
35
 
153
36
  // src/utils/objects.ts
154
- function deepClone(obj) {
37
+ function deepClone(obj, logger) {
155
38
  try {
156
39
  return JSON.parse(JSON.stringify(obj));
157
40
  } catch (error) {
158
- logger_default.warn("Failed to deep clone object, using shallow clone:", error);
41
+ if (logger) {
42
+ logger.warn("Failed to deep clone object, using shallow clone", { error });
43
+ }
159
44
  if (obj === null || typeof obj !== "object") {
160
45
  return obj;
161
46
  }
162
- return __spreadValues({}, obj);
47
+ return { ...obj };
163
48
  }
164
49
  }
165
50
  __name(deepClone, "deepClone");
@@ -174,11 +59,9 @@ function createAsyncIterableStream(source) {
174
59
  stream[Symbol.asyncIterator] = () => {
175
60
  const reader = stream.getReader();
176
61
  return {
177
- next() {
178
- return __async(this, null, function* () {
179
- const { done, value } = yield reader.read();
180
- return done ? { done: true, value: void 0 } : { done: false, value };
181
- });
62
+ async next() {
63
+ const { done, value } = await reader.read();
64
+ return done ? { done: true, value: void 0 } : { done: false, value };
182
65
  }
183
66
  };
184
67
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/dev/logger.ts","../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.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 debug: (_message?: any, ..._args: any[]) => {\n // todo: implement debug logging with pino\n return;\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n const nodeEnv = process.env.NODE_ENV;\n return nodeEnv !== \"production\" && nodeEnv !== \"test\" && nodeEnv !== \"ci\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\" | \"DEBUG\"): 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","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkBN,OAAO,wBAAC,YAAkB,SAAgB;AACxC,UAAI,MAAM,GAAG;AACX,gBAAQ,MAAM,gBAAgB,OAAO,GAAG,SAAS,GAAG,IAAI;AAAA,MAC1D;AAAA,IACF,GAJO;AAAA,IAMP,OAAO,wBAAC,aAAmB,UAAiB;AAE1C;AAAA,IACF,GAHO;AAAA,EAIT;AACF;AAjEgB;AAmEhB,IAAO,iBAAQ,gBAAgB;AAE/B,SAAS,eAAe;AACtB,QAAM,UAAU,QAAQ,IAAI;AAC5B,SAAO,YAAY,gBAAgB,YAAY,UAAU,YAAY;AACvE;AAHS;AAKT,SAAS,gBAAgB,OAAoD;AAC3E,SAAO,gBAAgB,UAAU,CAAC,KAAK,KAAK;AAC9C;AAFS;AAIT,SAAS,YAAoB;AAC3B,UAAO,oBAAI,KAAK,GAAE,YAAY,EAAE,QAAQ,KAAK,GAAG,EAAE,MAAM,GAAG,EAAE;AAC/D;AAFS;;;ACjFF,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;;;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;;;ACAT,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"],"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 { Logger } from \"../logger/types\";\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 * @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,EAAE,GAAG,IAAI;AAAA,EAClB;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,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;","names":[]}
package/package.json CHANGED
@@ -1,54 +1,82 @@
1
1
  {
2
2
  "name": "@voltagent/internal",
3
- "version": "0.0.5",
4
3
  "description": "VoltAgent internal - an internal set of tools for the VoltAgent packages",
5
- "license": "MIT",
4
+ "version": "0.0.7",
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"
11
- },
12
- "./dev": {
13
- "types": "./dist/dev/index.d.ts",
14
- "import": "./dist/dev/index.mjs",
15
- "require": "./dist/dev/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
+ }
16
23
  },
17
24
  "./test": {
18
- "types": "./dist/test/index.d.ts",
19
- "import": "./dist/test/index.mjs",
20
- "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
+ }
21
33
  },
22
34
  "./utils": {
23
- "types": "./dist/utils/index.d.ts",
24
- "import": "./dist/utils/index.mjs",
25
- "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
+ }
26
43
  },
27
44
  "./types": {
28
45
  "types": "./dist/types/index.d.ts"
29
46
  }
30
47
  },
31
- "main": "dist/main/index.js",
32
- "module": "dist/main/index.mjs",
33
- "types": "dist/main/index.d.ts",
34
48
  "files": [
35
49
  "dist/**/*",
36
50
  "dev/dist/**/*",
37
51
  "test/dist/**/*"
38
52
  ],
39
- "devDependencies": {
40
- "@types/node": "^24.0.3",
41
- "@vitest/coverage-v8": "^3.2.4",
42
- "tsup": "^8.5.0",
43
- "type-fest": "^4.41.0",
44
- "typescript": "^5.0.4",
45
- "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
+ }
46
72
  },
47
73
  "scripts": {
74
+ "attw": "attw --pack",
48
75
  "build": "tsup",
49
76
  "dev": "tsup --watch",
50
77
  "lint": "biome check .",
51
78
  "lint:fix": "biome check . --write",
79
+ "publint": "publint --strict",
52
80
  "test": "vitest",
53
81
  "test:coverage": "vitest run --coverage"
54
82
  }
@@ -1,103 +0,0 @@
1
- interface DevLoggerOptions {
2
- dev: boolean | (() => boolean);
3
- }
4
- /**
5
- * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not "development").
6
- *
7
- * @example
8
- * ```typescript
9
- * devLogger.info("Hello, world!");
10
- * ```
11
- */
12
- declare function createDevLogger(options?: DevLoggerOptions): {
13
- /**
14
- * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
15
- *
16
- * @example
17
- * ```typescript
18
- * devLogger.info("Hello, world!");
19
- *
20
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
21
- * ```
22
- *
23
- * @param message - The message to log.
24
- * @param args - The arguments to log.
25
- */
26
- info: (message?: any, ...args: any[]) => void;
27
- /**
28
- * 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".
29
- *
30
- * @example
31
- * ```typescript
32
- * devLogger.warn("Hello, world!");
33
- *
34
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
35
- * ```
36
- *
37
- * @param message - The message to log.
38
- * @param args - The arguments to log.
39
- */
40
- warn: (message?: any, ...args: any[]) => void;
41
- /**
42
- * Log a warning message to the console if the environment is development.
43
- *
44
- * @example
45
- * ```typescript
46
- * devLogger.error("Hello, world!");
47
- *
48
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
49
- * ```
50
- *
51
- * @param message - The message to log.
52
- * @param args - The arguments to log.
53
- */
54
- error: (message?: any, ...args: any[]) => void;
55
- debug: (_message?: any, ..._args: any[]) => void;
56
- };
57
- declare const _default: {
58
- /**
59
- * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
60
- *
61
- * @example
62
- * ```typescript
63
- * devLogger.info("Hello, world!");
64
- *
65
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
66
- * ```
67
- *
68
- * @param message - The message to log.
69
- * @param args - The arguments to log.
70
- */
71
- info: (message?: any, ...args: any[]) => void;
72
- /**
73
- * 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".
74
- *
75
- * @example
76
- * ```typescript
77
- * devLogger.warn("Hello, world!");
78
- *
79
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
80
- * ```
81
- *
82
- * @param message - The message to log.
83
- * @param args - The arguments to log.
84
- */
85
- warn: (message?: any, ...args: any[]) => void;
86
- /**
87
- * Log a warning message to the console if the environment is development.
88
- *
89
- * @example
90
- * ```typescript
91
- * devLogger.error("Hello, world!");
92
- *
93
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
94
- * ```
95
- *
96
- * @param message - The message to log.
97
- * @param args - The arguments to log.
98
- */
99
- error: (message?: any, ...args: any[]) => void;
100
- debug: (_message?: any, ..._args: any[]) => void;
101
- };
102
-
103
- export { type DevLoggerOptions, createDevLogger, _default as devLogger };
@@ -1,103 +0,0 @@
1
- interface DevLoggerOptions {
2
- dev: boolean | (() => boolean);
3
- }
4
- /**
5
- * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not "development").
6
- *
7
- * @example
8
- * ```typescript
9
- * devLogger.info("Hello, world!");
10
- * ```
11
- */
12
- declare function createDevLogger(options?: DevLoggerOptions): {
13
- /**
14
- * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
15
- *
16
- * @example
17
- * ```typescript
18
- * devLogger.info("Hello, world!");
19
- *
20
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
21
- * ```
22
- *
23
- * @param message - The message to log.
24
- * @param args - The arguments to log.
25
- */
26
- info: (message?: any, ...args: any[]) => void;
27
- /**
28
- * 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".
29
- *
30
- * @example
31
- * ```typescript
32
- * devLogger.warn("Hello, world!");
33
- *
34
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
35
- * ```
36
- *
37
- * @param message - The message to log.
38
- * @param args - The arguments to log.
39
- */
40
- warn: (message?: any, ...args: any[]) => void;
41
- /**
42
- * Log a warning message to the console if the environment is development.
43
- *
44
- * @example
45
- * ```typescript
46
- * devLogger.error("Hello, world!");
47
- *
48
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
49
- * ```
50
- *
51
- * @param message - The message to log.
52
- * @param args - The arguments to log.
53
- */
54
- error: (message?: any, ...args: any[]) => void;
55
- debug: (_message?: any, ..._args: any[]) => void;
56
- };
57
- declare const _default: {
58
- /**
59
- * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
60
- *
61
- * @example
62
- * ```typescript
63
- * devLogger.info("Hello, world!");
64
- *
65
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
66
- * ```
67
- *
68
- * @param message - The message to log.
69
- * @param args - The arguments to log.
70
- */
71
- info: (message?: any, ...args: any[]) => void;
72
- /**
73
- * 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".
74
- *
75
- * @example
76
- * ```typescript
77
- * devLogger.warn("Hello, world!");
78
- *
79
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
80
- * ```
81
- *
82
- * @param message - The message to log.
83
- * @param args - The arguments to log.
84
- */
85
- warn: (message?: any, ...args: any[]) => void;
86
- /**
87
- * Log a warning message to the console if the environment is development.
88
- *
89
- * @example
90
- * ```typescript
91
- * devLogger.error("Hello, world!");
92
- *
93
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
94
- * ```
95
- *
96
- * @param message - The message to log.
97
- * @param args - The arguments to log.
98
- */
99
- error: (message?: any, ...args: any[]) => void;
100
- debug: (_message?: any, ..._args: any[]) => void;
101
- };
102
-
103
- export { type DevLoggerOptions, createDevLogger, _default as devLogger };
package/dist/dev/index.js DELETED
@@ -1,115 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/dev/index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- createDevLogger: () => createDevLogger,
25
- devLogger: () => logger_default
26
- });
27
- module.exports = __toCommonJS(index_exports);
28
-
29
- // src/dev/logger.ts
30
- function createDevLogger(options) {
31
- const isDev = typeof (options == null ? void 0 : options.dev) === "function" ? options.dev : () => {
32
- var _a;
33
- return (_a = options == null ? void 0 : options.dev) != null ? _a : isDevNodeEnv();
34
- };
35
- return {
36
- /**
37
- * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
38
- *
39
- * @example
40
- * ```typescript
41
- * devLogger.info("Hello, world!");
42
- *
43
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
44
- * ```
45
- *
46
- * @param message - The message to log.
47
- * @param args - The arguments to log.
48
- */
49
- info: /* @__PURE__ */ __name((message, ...args) => {
50
- if (isDev()) {
51
- console.info(formatLogPrefix("INFO"), message, ...args);
52
- }
53
- }, "info"),
54
- /**
55
- * 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".
56
- *
57
- * @example
58
- * ```typescript
59
- * devLogger.warn("Hello, world!");
60
- *
61
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
62
- * ```
63
- *
64
- * @param message - The message to log.
65
- * @param args - The arguments to log.
66
- */
67
- warn: /* @__PURE__ */ __name((message, ...args) => {
68
- if (isDev()) {
69
- console.warn(formatLogPrefix("WARN"), message, ...args);
70
- }
71
- }, "warn"),
72
- /**
73
- * Log a warning message to the console if the environment is development.
74
- *
75
- * @example
76
- * ```typescript
77
- * devLogger.error("Hello, world!");
78
- *
79
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
80
- * ```
81
- *
82
- * @param message - The message to log.
83
- * @param args - The arguments to log.
84
- */
85
- error: /* @__PURE__ */ __name((message, ...args) => {
86
- if (isDev()) {
87
- console.error(formatLogPrefix("ERROR"), message, ...args);
88
- }
89
- }, "error"),
90
- debug: /* @__PURE__ */ __name((_message, ..._args) => {
91
- return;
92
- }, "debug")
93
- };
94
- }
95
- __name(createDevLogger, "createDevLogger");
96
- var logger_default = createDevLogger();
97
- function isDevNodeEnv() {
98
- const nodeEnv = process.env.NODE_ENV;
99
- return nodeEnv !== "production" && nodeEnv !== "test" && nodeEnv !== "ci";
100
- }
101
- __name(isDevNodeEnv, "isDevNodeEnv");
102
- function formatLogPrefix(level) {
103
- return `[VoltAgent] [${timestamp()}] ${level}: `;
104
- }
105
- __name(formatLogPrefix, "formatLogPrefix");
106
- function timestamp() {
107
- return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, -1);
108
- }
109
- __name(timestamp, "timestamp");
110
- // Annotate the CommonJS export names for ESM import in node:
111
- 0 && (module.exports = {
112
- createDevLogger,
113
- devLogger
114
- });
115
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/dev/index.ts","../../src/dev/logger.ts"],"sourcesContent":["export { createDevLogger, default as devLogger } from \"./logger\";\nexport type { DevLoggerOptions } from \"./logger\";\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 debug: (_message?: any, ..._args: any[]) => {\n // todo: implement debug logging with pino\n return;\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n const nodeEnv = process.env.NODE_ENV;\n return nodeEnv !== \"production\" && nodeEnv !== \"test\" && nodeEnv !== \"ci\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\" | \"DEBUG\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkBN,OAAO,wBAAC,YAAkB,SAAgB;AACxC,UAAI,MAAM,GAAG;AACX,gBAAQ,MAAM,gBAAgB,OAAO,GAAG,SAAS,GAAG,IAAI;AAAA,MAC1D;AAAA,IACF,GAJO;AAAA,IAMP,OAAO,wBAAC,aAAmB,UAAiB;AAE1C;AAAA,IACF,GAHO;AAAA,EAIT;AACF;AAjEgB;AAmEhB,IAAO,iBAAQ,gBAAgB;AAE/B,SAAS,eAAe;AACtB,QAAM,UAAU,QAAQ,IAAI;AAC5B,SAAO,YAAY,gBAAgB,YAAY,UAAU,YAAY;AACvE;AAHS;AAKT,SAAS,gBAAgB,OAAoD;AAC3E,SAAO,gBAAgB,UAAU,CAAC,KAAK,KAAK;AAC9C;AAFS;AAIT,SAAS,YAAoB;AAC3B,UAAO,oBAAI,KAAK,GAAE,YAAY,EAAE,QAAQ,KAAK,GAAG,EAAE,MAAM,GAAG,EAAE;AAC/D;AAFS;","names":[]}