@voltagent/internal 0.0.4 → 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 +138 -105
- package/dist/main/index.d.ts +138 -105
- package/dist/main/index.js +24 -88
- package/dist/main/index.js.map +1 -1
- package/dist/main/index.mjs +23 -86
- package/dist/main/index.mjs.map +1 -1
- package/dist/utils/index.d.mts +76 -3
- package/dist/utils/index.d.ts +76 -3
- package/dist/utils/index.js +44 -84
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +41 -82
- 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,106 +1,4 @@
|
|
|
1
|
-
import { SetRequired, EmptyObject } from 'type-fest';
|
|
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
|
-
};
|
|
1
|
+
import { SetRequired, EmptyObject, Merge } from 'type-fest';
|
|
104
2
|
|
|
105
3
|
/**
|
|
106
4
|
* Convert a readable stream to an array
|
|
@@ -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
|
*
|
|
@@ -207,4 +210,34 @@ declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
|
207
210
|
*/
|
|
208
211
|
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
209
212
|
|
|
210
|
-
|
|
213
|
+
/**
|
|
214
|
+
* An async iterable stream that can be read from.
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* const stream: AsyncIterableStream<string> = getStream();
|
|
218
|
+
* for await (const chunk of stream) {
|
|
219
|
+
* console.log(chunk);
|
|
220
|
+
* }
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
|
|
224
|
+
/**
|
|
225
|
+
* Create an async iterable stream from a readable stream.
|
|
226
|
+
*
|
|
227
|
+
* This is useful for creating an async iterable stream from a readable stream.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({
|
|
232
|
+
* start(controller) {
|
|
233
|
+
* controller.enqueue("Hello");
|
|
234
|
+
* controller.close();
|
|
235
|
+
* },
|
|
236
|
+
* }));
|
|
237
|
+
* ```
|
|
238
|
+
* @param source The readable stream to create an async iterable stream from.
|
|
239
|
+
* @returns The async iterable stream.
|
|
240
|
+
*/
|
|
241
|
+
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
242
|
+
|
|
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,106 +1,4 @@
|
|
|
1
|
-
import { SetRequired, EmptyObject } from 'type-fest';
|
|
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
|
-
};
|
|
1
|
+
import { SetRequired, EmptyObject, Merge } from 'type-fest';
|
|
104
2
|
|
|
105
3
|
/**
|
|
106
4
|
* Convert a readable stream to an array
|
|
@@ -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
|
*
|
|
@@ -207,4 +210,34 @@ declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
|
207
210
|
*/
|
|
208
211
|
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
209
212
|
|
|
210
|
-
|
|
213
|
+
/**
|
|
214
|
+
* An async iterable stream that can be read from.
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* const stream: AsyncIterableStream<string> = getStream();
|
|
218
|
+
* for await (const chunk of stream) {
|
|
219
|
+
* console.log(chunk);
|
|
220
|
+
* }
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
|
|
224
|
+
/**
|
|
225
|
+
* Create an async iterable stream from a readable stream.
|
|
226
|
+
*
|
|
227
|
+
* This is useful for creating an async iterable stream from a readable stream.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({
|
|
232
|
+
* start(controller) {
|
|
233
|
+
* controller.enqueue("Hello");
|
|
234
|
+
* controller.close();
|
|
235
|
+
* },
|
|
236
|
+
* }));
|
|
237
|
+
* ```
|
|
238
|
+
* @param source The readable stream to create an async iterable stream from.
|
|
239
|
+
* @returns The async iterable stream.
|
|
240
|
+
*/
|
|
241
|
+
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
242
|
+
|
|
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
|
@@ -77,9 +77,8 @@ __export(index_exports, {
|
|
|
77
77
|
convertAsyncIterableToArray: () => convertAsyncIterableToArray,
|
|
78
78
|
convertReadableStreamToArray: () => convertReadableStreamToArray,
|
|
79
79
|
convertResponseStreamToArray: () => convertResponseStreamToArray,
|
|
80
|
-
|
|
80
|
+
createAsyncIterableStream: () => createAsyncIterableStream,
|
|
81
81
|
deepClone: () => deepClone,
|
|
82
|
-
devLogger: () => logger_default,
|
|
83
82
|
hasKey: () => hasKey,
|
|
84
83
|
isEmptyObject: () => isEmptyObject,
|
|
85
84
|
isFunction: () => isFunction,
|
|
@@ -89,88 +88,6 @@ __export(index_exports, {
|
|
|
89
88
|
});
|
|
90
89
|
module.exports = __toCommonJS(index_exports);
|
|
91
90
|
|
|
92
|
-
// src/dev/logger.ts
|
|
93
|
-
function createDevLogger(options) {
|
|
94
|
-
const isDev = typeof (options == null ? void 0 : options.dev) === "function" ? options.dev : () => {
|
|
95
|
-
var _a;
|
|
96
|
-
return (_a = options == null ? void 0 : options.dev) != null ? _a : isDevNodeEnv();
|
|
97
|
-
};
|
|
98
|
-
return {
|
|
99
|
-
/**
|
|
100
|
-
* Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* devLogger.info("Hello, world!");
|
|
105
|
-
*
|
|
106
|
-
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
|
-
* @param message - The message to log.
|
|
110
|
-
* @param args - The arguments to log.
|
|
111
|
-
*/
|
|
112
|
-
info: /* @__PURE__ */ __name((message, ...args) => {
|
|
113
|
-
if (isDev()) {
|
|
114
|
-
console.info(formatLogPrefix("INFO"), message, ...args);
|
|
115
|
-
}
|
|
116
|
-
}, "info"),
|
|
117
|
-
/**
|
|
118
|
-
* 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".
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* ```typescript
|
|
122
|
-
* devLogger.warn("Hello, world!");
|
|
123
|
-
*
|
|
124
|
-
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
|
|
125
|
-
* ```
|
|
126
|
-
*
|
|
127
|
-
* @param message - The message to log.
|
|
128
|
-
* @param args - The arguments to log.
|
|
129
|
-
*/
|
|
130
|
-
warn: /* @__PURE__ */ __name((message, ...args) => {
|
|
131
|
-
if (isDev()) {
|
|
132
|
-
console.warn(formatLogPrefix("WARN"), message, ...args);
|
|
133
|
-
}
|
|
134
|
-
}, "warn"),
|
|
135
|
-
/**
|
|
136
|
-
* Log a warning message to the console if the environment is development.
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* ```typescript
|
|
140
|
-
* devLogger.error("Hello, world!");
|
|
141
|
-
*
|
|
142
|
-
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
|
|
143
|
-
* ```
|
|
144
|
-
*
|
|
145
|
-
* @param message - The message to log.
|
|
146
|
-
* @param args - The arguments to log.
|
|
147
|
-
*/
|
|
148
|
-
error: /* @__PURE__ */ __name((message, ...args) => {
|
|
149
|
-
if (isDev()) {
|
|
150
|
-
console.error(formatLogPrefix("ERROR"), message, ...args);
|
|
151
|
-
}
|
|
152
|
-
}, "error"),
|
|
153
|
-
debug: /* @__PURE__ */ __name((_message, ..._args) => {
|
|
154
|
-
return;
|
|
155
|
-
}, "debug")
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
__name(createDevLogger, "createDevLogger");
|
|
159
|
-
var logger_default = createDevLogger();
|
|
160
|
-
function isDevNodeEnv() {
|
|
161
|
-
const nodeEnv = process.env.NODE_ENV;
|
|
162
|
-
return nodeEnv !== "production" && nodeEnv !== "test" && nodeEnv !== "ci";
|
|
163
|
-
}
|
|
164
|
-
__name(isDevNodeEnv, "isDevNodeEnv");
|
|
165
|
-
function formatLogPrefix(level) {
|
|
166
|
-
return `[VoltAgent] [${timestamp()}] ${level}: `;
|
|
167
|
-
}
|
|
168
|
-
__name(formatLogPrefix, "formatLogPrefix");
|
|
169
|
-
function timestamp() {
|
|
170
|
-
return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, -1);
|
|
171
|
-
}
|
|
172
|
-
__name(timestamp, "timestamp");
|
|
173
|
-
|
|
174
91
|
// src/test/conversions.ts
|
|
175
92
|
function convertReadableStreamToArray(stream) {
|
|
176
93
|
return __async(this, null, function* () {
|
|
@@ -273,11 +190,13 @@ function isEmptyObject(obj) {
|
|
|
273
190
|
__name(isEmptyObject, "isEmptyObject");
|
|
274
191
|
|
|
275
192
|
// src/utils/objects.ts
|
|
276
|
-
function deepClone(obj) {
|
|
193
|
+
function deepClone(obj, logger) {
|
|
277
194
|
try {
|
|
278
195
|
return JSON.parse(JSON.stringify(obj));
|
|
279
196
|
} catch (error) {
|
|
280
|
-
|
|
197
|
+
if (logger) {
|
|
198
|
+
logger.warn("Failed to deep clone object, using shallow clone", { error });
|
|
199
|
+
}
|
|
281
200
|
if (obj === null || typeof obj !== "object") {
|
|
282
201
|
return obj;
|
|
283
202
|
}
|
|
@@ -289,6 +208,24 @@ function hasKey(obj, key) {
|
|
|
289
208
|
return isObject(obj) && key in obj;
|
|
290
209
|
}
|
|
291
210
|
__name(hasKey, "hasKey");
|
|
211
|
+
|
|
212
|
+
// src/utils/async-iterable-stream.ts
|
|
213
|
+
function createAsyncIterableStream(source) {
|
|
214
|
+
const stream = source.pipeThrough(new TransformStream());
|
|
215
|
+
stream[Symbol.asyncIterator] = () => {
|
|
216
|
+
const reader = stream.getReader();
|
|
217
|
+
return {
|
|
218
|
+
next() {
|
|
219
|
+
return __async(this, null, function* () {
|
|
220
|
+
const { done, value } = yield reader.read();
|
|
221
|
+
return done ? { done: true, value: void 0 } : { done: false, value };
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
return stream;
|
|
227
|
+
}
|
|
228
|
+
__name(createAsyncIterableStream, "createAsyncIterableStream");
|
|
292
229
|
// Annotate the CommonJS export names for ESM import in node:
|
|
293
230
|
0 && (module.exports = {
|
|
294
231
|
convertArrayToAsyncIterable,
|
|
@@ -296,9 +233,8 @@ __name(hasKey, "hasKey");
|
|
|
296
233
|
convertAsyncIterableToArray,
|
|
297
234
|
convertReadableStreamToArray,
|
|
298
235
|
convertResponseStreamToArray,
|
|
299
|
-
|
|
236
|
+
createAsyncIterableStream,
|
|
300
237
|
deepClone,
|
|
301
|
-
devLogger,
|
|
302
238
|
hasKey,
|
|
303
239
|
isEmptyObject,
|
|
304
240
|
isFunction,
|