@agentxjs/common 1.8.0 → 1.9.0
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 +222 -112
- package/dist/index.d.ts +37 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +5 -4
- package/dist/path/index.d.ts +83 -0
- package/dist/path/index.js +63 -0
- package/dist/path/index.js.map +10 -0
- package/dist/sqlite/index.d.ts +64 -0
- package/dist/sqlite/index.js +96 -0
- package/dist/sqlite/index.js.map +10 -0
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -6,16 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
`@agentxjs/common` provides shared utilities used by AgentX internal packages (`@agentxjs/agent`, `@agentxjs/runtime`, etc.). This is an internal package - application code should not depend on it directly.
|
|
8
8
|
|
|
9
|
-
**
|
|
9
|
+
**Modules:**
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
| Module | Import | Description |
|
|
12
|
+
| ------ | ------------------------- | ------------------------------------------------ |
|
|
13
|
+
| Logger | `@agentxjs/common` | Lazy-initialized logging with pluggable backends |
|
|
14
|
+
| SQLite | `@agentxjs/common/sqlite` | Unified SQLite abstraction for Bun/Node.js |
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
16
17
|
|
|
17
18
|
```bash
|
|
18
|
-
|
|
19
|
+
bun add @agentxjs/common
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
> **Note**: This package is typically installed transitively as a dependency of other AgentX packages.
|
|
@@ -94,12 +95,6 @@ Creates a new logger instance.
|
|
|
94
95
|
const logger = createLogger("agent/MyAgent");
|
|
95
96
|
```
|
|
96
97
|
|
|
97
|
-
**Parameters:**
|
|
98
|
-
|
|
99
|
-
- `category` - Logger category (e.g., `"engine/AgentEngine"`, `"runtime/Container"`)
|
|
100
|
-
|
|
101
|
-
**Returns:** `Logger` instance
|
|
102
|
-
|
|
103
98
|
#### `setLoggerFactory(factory: LoggerFactory): void`
|
|
104
99
|
|
|
105
100
|
Sets the global logger factory (called by Runtime).
|
|
@@ -115,154 +110,266 @@ setLoggerFactory(
|
|
|
115
110
|
);
|
|
116
111
|
```
|
|
117
112
|
|
|
118
|
-
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## SQLite
|
|
116
|
+
|
|
117
|
+
Unified SQLite abstraction that auto-detects runtime:
|
|
118
|
+
|
|
119
|
+
- **Bun** → uses `bun:sqlite` (built-in)
|
|
120
|
+
- **Node.js 22+** → uses `node:sqlite` (built-in)
|
|
121
|
+
|
|
122
|
+
### Quick Start
|
|
119
123
|
|
|
120
124
|
```typescript
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
import { openDatabase } from "@agentxjs/common/sqlite";
|
|
126
|
+
|
|
127
|
+
const db = openDatabase("./data/app.db");
|
|
128
|
+
|
|
129
|
+
// Create tables
|
|
130
|
+
db.exec(`
|
|
131
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
132
|
+
id INTEGER PRIMARY KEY,
|
|
133
|
+
name TEXT NOT NULL
|
|
134
|
+
)
|
|
135
|
+
`);
|
|
127
136
|
|
|
128
|
-
|
|
137
|
+
// Insert data
|
|
138
|
+
db.prepare("INSERT INTO users (name) VALUES (?)").run("Alice");
|
|
139
|
+
|
|
140
|
+
// Query data
|
|
141
|
+
const users = db.prepare("SELECT * FROM users").all();
|
|
142
|
+
console.log(users); // [{ id: 1, name: "Alice" }]
|
|
143
|
+
|
|
144
|
+
// Close when done
|
|
145
|
+
db.close();
|
|
129
146
|
```
|
|
130
147
|
|
|
131
|
-
|
|
148
|
+
### API
|
|
132
149
|
|
|
133
|
-
|
|
150
|
+
#### `openDatabase(path: string): Database`
|
|
134
151
|
|
|
135
|
-
|
|
152
|
+
Opens a SQLite database.
|
|
136
153
|
|
|
137
|
-
|
|
154
|
+
```typescript
|
|
155
|
+
import { openDatabase } from "@agentxjs/common/sqlite";
|
|
156
|
+
|
|
157
|
+
// File-based database
|
|
158
|
+
const db = openDatabase("./data/app.db");
|
|
159
|
+
|
|
160
|
+
// In-memory database (for testing)
|
|
161
|
+
const memDb = openDatabase(":memory:");
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Database Interface
|
|
138
165
|
|
|
139
166
|
```typescript
|
|
140
|
-
|
|
167
|
+
interface Database {
|
|
168
|
+
/** Execute raw SQL (no return value) */
|
|
169
|
+
exec(sql: string): void;
|
|
141
170
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
enableTimestamp: true,
|
|
145
|
-
enableColor: true,
|
|
146
|
-
});
|
|
171
|
+
/** Prepare a statement */
|
|
172
|
+
prepare(sql: string): Statement;
|
|
147
173
|
|
|
148
|
-
|
|
149
|
-
|
|
174
|
+
/** Close the database */
|
|
175
|
+
close(): void;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
interface Statement {
|
|
179
|
+
/** Execute with params, return changes */
|
|
180
|
+
run(...params: unknown[]): RunResult;
|
|
181
|
+
|
|
182
|
+
/** Get single row */
|
|
183
|
+
get(...params: unknown[]): unknown;
|
|
184
|
+
|
|
185
|
+
/** Get all rows */
|
|
186
|
+
all(...params: unknown[]): unknown[];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
interface RunResult {
|
|
190
|
+
changes: number;
|
|
191
|
+
lastInsertRowid: number | bigint;
|
|
192
|
+
}
|
|
150
193
|
```
|
|
151
194
|
|
|
152
|
-
|
|
195
|
+
### Example: Key-Value Store
|
|
153
196
|
|
|
154
197
|
```typescript
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
198
|
+
import { openDatabase } from "@agentxjs/common/sqlite";
|
|
199
|
+
|
|
200
|
+
const db = openDatabase("./kv.db");
|
|
201
|
+
|
|
202
|
+
db.exec(`
|
|
203
|
+
CREATE TABLE IF NOT EXISTS kv (
|
|
204
|
+
key TEXT PRIMARY KEY,
|
|
205
|
+
value TEXT
|
|
206
|
+
)
|
|
207
|
+
`);
|
|
208
|
+
|
|
209
|
+
function set(key: string, value: unknown) {
|
|
210
|
+
const json = JSON.stringify(value);
|
|
211
|
+
db.prepare("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)").run(key, json);
|
|
159
212
|
}
|
|
213
|
+
|
|
214
|
+
function get<T>(key: string): T | null {
|
|
215
|
+
const row = db.prepare("SELECT value FROM kv WHERE key = ?").get(key) as
|
|
216
|
+
| { value: string }
|
|
217
|
+
| undefined;
|
|
218
|
+
return row ? JSON.parse(row.value) : null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
set("user:1", { name: "Alice", age: 30 });
|
|
222
|
+
console.log(get("user:1")); // { name: "Alice", age: 30 }
|
|
160
223
|
```
|
|
161
224
|
|
|
162
|
-
|
|
225
|
+
---
|
|
163
226
|
|
|
164
|
-
|
|
227
|
+
## Path Utilities
|
|
228
|
+
|
|
229
|
+
Cross-runtime path helpers that work in both Bun and Node.js.
|
|
230
|
+
|
|
231
|
+
### Quick Start
|
|
165
232
|
|
|
166
233
|
```typescript
|
|
167
|
-
import {
|
|
234
|
+
import {
|
|
235
|
+
getModuleDir,
|
|
236
|
+
getPackageRoot,
|
|
237
|
+
getMonorepoRoot,
|
|
238
|
+
resolveFromRoot,
|
|
239
|
+
resolveFromPackage,
|
|
240
|
+
} from "@agentxjs/common/path";
|
|
241
|
+
|
|
242
|
+
// Current module directory
|
|
243
|
+
const __dirname = getModuleDir(import.meta);
|
|
244
|
+
// e.g., /Users/sean/AgentX/packages/queue/src
|
|
245
|
+
|
|
246
|
+
// Package root (where package.json is)
|
|
247
|
+
const pkgRoot = getPackageRoot(import.meta);
|
|
248
|
+
// e.g., /Users/sean/AgentX/packages/queue
|
|
249
|
+
|
|
250
|
+
// Monorepo root
|
|
251
|
+
const root = getMonorepoRoot(import.meta);
|
|
252
|
+
// e.g., /Users/sean/AgentX
|
|
253
|
+
|
|
254
|
+
// Resolve from monorepo root
|
|
255
|
+
const dataDir = resolveFromRoot(import.meta, "data", "logs");
|
|
256
|
+
// e.g., /Users/sean/AgentX/data/logs
|
|
257
|
+
|
|
258
|
+
// Resolve from package root
|
|
259
|
+
const testsDir = resolveFromPackage(import.meta, "tests", "fixtures");
|
|
260
|
+
// e.g., /Users/sean/AgentX/packages/queue/tests/fixtures
|
|
261
|
+
```
|
|
168
262
|
|
|
169
|
-
|
|
170
|
-
level: "info",
|
|
171
|
-
enableTimestamp: false,
|
|
172
|
-
});
|
|
263
|
+
### API
|
|
173
264
|
|
|
174
|
-
|
|
265
|
+
#### `getModuleDir(meta: ImportMeta): string`
|
|
266
|
+
|
|
267
|
+
Get the directory of the current module.
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
const __dirname = getModuleDir(import.meta);
|
|
175
271
|
```
|
|
176
272
|
|
|
177
|
-
|
|
273
|
+
**Compatibility:**
|
|
178
274
|
|
|
179
|
-
|
|
275
|
+
- Bun: uses `import.meta.dir`
|
|
276
|
+
- Node.js: converts `import.meta.url` to path
|
|
180
277
|
|
|
181
|
-
|
|
278
|
+
#### `getPackageRoot(meta: ImportMeta): string`
|
|
279
|
+
|
|
280
|
+
Get the package root directory (walks up to find `package.json`).
|
|
182
281
|
|
|
183
282
|
```typescript
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
// Custom logger (e.g., sends logs to external service)
|
|
187
|
-
class RemoteLogger implements Logger {
|
|
188
|
-
constructor(private category: string) {}
|
|
189
|
-
|
|
190
|
-
debug(message: string, context?: LogContext) {
|
|
191
|
-
this.send("debug", message, context);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
info(message: string, context?: LogContext) {
|
|
195
|
-
this.send("info", message, context);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
warn(message: string, context?: LogContext) {
|
|
199
|
-
this.send("warn", message, context);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
error(message: string, context?: LogContext) {
|
|
203
|
-
this.send("error", message, context);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
private send(level: string, message: string, context?: LogContext) {
|
|
207
|
-
fetch("/api/logs", {
|
|
208
|
-
method: "POST",
|
|
209
|
-
body: JSON.stringify({ level, category: this.category, message, context }),
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
283
|
+
const pkgRoot = getPackageRoot(import.meta);
|
|
284
|
+
```
|
|
213
285
|
|
|
214
|
-
|
|
215
|
-
class RemoteLoggerFactory implements LoggerFactory {
|
|
216
|
-
createLogger(category: string): Logger {
|
|
217
|
-
return new RemoteLogger(category);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
286
|
+
#### `getMonorepoRoot(meta: ImportMeta): string`
|
|
220
287
|
|
|
221
|
-
|
|
222
|
-
|
|
288
|
+
Get the monorepo root directory (walks up to find lock files).
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
const root = getMonorepoRoot(import.meta);
|
|
223
292
|
```
|
|
224
293
|
|
|
225
|
-
|
|
294
|
+
**Detects:**
|
|
226
295
|
|
|
227
|
-
|
|
296
|
+
- `pnpm-workspace.yaml` (pnpm monorepo)
|
|
297
|
+
- `bun.lock` (bun workspace)
|
|
298
|
+
- `package-lock.json` (npm workspace)
|
|
299
|
+
- `yarn.lock` (yarn workspace)
|
|
228
300
|
|
|
229
|
-
|
|
301
|
+
#### `resolveFromRoot(meta: ImportMeta, ...paths: string[]): string`
|
|
230
302
|
|
|
231
|
-
|
|
303
|
+
Resolve a path relative to the monorepo root.
|
|
232
304
|
|
|
233
305
|
```typescript
|
|
234
|
-
|
|
235
|
-
|
|
306
|
+
const configPath = resolveFromRoot(import.meta, "config", "settings.json");
|
|
307
|
+
```
|
|
236
308
|
|
|
237
|
-
|
|
309
|
+
#### `resolveFromPackage(meta: ImportMeta, ...paths: string[]): string`
|
|
238
310
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
311
|
+
Resolve a path relative to the package root.
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
const testData = resolveFromPackage(import.meta, "tests", "fixtures", "data.json");
|
|
242
315
|
```
|
|
243
316
|
|
|
244
|
-
|
|
317
|
+
### Example: Test Fixtures
|
|
245
318
|
|
|
246
|
-
|
|
319
|
+
```typescript
|
|
320
|
+
import { resolveFromPackage } from "@agentxjs/common/path";
|
|
321
|
+
import { readFileSync } from "node:fs";
|
|
247
322
|
|
|
248
|
-
|
|
323
|
+
// Load test fixture from current package
|
|
324
|
+
const fixturePath = resolveFromPackage(import.meta, "tests", "fixtures", "sample.json");
|
|
325
|
+
const data = JSON.parse(readFileSync(fixturePath, "utf-8"));
|
|
326
|
+
```
|
|
249
327
|
|
|
250
|
-
|
|
251
|
-
- **Production** - Structured JSON logs
|
|
252
|
-
- **Browser** - Send to analytics service
|
|
253
|
-
- **Testing** - Silent or mock
|
|
328
|
+
---
|
|
254
329
|
|
|
255
|
-
|
|
330
|
+
## Built-in Implementations
|
|
256
331
|
|
|
257
|
-
###
|
|
332
|
+
### ConsoleLogger
|
|
258
333
|
|
|
259
|
-
|
|
334
|
+
Default console-based logger with formatting.
|
|
260
335
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
3. **No routing** - Can't send logs to services
|
|
336
|
+
```typescript
|
|
337
|
+
import { ConsoleLogger } from "@agentxjs/common";
|
|
264
338
|
|
|
265
|
-
|
|
339
|
+
const logger = new ConsoleLogger("my-category", {
|
|
340
|
+
level: "debug",
|
|
341
|
+
enableTimestamp: true,
|
|
342
|
+
enableColor: true,
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
logger.info("Hello", { foo: "bar" });
|
|
346
|
+
// Output: [INFO] my-category: Hello {"foo":"bar"}
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
**Options:**
|
|
350
|
+
|
|
351
|
+
```typescript
|
|
352
|
+
interface ConsoleLoggerOptions {
|
|
353
|
+
level?: LogLevel; // Minimum log level (default: "info")
|
|
354
|
+
enableTimestamp?: boolean; // Show timestamps (default: false)
|
|
355
|
+
enableColor?: boolean; // Colorize output (default: true in TTY)
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### LoggerFactoryImpl
|
|
360
|
+
|
|
361
|
+
Default factory that creates `ConsoleLogger` instances.
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
import { LoggerFactoryImpl } from "@agentxjs/common";
|
|
365
|
+
|
|
366
|
+
const factory = new LoggerFactoryImpl({
|
|
367
|
+
level: "info",
|
|
368
|
+
enableTimestamp: false,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
const logger = factory.createLogger("test");
|
|
372
|
+
```
|
|
266
373
|
|
|
267
374
|
---
|
|
268
375
|
|
|
@@ -271,9 +378,11 @@ The logger facade solves all these issues.
|
|
|
271
378
|
```text
|
|
272
379
|
@agentxjs/types Type definitions
|
|
273
380
|
↑
|
|
274
|
-
@agentxjs/common This package (logger
|
|
381
|
+
@agentxjs/common This package (logger + sqlite)
|
|
382
|
+
↑
|
|
383
|
+
@agentxjs/queue Uses sqlite
|
|
275
384
|
↑
|
|
276
|
-
@agentxjs/
|
|
385
|
+
@agentxjs/persistence Uses sqlite
|
|
277
386
|
↑
|
|
278
387
|
@agentxjs/runtime Uses logger + provides factory
|
|
279
388
|
```
|
|
@@ -283,8 +392,9 @@ The logger facade solves all these issues.
|
|
|
283
392
|
## Related Packages
|
|
284
393
|
|
|
285
394
|
- **[@agentxjs/types](../types)** - Type definitions
|
|
286
|
-
- **[@agentxjs/
|
|
287
|
-
- **[@agentxjs/
|
|
395
|
+
- **[@agentxjs/queue](../queue)** - Event queue (uses SQLite)
|
|
396
|
+
- **[@agentxjs/persistence](../persistence)** - Storage layer (uses SQLite)
|
|
397
|
+
- **[@agentxjs/runtime](../runtime)** - Runtime implementation
|
|
288
398
|
|
|
289
399
|
---
|
|
290
400
|
|
package/dist/index.d.ts
CHANGED
|
@@ -59,4 +59,40 @@ declare function setLoggerFactory(factory: LoggerFactory): void;
|
|
|
59
59
|
* @returns Logger instance (lazy proxy)
|
|
60
60
|
*/
|
|
61
61
|
declare function createLogger(name: string): Logger2;
|
|
62
|
-
|
|
62
|
+
/**
|
|
63
|
+
* ID Generation Utilities
|
|
64
|
+
*
|
|
65
|
+
* Provides consistent ID generation patterns across the AgentX platform.
|
|
66
|
+
*
|
|
67
|
+
* @packageDocumentation
|
|
68
|
+
*/
|
|
69
|
+
/**
|
|
70
|
+
* Generate a unique request ID for command request/response correlation.
|
|
71
|
+
*
|
|
72
|
+
* Format: `req_{timestamp}_{random}`
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const requestId = generateRequestId();
|
|
77
|
+
* // => "req_1704067200000_a1b2c3"
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
declare function generateRequestId(): string;
|
|
81
|
+
/**
|
|
82
|
+
* Generate a unique ID with a custom prefix.
|
|
83
|
+
*
|
|
84
|
+
* Format: `{prefix}_{timestamp}_{random}`
|
|
85
|
+
*
|
|
86
|
+
* @param prefix - The prefix for the ID (e.g., "msg", "agent", "session")
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const msgId = generateId("msg");
|
|
91
|
+
* // => "msg_1704067200000_a1b2c3"
|
|
92
|
+
*
|
|
93
|
+
* const agentId = generateId("agent");
|
|
94
|
+
* // => "agent_1704067200000_x7y8z9"
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function generateId(prefix: string): string;
|
|
98
|
+
export { setLoggerFactory, generateRequestId, generateId, createLogger, LoggerFactoryImpl, LoggerFactoryConfig, LoggerFactory2 as LoggerFactory, Logger3 as Logger, LogLevel3 as LogLevel, LogContext2 as LogContext, ConsoleLoggerOptions, ConsoleLogger };
|
package/dist/index.js
CHANGED
|
@@ -173,11 +173,20 @@ function setLoggerFactory(factory) {
|
|
|
173
173
|
function createLogger(name) {
|
|
174
174
|
return LoggerFactoryImpl.getLogger(name);
|
|
175
175
|
}
|
|
176
|
+
// src/id/index.ts
|
|
177
|
+
function generateRequestId() {
|
|
178
|
+
return `req_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
|
179
|
+
}
|
|
180
|
+
function generateId(prefix) {
|
|
181
|
+
return `${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
182
|
+
}
|
|
176
183
|
export {
|
|
177
184
|
setLoggerFactory,
|
|
185
|
+
generateRequestId,
|
|
186
|
+
generateId,
|
|
178
187
|
createLogger,
|
|
179
188
|
LoggerFactoryImpl,
|
|
180
189
|
ConsoleLogger
|
|
181
190
|
};
|
|
182
191
|
|
|
183
|
-
//# debugId=
|
|
192
|
+
//# debugId=1EB63110DA82C92A64756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/logger/ConsoleLogger.ts", "../src/logger/LoggerFactoryImpl.ts"],
|
|
3
|
+
"sources": ["../src/logger/ConsoleLogger.ts", "../src/logger/LoggerFactoryImpl.ts", "../src/id/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * ConsoleLogger - Default logger implementation\n *\n * Simple console-based logger with color support.\n * Used as fallback when no custom LoggerFactory is provided.\n */\n\nimport type { Logger, LogContext, LogLevel } from \"@agentxjs/types\";\n\nexport interface ConsoleLoggerOptions {\n level?: LogLevel;\n colors?: boolean;\n timestamps?: boolean;\n}\n\nexport class ConsoleLogger implements Logger {\n readonly name: string;\n readonly level: LogLevel;\n private readonly colors: boolean;\n private readonly timestamps: boolean;\n\n private static readonly COLORS = {\n DEBUG: \"\\x1b[36m\",\n INFO: \"\\x1b[32m\",\n WARN: \"\\x1b[33m\",\n ERROR: \"\\x1b[31m\",\n RESET: \"\\x1b[0m\",\n };\n\n constructor(name: string, options: ConsoleLoggerOptions = {}) {\n this.name = name;\n this.level = options.level ?? \"info\";\n this.colors = options.colors ?? this.isNodeEnvironment();\n this.timestamps = options.timestamps ?? true;\n }\n\n debug(message: string, context?: LogContext): void {\n if (this.isDebugEnabled()) {\n this.log(\"DEBUG\", message, context);\n }\n }\n\n info(message: string, context?: LogContext): void {\n if (this.isInfoEnabled()) {\n this.log(\"INFO\", message, context);\n }\n }\n\n warn(message: string, context?: LogContext): void {\n if (this.isWarnEnabled()) {\n this.log(\"WARN\", message, context);\n }\n }\n\n error(message: string | Error, context?: LogContext): void {\n if (this.isErrorEnabled()) {\n if (message instanceof Error) {\n this.log(\"ERROR\", message.message, { ...context, stack: message.stack });\n } else {\n this.log(\"ERROR\", message, context);\n }\n }\n }\n\n isDebugEnabled(): boolean {\n return this.getLevelValue(this.level) <= this.getLevelValue(\"debug\");\n }\n\n isInfoEnabled(): boolean {\n return this.getLevelValue(this.level) <= this.getLevelValue(\"info\");\n }\n\n isWarnEnabled(): boolean {\n return this.getLevelValue(this.level) <= this.getLevelValue(\"warn\");\n }\n\n isErrorEnabled(): boolean {\n return this.getLevelValue(this.level) <= this.getLevelValue(\"error\");\n }\n\n private getLevelValue(level: LogLevel): number {\n const levels: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n silent: 4,\n };\n return levels[level];\n }\n\n private log(level: string, message: string, context?: LogContext): void {\n const parts: string[] = [];\n\n if (this.timestamps) {\n parts.push(new Date().toISOString());\n }\n\n if (this.colors) {\n const color = ConsoleLogger.COLORS[level as keyof typeof ConsoleLogger.COLORS];\n parts.push(`${color}${level.padEnd(5)}${ConsoleLogger.COLORS.RESET}`);\n } else {\n parts.push(level.padEnd(5));\n }\n\n parts.push(`[${this.name}]`);\n parts.push(message);\n\n const logLine = parts.join(\" \");\n const consoleMethod = this.getConsoleMethod(level);\n\n if (context && Object.keys(context).length > 0) {\n consoleMethod(logLine, context);\n } else {\n consoleMethod(logLine);\n }\n }\n\n private getConsoleMethod(level: string): (...args: unknown[]) => void {\n switch (level) {\n case \"DEBUG\":\n return console.debug.bind(console);\n case \"INFO\":\n return console.info.bind(console);\n case \"WARN\":\n return console.warn.bind(console);\n case \"ERROR\":\n return console.error.bind(console);\n default:\n return console.log.bind(console);\n }\n }\n\n private isNodeEnvironment(): boolean {\n return typeof process !== \"undefined\" && process.versions?.node !== undefined;\n }\n}\n",
|
|
6
|
-
"/**\n * LoggerFactoryImpl - Central factory for creating logger instances\n *\n * Implements lazy initialization pattern:\n * - createLogger() can be called at module level (before config)\n * - Real logger is created on first use\n * - External LoggerFactory can be injected via Runtime\n */\n\nimport type { Logger, LoggerFactory, LogContext, LogLevel } from \"@agentxjs/types\";\nimport { ConsoleLogger, type ConsoleLoggerOptions } from \"./ConsoleLogger\";\n\n// External factory injected via Runtime\nlet externalFactory: LoggerFactory | null = null;\n\n// Version counter to invalidate cached real loggers\nlet factoryVersion = 0;\n\nexport interface LoggerFactoryConfig {\n defaultImplementation?: (name: string) => Logger;\n defaultLevel?: LogLevel;\n consoleOptions?: Omit<ConsoleLoggerOptions, \"level\">;\n}\n\n/**\n * Internal LoggerFactory implementation\n *\n * Uses lazy proxy pattern to allow module-level createLogger() calls.\n */\nexport class LoggerFactoryImpl {\n private static loggers: Map<string, Logger> = new Map();\n private static config: LoggerFactoryConfig = {\n defaultLevel: \"info\",\n };\n\n static getLogger(nameOrClass: string | (new (...args: unknown[]) => unknown)): Logger {\n const name = typeof nameOrClass === \"string\" ? nameOrClass : nameOrClass.name;\n\n if (this.loggers.has(name)) {\n return this.loggers.get(name)!;\n }\n\n const lazyLogger = this.createLazyLogger(name);\n this.loggers.set(name, lazyLogger);\n return lazyLogger;\n }\n\n static configure(config: LoggerFactoryConfig): void {\n this.config = { ...this.config, ...config };\n }\n\n static reset(): void {\n this.loggers.clear();\n this.config = { defaultLevel: \"info\" };\n externalFactory = null;\n factoryVersion++; // Invalidate all cached real loggers\n }\n\n private static createLazyLogger(name: string): Logger {\n let realLogger: Logger | null = null;\n let loggerVersion = -1; // Track which factory version created this logger\n\n const getRealLogger = (): Logger => {\n // Recreate logger if factory version changed (setLoggerFactory was called)\n if (!realLogger || loggerVersion !== factoryVersion) {\n realLogger = this.createLogger(name);\n loggerVersion = factoryVersion;\n }\n return realLogger;\n };\n\n return {\n name,\n level: this.config.defaultLevel || \"info\",\n debug: (message: string, context?: LogContext) => getRealLogger().debug(message, context),\n info: (message: string, context?: LogContext) => getRealLogger().info(message, context),\n warn: (message: string, context?: LogContext) => getRealLogger().warn(message, context),\n error: (message: string | Error, context?: LogContext) =>\n getRealLogger().error(message, context),\n isDebugEnabled: () => getRealLogger().isDebugEnabled(),\n isInfoEnabled: () => getRealLogger().isInfoEnabled(),\n isWarnEnabled: () => getRealLogger().isWarnEnabled(),\n isErrorEnabled: () => getRealLogger().isErrorEnabled(),\n };\n }\n\n private static createLogger(name: string): Logger {\n if (externalFactory) {\n return externalFactory.getLogger(name);\n }\n\n if (this.config.defaultImplementation) {\n return this.config.defaultImplementation(name);\n }\n\n return new ConsoleLogger(name, {\n level: this.config.defaultLevel,\n ...this.config.consoleOptions,\n });\n }\n}\n\n/**\n * Set external LoggerFactory (called by Runtime initialization)\n */\nexport function setLoggerFactory(factory: LoggerFactory): void {\n externalFactory = factory;\n LoggerFactoryImpl.reset();\n externalFactory = factory;\n}\n\n/**\n * Create a logger instance\n *\n * Safe to call at module level before Runtime is configured.\n * Uses lazy initialization - actual logger is created on first use.\n *\n * @param name - Logger name (hierarchical, e.g., \"engine/AgentEngine\")\n * @returns Logger instance (lazy proxy)\n */\nexport function createLogger(name: string): Logger {\n return LoggerFactoryImpl.getLogger(name);\n}\n"
|
|
6
|
+
"/**\n * LoggerFactoryImpl - Central factory for creating logger instances\n *\n * Implements lazy initialization pattern:\n * - createLogger() can be called at module level (before config)\n * - Real logger is created on first use\n * - External LoggerFactory can be injected via Runtime\n */\n\nimport type { Logger, LoggerFactory, LogContext, LogLevel } from \"@agentxjs/types\";\nimport { ConsoleLogger, type ConsoleLoggerOptions } from \"./ConsoleLogger\";\n\n// External factory injected via Runtime\nlet externalFactory: LoggerFactory | null = null;\n\n// Version counter to invalidate cached real loggers\nlet factoryVersion = 0;\n\nexport interface LoggerFactoryConfig {\n defaultImplementation?: (name: string) => Logger;\n defaultLevel?: LogLevel;\n consoleOptions?: Omit<ConsoleLoggerOptions, \"level\">;\n}\n\n/**\n * Internal LoggerFactory implementation\n *\n * Uses lazy proxy pattern to allow module-level createLogger() calls.\n */\nexport class LoggerFactoryImpl {\n private static loggers: Map<string, Logger> = new Map();\n private static config: LoggerFactoryConfig = {\n defaultLevel: \"info\",\n };\n\n static getLogger(nameOrClass: string | (new (...args: unknown[]) => unknown)): Logger {\n const name = typeof nameOrClass === \"string\" ? nameOrClass : nameOrClass.name;\n\n if (this.loggers.has(name)) {\n return this.loggers.get(name)!;\n }\n\n const lazyLogger = this.createLazyLogger(name);\n this.loggers.set(name, lazyLogger);\n return lazyLogger;\n }\n\n static configure(config: LoggerFactoryConfig): void {\n this.config = { ...this.config, ...config };\n }\n\n static reset(): void {\n this.loggers.clear();\n this.config = { defaultLevel: \"info\" };\n externalFactory = null;\n factoryVersion++; // Invalidate all cached real loggers\n }\n\n private static createLazyLogger(name: string): Logger {\n let realLogger: Logger | null = null;\n let loggerVersion = -1; // Track which factory version created this logger\n\n const getRealLogger = (): Logger => {\n // Recreate logger if factory version changed (setLoggerFactory was called)\n if (!realLogger || loggerVersion !== factoryVersion) {\n realLogger = this.createLogger(name);\n loggerVersion = factoryVersion;\n }\n return realLogger;\n };\n\n return {\n name,\n level: this.config.defaultLevel || \"info\",\n debug: (message: string, context?: LogContext) => getRealLogger().debug(message, context),\n info: (message: string, context?: LogContext) => getRealLogger().info(message, context),\n warn: (message: string, context?: LogContext) => getRealLogger().warn(message, context),\n error: (message: string | Error, context?: LogContext) =>\n getRealLogger().error(message, context),\n isDebugEnabled: () => getRealLogger().isDebugEnabled(),\n isInfoEnabled: () => getRealLogger().isInfoEnabled(),\n isWarnEnabled: () => getRealLogger().isWarnEnabled(),\n isErrorEnabled: () => getRealLogger().isErrorEnabled(),\n };\n }\n\n private static createLogger(name: string): Logger {\n if (externalFactory) {\n return externalFactory.getLogger(name);\n }\n\n if (this.config.defaultImplementation) {\n return this.config.defaultImplementation(name);\n }\n\n return new ConsoleLogger(name, {\n level: this.config.defaultLevel,\n ...this.config.consoleOptions,\n });\n }\n}\n\n/**\n * Set external LoggerFactory (called by Runtime initialization)\n */\nexport function setLoggerFactory(factory: LoggerFactory): void {\n externalFactory = factory;\n LoggerFactoryImpl.reset();\n externalFactory = factory;\n}\n\n/**\n * Create a logger instance\n *\n * Safe to call at module level before Runtime is configured.\n * Uses lazy initialization - actual logger is created on first use.\n *\n * @param name - Logger name (hierarchical, e.g., \"engine/AgentEngine\")\n * @returns Logger instance (lazy proxy)\n */\nexport function createLogger(name: string): Logger {\n return LoggerFactoryImpl.getLogger(name);\n}\n",
|
|
7
|
+
"/**\n * ID Generation Utilities\n *\n * Provides consistent ID generation patterns across the AgentX platform.\n *\n * @packageDocumentation\n */\n\n/**\n * Generate a unique request ID for command request/response correlation.\n *\n * Format: `req_{timestamp}_{random}`\n *\n * @example\n * ```typescript\n * const requestId = generateRequestId();\n * // => \"req_1704067200000_a1b2c3\"\n * ```\n */\nexport function generateRequestId(): string {\n return `req_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;\n}\n\n/**\n * Generate a unique ID with a custom prefix.\n *\n * Format: `{prefix}_{timestamp}_{random}`\n *\n * @param prefix - The prefix for the ID (e.g., \"msg\", \"agent\", \"session\")\n *\n * @example\n * ```typescript\n * const msgId = generateId(\"msg\");\n * // => \"msg_1704067200000_a1b2c3\"\n *\n * const agentId = generateId(\"agent\");\n * // => \"agent_1704067200000_x7y8z9\"\n * ```\n */\nexport function generateId(prefix: string): string {\n return `${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n}\n"
|
|
7
8
|
],
|
|
8
|
-
"mappings": ";AAeO,MAAM,cAAgC;AAAA,EAClC;AAAA,EACA;AAAA,EACQ;AAAA,EACA;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83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the directory of the current module
|
|
3
|
+
*
|
|
4
|
+
* @param meta - Pass `import.meta` from your module
|
|
5
|
+
* @returns Absolute path to the directory containing the module
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { getModuleDir } from "@agentxjs/common/path";
|
|
10
|
+
*
|
|
11
|
+
* const __dirname = getModuleDir(import.meta);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
declare function getModuleDir(meta: ImportMeta): string;
|
|
15
|
+
/**
|
|
16
|
+
* Get the root directory of the current package (where package.json is)
|
|
17
|
+
*
|
|
18
|
+
* @param meta - Pass `import.meta` from your module
|
|
19
|
+
* @returns Absolute path to the package root
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { getPackageRoot } from "@agentxjs/common/path";
|
|
24
|
+
*
|
|
25
|
+
* const pkgRoot = getPackageRoot(import.meta);
|
|
26
|
+
* // e.g., /Users/sean/AgentX/packages/queue
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function getPackageRoot(meta: ImportMeta): string;
|
|
30
|
+
/**
|
|
31
|
+
* Get the monorepo root directory (where pnpm-workspace.yaml or root package.json is)
|
|
32
|
+
*
|
|
33
|
+
* @param meta - Pass `import.meta` from your module
|
|
34
|
+
* @returns Absolute path to the monorepo root
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { getMonorepoRoot } from "@agentxjs/common/path";
|
|
39
|
+
*
|
|
40
|
+
* const root = getMonorepoRoot(import.meta);
|
|
41
|
+
* // e.g., /Users/sean/AgentX
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function getMonorepoRoot(meta: ImportMeta): string;
|
|
45
|
+
/**
|
|
46
|
+
* Resolve a path relative to the monorepo root
|
|
47
|
+
*
|
|
48
|
+
* @param meta - Pass `import.meta` from your module
|
|
49
|
+
* @param paths - Path segments to resolve
|
|
50
|
+
* @returns Absolute resolved path
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { resolveFromRoot } from "@agentxjs/common/path";
|
|
55
|
+
*
|
|
56
|
+
* const dataDir = resolveFromRoot(import.meta, "data");
|
|
57
|
+
* // e.g., /Users/sean/AgentX/data
|
|
58
|
+
*
|
|
59
|
+
* const config = resolveFromRoot(import.meta, "packages", "config", "settings.json");
|
|
60
|
+
* // e.g., /Users/sean/AgentX/packages/config/settings.json
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function resolveFromRoot(meta: ImportMeta, ...paths: string[]): string;
|
|
64
|
+
/**
|
|
65
|
+
* Resolve a path relative to the current package root
|
|
66
|
+
*
|
|
67
|
+
* @param meta - Pass `import.meta` from your module
|
|
68
|
+
* @param paths - Path segments to resolve
|
|
69
|
+
* @returns Absolute resolved path
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* import { resolveFromPackage } from "@agentxjs/common/path";
|
|
74
|
+
*
|
|
75
|
+
* const testsDir = resolveFromPackage(import.meta, "tests");
|
|
76
|
+
* // e.g., /Users/sean/AgentX/packages/queue/tests
|
|
77
|
+
*
|
|
78
|
+
* const fixtures = resolveFromPackage(import.meta, "tests", "fixtures", "data.json");
|
|
79
|
+
* // e.g., /Users/sean/AgentX/packages/queue/tests/fixtures/data.json
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare function resolveFromPackage(meta: ImportMeta, ...paths: string[]): string;
|
|
83
|
+
export { resolveFromRoot, resolveFromPackage, getPackageRoot, getMonorepoRoot, getModuleDir };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/path/path.ts
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
function getModuleDir(meta) {
|
|
6
|
+
if (meta.dir) {
|
|
7
|
+
return meta.dir;
|
|
8
|
+
}
|
|
9
|
+
return dirname(fileURLToPath(meta.url));
|
|
10
|
+
}
|
|
11
|
+
function getPackageRoot(meta) {
|
|
12
|
+
const startDir = getModuleDir(meta);
|
|
13
|
+
return findUp(startDir, "package.json");
|
|
14
|
+
}
|
|
15
|
+
function getMonorepoRoot(meta) {
|
|
16
|
+
const startDir = getModuleDir(meta);
|
|
17
|
+
const markers = [
|
|
18
|
+
"pnpm-workspace.yaml",
|
|
19
|
+
"pnpm-lock.yaml",
|
|
20
|
+
"bun.lock",
|
|
21
|
+
"bun.lockb",
|
|
22
|
+
"package-lock.json",
|
|
23
|
+
"yarn.lock"
|
|
24
|
+
];
|
|
25
|
+
for (const marker of markers) {
|
|
26
|
+
try {
|
|
27
|
+
return findUp(startDir, marker);
|
|
28
|
+
} catch {}
|
|
29
|
+
}
|
|
30
|
+
return findUp(startDir, "package.json");
|
|
31
|
+
}
|
|
32
|
+
function resolveFromRoot(meta, ...paths) {
|
|
33
|
+
const root = getMonorepoRoot(meta);
|
|
34
|
+
return resolve(root, ...paths);
|
|
35
|
+
}
|
|
36
|
+
function resolveFromPackage(meta, ...paths) {
|
|
37
|
+
const pkgRoot = getPackageRoot(meta);
|
|
38
|
+
return resolve(pkgRoot, ...paths);
|
|
39
|
+
}
|
|
40
|
+
function findUp(startDir, filename) {
|
|
41
|
+
let current = startDir;
|
|
42
|
+
const root = resolve("/");
|
|
43
|
+
while (current !== root) {
|
|
44
|
+
const candidate = resolve(current, filename);
|
|
45
|
+
if (existsSync(candidate)) {
|
|
46
|
+
return current;
|
|
47
|
+
}
|
|
48
|
+
const parent = dirname(current);
|
|
49
|
+
if (parent === current)
|
|
50
|
+
break;
|
|
51
|
+
current = parent;
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`Could not find ${filename} starting from ${startDir}`);
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
resolveFromRoot,
|
|
57
|
+
resolveFromPackage,
|
|
58
|
+
getPackageRoot,
|
|
59
|
+
getMonorepoRoot,
|
|
60
|
+
getModuleDir
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//# debugId=6C5E3AD0868C9DBF64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/path/path.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Path Utilities - Cross-runtime path helpers\n *\n * Works in both Bun and Node.js environments.\n */\n\nimport { dirname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { existsSync } from \"node:fs\";\n\ndeclare const Bun: unknown;\n\n/**\n * Get the directory of the current module\n *\n * @param meta - Pass `import.meta` from your module\n * @returns Absolute path to the directory containing the module\n *\n * @example\n * ```typescript\n * import { getModuleDir } from \"@agentxjs/common/path\";\n *\n * const __dirname = getModuleDir(import.meta);\n * ```\n */\nexport function getModuleDir(meta: ImportMeta): string {\n // Bun has import.meta.dir\n if ((meta as any).dir) {\n return (meta as any).dir;\n }\n // Node.js: convert file:// URL to path\n return dirname(fileURLToPath(meta.url));\n}\n\n/**\n * Get the root directory of the current package (where package.json is)\n *\n * @param meta - Pass `import.meta` from your module\n * @returns Absolute path to the package root\n *\n * @example\n * ```typescript\n * import { getPackageRoot } from \"@agentxjs/common/path\";\n *\n * const pkgRoot = getPackageRoot(import.meta);\n * // e.g., /Users/sean/AgentX/packages/queue\n * ```\n */\nexport function getPackageRoot(meta: ImportMeta): string {\n const startDir = getModuleDir(meta);\n return findUp(startDir, \"package.json\");\n}\n\n/**\n * Get the monorepo root directory (where pnpm-workspace.yaml or root package.json is)\n *\n * @param meta - Pass `import.meta` from your module\n * @returns Absolute path to the monorepo root\n *\n * @example\n * ```typescript\n * import { getMonorepoRoot } from \"@agentxjs/common/path\";\n *\n * const root = getMonorepoRoot(import.meta);\n * // e.g., /Users/sean/AgentX\n * ```\n */\nexport function getMonorepoRoot(meta: ImportMeta): string {\n const startDir = getModuleDir(meta);\n\n // Try common monorepo markers in order\n const markers = [\n \"pnpm-workspace.yaml\", // pnpm monorepo\n \"pnpm-lock.yaml\", // pnpm\n \"bun.lock\", // bun workspace\n \"bun.lockb\", // bun workspace (binary)\n \"package-lock.json\", // npm workspace\n \"yarn.lock\", // yarn workspace\n ];\n\n for (const marker of markers) {\n try {\n return findUp(startDir, marker);\n } catch {\n // Try next marker\n }\n }\n\n // Last resort: find root package.json\n return findUp(startDir, \"package.json\");\n}\n\n/**\n * Resolve a path relative to the monorepo root\n *\n * @param meta - Pass `import.meta` from your module\n * @param paths - Path segments to resolve\n * @returns Absolute resolved path\n *\n * @example\n * ```typescript\n * import { resolveFromRoot } from \"@agentxjs/common/path\";\n *\n * const dataDir = resolveFromRoot(import.meta, \"data\");\n * // e.g., /Users/sean/AgentX/data\n *\n * const config = resolveFromRoot(import.meta, \"packages\", \"config\", \"settings.json\");\n * // e.g., /Users/sean/AgentX/packages/config/settings.json\n * ```\n */\nexport function resolveFromRoot(meta: ImportMeta, ...paths: string[]): string {\n const root = getMonorepoRoot(meta);\n return resolve(root, ...paths);\n}\n\n/**\n * Resolve a path relative to the current package root\n *\n * @param meta - Pass `import.meta` from your module\n * @param paths - Path segments to resolve\n * @returns Absolute resolved path\n *\n * @example\n * ```typescript\n * import { resolveFromPackage } from \"@agentxjs/common/path\";\n *\n * const testsDir = resolveFromPackage(import.meta, \"tests\");\n * // e.g., /Users/sean/AgentX/packages/queue/tests\n *\n * const fixtures = resolveFromPackage(import.meta, \"tests\", \"fixtures\", \"data.json\");\n * // e.g., /Users/sean/AgentX/packages/queue/tests/fixtures/data.json\n * ```\n */\nexport function resolveFromPackage(meta: ImportMeta, ...paths: string[]): string {\n const pkgRoot = getPackageRoot(meta);\n return resolve(pkgRoot, ...paths);\n}\n\n/**\n * Find a file by walking up the directory tree\n */\nfunction findUp(startDir: string, filename: string): string {\n let current = startDir;\n const root = resolve(\"/\");\n\n while (current !== root) {\n const candidate = resolve(current, filename);\n if (existsSync(candidate)) {\n return current;\n }\n const parent = dirname(current);\n if (parent === current) break;\n current = parent;\n }\n\n throw new Error(`Could not find ${filename} starting from ${startDir}`);\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAMA;AACA;AACA;AAiBO,SAAS,YAAY,CAAC,MAA0B;AAAA,EAErD,IAAK,KAAa,KAAK;AAAA,IACrB,OAAQ,KAAa;AAAA,EACvB;AAAA,EAEA,OAAO,QAAQ,cAAc,KAAK,GAAG,CAAC;AAAA;AAiBjC,SAAS,cAAc,CAAC,MAA0B;AAAA,EACvD,MAAM,WAAW,aAAa,IAAI;AAAA,EAClC,OAAO,OAAO,UAAU,cAAc;AAAA;AAiBjC,SAAS,eAAe,CAAC,MAA0B;AAAA,EACxD,MAAM,WAAW,aAAa,IAAI;AAAA,EAGlC,MAAM,UAAU;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EAEA,WAAW,UAAU,SAAS;AAAA,IAC5B,IAAI;AAAA,MACF,OAAO,OAAO,UAAU,MAAM;AAAA,MAC9B,MAAM;AAAA,EAGV;AAAA,EAGA,OAAO,OAAO,UAAU,cAAc;AAAA;AAqBjC,SAAS,eAAe,CAAC,SAAqB,OAAyB;AAAA,EAC5E,MAAM,OAAO,gBAAgB,IAAI;AAAA,EACjC,OAAO,QAAQ,MAAM,GAAG,KAAK;AAAA;AAqBxB,SAAS,kBAAkB,CAAC,SAAqB,OAAyB;AAAA,EAC/E,MAAM,UAAU,eAAe,IAAI;AAAA,EACnC,OAAO,QAAQ,SAAS,GAAG,KAAK;AAAA;AAMlC,SAAS,MAAM,CAAC,UAAkB,UAA0B;AAAA,EAC1D,IAAI,UAAU;AAAA,EACd,MAAM,OAAO,QAAQ,GAAG;AAAA,EAExB,OAAO,YAAY,MAAM;AAAA,IACvB,MAAM,YAAY,QAAQ,SAAS,QAAQ;AAAA,IAC3C,IAAI,WAAW,SAAS,GAAG;AAAA,MACzB,OAAO;AAAA,IACT;AAAA,IACA,MAAM,SAAS,QAAQ,OAAO;AAAA,IAC9B,IAAI,WAAW;AAAA,MAAS;AAAA,IACxB,UAAU;AAAA,EACZ;AAAA,EAEA,MAAM,IAAI,MAAM,kBAAkB,0BAA0B,UAAU;AAAA;",
|
|
8
|
+
"debugId": "6C5E3AD0868C9DBF64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite Database Abstraction Types
|
|
3
|
+
*
|
|
4
|
+
* Unified interface for Node.js (node:sqlite) and Bun (bun:sqlite)
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Query execution result
|
|
8
|
+
*/
|
|
9
|
+
interface RunResult {
|
|
10
|
+
/** Number of rows changed */
|
|
11
|
+
changes: number;
|
|
12
|
+
/** Last inserted row ID */
|
|
13
|
+
lastInsertRowid: number | bigint;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Prepared statement
|
|
17
|
+
*/
|
|
18
|
+
interface Statement {
|
|
19
|
+
/** Execute statement with parameters, return result */
|
|
20
|
+
run(...params: unknown[]): RunResult;
|
|
21
|
+
/** Get single row */
|
|
22
|
+
get(...params: unknown[]): unknown;
|
|
23
|
+
/** Get all rows */
|
|
24
|
+
all(...params: unknown[]): unknown[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Database connection
|
|
28
|
+
*/
|
|
29
|
+
interface Database {
|
|
30
|
+
/** Execute raw SQL (no return value) */
|
|
31
|
+
exec(sql: string): void;
|
|
32
|
+
/** Prepare a statement for execution */
|
|
33
|
+
prepare(sql: string): Statement;
|
|
34
|
+
/** Close the database connection */
|
|
35
|
+
close(): void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Open a SQLite database
|
|
39
|
+
*
|
|
40
|
+
* Automatically detects runtime:
|
|
41
|
+
* - Bun → uses bun:sqlite
|
|
42
|
+
* - Node.js 22+ → uses node:sqlite
|
|
43
|
+
*
|
|
44
|
+
* @param path - Database file path (use ":memory:" for in-memory)
|
|
45
|
+
* @returns Database instance
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { openDatabase } from "@agentxjs/common";
|
|
50
|
+
*
|
|
51
|
+
* const db = openDatabase("./data/app.db");
|
|
52
|
+
* db.exec("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)");
|
|
53
|
+
*
|
|
54
|
+
* const stmt = db.prepare("INSERT INTO users (name) VALUES (?)");
|
|
55
|
+
* stmt.run("Alice");
|
|
56
|
+
*
|
|
57
|
+
* const users = db.prepare("SELECT * FROM users").all();
|
|
58
|
+
* console.log(users);
|
|
59
|
+
*
|
|
60
|
+
* db.close();
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function openDatabase(path: string): Database;
|
|
64
|
+
export { openDatabase, Statement, RunResult, Database };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// src/sqlite/database.ts
|
|
5
|
+
import { dirname } from "node:path";
|
|
6
|
+
import { mkdirSync, existsSync } from "node:fs";
|
|
7
|
+
function ensureDir(path) {
|
|
8
|
+
if (path === ":memory:")
|
|
9
|
+
return;
|
|
10
|
+
const dir = dirname(path);
|
|
11
|
+
if (!existsSync(dir)) {
|
|
12
|
+
mkdirSync(dir, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function isBun() {
|
|
16
|
+
return typeof Bun !== "undefined";
|
|
17
|
+
}
|
|
18
|
+
function hasNodeSqlite() {
|
|
19
|
+
return typeof globalThis.process?.getBuiltinModule === "function" && globalThis.process.getBuiltinModule("node:sqlite") !== undefined;
|
|
20
|
+
}
|
|
21
|
+
function openDatabase(path) {
|
|
22
|
+
ensureDir(path);
|
|
23
|
+
if (isBun()) {
|
|
24
|
+
return openBunDatabase(path);
|
|
25
|
+
}
|
|
26
|
+
if (hasNodeSqlite()) {
|
|
27
|
+
return openNodeDatabase(path);
|
|
28
|
+
}
|
|
29
|
+
throw new Error("No SQLite runtime available. Requires Bun or Node.js 22+ with built-in sqlite.");
|
|
30
|
+
}
|
|
31
|
+
function openBunDatabase(path) {
|
|
32
|
+
const { Database: BunDatabase } = __require("bun:sqlite");
|
|
33
|
+
const db = new BunDatabase(path);
|
|
34
|
+
return {
|
|
35
|
+
exec(sql) {
|
|
36
|
+
db.exec(sql);
|
|
37
|
+
},
|
|
38
|
+
prepare(sql) {
|
|
39
|
+
const stmt = db.prepare(sql);
|
|
40
|
+
return {
|
|
41
|
+
run(...params) {
|
|
42
|
+
const result = stmt.run(...params);
|
|
43
|
+
return {
|
|
44
|
+
changes: result.changes,
|
|
45
|
+
lastInsertRowid: result.lastInsertRowid
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
get(...params) {
|
|
49
|
+
return stmt.get(...params);
|
|
50
|
+
},
|
|
51
|
+
all(...params) {
|
|
52
|
+
return stmt.all(...params);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
close() {
|
|
57
|
+
db.close();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function openNodeDatabase(path) {
|
|
62
|
+
const nodeSqlite = globalThis.process.getBuiltinModule("node:sqlite");
|
|
63
|
+
const { DatabaseSync } = nodeSqlite;
|
|
64
|
+
const db = new DatabaseSync(path);
|
|
65
|
+
return {
|
|
66
|
+
exec(sql) {
|
|
67
|
+
db.exec(sql);
|
|
68
|
+
},
|
|
69
|
+
prepare(sql) {
|
|
70
|
+
const stmt = db.prepare(sql);
|
|
71
|
+
return {
|
|
72
|
+
run(...params) {
|
|
73
|
+
const result = stmt.run(...params);
|
|
74
|
+
return {
|
|
75
|
+
changes: result.changes,
|
|
76
|
+
lastInsertRowid: result.lastInsertRowid
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
get(...params) {
|
|
80
|
+
return stmt.get(...params);
|
|
81
|
+
},
|
|
82
|
+
all(...params) {
|
|
83
|
+
return stmt.all(...params);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
close() {
|
|
88
|
+
db.close();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
openDatabase
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
//# debugId=E89B6E8118FDB35764756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/sqlite/database.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * SQLite Database Implementation\n *\n * Auto-detects runtime and uses:\n * - Bun: bun:sqlite (built-in)\n * - Node.js 22+: node:sqlite (built-in)\n */\n\nimport { dirname } from \"node:path\";\nimport { mkdirSync, existsSync } from \"node:fs\";\nimport type { Database, Statement, RunResult } from \"./types\";\n\ndeclare const Bun: unknown;\n\n/**\n * Ensure parent directory exists for database file\n */\nfunction ensureDir(path: string): void {\n if (path === \":memory:\") return;\n const dir = dirname(path);\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n}\n\n/**\n * Detect if running in Bun\n */\nfunction isBun(): boolean {\n return typeof Bun !== \"undefined\";\n}\n\n/**\n * Detect if Node.js has built-in SQLite (22+)\n */\nfunction hasNodeSqlite(): boolean {\n return (\n typeof globalThis.process?.getBuiltinModule === \"function\" &&\n globalThis.process.getBuiltinModule(\"node:sqlite\") !== undefined\n );\n}\n\n/**\n * Open a SQLite database\n *\n * Automatically detects runtime:\n * - Bun → uses bun:sqlite\n * - Node.js 22+ → uses node:sqlite\n *\n * @param path - Database file path (use \":memory:\" for in-memory)\n * @returns Database instance\n *\n * @example\n * ```typescript\n * import { openDatabase } from \"@agentxjs/common\";\n *\n * const db = openDatabase(\"./data/app.db\");\n * db.exec(\"CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)\");\n *\n * const stmt = db.prepare(\"INSERT INTO users (name) VALUES (?)\");\n * stmt.run(\"Alice\");\n *\n * const users = db.prepare(\"SELECT * FROM users\").all();\n * console.log(users);\n *\n * db.close();\n * ```\n */\nexport function openDatabase(path: string): Database {\n // Ensure parent directory exists\n ensureDir(path);\n\n if (isBun()) {\n return openBunDatabase(path);\n }\n\n if (hasNodeSqlite()) {\n return openNodeDatabase(path);\n }\n\n throw new Error(\"No SQLite runtime available. Requires Bun or Node.js 22+ with built-in sqlite.\");\n}\n\n/**\n * Open database using Bun's bun:sqlite\n */\nfunction openBunDatabase(path: string): Database {\n // Dynamic require to avoid bundling issues\n\n const { Database: BunDatabase } = require(\"bun:sqlite\");\n const db = new BunDatabase(path);\n\n return {\n exec(sql: string): void {\n db.exec(sql);\n },\n\n prepare(sql: string): Statement {\n const stmt = db.prepare(sql);\n return {\n run(...params: unknown[]): RunResult {\n const result = stmt.run(...params);\n return {\n changes: result.changes,\n lastInsertRowid: result.lastInsertRowid,\n };\n },\n get(...params: unknown[]): unknown {\n return stmt.get(...params);\n },\n all(...params: unknown[]): unknown[] {\n return stmt.all(...params);\n },\n };\n },\n\n close(): void {\n db.close();\n },\n };\n}\n\n/**\n * Open database using Node.js node:sqlite\n */\nfunction openNodeDatabase(path: string): Database {\n const nodeSqlite = globalThis.process.getBuiltinModule(\"node:sqlite\") as any;\n const { DatabaseSync } = nodeSqlite;\n const db = new DatabaseSync(path);\n\n return {\n exec(sql: string): void {\n db.exec(sql);\n },\n\n prepare(sql: string): Statement {\n const stmt = db.prepare(sql);\n return {\n run(...params: unknown[]): RunResult {\n const result = stmt.run(...params);\n return {\n changes: result.changes,\n lastInsertRowid: result.lastInsertRowid,\n };\n },\n get(...params: unknown[]): unknown {\n return stmt.get(...params);\n },\n all(...params: unknown[]): unknown[] {\n return stmt.all(...params);\n },\n };\n },\n\n close(): void {\n db.close();\n },\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;AAQA;AACA;AAQA,SAAS,SAAS,CAAC,MAAoB;AAAA,EACrC,IAAI,SAAS;AAAA,IAAY;AAAA,EACzB,MAAM,MAAM,QAAQ,IAAI;AAAA,EACxB,IAAI,CAAC,WAAW,GAAG,GAAG;AAAA,IACpB,UAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,EACpC;AAAA;AAMF,SAAS,KAAK,GAAY;AAAA,EACxB,OAAO,OAAO,QAAQ;AAAA;AAMxB,SAAS,aAAa,GAAY;AAAA,EAChC,OACE,OAAO,WAAW,SAAS,qBAAqB,cAChD,WAAW,QAAQ,iBAAiB,aAAa,MAAM;AAAA;AA8BpD,SAAS,YAAY,CAAC,MAAwB;AAAA,EAEnD,UAAU,IAAI;AAAA,EAEd,IAAI,MAAM,GAAG;AAAA,IACX,OAAO,gBAAgB,IAAI;AAAA,EAC7B;AAAA,EAEA,IAAI,cAAc,GAAG;AAAA,IACnB,OAAO,iBAAiB,IAAI;AAAA,EAC9B;AAAA,EAEA,MAAM,IAAI,MAAM,gFAAgF;AAAA;AAMlG,SAAS,eAAe,CAAC,MAAwB;AAAA,EAG/C,QAAQ,UAAU;AAAA,EAClB,MAAM,KAAK,IAAI,YAAY,IAAI;AAAA,EAE/B,OAAO;AAAA,IACL,IAAI,CAAC,KAAmB;AAAA,MACtB,GAAG,KAAK,GAAG;AAAA;AAAA,IAGb,OAAO,CAAC,KAAwB;AAAA,MAC9B,MAAM,OAAO,GAAG,QAAQ,GAAG;AAAA,MAC3B,OAAO;AAAA,QACL,GAAG,IAAI,QAA8B;AAAA,UACnC,MAAM,SAAS,KAAK,IAAI,GAAG,MAAM;AAAA,UACjC,OAAO;AAAA,YACL,SAAS,OAAO;AAAA,YAChB,iBA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": "1.9.0",
|
|
4
4
|
"description": "Common utilities for AgentX platform - Logger facade and shared infrastructure",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentx",
|
|
@@ -24,6 +24,14 @@
|
|
|
24
24
|
".": {
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
26
|
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./sqlite": {
|
|
29
|
+
"types": "./dist/sqlite/index.d.ts",
|
|
30
|
+
"default": "./dist/sqlite/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./path": {
|
|
33
|
+
"types": "./dist/path/index.d.ts",
|
|
34
|
+
"default": "./dist/path/index.js"
|
|
27
35
|
}
|
|
28
36
|
},
|
|
29
37
|
"files": [
|
|
@@ -37,7 +45,7 @@
|
|
|
37
45
|
"clean": "rm -rf dist"
|
|
38
46
|
},
|
|
39
47
|
"dependencies": {
|
|
40
|
-
"@agentxjs/types": "^1.
|
|
48
|
+
"@agentxjs/types": "^1.9.0"
|
|
41
49
|
},
|
|
42
50
|
"devDependencies": {},
|
|
43
51
|
"publishConfig": {
|