@voltagent/internal 0.0.5 → 0.0.6
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 +6 -4
- package/dist/main/index.d.mts +107 -104
- package/dist/main/index.d.ts +107 -104
- package/dist/main/index.js +4 -88
- package/dist/main/index.js.map +1 -1
- package/dist/main/index.mjs +4 -86
- package/dist/main/index.mjs.map +1 -1
- package/dist/utils/index.d.mts +44 -1
- package/dist/utils/index.d.ts +44 -1
- package/dist/utils/index.js +4 -84
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +4 -84
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +1 -6
- package/dist/dev/index.d.mts +0 -103
- package/dist/dev/index.d.ts +0 -103
- package/dist/dev/index.js +0 -115
- package/dist/dev/index.js.map +0 -1
- package/dist/dev/index.mjs +0 -89
- package/dist/dev/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -9,10 +9,12 @@ pnpm add @voltagent/internal
|
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
import {
|
|
12
|
+
import { isObject, isString } from "@voltagent/internal";
|
|
13
13
|
|
|
14
|
-
//
|
|
15
|
-
|
|
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.
|
package/dist/main/index.d.mts
CHANGED
|
@@ -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
|
|
@@ -155,13 +53,118 @@ type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
|
155
53
|
*/
|
|
156
54
|
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
157
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Shared logger types for VoltAgent
|
|
58
|
+
* These types define the minimal logger interface that both core and logger packages use
|
|
59
|
+
*/
|
|
60
|
+
/**
|
|
61
|
+
* Valid log levels
|
|
62
|
+
*/
|
|
63
|
+
type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silent";
|
|
64
|
+
/**
|
|
65
|
+
* Log function signatures
|
|
66
|
+
*/
|
|
67
|
+
interface LogFn {
|
|
68
|
+
(msg: string, context?: object): void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Minimal logger interface for VoltAgent
|
|
72
|
+
* This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
|
|
73
|
+
*/
|
|
74
|
+
interface Logger {
|
|
75
|
+
/**
|
|
76
|
+
* Log at trace level - most detailed level
|
|
77
|
+
*/
|
|
78
|
+
trace: LogFn;
|
|
79
|
+
/**
|
|
80
|
+
* Log at debug level - detailed information for debugging
|
|
81
|
+
*/
|
|
82
|
+
debug: LogFn;
|
|
83
|
+
/**
|
|
84
|
+
* Log at info level - general informational messages
|
|
85
|
+
*/
|
|
86
|
+
info: LogFn;
|
|
87
|
+
/**
|
|
88
|
+
* Log at warn level - warning messages
|
|
89
|
+
*/
|
|
90
|
+
warn: LogFn;
|
|
91
|
+
/**
|
|
92
|
+
* Log at error level - error messages
|
|
93
|
+
*/
|
|
94
|
+
error: LogFn;
|
|
95
|
+
/**
|
|
96
|
+
* Log at fatal level - fatal error messages
|
|
97
|
+
*/
|
|
98
|
+
fatal: LogFn;
|
|
99
|
+
/**
|
|
100
|
+
* Create a child logger with additional context
|
|
101
|
+
* @param bindings - Additional context to bind to the child logger
|
|
102
|
+
*/
|
|
103
|
+
child(bindings: Record<string, any>): Logger;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Logger options for configuration
|
|
107
|
+
*/
|
|
108
|
+
interface LoggerOptions {
|
|
109
|
+
/**
|
|
110
|
+
* Log level
|
|
111
|
+
*/
|
|
112
|
+
level?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Logger name
|
|
115
|
+
*/
|
|
116
|
+
name?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Additional options specific to the logger implementation
|
|
119
|
+
*/
|
|
120
|
+
[key: string]: any;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Log entry structure
|
|
124
|
+
*/
|
|
125
|
+
interface LogEntry {
|
|
126
|
+
timestamp: string;
|
|
127
|
+
level: LogLevel;
|
|
128
|
+
msg: string;
|
|
129
|
+
component?: string;
|
|
130
|
+
agentId?: string;
|
|
131
|
+
conversationId?: string;
|
|
132
|
+
workflowId?: string;
|
|
133
|
+
executionId?: string;
|
|
134
|
+
userId?: string;
|
|
135
|
+
[key: string]: any;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Log filter for querying logs
|
|
139
|
+
*/
|
|
140
|
+
interface LogFilter {
|
|
141
|
+
level?: LogLevel;
|
|
142
|
+
agentId?: string;
|
|
143
|
+
conversationId?: string;
|
|
144
|
+
workflowId?: string;
|
|
145
|
+
executionId?: string;
|
|
146
|
+
since?: Date;
|
|
147
|
+
until?: Date;
|
|
148
|
+
limit?: number;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Log buffer interface for storing logs in memory
|
|
152
|
+
*/
|
|
153
|
+
interface LogBuffer {
|
|
154
|
+
add(entry: LogEntry): void;
|
|
155
|
+
query(filter?: LogFilter): LogEntry[];
|
|
156
|
+
clear(): void;
|
|
157
|
+
size(): number;
|
|
158
|
+
}
|
|
159
|
+
|
|
158
160
|
/**
|
|
159
161
|
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
160
162
|
*
|
|
161
163
|
* @param obj - The object to clone
|
|
164
|
+
* @param logger - Optional logger for warnings
|
|
162
165
|
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
163
166
|
*/
|
|
164
|
-
declare function deepClone<T>(obj: T): T;
|
|
167
|
+
declare function deepClone<T>(obj: T, logger?: Logger): T;
|
|
165
168
|
/**
|
|
166
169
|
* Check if an object has a key
|
|
167
170
|
*
|
|
@@ -237,4 +240,4 @@ type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
|
|
|
237
240
|
*/
|
|
238
241
|
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
239
242
|
|
|
240
|
-
export { type AsyncIterableStream, type
|
|
243
|
+
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 };
|
package/dist/main/index.d.ts
CHANGED
|
@@ -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
|
|
@@ -155,13 +53,118 @@ type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
|
155
53
|
*/
|
|
156
54
|
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
157
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Shared logger types for VoltAgent
|
|
58
|
+
* These types define the minimal logger interface that both core and logger packages use
|
|
59
|
+
*/
|
|
60
|
+
/**
|
|
61
|
+
* Valid log levels
|
|
62
|
+
*/
|
|
63
|
+
type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silent";
|
|
64
|
+
/**
|
|
65
|
+
* Log function signatures
|
|
66
|
+
*/
|
|
67
|
+
interface LogFn {
|
|
68
|
+
(msg: string, context?: object): void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Minimal logger interface for VoltAgent
|
|
72
|
+
* This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
|
|
73
|
+
*/
|
|
74
|
+
interface Logger {
|
|
75
|
+
/**
|
|
76
|
+
* Log at trace level - most detailed level
|
|
77
|
+
*/
|
|
78
|
+
trace: LogFn;
|
|
79
|
+
/**
|
|
80
|
+
* Log at debug level - detailed information for debugging
|
|
81
|
+
*/
|
|
82
|
+
debug: LogFn;
|
|
83
|
+
/**
|
|
84
|
+
* Log at info level - general informational messages
|
|
85
|
+
*/
|
|
86
|
+
info: LogFn;
|
|
87
|
+
/**
|
|
88
|
+
* Log at warn level - warning messages
|
|
89
|
+
*/
|
|
90
|
+
warn: LogFn;
|
|
91
|
+
/**
|
|
92
|
+
* Log at error level - error messages
|
|
93
|
+
*/
|
|
94
|
+
error: LogFn;
|
|
95
|
+
/**
|
|
96
|
+
* Log at fatal level - fatal error messages
|
|
97
|
+
*/
|
|
98
|
+
fatal: LogFn;
|
|
99
|
+
/**
|
|
100
|
+
* Create a child logger with additional context
|
|
101
|
+
* @param bindings - Additional context to bind to the child logger
|
|
102
|
+
*/
|
|
103
|
+
child(bindings: Record<string, any>): Logger;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Logger options for configuration
|
|
107
|
+
*/
|
|
108
|
+
interface LoggerOptions {
|
|
109
|
+
/**
|
|
110
|
+
* Log level
|
|
111
|
+
*/
|
|
112
|
+
level?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Logger name
|
|
115
|
+
*/
|
|
116
|
+
name?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Additional options specific to the logger implementation
|
|
119
|
+
*/
|
|
120
|
+
[key: string]: any;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Log entry structure
|
|
124
|
+
*/
|
|
125
|
+
interface LogEntry {
|
|
126
|
+
timestamp: string;
|
|
127
|
+
level: LogLevel;
|
|
128
|
+
msg: string;
|
|
129
|
+
component?: string;
|
|
130
|
+
agentId?: string;
|
|
131
|
+
conversationId?: string;
|
|
132
|
+
workflowId?: string;
|
|
133
|
+
executionId?: string;
|
|
134
|
+
userId?: string;
|
|
135
|
+
[key: string]: any;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Log filter for querying logs
|
|
139
|
+
*/
|
|
140
|
+
interface LogFilter {
|
|
141
|
+
level?: LogLevel;
|
|
142
|
+
agentId?: string;
|
|
143
|
+
conversationId?: string;
|
|
144
|
+
workflowId?: string;
|
|
145
|
+
executionId?: string;
|
|
146
|
+
since?: Date;
|
|
147
|
+
until?: Date;
|
|
148
|
+
limit?: number;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Log buffer interface for storing logs in memory
|
|
152
|
+
*/
|
|
153
|
+
interface LogBuffer {
|
|
154
|
+
add(entry: LogEntry): void;
|
|
155
|
+
query(filter?: LogFilter): LogEntry[];
|
|
156
|
+
clear(): void;
|
|
157
|
+
size(): number;
|
|
158
|
+
}
|
|
159
|
+
|
|
158
160
|
/**
|
|
159
161
|
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
160
162
|
*
|
|
161
163
|
* @param obj - The object to clone
|
|
164
|
+
* @param logger - Optional logger for warnings
|
|
162
165
|
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
163
166
|
*/
|
|
164
|
-
declare function deepClone<T>(obj: T): T;
|
|
167
|
+
declare function deepClone<T>(obj: T, logger?: Logger): T;
|
|
165
168
|
/**
|
|
166
169
|
* Check if an object has a key
|
|
167
170
|
*
|
|
@@ -237,4 +240,4 @@ type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
|
|
|
237
240
|
*/
|
|
238
241
|
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
239
242
|
|
|
240
|
-
export { type AsyncIterableStream, type
|
|
243
|
+
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 };
|
package/dist/main/index.js
CHANGED
|
@@ -78,9 +78,7 @@ __export(index_exports, {
|
|
|
78
78
|
convertReadableStreamToArray: () => convertReadableStreamToArray,
|
|
79
79
|
convertResponseStreamToArray: () => convertResponseStreamToArray,
|
|
80
80
|
createAsyncIterableStream: () => createAsyncIterableStream,
|
|
81
|
-
createDevLogger: () => createDevLogger,
|
|
82
81
|
deepClone: () => deepClone,
|
|
83
|
-
devLogger: () => logger_default,
|
|
84
82
|
hasKey: () => hasKey,
|
|
85
83
|
isEmptyObject: () => isEmptyObject,
|
|
86
84
|
isFunction: () => isFunction,
|
|
@@ -90,88 +88,6 @@ __export(index_exports, {
|
|
|
90
88
|
});
|
|
91
89
|
module.exports = __toCommonJS(index_exports);
|
|
92
90
|
|
|
93
|
-
// src/dev/logger.ts
|
|
94
|
-
function createDevLogger(options) {
|
|
95
|
-
const isDev = typeof (options == null ? void 0 : options.dev) === "function" ? options.dev : () => {
|
|
96
|
-
var _a;
|
|
97
|
-
return (_a = options == null ? void 0 : options.dev) != null ? _a : isDevNodeEnv();
|
|
98
|
-
};
|
|
99
|
-
return {
|
|
100
|
-
/**
|
|
101
|
-
* Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* ```typescript
|
|
105
|
-
* devLogger.info("Hello, world!");
|
|
106
|
-
*
|
|
107
|
-
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
|
|
108
|
-
* ```
|
|
109
|
-
*
|
|
110
|
-
* @param message - The message to log.
|
|
111
|
-
* @param args - The arguments to log.
|
|
112
|
-
*/
|
|
113
|
-
info: /* @__PURE__ */ __name((message, ...args) => {
|
|
114
|
-
if (isDev()) {
|
|
115
|
-
console.info(formatLogPrefix("INFO"), message, ...args);
|
|
116
|
-
}
|
|
117
|
-
}, "info"),
|
|
118
|
-
/**
|
|
119
|
-
* 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".
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* ```typescript
|
|
123
|
-
* devLogger.warn("Hello, world!");
|
|
124
|
-
*
|
|
125
|
-
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
|
|
126
|
-
* ```
|
|
127
|
-
*
|
|
128
|
-
* @param message - The message to log.
|
|
129
|
-
* @param args - The arguments to log.
|
|
130
|
-
*/
|
|
131
|
-
warn: /* @__PURE__ */ __name((message, ...args) => {
|
|
132
|
-
if (isDev()) {
|
|
133
|
-
console.warn(formatLogPrefix("WARN"), message, ...args);
|
|
134
|
-
}
|
|
135
|
-
}, "warn"),
|
|
136
|
-
/**
|
|
137
|
-
* Log a warning message to the console if the environment is development.
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```typescript
|
|
141
|
-
* devLogger.error("Hello, world!");
|
|
142
|
-
*
|
|
143
|
-
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
|
|
144
|
-
* ```
|
|
145
|
-
*
|
|
146
|
-
* @param message - The message to log.
|
|
147
|
-
* @param args - The arguments to log.
|
|
148
|
-
*/
|
|
149
|
-
error: /* @__PURE__ */ __name((message, ...args) => {
|
|
150
|
-
if (isDev()) {
|
|
151
|
-
console.error(formatLogPrefix("ERROR"), message, ...args);
|
|
152
|
-
}
|
|
153
|
-
}, "error"),
|
|
154
|
-
debug: /* @__PURE__ */ __name((_message, ..._args) => {
|
|
155
|
-
return;
|
|
156
|
-
}, "debug")
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
__name(createDevLogger, "createDevLogger");
|
|
160
|
-
var logger_default = createDevLogger();
|
|
161
|
-
function isDevNodeEnv() {
|
|
162
|
-
const nodeEnv = process.env.NODE_ENV;
|
|
163
|
-
return nodeEnv !== "production" && nodeEnv !== "test" && nodeEnv !== "ci";
|
|
164
|
-
}
|
|
165
|
-
__name(isDevNodeEnv, "isDevNodeEnv");
|
|
166
|
-
function formatLogPrefix(level) {
|
|
167
|
-
return `[VoltAgent] [${timestamp()}] ${level}: `;
|
|
168
|
-
}
|
|
169
|
-
__name(formatLogPrefix, "formatLogPrefix");
|
|
170
|
-
function timestamp() {
|
|
171
|
-
return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, -1);
|
|
172
|
-
}
|
|
173
|
-
__name(timestamp, "timestamp");
|
|
174
|
-
|
|
175
91
|
// src/test/conversions.ts
|
|
176
92
|
function convertReadableStreamToArray(stream) {
|
|
177
93
|
return __async(this, null, function* () {
|
|
@@ -274,11 +190,13 @@ function isEmptyObject(obj) {
|
|
|
274
190
|
__name(isEmptyObject, "isEmptyObject");
|
|
275
191
|
|
|
276
192
|
// src/utils/objects.ts
|
|
277
|
-
function deepClone(obj) {
|
|
193
|
+
function deepClone(obj, logger) {
|
|
278
194
|
try {
|
|
279
195
|
return JSON.parse(JSON.stringify(obj));
|
|
280
196
|
} catch (error) {
|
|
281
|
-
|
|
197
|
+
if (logger) {
|
|
198
|
+
logger.warn("Failed to deep clone object, using shallow clone", { error });
|
|
199
|
+
}
|
|
282
200
|
if (obj === null || typeof obj !== "object") {
|
|
283
201
|
return obj;
|
|
284
202
|
}
|
|
@@ -316,9 +234,7 @@ __name(createAsyncIterableStream, "createAsyncIterableStream");
|
|
|
316
234
|
convertReadableStreamToArray,
|
|
317
235
|
convertResponseStreamToArray,
|
|
318
236
|
createAsyncIterableStream,
|
|
319
|
-
createDevLogger,
|
|
320
237
|
deepClone,
|
|
321
|
-
devLogger,
|
|
322
238
|
hasKey,
|
|
323
239
|
isEmptyObject,
|
|
324
240
|
isFunction,
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/dev/logger.ts","../../src/test/conversions.ts","../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.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 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","/**\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","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n * console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n * start(controller) {\n * controller.enqueue(\"Hello\");\n * controller.close();\n * },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n const stream = source.pipeThrough(new TransformStream<T, T>());\n\n (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n const reader = stream.getReader();\n return {\n async next(): Promise<IteratorResult<T>> {\n const { done, value } = await reader.read();\n return done ? { done: true, value: undefined } : { done: false, value };\n },\n };\n };\n\n return stream as AsyncIterableStream<T>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkBN,OAAO,wBAAC,YAAkB,SAAgB;AACxC,UAAI,MAAM,GAAG;AACX,gBAAQ,MAAM,gBAAgB,OAAO,GA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,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/index.ts","../../src/test/conversions.ts","../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts"],"sourcesContent":["export * from \"./test\";\nexport * from \"./utils\";\nexport * from \"./logger/types\";\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 type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\nimport type { Logger } from \"../logger/types\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @param logger - Optional logger for warnings\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T, logger?: Logger): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n if (logger) {\n logger.warn(\"Failed to deep clone object, using shallow clone\", { error });\n }\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n * console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n * start(controller) {\n * controller.enqueue(\"Hello\");\n * controller.close();\n * },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n const stream = source.pipeThrough(new TransformStream<T, T>());\n\n (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n const reader = stream.getReader();\n return {\n async next(): Promise<IteratorResult<T>> {\n const { done, value } = await reader.read();\n return done ? { done: true, value: undefined } : { done: false, value };\n },\n };\n };\n\n return st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