@agentxjs/node-platform 2.0.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.
Files changed (46) hide show
  1. package/README.md +134 -0
  2. package/dist/WebSocketConnection-BUL85bFC.d.ts +66 -0
  3. package/dist/WebSocketFactory-SDWPRZVB.js +8 -0
  4. package/dist/WebSocketFactory-SDWPRZVB.js.map +1 -0
  5. package/dist/chunk-BBZV6B5R.js +264 -0
  6. package/dist/chunk-BBZV6B5R.js.map +1 -0
  7. package/dist/chunk-DGUM43GV.js +11 -0
  8. package/dist/chunk-DGUM43GV.js.map +1 -0
  9. package/dist/chunk-PK2K7CCJ.js +213 -0
  10. package/dist/chunk-PK2K7CCJ.js.map +1 -0
  11. package/dist/chunk-TXESAX3X.js +361 -0
  12. package/dist/chunk-TXESAX3X.js.map +1 -0
  13. package/dist/chunk-V664KD3R.js +14 -0
  14. package/dist/chunk-V664KD3R.js.map +1 -0
  15. package/dist/index.d.ts +140 -0
  16. package/dist/index.js +223 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/mq/index.d.ts +63 -0
  19. package/dist/mq/index.js +10 -0
  20. package/dist/mq/index.js.map +1 -0
  21. package/dist/network/index.d.ts +17 -0
  22. package/dist/network/index.js +14 -0
  23. package/dist/network/index.js.map +1 -0
  24. package/dist/persistence/index.d.ts +175 -0
  25. package/dist/persistence/index.js +18 -0
  26. package/dist/persistence/index.js.map +1 -0
  27. package/package.json +50 -0
  28. package/src/bash/NodeBashProvider.ts +54 -0
  29. package/src/index.ts +151 -0
  30. package/src/logger/FileLoggerFactory.ts +175 -0
  31. package/src/logger/index.ts +5 -0
  32. package/src/mq/OffsetGenerator.ts +48 -0
  33. package/src/mq/SqliteMessageQueue.ts +240 -0
  34. package/src/mq/index.ts +30 -0
  35. package/src/network/WebSocketConnection.ts +206 -0
  36. package/src/network/WebSocketFactory.ts +17 -0
  37. package/src/network/WebSocketServer.ts +156 -0
  38. package/src/network/index.ts +32 -0
  39. package/src/persistence/Persistence.ts +53 -0
  40. package/src/persistence/StorageContainerRepository.ts +58 -0
  41. package/src/persistence/StorageImageRepository.ts +153 -0
  42. package/src/persistence/StorageSessionRepository.ts +171 -0
  43. package/src/persistence/index.ts +38 -0
  44. package/src/persistence/memory.ts +27 -0
  45. package/src/persistence/sqlite.ts +111 -0
  46. package/src/persistence/types.ts +32 -0
