@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.
package/README.md CHANGED
@@ -9,10 +9,12 @@ pnpm add @voltagent/internal
9
9
  ```
10
10
 
11
11
  ```typescript
12
- import { devLogger } from "@voltagent/internal";
12
+ import { isObject, isString } from "@voltagent/internal";
13
13
 
14
- // will only log if process.env.NODE_ENV is "development"
15
- devLogger.info("Hello, world!");
14
+ // Use utility functions
15
+ if (isObject(data)) {
16
+ console.log("Data is an object");
17
+ }
16
18
  ```
17
19
 
18
20
  ## 📦 Imports
@@ -20,8 +22,8 @@ devLogger.info("Hello, world!");
20
22
  You can also import specific subsets of the package:
21
23
 
22
24
  ```typescript
23
- import { devLogger } from "@voltagent/internal/dev";
24
25
  import { convertArrayToAsyncIterable } from "@voltagent/internal/test";
26
+ import { deepClone, hasKey } from "@voltagent/internal/utils";
25
27
  ```
26
28
 
27
29
  Allowing you to only import the tools you need.
@@ -1,107 +1,5 @@
1
1
  import { SetRequired, EmptyObject, Merge } from 'type-fest';
2
2
 
3
- interface DevLoggerOptions {
4
- dev: boolean | (() => boolean);
5
- }
6
- /**
7
- * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not "development").
8
- *
9
- * @example
10
- * ```typescript
11
- * devLogger.info("Hello, world!");
12
- * ```
13
- */
14
- declare function createDevLogger(options?: DevLoggerOptions): {
15
- /**
16
- * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
17
- *
18
- * @example
19
- * ```typescript
20
- * devLogger.info("Hello, world!");
21
- *
22
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
23
- * ```
24
- *
25
- * @param message - The message to log.
26
- * @param args - The arguments to log.
27
- */
28
- info: (message?: any, ...args: any[]) => void;
29
- /**
30
- * 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".
31
- *
32
- * @example
33
- * ```typescript
34
- * devLogger.warn("Hello, world!");
35
- *
36
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
37
- * ```
38
- *
39
- * @param message - The message to log.
40
- * @param args - The arguments to log.
41
- */
42
- warn: (message?: any, ...args: any[]) => void;
43
- /**
44
- * Log a warning message to the console if the environment is development.
45
- *
46
- * @example
47
- * ```typescript
48
- * devLogger.error("Hello, world!");
49
- *
50
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
51
- * ```
52
- *
53
- * @param message - The message to log.
54
- * @param args - The arguments to log.
55
- */
56
- error: (message?: any, ...args: any[]) => void;
57
- debug: (_message?: any, ..._args: any[]) => void;
58
- };
59
- declare const _default: {
60
- /**
61
- * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
62
- *
63
- * @example
64
- * ```typescript
65
- * devLogger.info("Hello, world!");
66
- *
67
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
68
- * ```
69
- *
70
- * @param message - The message to log.
71
- * @param args - The arguments to log.
72
- */
73
- info: (message?: any, ...args: any[]) => void;
74
- /**
75
- * 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".
76
- *
77
- * @example
78
- * ```typescript
79
- * devLogger.warn("Hello, world!");
80
- *
81
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
82
- * ```
83
- *
84
- * @param message - The message to log.
85
- * @param args - The arguments to log.
86
- */
87
- warn: (message?: any, ...args: any[]) => void;
88
- /**
89
- * Log a warning message to the console if the environment is development.
90
- *
91
- * @example
92
- * ```typescript
93
- * devLogger.error("Hello, world!");
94
- *
95
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
96
- * ```
97
- *
98
- * @param message - The message to log.
99
- * @param args - The arguments to log.
100
- */
101
- error: (message?: any, ...args: any[]) => void;
102
- debug: (_message?: any, ..._args: any[]) => void;
103
- };
104
-
105
3
  /**
106
4
  * Convert a readable stream to an array
107
5
  * @param stream - The readable stream to convert
@@ -133,6 +31,108 @@ declare function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T>
133
31
  */
134
32
  declare function convertResponseStreamToArray(response: Response): Promise<string[]>;
135
33
 
34
+ /**
35
+ * Shared logger types for VoltAgent
36
+ * These types define the minimal logger interface that both core and logger packages use
37
+ */
38
+ /**
39
+ * Valid log levels
40
+ */
41
+ type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silent";
42
+ /**
43
+ * Log function signatures
44
+ */
45
+ type LogFn = (msg: string, context?: object) => void;
46
+ /**
47
+ * Minimal logger interface for VoltAgent
48
+ * This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
49
+ */
50
+ interface Logger {
51
+ /**
52
+ * Log at trace level - most detailed level
53
+ */
54
+ trace: LogFn;
55
+ /**
56
+ * Log at debug level - detailed information for debugging
57
+ */
58
+ debug: LogFn;
59
+ /**
60
+ * Log at info level - general informational messages
61
+ */
62
+ info: LogFn;
63
+ /**
64
+ * Log at warn level - warning messages
65
+ */
66
+ warn: LogFn;
67
+ /**
68
+ * Log at error level - error messages
69
+ */
70
+ error: LogFn;
71
+ /**
72
+ * Log at fatal level - fatal error messages
73
+ */
74
+ fatal: LogFn;
75
+ /**
76
+ * Create a child logger with additional context
77
+ * @param bindings - Additional context to bind to the child logger
78
+ */
79
+ child(bindings: Record<string, any>): Logger;
80
+ }
81
+ /**
82
+ * Logger options for configuration
83
+ */
84
+ interface LoggerOptions {
85
+ /**
86
+ * Log level
87
+ */
88
+ level?: string;
89
+ /**
90
+ * Logger name
91
+ */
92
+ name?: string;
93
+ /**
94
+ * Additional options specific to the logger implementation
95
+ */
96
+ [key: string]: any;
97
+ }
98
+ /**
99
+ * Log entry structure
100
+ */
101
+ interface LogEntry {
102
+ timestamp: string;
103
+ level: LogLevel;
104
+ msg: string;
105
+ component?: string;
106
+ agentId?: string;
107
+ conversationId?: string;
108
+ workflowId?: string;
109
+ executionId?: string;
110
+ userId?: string;
111
+ [key: string]: any;
112
+ }
113
+ /**
114
+ * Log filter for querying logs
115
+ */
116
+ interface LogFilter {
117
+ level?: LogLevel;
118
+ agentId?: string;
119
+ conversationId?: string;
120
+ workflowId?: string;
121
+ executionId?: string;
122
+ since?: Date;
123
+ until?: Date;
124
+ limit?: number;
125
+ }
126
+ /**
127
+ * Log buffer interface for storing logs in memory
128
+ */
129
+ interface LogBuffer {
130
+ add(entry: LogEntry): void;
131
+ query(filter?: LogFilter): LogEntry[];
132
+ clear(): void;
133
+ size(): number;
134
+ }
135
+
136
136
  /**
137
137
  * A plain object is an object that has no special properties or methods,
138
138
  * and just has properties that are strings, numbers, or symbols.
@@ -159,9 +159,10 @@ type AnyFunction = AnyAsyncFunction | AnySyncFunction;
159
159
  * Deep clone an object using JSON serialization with fallback to shallow clone
160
160
  *
161
161
  * @param obj - The object to clone
162
+ * @param logger - Optional logger for warnings
162
163
  * @returns A deep copy of the object, or shallow copy if JSON serialization fails
163
164
  */
164
- declare function deepClone<T>(obj: T): T;
165
+ declare function deepClone<T>(obj: T, logger?: Logger): T;
165
166
  /**
166
167
  * Check if an object has a key
167
168
  *
@@ -237,4 +238,4 @@ type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
237
238
  */
238
239
  declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
239
240
 
240
- export { type AsyncIterableStream, type DevLoggerOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createAsyncIterableStream, createDevLogger, deepClone, _default as devLogger, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
241
+ export { type AsyncIterableStream, type LogBuffer, type LogEntry, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createAsyncIterableStream, deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
@@ -1,107 +1,5 @@
1
1
  import { SetRequired, EmptyObject, Merge } from 'type-fest';
2
2
 
3
- interface DevLoggerOptions {
4
- dev: boolean | (() => boolean);
5
- }
6
- /**
7
- * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not "development").
8
- *
9
- * @example
10
- * ```typescript
11
- * devLogger.info("Hello, world!");
12
- * ```
13
- */
14
- declare function createDevLogger(options?: DevLoggerOptions): {
15
- /**
16
- * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
17
- *
18
- * @example
19
- * ```typescript
20
- * devLogger.info("Hello, world!");
21
- *
22
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
23
- * ```
24
- *
25
- * @param message - The message to log.
26
- * @param args - The arguments to log.
27
- */
28
- info: (message?: any, ...args: any[]) => void;
29
- /**
30
- * 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".
31
- *
32
- * @example
33
- * ```typescript
34
- * devLogger.warn("Hello, world!");
35
- *
36
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
37
- * ```
38
- *
39
- * @param message - The message to log.
40
- * @param args - The arguments to log.
41
- */
42
- warn: (message?: any, ...args: any[]) => void;
43
- /**
44
- * Log a warning message to the console if the environment is development.
45
- *
46
- * @example
47
- * ```typescript
48
- * devLogger.error("Hello, world!");
49
- *
50
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
51
- * ```
52
- *
53
- * @param message - The message to log.
54
- * @param args - The arguments to log.
55
- */
56
- error: (message?: any, ...args: any[]) => void;
57
- debug: (_message?: any, ..._args: any[]) => void;
58
- };
59
- declare const _default: {
60
- /**
61
- * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
62
- *
63
- * @example
64
- * ```typescript
65
- * devLogger.info("Hello, world!");
66
- *
67
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
68
- * ```
69
- *
70
- * @param message - The message to log.
71
- * @param args - The arguments to log.
72
- */
73
- info: (message?: any, ...args: any[]) => void;
74
- /**
75
- * 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".
76
- *
77
- * @example
78
- * ```typescript
79
- * devLogger.warn("Hello, world!");
80
- *
81
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
82
- * ```
83
- *
84
- * @param message - The message to log.
85
- * @param args - The arguments to log.
86
- */
87
- warn: (message?: any, ...args: any[]) => void;
88
- /**
89
- * Log a warning message to the console if the environment is development.
90
- *
91
- * @example
92
- * ```typescript
93
- * devLogger.error("Hello, world!");
94
- *
95
- * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
96
- * ```
97
- *
98
- * @param message - The message to log.
99
- * @param args - The arguments to log.
100
- */
101
- error: (message?: any, ...args: any[]) => void;
102
- debug: (_message?: any, ..._args: any[]) => void;
103
- };
104
-
105
3
  /**
106
4
  * Convert a readable stream to an array
107
5
  * @param stream - The readable stream to convert
@@ -133,6 +31,108 @@ declare function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T>
133
31
  */
134
32
  declare function convertResponseStreamToArray(response: Response): Promise<string[]>;
135
33
 
34
+ /**
35
+ * Shared logger types for VoltAgent
36
+ * These types define the minimal logger interface that both core and logger packages use
37
+ */
38
+ /**
39
+ * Valid log levels
40
+ */
41
+ type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silent";
42
+ /**
43
+ * Log function signatures
44
+ */
45
+ type LogFn = (msg: string, context?: object) => void;
46
+ /**
47
+ * Minimal logger interface for VoltAgent
48
+ * This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
49
+ */
50
+ interface Logger {
51
+ /**
52
+ * Log at trace level - most detailed level
53
+ */
54
+ trace: LogFn;
55
+ /**
56
+ * Log at debug level - detailed information for debugging
57
+ */
58
+ debug: LogFn;
59
+ /**
60
+ * Log at info level - general informational messages
61
+ */
62
+ info: LogFn;
63
+ /**
64
+ * Log at warn level - warning messages
65
+ */
66
+ warn: LogFn;
67
+ /**
68
+ * Log at error level - error messages
69
+ */
70
+ error: LogFn;
71
+ /**
72
+ * Log at fatal level - fatal error messages
73
+ */
74
+ fatal: LogFn;
75
+ /**
76
+ * Create a child logger with additional context
77
+ * @param bindings - Additional context to bind to the child logger
78
+ */
79
+ child(bindings: Record<string, any>): Logger;
80
+ }
81
+ /**
82
+ * Logger options for configuration
83
+ */
84
+ interface LoggerOptions {
85
+ /**
86
+ * Log level
87
+ */
88
+ level?: string;
89
+ /**
90
+ * Logger name
91
+ */
92
+ name?: string;
93
+ /**
94
+ * Additional options specific to the logger implementation
95
+ */
96
+ [key: string]: any;
97
+ }
98
+ /**
99
+ * Log entry structure
100
+ */
101
+ interface LogEntry {
102
+ timestamp: string;
103
+ level: LogLevel;
104
+ msg: string;
105
+ component?: string;
106
+ agentId?: string;
107
+ conversationId?: string;
108
+ workflowId?: string;
109
+ executionId?: string;
110
+ userId?: string;
111
+ [key: string]: any;
112
+ }
113
+ /**
114
+ * Log filter for querying logs
115
+ */
116
+ interface LogFilter {
117
+ level?: LogLevel;
118
+ agentId?: string;
119
+ conversationId?: string;
120
+ workflowId?: string;
121
+ executionId?: string;
122
+ since?: Date;
123
+ until?: Date;
124
+ limit?: number;
125
+ }
126
+ /**
127
+ * Log buffer interface for storing logs in memory
128
+ */
129
+ interface LogBuffer {
130
+ add(entry: LogEntry): void;
131
+ query(filter?: LogFilter): LogEntry[];
132
+ clear(): void;
133
+ size(): number;
134
+ }
135
+
136
136
  /**
137
137
  * A plain object is an object that has no special properties or methods,
138
138
  * and just has properties that are strings, numbers, or symbols.
@@ -159,9 +159,10 @@ type AnyFunction = AnyAsyncFunction | AnySyncFunction;
159
159
  * Deep clone an object using JSON serialization with fallback to shallow clone
160
160
  *
161
161
  * @param obj - The object to clone
162
+ * @param logger - Optional logger for warnings
162
163
  * @returns A deep copy of the object, or shallow copy if JSON serialization fails
163
164
  */
164
- declare function deepClone<T>(obj: T): T;
165
+ declare function deepClone<T>(obj: T, logger?: Logger): T;
165
166
  /**
166
167
  * Check if an object has a key
167
168
  *
@@ -237,4 +238,4 @@ type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
237
238
  */
238
239
  declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
239
240
 
240
- export { type AsyncIterableStream, type DevLoggerOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createAsyncIterableStream, createDevLogger, deepClone, _default as devLogger, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
241
+ export { type AsyncIterableStream, type LogBuffer, type LogEntry, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createAsyncIterableStream, deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };