@agentuity/server 0.0.41 → 0.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/api.d.ts +5 -1
- package/dist/api/api.d.ts.map +1 -1
- package/dist/api/api.js +4 -0
- package/dist/api/api.js.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/project/create.d.ts +1 -1
- package/dist/api/project/create.js +1 -1
- package/dist/api/project/delete.d.ts +3 -0
- package/dist/api/project/delete.d.ts.map +1 -0
- package/dist/api/project/delete.js +12 -0
- package/dist/api/project/delete.js.map +1 -0
- package/dist/api/project/env-delete.d.ts +15 -0
- package/dist/api/project/env-delete.d.ts.map +1 -0
- package/dist/api/project/env-delete.js +24 -0
- package/dist/api/project/env-delete.js.map +1 -0
- package/dist/api/project/env-update.d.ts +17 -0
- package/dist/api/project/env-update.d.ts.map +1 -0
- package/dist/api/project/env-update.js +37 -0
- package/dist/api/project/env-update.js.map +1 -0
- package/dist/api/project/exists.d.ts +1 -1
- package/dist/api/project/exists.d.ts.map +1 -1
- package/dist/api/project/exists.js +1 -18
- package/dist/api/project/exists.js.map +1 -1
- package/dist/api/project/get.d.ts +23 -0
- package/dist/api/project/get.d.ts.map +1 -0
- package/dist/api/project/get.js +21 -0
- package/dist/api/project/get.js.map +1 -0
- package/dist/api/project/index.d.ts +5 -0
- package/dist/api/project/index.d.ts.map +1 -1
- package/dist/api/project/index.js +5 -0
- package/dist/api/project/index.js.map +1 -1
- package/dist/api/project/list.d.ts +24 -0
- package/dist/api/project/list.d.ts.map +1 -0
- package/dist/api/project/list.js +23 -0
- package/dist/api/project/list.js.map +1 -0
- package/dist/api/user/index.d.ts +2 -0
- package/dist/api/user/index.d.ts.map +1 -0
- package/dist/api/user/index.js +2 -0
- package/dist/api/user/index.js.map +1 -0
- package/dist/api/user/whoami.d.ts +25 -0
- package/dist/api/user/whoami.d.ts.map +1 -0
- package/dist/api/user/whoami.js +23 -0
- package/dist/api/user/whoami.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +39 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +238 -0
- package/dist/logger.js.map +1 -0
- package/package.json +1 -1
- package/src/api/api.ts +10 -1
- package/src/api/index.ts +1 -0
- package/src/api/project/create.ts +1 -1
- package/src/api/project/delete.ts +24 -0
- package/src/api/project/env-delete.ts +40 -0
- package/src/api/project/env-update.ts +57 -0
- package/src/api/project/exists.ts +1 -20
- package/src/api/project/get.ts +36 -0
- package/src/api/project/index.ts +5 -0
- package/src/api/project/list.ts +37 -0
- package/src/api/user/index.ts +1 -0
- package/src/api/user/whoami.ts +30 -0
- package/src/index.ts +1 -0
- package/src/logger.ts +287 -0
package/src/logger.ts
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import type { Logger, LogLevel } from '@agentuity/core';
|
|
2
|
+
import { format, inspect } from 'node:util';
|
|
3
|
+
|
|
4
|
+
const LOG_LEVELS: Record<LogLevel, number> = {
|
|
5
|
+
trace: 0,
|
|
6
|
+
debug: 1,
|
|
7
|
+
info: 2,
|
|
8
|
+
warn: 3,
|
|
9
|
+
error: 4,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const BOLD = '\x1b[1m';
|
|
13
|
+
const RESET = '\x1b[0m';
|
|
14
|
+
|
|
15
|
+
// Helper to convert hex color to ANSI 24-bit color code
|
|
16
|
+
function hexToAnsi(hex: string): string {
|
|
17
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
18
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
19
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
20
|
+
return `\x1b[38;2;${r};${g};${b}m`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function shouldUseColors(): boolean {
|
|
24
|
+
// Check for NO_COLOR environment variable (any non-empty value disables colors)
|
|
25
|
+
if (process.env.NO_COLOR) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Check for TERM=dumb
|
|
30
|
+
if (process.env.TERM === 'dumb') {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Check if stdout is a TTY
|
|
35
|
+
if (process.stdout && typeof process.stdout.isTTY !== 'undefined' && !process.stdout.isTTY) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const USE_COLORS = shouldUseColors();
|
|
43
|
+
|
|
44
|
+
interface LogColors {
|
|
45
|
+
level: string;
|
|
46
|
+
message: string;
|
|
47
|
+
timestamp: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ColorScheme = 'light' | 'dark';
|
|
51
|
+
|
|
52
|
+
function getLogColors(scheme: ColorScheme): Record<LogLevel, LogColors> {
|
|
53
|
+
if (scheme === 'light') {
|
|
54
|
+
// Darker, high-contrast colors for light backgrounds
|
|
55
|
+
return {
|
|
56
|
+
trace: {
|
|
57
|
+
level: hexToAnsi('#008B8B') + BOLD, // Dark cyan
|
|
58
|
+
message: hexToAnsi('#4B4B4B'), // Dark gray
|
|
59
|
+
timestamp: hexToAnsi('#808080'), // Gray
|
|
60
|
+
},
|
|
61
|
+
debug: {
|
|
62
|
+
level: hexToAnsi('#0000CD') + BOLD, // Medium blue
|
|
63
|
+
message: hexToAnsi('#006400'), // Dark green
|
|
64
|
+
timestamp: hexToAnsi('#808080'),
|
|
65
|
+
},
|
|
66
|
+
info: {
|
|
67
|
+
level: hexToAnsi('#FF8C00') + BOLD, // Dark orange
|
|
68
|
+
message: hexToAnsi('#0066CC') + BOLD, // Strong blue
|
|
69
|
+
timestamp: hexToAnsi('#808080'),
|
|
70
|
+
},
|
|
71
|
+
warn: {
|
|
72
|
+
level: hexToAnsi('#9400D3') + BOLD, // Dark violet
|
|
73
|
+
message: hexToAnsi('#8B008B'), // Dark magenta
|
|
74
|
+
timestamp: hexToAnsi('#808080'),
|
|
75
|
+
},
|
|
76
|
+
error: {
|
|
77
|
+
level: hexToAnsi('#DC143C') + BOLD, // Crimson
|
|
78
|
+
message: hexToAnsi('#8B0000') + BOLD, // Dark red
|
|
79
|
+
timestamp: hexToAnsi('#808080'),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Dark mode colors (brighter for dark backgrounds)
|
|
85
|
+
return {
|
|
86
|
+
trace: {
|
|
87
|
+
level: hexToAnsi('#00FFFF') + BOLD, // Cyan
|
|
88
|
+
message: hexToAnsi('#A0A0A0'), // Light gray
|
|
89
|
+
timestamp: hexToAnsi('#666666'),
|
|
90
|
+
},
|
|
91
|
+
debug: {
|
|
92
|
+
level: hexToAnsi('#5C9CFF') + BOLD, // Blue
|
|
93
|
+
message: hexToAnsi('#90EE90'), // Light green
|
|
94
|
+
timestamp: hexToAnsi('#666666'),
|
|
95
|
+
},
|
|
96
|
+
info: {
|
|
97
|
+
level: hexToAnsi('#FFD700') + BOLD, // Gold/Yellow
|
|
98
|
+
message: hexToAnsi('#FFFFFF') + BOLD, // White
|
|
99
|
+
timestamp: hexToAnsi('#666666'),
|
|
100
|
+
},
|
|
101
|
+
warn: {
|
|
102
|
+
level: hexToAnsi('#FF00FF') + BOLD, // Magenta
|
|
103
|
+
message: hexToAnsi('#FF00FF'), // Magenta
|
|
104
|
+
timestamp: hexToAnsi('#666666'),
|
|
105
|
+
},
|
|
106
|
+
error: {
|
|
107
|
+
level: hexToAnsi('#FF4444') + BOLD, // Red
|
|
108
|
+
message: hexToAnsi('#FF4444'), // Red
|
|
109
|
+
timestamp: hexToAnsi('#666666'),
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Console logger implementation
|
|
116
|
+
*/
|
|
117
|
+
export class ConsoleLogger implements Logger {
|
|
118
|
+
public level: LogLevel;
|
|
119
|
+
private showTimestamp: boolean;
|
|
120
|
+
private colorScheme: ColorScheme;
|
|
121
|
+
private colors: Record<LogLevel, LogColors>;
|
|
122
|
+
private showPrefix = true;
|
|
123
|
+
private context: Record<string, unknown>;
|
|
124
|
+
|
|
125
|
+
constructor(
|
|
126
|
+
level: LogLevel = 'info',
|
|
127
|
+
showTimestamp: boolean = false,
|
|
128
|
+
colorScheme: ColorScheme = 'dark',
|
|
129
|
+
context: Record<string, unknown> = {}
|
|
130
|
+
) {
|
|
131
|
+
this.level = level;
|
|
132
|
+
this.showTimestamp = showTimestamp;
|
|
133
|
+
this.colorScheme = colorScheme;
|
|
134
|
+
this.colors = getLogColors(this.colorScheme);
|
|
135
|
+
this.context = context;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
setLevel(level: LogLevel): void {
|
|
139
|
+
this.level = level;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
setTimestamp(enabled: boolean): void {
|
|
143
|
+
this.showTimestamp = enabled;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
setColorScheme(scheme: ColorScheme): void {
|
|
147
|
+
this.colorScheme = scheme;
|
|
148
|
+
this.colors = getLogColors(this.colorScheme);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
setShowPrefix(show: boolean): void {
|
|
152
|
+
this.showPrefix = show;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private shouldLog(level: LogLevel): boolean {
|
|
156
|
+
return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private formatMessage(message: unknown, args: unknown[]): string {
|
|
160
|
+
try {
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
162
|
+
const base = format(message as any, ...(args as any[]));
|
|
163
|
+
|
|
164
|
+
if (!this.context || Object.keys(this.context).length === 0) {
|
|
165
|
+
return base;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const ctx = Object.entries(this.context)
|
|
169
|
+
.map(
|
|
170
|
+
([k, v]) =>
|
|
171
|
+
`${k}=${typeof v === 'object' ? inspect(v, { depth: 2, maxArrayLength: 50, colors: false }) : String(v)}`
|
|
172
|
+
)
|
|
173
|
+
.join(' ');
|
|
174
|
+
|
|
175
|
+
const result = `${base} ${ctx}`;
|
|
176
|
+
|
|
177
|
+
const MAX_LENGTH = 10000;
|
|
178
|
+
if (result.length > MAX_LENGTH) {
|
|
179
|
+
return `${result.slice(0, MAX_LENGTH)} …(+${result.length - MAX_LENGTH} chars truncated)`;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return result;
|
|
183
|
+
} catch {
|
|
184
|
+
const base = [String(message), ...args.map((a) => String(a))].join(' ');
|
|
185
|
+
return this.context && Object.keys(this.context).length > 0
|
|
186
|
+
? `${base} ${JSON.stringify(this.context)}`
|
|
187
|
+
: base;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private log(level: LogLevel, message: unknown, ...args: unknown[]): void {
|
|
192
|
+
if (!this.shouldLog(level)) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const colors = this.colors[level];
|
|
197
|
+
const levelText = `[${level.toUpperCase()}]`;
|
|
198
|
+
const formattedMessage = this.formatMessage(message, args);
|
|
199
|
+
|
|
200
|
+
let output = '';
|
|
201
|
+
|
|
202
|
+
if (USE_COLORS) {
|
|
203
|
+
if (this.showPrefix) {
|
|
204
|
+
if (this.showTimestamp) {
|
|
205
|
+
const timestamp = new Date().toISOString();
|
|
206
|
+
output = `${colors.timestamp}[${timestamp}]${RESET} ${colors.level}${levelText}${RESET} ${colors.message}${formattedMessage}${RESET}`;
|
|
207
|
+
} else {
|
|
208
|
+
output = `${colors.level}${levelText}${RESET} ${colors.message}${formattedMessage}${RESET}`;
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
// No prefix - just the message with color
|
|
212
|
+
output = `${colors.message}${formattedMessage}${RESET}`;
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
// No colors - plain text output
|
|
216
|
+
if (this.showPrefix) {
|
|
217
|
+
if (this.showTimestamp) {
|
|
218
|
+
const timestamp = new Date().toISOString();
|
|
219
|
+
output = `[${timestamp}] ${levelText} ${formattedMessage}`;
|
|
220
|
+
} else {
|
|
221
|
+
output = `${levelText} ${formattedMessage}`;
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
// No prefix, no colors - just message
|
|
225
|
+
output = formattedMessage;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (level === 'error') {
|
|
230
|
+
console.error(output);
|
|
231
|
+
} else if (level === 'warn') {
|
|
232
|
+
console.warn(output);
|
|
233
|
+
} else {
|
|
234
|
+
console.log(output);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
trace(message: unknown, ...args: unknown[]): void {
|
|
239
|
+
this.log('trace', message, ...args);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
debug(message: unknown, ...args: unknown[]): void {
|
|
243
|
+
this.log('debug', message, ...args);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
info(message: unknown, ...args: unknown[]): void {
|
|
247
|
+
this.log('info', message, ...args);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
warn(message: unknown, ...args: unknown[]): void {
|
|
251
|
+
this.log('warn', message, ...args);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
error(message: unknown, ...args: unknown[]): void {
|
|
255
|
+
this.log('error', message, ...args);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
fatal(message: unknown, ...args: unknown[]): never {
|
|
259
|
+
this.log('error', message, ...args);
|
|
260
|
+
process.exit(1);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
child(opts: Record<string, unknown>): Logger {
|
|
264
|
+
return new ConsoleLogger(this.level, this.showTimestamp, this.colorScheme, {
|
|
265
|
+
...this.context,
|
|
266
|
+
...opts,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Create a new console logger instance
|
|
273
|
+
*
|
|
274
|
+
* @param level - The minimum log level to display
|
|
275
|
+
* @param showTimestamp - Whether to show timestamps in log messages
|
|
276
|
+
* @param colorScheme - The color scheme to use ('light' or 'dark')
|
|
277
|
+
* @param context - Initial context for the logger
|
|
278
|
+
* @returns A new ConsoleLogger instance
|
|
279
|
+
*/
|
|
280
|
+
export function createLogger(
|
|
281
|
+
level: LogLevel = 'info',
|
|
282
|
+
showTimestamp: boolean = false,
|
|
283
|
+
colorScheme: ColorScheme = 'dark',
|
|
284
|
+
context: Record<string, unknown> = {}
|
|
285
|
+
): Logger {
|
|
286
|
+
return new ConsoleLogger(level, showTimestamp, colorScheme, context);
|
|
287
|
+
}
|