@@ -0,0 +1,140 @@
1
+ import { AgentXPlatform } from '@agentxjs/core/runtime';
2
+ import { LoggerFactory, LogLevel, Logger } from 'commonxjs/logger';
3
+ export { Persistence, PersistenceDriver, SqliteDriverOptions, StorageContainerRepository, StorageImageRepository, StorageSessionRepository, createPersistence, memoryDriver, sqliteDriver } from './persistence/index.js';
4
+ import { BashProvider, BashOptions, BashResult } from '@agentxjs/core/bash';
5
+ export { OffsetGenerator, SqliteMessageQueue } from './mq/index.js';
6
+ export { a as WebSocketConnection, W as WebSocketServer } from './WebSocketConnection-BUL85bFC.js';
7
+ import 'unstorage';
8
+ import '@agentxjs/core/persistence';
9
+ import '@agentxjs/core/agent';
10
+ import '@agentxjs/core/mq';
11
+ import '@agentxjs/core/network';
12
+ import 'ws';
13
+
14
+ /**
15
+ * NodeBashProvider - Node.js implementation of BashProvider
16
+ *
17
+ * Uses execa for subprocess execution with proper timeout,
18
+ * error handling, and cross-platform shell support.
19
+ */
20
+
21
+ /**
22
+ * NodeBashProvider - Executes shell commands via execa
23
+ */
24
+ declare class NodeBashProvider implements BashProvider {
25
+ readonly type = "child-process";
26
+ execute(command: string, options?: BashOptions): Promise<BashResult>;
27
+ }
28
+
29
+ /**
30
+ * FileLoggerFactory - File-based logger for Node.js
31
+ *
32
+ * Writes logs to a file instead of console.
33
+ * Useful for TUI applications where console output interferes with the UI.
34
+ *
35
+ * Usage:
36
+ * tail -f .agentx/logs/app.log
37
+ */
38
+
39
+ /**
40
+ * FileLoggerFactory options
41
+ */
42
+ interface FileLoggerFactoryOptions {
43
+ /**
44
+ * Directory for log files
45
+ */
46
+ logDir: string;
47
+ /**
48
+ * Log level
49
+ * @default "debug"
50
+ */
51
+ level?: LogLevel;
52
+ /**
53
+ * Log file name
54
+ * @default "app.log"
55
+ */
56
+ filename?: string;
57
+ }
58
+ /**
59
+ * FileLoggerFactory - Creates FileLogger instances
60
+ */
61
+ declare class FileLoggerFactory implements LoggerFactory {
62
+ private readonly filePath;
63
+ private readonly level;
64
+ private readonly loggers;
65
+ constructor(options: FileLoggerFactoryOptions);
66
+ getLogger(name: string): Logger;
67
+ }
68
+
69
+ /**
70
+ * @agentxjs/node-platform
71
+ *
72
+ * Node.js platform for AgentX.
73
+ * Provides implementations for persistence, bash, and network.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * import { createNodePlatform } from "@agentxjs/node-platform";
78
+ *
79
+ * const platform = await createNodePlatform({ dataPath: "./data" });
80
+ * ```
81
+ */
82
+
83
+ /**
84
+ * Options for creating a Node platform
85
+ */
86
+ interface NodePlatformOptions {
87
+ /**
88
+ * Base path for data storage
89
+ * @default "./data"
90
+ */
91
+ dataPath?: string;
92
+ /**
93
+ * Directory for log files
94
+ * If provided, enables file logging instead of console
95
+ * @example ".agentx/logs"
96
+ */
97
+ logDir?: string;
98
+ /**
99
+ * Log level
100
+ * @default "debug" for file logging, "info" for console
101
+ */
102
+ logLevel?: LogLevel;
103
+ }
104
+ /**
105
+ * Deferred platform config - resolved lazily
106
+ */
107
+ interface DeferredPlatformConfig {
108
+ readonly __deferred: true;
109
+ readonly options: NodePlatformOptions;
110
+ resolve(): Promise<AgentXPlatform>;
111
+ }
112
+ /**
113
+ * Create a Node.js platform configuration (deferred initialization)
114
+ *
115
+ * Use this for function-style API. The platform is initialized lazily.
116
+ *
117
+ * @param options - Platform options
118
+ * @returns Deferred platform config
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const server = await createServer({
123
+ * platform: nodePlatform({ dataPath: "./data" }),
124
+ * });
125
+ * ```
126
+ */
127
+ declare function nodePlatform(options?: NodePlatformOptions): DeferredPlatformConfig;
128
+ /**
129
+ * Create a Node.js platform for AgentX (immediate initialization)
130
+ *
131
+ * @param options - Platform options
132
+ * @returns AgentXPlatform instance
133
+ */
134
+ declare function createNodePlatform(options?: NodePlatformOptions): Promise<AgentXPlatform>;
135
+ /**
136
+ * Check if value is a deferred platform config
137
+ */
138
+ declare function isDeferredPlatform(value: unknown): value is DeferredPlatformConfig;
139
+
140
+ export { type DeferredPlatformConfig, FileLoggerFactory, type FileLoggerFactoryOptions, NodeBashProvider, type NodePlatformOptions, createNodePlatform, isDeferredPlatform, nodePlatform };
package/dist/index.js ADDED
@@ -0,0 +1,223 @@
1
+ import {
2
+ StorageContainerRepository,
3
+ StorageImageRepository,
4
+ StorageSessionRepository,
5
+ createPersistence,
6
+ memoryDriver,
7
+ sqliteDriver
8
+ } from "./chunk-TXESAX3X.js";
9
+ import {
10
+ OffsetGenerator,
11
+ SqliteMessageQueue
12
+ } from "./chunk-PK2K7CCJ.js";
13
+ import {
14
+ WebSocketConnection,
15
+ WebSocketServer
16
+ } from "./chunk-BBZV6B5R.js";
17
+ import "./chunk-V664KD3R.js";
18
+ import "./chunk-DGUM43GV.js";
19
+
20
+ // src/index.ts
21
+ import { setLoggerFactory, ConsoleLogger } from "commonxjs/logger";
22
+ import { EventBusImpl } from "@agentxjs/core/event";
23
+
24
+ // src/bash/NodeBashProvider.ts
25
+ import { execa } from "execa";
26
+ import { createLogger } from "commonxjs/logger";
27
+ var logger = createLogger("node-platform/NodeBashProvider");
28
+ var DEFAULT_TIMEOUT = 3e4;
29
+ var NodeBashProvider = class {
30
+ type = "child-process";
31
+ async execute(command, options) {
32
+ const timeout = options?.timeout ?? DEFAULT_TIMEOUT;
33
+ logger.debug("Executing command", {
34
+ command: command.substring(0, 100),
35
+ cwd: options?.cwd,
36
+ timeout
37
+ });
38
+ const result = await execa({
39
+ shell: true,
40
+ cwd: options?.cwd,
41
+ timeout,
42
+ env: options?.env ? { ...process.env, ...options.env } : void 0,
43
+ reject: false
44
+ })`${command}`;
45
+ logger.debug("Command completed", {
46
+ exitCode: result.exitCode,
47
+ stdoutLength: result.stdout.length,
48
+ stderrLength: result.stderr.length
49
+ });
50
+ return {
51
+ stdout: result.stdout,
52
+ stderr: result.stderr,
53
+ exitCode: result.exitCode ?? 1
54
+ };
55
+ }
56
+ };
57
+
58
+ // src/logger/FileLoggerFactory.ts
59
+ import { appendFileSync, mkdirSync, existsSync } from "fs";
60
+ import { dirname, join } from "path";
61
+ var FileLogger = class {
62
+ name;
63
+ level;
64
+ timestamps;
65
+ filePath;
66
+ initialized = false;
67
+ constructor(name, filePath, options = {}) {
68
+ this.name = name;
69
+ this.filePath = filePath;
70
+ this.level = options.level ?? "debug";
71
+ this.timestamps = options.timestamps ?? true;
72
+ }
73
+ ensureDir() {
74
+ if (this.initialized) return;
75
+ const dir = dirname(this.filePath);
76
+ if (!existsSync(dir)) {
77
+ mkdirSync(dir, { recursive: true });
78
+ }
79
+ this.initialized = true;
80
+ }
81
+ debug(message, context) {
82
+ if (this.isDebugEnabled()) {
83
+ this.log("DEBUG", message, context);
84
+ }
85
+ }
86
+ info(message, context) {
87
+ if (this.isInfoEnabled()) {
88
+ this.log("INFO", message, context);
89
+ }
90
+ }
91
+ warn(message, context) {
92
+ if (this.isWarnEnabled()) {
93
+ this.log("WARN", message, context);
94
+ }
95
+ }
96
+ error(message, context) {
97
+ if (this.isErrorEnabled()) {
98
+ if (message instanceof Error) {
99
+ this.log("ERROR", message.message, { ...context, stack: message.stack });
100
+ } else {
101
+ this.log("ERROR", message, context);
102
+ }
103
+ }
104
+ }
105
+ isDebugEnabled() {
106
+ return this.getLevelValue(this.level) <= this.getLevelValue("debug");
107
+ }
108
+ isInfoEnabled() {
109
+ return this.getLevelValue(this.level) <= this.getLevelValue("info");
110
+ }
111
+ isWarnEnabled() {
112
+ return this.getLevelValue(this.level) <= this.getLevelValue("warn");
113
+ }
114
+ isErrorEnabled() {
115
+ return this.getLevelValue(this.level) <= this.getLevelValue("error");
116
+ }
117
+ getLevelValue(level) {
118
+ const levels = {
119
+ debug: 0,
120
+ info: 1,
121
+ warn: 2,
122
+ error: 3,
123
+ silent: 4
124
+ };
125
+ return levels[level];
126
+ }
127
+ log(level, message, context) {
128
+ this.ensureDir();
129
+ const parts = [];
130
+ if (this.timestamps) {
131
+ parts.push((/* @__PURE__ */ new Date()).toISOString());
132
+ }
133
+ parts.push(level.padEnd(5));
134
+ parts.push(`[${this.name}]`);
135
+ parts.push(message);
136
+ let logLine = parts.join(" ");
137
+ if (context && Object.keys(context).length > 0) {
138
+ logLine += " " + JSON.stringify(context);
139
+ }
140
+ logLine += "\n";
141
+ try {
142
+ appendFileSync(this.filePath, logLine);
143
+ } catch {
144
+ process.stderr.write(`[FileLogger] Failed to write: ${logLine}`);
145
+ }
146
+ }
147
+ };
148
+ var FileLoggerFactory = class {
149
+ filePath;
150
+ level;
151
+ loggers = /* @__PURE__ */ new Map();
152
+ constructor(options) {
153
+ this.filePath = join(options.logDir, options.filename ?? "app.log");
154
+ this.level = options.level ?? "debug";
155
+ }
156
+ getLogger(name) {
157
+ if (this.loggers.has(name)) {
158
+ return this.loggers.get(name);
159
+ }
160
+ const logger2 = new FileLogger(name, this.filePath, {
161
+ level: this.level
162
+ });
163
+ this.loggers.set(name, logger2);
164
+ return logger2;
165
+ }
166
+ };
167
+
168
+ // src/index.ts
169
+ import { join as join2 } from "path";
170
+ function nodePlatform(options = {}) {
171
+ return {
172
+ __deferred: true,
173
+ options,
174
+ resolve: () => createNodePlatform(options)
175
+ };
176
+ }
177
+ async function createNodePlatform(options = {}) {
178
+ const dataPath = options.dataPath ?? "./data";
179
+ if (options.logDir) {
180
+ const loggerFactory = new FileLoggerFactory({
181
+ logDir: options.logDir,
182
+ level: options.logLevel ?? "debug"
183
+ });
184
+ setLoggerFactory(loggerFactory);
185
+ } else if (options.logLevel) {
186
+ setLoggerFactory({
187
+ getLogger: (name) => new ConsoleLogger(name, { level: options.logLevel })
188
+ });
189
+ }
190
+ const persistence = await createPersistence(sqliteDriver({ path: join2(dataPath, "agentx.db") }));
191
+ const bashProvider = new NodeBashProvider();
192
+ const eventBus = new EventBusImpl();
193
+ const { createNodeWebSocket } = await import("./WebSocketFactory-SDWPRZVB.js");
194
+ return {
195
+ containerRepository: persistence.containers,
196
+ imageRepository: persistence.images,
197
+ sessionRepository: persistence.sessions,
198
+ eventBus,
199
+ bashProvider,
200
+ webSocketFactory: createNodeWebSocket
201
+ };
202
+ }
203
+ function isDeferredPlatform(value) {
204
+ return typeof value === "object" && value !== null && "__deferred" in value && value.__deferred === true;
205
+ }
206
+ export {
207
+ FileLoggerFactory,
208
+ NodeBashProvider,
209
+ OffsetGenerator,
210
+ SqliteMessageQueue,
211
+ StorageContainerRepository,
212
+ StorageImageRepository,
213
+ StorageSessionRepository,
214
+ WebSocketConnection,
215
+ WebSocketServer,
216
+ createNodePlatform,
217
+ createPersistence,
218
+ isDeferredPlatform,
219
+ memoryDriver,
220
+ nodePlatform,
221
+ sqliteDriver
222
+ };
223
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/bash/NodeBashProvider.ts","../src/logger/FileLoggerFactory.ts"],"sourcesContent":["/**\n * @agentxjs/node-platform\n *\n * Node.js platform for AgentX.\n * Provides implementations for persistence, bash, and network.\n *\n * @example\n * ```typescript\n * import { createNodePlatform } from \"@agentxjs/node-platform\";\n *\n * const platform = await createNodePlatform({ dataPath: \"./data\" });\n * ```\n */\n\nimport type { AgentXPlatform } from \"@agentxjs/core/runtime\";\nimport type { LogLevel } from \"commonxjs/logger\";\nimport { setLoggerFactory, ConsoleLogger } from \"commonxjs/logger\";\nimport { EventBusImpl } from \"@agentxjs/core/event\";\nimport { createPersistence, sqliteDriver } from \"./persistence\";\nimport { NodeBashProvider } from \"./bash/NodeBashProvider\";\nimport { FileLoggerFactory } from \"./logger\";\nimport { join } from \"node:path\";\n\n/**\n * Options for creating a Node platform\n */\nexport interface NodePlatformOptions {\n /**\n * Base path for data storage\n * @default \"./data\"\n */\n dataPath?: string;\n\n /**\n * Directory for log files\n * If provided, enables file logging instead of console\n * @example \".agentx/logs\"\n */\n logDir?: string;\n\n /**\n * Log level\n * @default \"debug\" for file logging, \"info\" for console\n */\n logLevel?: LogLevel;\n}\n\n/**\n * Deferred platform config - resolved lazily\n */\nexport interface DeferredPlatformConfig {\n readonly __deferred: true;\n readonly options: NodePlatformOptions;\n resolve(): Promise<AgentXPlatform>;\n}\n\n/**\n * Create a Node.js platform configuration (deferred initialization)\n *\n * Use this for function-style API. The platform is initialized lazily.\n *\n * @param options - Platform options\n * @returns Deferred platform config\n *\n * @example\n * ```typescript\n * const server = await createServer({\n * platform: nodePlatform({ dataPath: \"./data\" }),\n * });\n * ```\n */\nexport function nodePlatform(options: NodePlatformOptions = {}): DeferredPlatformConfig {\n return {\n __deferred: true,\n options,\n resolve: () => createNodePlatform(options),\n };\n}\n\n/**\n * Create a Node.js platform for AgentX (immediate initialization)\n *\n * @param options - Platform options\n * @returns AgentXPlatform instance\n */\nexport async function createNodePlatform(\n options: NodePlatformOptions = {}\n): Promise<AgentXPlatform> {\n const dataPath = options.dataPath ?? \"./data\";\n\n // Configure logging\n if (options.logDir) {\n const loggerFactory = new FileLoggerFactory({\n logDir: options.logDir,\n level: options.logLevel ?? \"debug\",\n });\n setLoggerFactory(loggerFactory);\n } else if (options.logLevel) {\n setLoggerFactory({\n getLogger: (name: string) => new ConsoleLogger(name, { level: options.logLevel }),\n });\n }\n\n // Create persistence with SQLite\n const persistence = await createPersistence(sqliteDriver({ path: join(dataPath, \"agentx.db\") }));\n\n // Create bash provider\n const bashProvider = new NodeBashProvider();\n\n // Create event bus\n const eventBus = new EventBusImpl();\n\n // Create WebSocket factory (uses ws library for Node.js)\n const { createNodeWebSocket } = await import(\"./network/WebSocketFactory\");\n\n return {\n containerRepository: persistence.containers,\n imageRepository: persistence.images,\n sessionRepository: persistence.sessions,\n eventBus,\n bashProvider,\n webSocketFactory: createNodeWebSocket,\n };\n}\n\n/**\n * Check if value is a deferred platform config\n */\nexport function isDeferredPlatform(value: unknown): value is DeferredPlatformConfig {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"__deferred\" in value &&\n (value as DeferredPlatformConfig).__deferred === true\n );\n}\n\n// Re-export persistence\nexport * from \"./persistence\";\n\n// Re-export bash\nexport { NodeBashProvider } from \"./bash/NodeBashProvider\";\n\n// Re-export mq\nexport { SqliteMessageQueue, OffsetGenerator } from \"./mq\";\n\n// Re-export network\nexport { WebSocketServer, WebSocketConnection } from \"./network\";\n\n// Re-export logger\nexport { FileLoggerFactory, type FileLoggerFactoryOptions } from \"./logger\";\n","/**\n * NodeBashProvider - Node.js implementation of BashProvider\n *\n * Uses execa for subprocess execution with proper timeout,\n * error handling, and cross-platform shell support.\n */\n\nimport { execa } from \"execa\";\nimport type { BashProvider, BashResult, BashOptions } from \"@agentxjs/core/bash\";\nimport { createLogger } from \"commonxjs/logger\";\n\nconst logger = createLogger(\"node-platform/NodeBashProvider\");\n\n/**\n * Default timeout: 30 seconds\n */\nconst DEFAULT_TIMEOUT = 30_000;\n\n/**\n * NodeBashProvider - Executes shell commands via execa\n */\nexport class NodeBashProvider implements BashProvider {\n readonly type = \"child-process\";\n\n async execute(command: string, options?: BashOptions): Promise<BashResult> {\n const timeout = options?.timeout ?? DEFAULT_TIMEOUT;\n\n logger.debug(\"Executing command\", {\n command: command.substring(0, 100),\n cwd: options?.cwd,\n timeout,\n });\n\n const result = await execa({\n shell: true,\n cwd: options?.cwd,\n timeout,\n env: options?.env ? { ...process.env, ...options.env } : undefined,\n reject: false,\n })`${command}`;\n\n logger.debug(\"Command completed\", {\n exitCode: result.exitCode,\n stdoutLength: result.stdout.length,\n stderrLength: result.stderr.length,\n });\n\n return {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode ?? 1,\n };\n }\n}\n","/**\n * FileLoggerFactory - File-based logger for Node.js\n *\n * Writes logs to a file instead of console.\n * Useful for TUI applications where console output interferes with the UI.\n *\n * Usage:\n * tail -f .agentx/logs/app.log\n */\n\nimport { appendFileSync, mkdirSync, existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport type { Logger, LoggerFactory, LogContext, LogLevel } from \"commonxjs/logger\";\n\nexport interface FileLoggerOptions {\n level?: LogLevel;\n timestamps?: boolean;\n}\n\nclass FileLogger implements Logger {\n readonly name: string;\n readonly level: LogLevel;\n private readonly timestamps: boolean;\n private readonly filePath: string;\n private initialized = false;\n\n constructor(name: string, filePath: string, options: FileLoggerOptions = {}) {\n this.name = name;\n this.filePath = filePath;\n this.level = options.level ?? \"debug\";\n this.timestamps = options.timestamps ?? true;\n }\n\n private ensureDir(): void {\n if (this.initialized) return;\n const dir = dirname(this.filePath);\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n this.initialized = 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 this.ensureDir();\n\n const parts: string[] = [];\n\n if (this.timestamps) {\n parts.push(new Date().toISOString());\n }\n\n parts.push(level.padEnd(5));\n parts.push(`[${this.name}]`);\n parts.push(message);\n\n let logLine = parts.join(\" \");\n\n if (context && Object.keys(context).length > 0) {\n logLine += \" \" + JSON.stringify(context);\n }\n\n logLine += \"\\n\";\n\n try {\n appendFileSync(this.filePath, logLine);\n } catch {\n // Fallback to stderr if file write fails\n process.stderr.write(`[FileLogger] Failed to write: ${logLine}`);\n }\n }\n}\n\n/**\n * FileLoggerFactory options\n */\nexport interface FileLoggerFactoryOptions {\n /**\n * Directory for log files\n */\n logDir: string;\n\n /**\n * Log level\n * @default \"debug\"\n */\n level?: LogLevel;\n\n /**\n * Log file name\n * @default \"app.log\"\n */\n filename?: string;\n}\n\n/**\n * FileLoggerFactory - Creates FileLogger instances\n */\nexport class FileLoggerFactory implements LoggerFactory {\n private readonly filePath: string;\n private readonly level: LogLevel;\n private readonly loggers: Map<string, FileLogger> = new Map();\n\n constructor(options: FileLoggerFactoryOptions) {\n this.filePath = join(options.logDir, options.filename ?? \"app.log\");\n this.level = options.level ?? \"debug\";\n }\n\n getLogger(name: string): Logger {\n if (this.loggers.has(name)) {\n return this.loggers.get(name)!;\n }\n\n const logger = new FileLogger(name, this.filePath, {\n level: this.level,\n });\n\n this.loggers.set(name, logger);\n return logger;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAgBA,SAAS,kBAAkB,qBAAqB;AAChD,SAAS,oBAAoB;;;ACV7B,SAAS,aAAa;AAEtB,SAAS,oBAAoB;AAE7B,IAAM,SAAS,aAAa,gCAAgC;AAK5D,IAAM,kBAAkB;AAKjB,IAAM,mBAAN,MAA+C;AAAA,EAC3C,OAAO;AAAA,EAEhB,MAAM,QAAQ,SAAiB,SAA4C;AACzE,UAAM,UAAU,SAAS,WAAW;AAEpC,WAAO,MAAM,q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,qBAAiB,aAAa;AAAA,EAChC,WAAW,QAAQ,UAAU;AAC3B,qBAAiB;AAAA,MACf,WAAW,CAAC,SAAiB,IAAI,cAAc,MAAM,EAAE,OAAO,QAAQ,SAAS,CAAC;AAAA,IAClF,CAAC;AAAA,EACH;AAGA,QAAM,cAAc,MAAM,kBAAkB,aAAa,EAAE,MAAMA,MAAK,UAAU,WAAW,EAAE,CAAC,CAAC;AAG/F,QAAM,eAAe,IAAI,iBAAiB;AAG1C,QAAM,WAAW,IAAI,aAAa;AAGlC,QAAM,EAAE,oBAAoB,IAAI,MAAM,OAAO,gCAA4B;AAEzE,SAAO;AAAA,IACL,qBAAqB,YAAY;AAAA,IACjC,iBAAiB,YAAY;AAAA,IAC7B,mBAAmB,YAAY;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,kBAAkB;AAAA,EACpB;AACF;AAKO,SAAS,mBAAmB,OAAiD;AAClF,SACE,OAAO,UAAU,YACjB,UAAU,QACV,gBAAgB,SACf,MAAiC,eAAe;AAErD;","names":["logger","join"]}
@@ -0,0 +1,63 @@
1
+ import { MessageQueue, QueueConfig, QueueEntry, Unsubscribe } from '@agentxjs/core/mq';
2
+
3
+ /**
4
+ * SqliteMessageQueue - RxJS-based message queue with SQLite persistence
5
+ *
6
+ * - In-memory pub/sub using RxJS Subject (real-time)
7
+ * - SQLite persistence for recovery guarantee
8
+ * - Consumer offset tracking for at-least-once delivery
9
+ */
10
+
11
+ /**
12
+ * SqliteMessageQueue implementation
13
+ */
14
+ declare class SqliteMessageQueue implements MessageQueue {
15
+ private readonly subject;
16
+ private readonly offsetGen;
17
+ private readonly config;
18
+ private readonly db;
19
+ private cleanupTimer?;
20
+ private isClosed;
21
+ private constructor();
22
+ /**
23
+ * Create a new SqliteMessageQueue instance
24
+ */
25
+ static create(path: string, config?: QueueConfig): SqliteMessageQueue;
26
+ publish(topic: string, event: unknown): Promise<string>;
27
+ subscribe(topic: string, handler: (entry: QueueEntry) => void): Unsubscribe;
28
+ ack(consumerId: string, topic: string, offset: string): Promise<void>;
29
+ getOffset(consumerId: string, topic: string): Promise<string | null>;
30
+ recover(topic: string, afterOffset?: string, limit?: number): Promise<QueueEntry[]>;
31
+ close(): Promise<void>;
32
+ /**
33
+ * Cleanup old entries based on retention policy
34
+ */
35
+ private cleanup;
36
+ }
37
+
38
+ /**
39
+ * OffsetGenerator - Generates monotonically increasing offsets
40
+ *
41
+ * Format: "{timestamp_base36}-{sequence_padded}"
42
+ * Example: "lq5x4g2-0001"
43
+ *
44
+ * This format ensures:
45
+ * - Lexicographic ordering matches temporal ordering
46
+ * - Multiple events in same millisecond get unique offsets
47
+ * - Human-readable and compact
48
+ */
49
+ declare class OffsetGenerator {
50
+ private lastTimestamp;
51
+ private sequence;
52
+ /**
53
+ * Generate a new offset
54
+ */
55
+ generate(): string;
56
+ /**
57
+ * Compare two offsets
58
+ * @returns negative if a < b, 0 if a == b, positive if a > b
59
+ */
60
+ static compare(a: string, b: string): number;
61
+ }
62
+
63
+ export { OffsetGenerator, SqliteMessageQueue };
@@ -0,0 +1,10 @@
1
+ import {
2
+ OffsetGenerator,
3
+ SqliteMessageQueue
4
+ } from "../chunk-PK2K7CCJ.js";
5
+ import "../chunk-DGUM43GV.js";
6
+ export {
7
+ OffsetGenerator,
8
+ SqliteMessageQueue
9
+ };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,17 @@
1
+ export { a as WebSocketConnection, W as WebSocketServer } from '../WebSocketConnection-BUL85bFC.js';
2
+ import { WebSocketFactory } from '@agentxjs/core/network';
3
+ import 'ws';
4
+
5
+ /**
6
+ * Node.js WebSocket factory using the ws library
7
+ *
8
+ * Provides WebSocketFactory implementation for @agentxjs/core RpcClient.
9
+ * Browser environments use native WebSocket (the default in RpcClient).
10
+ */
11
+
12
+ /**
13
+ * Create a WebSocket instance using the ws library (Node.js)
14
+ */
15
+ declare const createNodeWebSocket: WebSocketFactory;
16
+
17
+ export { createNodeWebSocket };
@@ -0,0 +1,14 @@
1
+ import {
2
+ WebSocketConnection,
3
+ WebSocketServer
4
+ } from "../chunk-BBZV6B5R.js";
5
+ import {
6
+ createNodeWebSocket
7
+ } from "../chunk-V664KD3R.js";
8
+ import "../chunk-DGUM43GV.js";
9
+ export {
10
+ WebSocketConnection,
11
+ WebSocketServer,
12
+ createNodeWebSocket
13
+ };
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,175 @@
1
+ import { Storage } from 'unstorage';
2
+ import { ContainerRepository, ImageRepository, SessionRepository, ContainerRecord, ImageRecord, ImageMetadata, SessionRecord } from '@agentxjs/core/persistence';
3
+ import { Message } from '@agentxjs/core/agent';
4
+
5
+ /**
6
+ * Persistence Types for Node Provider
7
+ */
8
+
9
+ /**
10
+ * Persistence driver interface
11
+ *
12
+ * Each driver must implement this interface.
13
+ * The createStorage() method is called once during initialization.
14
+ */
15
+ interface PersistenceDriver {
16
+ /**
17
+ * Create the underlying storage instance
18
+ */
19
+ createStorage(): Promise<Storage>;
20
+ }
21
+ /**
22
+ * Persistence - Aggregated repositories
23
+ */
24
+ interface Persistence {
25
+ readonly containers: ContainerRepository;
26
+ readonly images: ImageRepository;
27
+ readonly sessions: SessionRepository;
28
+ }
29
+
30
+ /**
31
+ * Persistence - Core persistence implementation
32
+ *
33
+ * Creates a Persistence instance from a driver.
34
+ * Each driver provides a createStorage() method that returns an unstorage Storage instance.
35
+ */
36
+
37
+ /**
38
+ * Create a Persistence instance from a driver
39
+ *
40
+ * @param driver - The persistence driver to use
41
+ * @returns Promise<Persistence> instance
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * import { createPersistence, memoryDriver } from "@agentxjs/node-platform/persistence";
46
+ *
47
+ * const persistence = await createPersistence(memoryDriver());
48
+ * ```
49
+ */
50
+ declare function createPersistence(driver: PersistenceDriver): Promise<Persistence>;
51
+
52
+ /**
53
+ * SQLite Driver - SQLite database storage
54
+ *
55
+ * Uses commonxjs SQLite abstraction with automatic runtime detection:
56
+ * - Bun: uses bun:sqlite (built-in)
57
+ * - Node.js 22+: uses node:sqlite (built-in)
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * import { createPersistence, sqliteDriver } from "@agentxjs/node-platform/persistence";
62
+ *
63
+ * const persistence = await createPersistence(
64
+ * sqliteDriver({ path: "./data/agentx.db" })
65
+ * );
66
+ * ```
67
+ */
68
+
69
+ interface SqliteDriverOptions {
70
+ /**
71
+ * Path to SQLite database file
72
+ * @example "./data/agentx.db"
73
+ */
74
+ path: string;
75
+ }
76
+ /**
77
+ * Create a SQLite driver
78
+ *
79
+ * @param options - Driver options
80
+ */
81
+ declare function sqliteDriver(options: SqliteDriverOptions): PersistenceDriver;
82
+
83
+ /**
84
+ * Memory Driver - In-memory storage
85
+ *
86
+ * Useful for testing and development.
87
+ * Data is lost when the process exits.
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * import { createPersistence, memoryDriver } from "@agentxjs/node-platform/persistence";
92
+ *
93
+ * const persistence = await createPersistence(memoryDriver());
94
+ * ```
95
+ */
96
+
97
+ /**
98
+ * Create a memory driver
99
+ */
100
+ declare function memoryDriver(): PersistenceDriver;
101
+
102
+ /**
103
+ * StorageContainerRepository - unstorage-based ContainerRepository
104
+ *
105
+ * Uses unstorage for backend-agnostic storage (Memory, Redis, SQLite, etc.)
106
+ */
107
+
108
+ /**
109
+ * StorageContainerRepository - unstorage implementation
110
+ */
111
+ declare class StorageContainerRepository implements ContainerRepository {
112
+ private readonly storage;
113
+ constructor(storage: Storage);
114
+ private key;
115
+ saveContainer(record: ContainerRecord): Promise<void>;
116
+ findContainerById(containerId: string): Promise<ContainerRecord | null>;
117
+ findAllContainers(): Promise<ContainerRecord[]>;
118
+ deleteContainer(containerId: string): Promise<void>;
119
+ containerExists(containerId: string): Promise<boolean>;
120
+ }
121
+
122
+ /**
123
+ * StorageImageRepository - unstorage-based ImageRepository
124
+ *
125
+ * Uses unstorage for backend-agnostic storage (Memory, Redis, SQLite, etc.)
126
+ */
127
+
128
+ /**
129
+ * StorageImageRepository - unstorage implementation
130
+ */
131
+ declare class StorageImageRepository implements ImageRepository {
132
+ private readonly storage;
133
+ constructor(storage: Storage);
134
+ private key;
135
+ private nameIndexKey;
136
+ private containerIndexKey;
137
+ saveImage(record: ImageRecord): Promise<void>;
138
+ findImageById(imageId: string): Promise<ImageRecord | null>;
139
+ findAllImages(): Promise<ImageRecord[]>;
140
+ findImagesByName(name: string): Promise<ImageRecord[]>;
141
+ findImagesByContainerId(containerId: string): Promise<ImageRecord[]>;
142
+ deleteImage(imageId: string): Promise<void>;
143
+ imageExists(imageId: string): Promise<boolean>;
144
+ updateMetadata(imageId: string, metadata: Partial<ImageMetadata>): Promise<void>;
145
+ }
146
+
147
+ /**
148
+ * StorageSessionRepository - unstorage-based SessionRepository
149
+ *
150
+ * Uses unstorage for backend-agnostic storage (Memory, Redis, SQLite, etc.)
151
+ */
152
+
153
+ /**
154
+ * StorageSessionRepository - unstorage implementation
155
+ */
156
+ declare class StorageSessionRepository implements SessionRepository {
157
+ private readonly storage;
158
+ constructor(storage: Storage);
159
+ private key;
160
+ private messagesKey;
161
+ private imageIndexKey;
162
+ private containerIndexKey;
163
+ saveSession(record: SessionRecord): Promise<void>;
164
+ findSessionById(sessionId: string): Promise<SessionRecord | null>;
165
+ findSessionByImageId(imageId: string): Promise<SessionRecord | null>;
166
+ findSessionsByContainerId(containerId: string): Promise<SessionRecord[]>;
167
+ findAllSessions(): Promise<SessionRecord[]>;
168
+ deleteSession(sessionId: string): Promise<void>;
169
+ sessionExists(sessionId: string): Promise<boolean>;
170
+ addMessage(sessionId: string, message: Message): Promise<void>;
171
+ getMessages(sessionId: string): Promise<Message[]>;
172
+ clearMessages(sessionId: string): Promise<void>;
173
+ }
174
+
175
+ export { type Persistence, type PersistenceDriver, type SqliteDriverOptions, StorageContainerRepository, StorageImageRepository, StorageSessionRepository, createPersistence, memoryDriver, sqliteDriver };