@axiom-lattice/core 2.1.14 → 2.1.15
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/index.d.mts +130 -2
- package/dist/index.d.ts +130 -2
- package/dist/index.js +327 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +323 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -5237,6 +5237,323 @@ var registerVectorStoreLattice = (key, vectorStore) => vectorStoreLatticeManager
|
|
|
5237
5237
|
var getVectorStoreLattice = (key) => vectorStoreLatticeManager.getVectorStoreLattice(key);
|
|
5238
5238
|
var getVectorStoreClient = (key) => vectorStoreLatticeManager.getVectorStoreClient(key);
|
|
5239
5239
|
|
|
5240
|
+
// src/logger_lattice/LoggerLatticeManager.ts
|
|
5241
|
+
import {
|
|
5242
|
+
LoggerType
|
|
5243
|
+
} from "@axiom-lattice/protocols";
|
|
5244
|
+
|
|
5245
|
+
// src/logger_lattice/PinoLoggerClient.ts
|
|
5246
|
+
import pino from "pino";
|
|
5247
|
+
import "pino-pretty";
|
|
5248
|
+
import "pino-roll";
|
|
5249
|
+
var PinoLoggerClient = class _PinoLoggerClient {
|
|
5250
|
+
constructor(config) {
|
|
5251
|
+
this.config = config;
|
|
5252
|
+
this.context = config.context || {};
|
|
5253
|
+
const loggerConfig = {
|
|
5254
|
+
// Custom timestamp format
|
|
5255
|
+
timestamp: () => `,"@timestamp":"${(/* @__PURE__ */ new Date()).toISOString()}"`,
|
|
5256
|
+
// Base metadata
|
|
5257
|
+
base: {
|
|
5258
|
+
"@version": "1",
|
|
5259
|
+
app_name: "lattice",
|
|
5260
|
+
service_name: config.serviceName || "lattice-service",
|
|
5261
|
+
thread_name: "main",
|
|
5262
|
+
logger_name: config.loggerName || config.name || "lattice-logger"
|
|
5263
|
+
},
|
|
5264
|
+
formatters: {
|
|
5265
|
+
level: (label, number) => {
|
|
5266
|
+
return {
|
|
5267
|
+
level: label.toUpperCase(),
|
|
5268
|
+
level_value: number * 1e3
|
|
5269
|
+
};
|
|
5270
|
+
}
|
|
5271
|
+
}
|
|
5272
|
+
};
|
|
5273
|
+
const useFileLogging = this.shouldUseFileLogging(config);
|
|
5274
|
+
const fileOptions = this.getFileOptions(config);
|
|
5275
|
+
if (useFileLogging && fileOptions) {
|
|
5276
|
+
try {
|
|
5277
|
+
this.pinoLogger = pino(
|
|
5278
|
+
loggerConfig,
|
|
5279
|
+
pino.transport({
|
|
5280
|
+
target: "pino-roll",
|
|
5281
|
+
options: {
|
|
5282
|
+
file: fileOptions.file || "./logs/app",
|
|
5283
|
+
frequency: fileOptions.frequency || "daily",
|
|
5284
|
+
mkdir: fileOptions.mkdir !== false,
|
|
5285
|
+
// Default to true
|
|
5286
|
+
size: fileOptions.size,
|
|
5287
|
+
maxFiles: fileOptions.maxFiles
|
|
5288
|
+
}
|
|
5289
|
+
})
|
|
5290
|
+
);
|
|
5291
|
+
} catch (error) {
|
|
5292
|
+
console.error(
|
|
5293
|
+
"Failed to initialize pino-roll logger, falling back to console",
|
|
5294
|
+
error
|
|
5295
|
+
);
|
|
5296
|
+
this.pinoLogger = pino({
|
|
5297
|
+
...loggerConfig,
|
|
5298
|
+
transport: {
|
|
5299
|
+
target: "pino-pretty",
|
|
5300
|
+
options: {
|
|
5301
|
+
colorize: true
|
|
5302
|
+
}
|
|
5303
|
+
}
|
|
5304
|
+
});
|
|
5305
|
+
}
|
|
5306
|
+
} else {
|
|
5307
|
+
this.pinoLogger = pino({
|
|
5308
|
+
...loggerConfig,
|
|
5309
|
+
transport: {
|
|
5310
|
+
target: "pino-pretty",
|
|
5311
|
+
options: {
|
|
5312
|
+
colorize: true
|
|
5313
|
+
}
|
|
5314
|
+
}
|
|
5315
|
+
});
|
|
5316
|
+
}
|
|
5317
|
+
}
|
|
5318
|
+
/**
|
|
5319
|
+
* Determine if file logging should be used
|
|
5320
|
+
*/
|
|
5321
|
+
shouldUseFileLogging(config) {
|
|
5322
|
+
const hasFileConfig = config.file !== void 0;
|
|
5323
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
5324
|
+
return hasFileConfig || isProduction;
|
|
5325
|
+
}
|
|
5326
|
+
/**
|
|
5327
|
+
* Get file options from config
|
|
5328
|
+
*/
|
|
5329
|
+
getFileOptions(config) {
|
|
5330
|
+
if (!config.file) {
|
|
5331
|
+
if (process.env.NODE_ENV === "production") {
|
|
5332
|
+
return {
|
|
5333
|
+
file: "./logs/app",
|
|
5334
|
+
frequency: "daily",
|
|
5335
|
+
mkdir: true
|
|
5336
|
+
};
|
|
5337
|
+
}
|
|
5338
|
+
return null;
|
|
5339
|
+
}
|
|
5340
|
+
if (typeof config.file === "string") {
|
|
5341
|
+
return {
|
|
5342
|
+
file: config.file,
|
|
5343
|
+
frequency: "daily",
|
|
5344
|
+
mkdir: true
|
|
5345
|
+
};
|
|
5346
|
+
}
|
|
5347
|
+
return config.file;
|
|
5348
|
+
}
|
|
5349
|
+
/**
|
|
5350
|
+
* Get contextual logger with merged context
|
|
5351
|
+
*/
|
|
5352
|
+
getContextualLogger(additionalContext) {
|
|
5353
|
+
const contextObj = {
|
|
5354
|
+
"x-user-id": this.context["x-user-id"] || "",
|
|
5355
|
+
"x-tenant-id": this.context["x-tenant-id"] || "",
|
|
5356
|
+
"x-request-id": this.context["x-request-id"] || "",
|
|
5357
|
+
"x-thread-id": this.context["x-thread-id"] || "",
|
|
5358
|
+
service_name: this.config.serviceName || "lattice-service",
|
|
5359
|
+
logger_name: this.config.loggerName || this.config.name || "lattice-logger",
|
|
5360
|
+
...additionalContext
|
|
5361
|
+
};
|
|
5362
|
+
return this.pinoLogger.child(contextObj);
|
|
5363
|
+
}
|
|
5364
|
+
info(msg, obj) {
|
|
5365
|
+
this.getContextualLogger(obj).info(msg);
|
|
5366
|
+
}
|
|
5367
|
+
error(msg, obj) {
|
|
5368
|
+
this.getContextualLogger(obj).error(msg);
|
|
5369
|
+
}
|
|
5370
|
+
warn(msg, obj) {
|
|
5371
|
+
this.getContextualLogger(obj).warn(msg);
|
|
5372
|
+
}
|
|
5373
|
+
debug(msg, obj) {
|
|
5374
|
+
this.getContextualLogger(obj).debug(msg);
|
|
5375
|
+
}
|
|
5376
|
+
updateContext(context) {
|
|
5377
|
+
this.context = {
|
|
5378
|
+
...this.context,
|
|
5379
|
+
...context
|
|
5380
|
+
};
|
|
5381
|
+
}
|
|
5382
|
+
child(options) {
|
|
5383
|
+
return new _PinoLoggerClient({
|
|
5384
|
+
...this.config,
|
|
5385
|
+
...options,
|
|
5386
|
+
context: {
|
|
5387
|
+
...this.context,
|
|
5388
|
+
...options.context
|
|
5389
|
+
}
|
|
5390
|
+
});
|
|
5391
|
+
}
|
|
5392
|
+
};
|
|
5393
|
+
|
|
5394
|
+
// src/logger_lattice/ConsoleLoggerClient.ts
|
|
5395
|
+
var ConsoleLoggerClient = class _ConsoleLoggerClient {
|
|
5396
|
+
constructor(config) {
|
|
5397
|
+
this.config = config;
|
|
5398
|
+
this.context = config.context || {};
|
|
5399
|
+
}
|
|
5400
|
+
formatMessage(level, msg, obj) {
|
|
5401
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
5402
|
+
const contextStr = Object.keys(this.context).length > 0 ? ` [${JSON.stringify(this.context)}]` : "";
|
|
5403
|
+
const objStr = obj ? ` ${JSON.stringify(obj)}` : "";
|
|
5404
|
+
return `[${timestamp}] [${level}]${contextStr} ${msg}${objStr}`;
|
|
5405
|
+
}
|
|
5406
|
+
info(msg, obj) {
|
|
5407
|
+
console.log(this.formatMessage("INFO", msg, obj));
|
|
5408
|
+
}
|
|
5409
|
+
error(msg, obj) {
|
|
5410
|
+
console.error(this.formatMessage("ERROR", msg, obj));
|
|
5411
|
+
}
|
|
5412
|
+
warn(msg, obj) {
|
|
5413
|
+
console.warn(this.formatMessage("WARN", msg, obj));
|
|
5414
|
+
}
|
|
5415
|
+
debug(msg, obj) {
|
|
5416
|
+
console.debug(this.formatMessage("DEBUG", msg, obj));
|
|
5417
|
+
}
|
|
5418
|
+
updateContext(context) {
|
|
5419
|
+
this.context = {
|
|
5420
|
+
...this.context,
|
|
5421
|
+
...context
|
|
5422
|
+
};
|
|
5423
|
+
}
|
|
5424
|
+
child(options) {
|
|
5425
|
+
const childClient = new _ConsoleLoggerClient({
|
|
5426
|
+
...this.config,
|
|
5427
|
+
...options,
|
|
5428
|
+
context: {
|
|
5429
|
+
...this.context,
|
|
5430
|
+
...options.context
|
|
5431
|
+
}
|
|
5432
|
+
});
|
|
5433
|
+
return childClient;
|
|
5434
|
+
}
|
|
5435
|
+
};
|
|
5436
|
+
|
|
5437
|
+
// src/logger_lattice/LoggerLatticeManager.ts
|
|
5438
|
+
var LoggerLatticeManager = class _LoggerLatticeManager extends BaseLatticeManager {
|
|
5439
|
+
/**
|
|
5440
|
+
* Get LoggerLatticeManager singleton instance
|
|
5441
|
+
*/
|
|
5442
|
+
static getInstance() {
|
|
5443
|
+
if (!_LoggerLatticeManager._instance) {
|
|
5444
|
+
_LoggerLatticeManager._instance = new _LoggerLatticeManager();
|
|
5445
|
+
}
|
|
5446
|
+
return _LoggerLatticeManager._instance;
|
|
5447
|
+
}
|
|
5448
|
+
/**
|
|
5449
|
+
* Get Lattice type prefix
|
|
5450
|
+
*/
|
|
5451
|
+
getLatticeType() {
|
|
5452
|
+
return "loggers";
|
|
5453
|
+
}
|
|
5454
|
+
/**
|
|
5455
|
+
* Register logger Lattice
|
|
5456
|
+
* @param key Lattice key name
|
|
5457
|
+
* @param config Logger configuration
|
|
5458
|
+
* @param client Optional logger client. If not provided, will create based on config type.
|
|
5459
|
+
*/
|
|
5460
|
+
registerLattice(key, config, client) {
|
|
5461
|
+
let loggerClient;
|
|
5462
|
+
if (client) {
|
|
5463
|
+
loggerClient = client;
|
|
5464
|
+
} else {
|
|
5465
|
+
if (config.type === LoggerType.PINO) {
|
|
5466
|
+
loggerClient = new PinoLoggerClient(config);
|
|
5467
|
+
} else if (config.type === LoggerType.CONSOLE) {
|
|
5468
|
+
loggerClient = new ConsoleLoggerClient(config);
|
|
5469
|
+
} else if (config.type === LoggerType.CUSTOM) {
|
|
5470
|
+
throw new Error(
|
|
5471
|
+
`Custom logger client must be provided. Please pass the client to registerLattice.`
|
|
5472
|
+
);
|
|
5473
|
+
} else {
|
|
5474
|
+
loggerClient = new PinoLoggerClient(config);
|
|
5475
|
+
}
|
|
5476
|
+
}
|
|
5477
|
+
const loggerLattice = {
|
|
5478
|
+
key,
|
|
5479
|
+
config,
|
|
5480
|
+
client: loggerClient,
|
|
5481
|
+
// Logger operations
|
|
5482
|
+
info: (msg, obj) => {
|
|
5483
|
+
loggerClient.info(msg, obj);
|
|
5484
|
+
},
|
|
5485
|
+
error: (msg, obj) => {
|
|
5486
|
+
loggerClient.error(msg, obj);
|
|
5487
|
+
},
|
|
5488
|
+
warn: (msg, obj) => {
|
|
5489
|
+
loggerClient.warn(msg, obj);
|
|
5490
|
+
},
|
|
5491
|
+
debug: (msg, obj) => {
|
|
5492
|
+
loggerClient.debug(msg, obj);
|
|
5493
|
+
},
|
|
5494
|
+
updateContext: loggerClient.updateContext ? (context) => {
|
|
5495
|
+
loggerClient.updateContext(context);
|
|
5496
|
+
} : void 0,
|
|
5497
|
+
child: loggerClient.child ? (options) => {
|
|
5498
|
+
return loggerClient.child(options);
|
|
5499
|
+
} : void 0
|
|
5500
|
+
};
|
|
5501
|
+
this.register(key, loggerLattice);
|
|
5502
|
+
}
|
|
5503
|
+
/**
|
|
5504
|
+
* Get LoggerLattice
|
|
5505
|
+
* @param key Lattice key name
|
|
5506
|
+
*/
|
|
5507
|
+
getLoggerLattice(key) {
|
|
5508
|
+
const loggerLattice = this.get(key);
|
|
5509
|
+
if (!loggerLattice) {
|
|
5510
|
+
throw new Error(`LoggerLattice ${key} not found`);
|
|
5511
|
+
}
|
|
5512
|
+
return loggerLattice;
|
|
5513
|
+
}
|
|
5514
|
+
/**
|
|
5515
|
+
* Get all Lattices
|
|
5516
|
+
*/
|
|
5517
|
+
getAllLattices() {
|
|
5518
|
+
return this.getAll();
|
|
5519
|
+
}
|
|
5520
|
+
/**
|
|
5521
|
+
* Check if Lattice exists
|
|
5522
|
+
* @param key Lattice key name
|
|
5523
|
+
*/
|
|
5524
|
+
hasLattice(key) {
|
|
5525
|
+
return this.has(key);
|
|
5526
|
+
}
|
|
5527
|
+
/**
|
|
5528
|
+
* Remove Lattice
|
|
5529
|
+
* @param key Lattice key name
|
|
5530
|
+
*/
|
|
5531
|
+
removeLattice(key) {
|
|
5532
|
+
return this.remove(key);
|
|
5533
|
+
}
|
|
5534
|
+
/**
|
|
5535
|
+
* Clear all Lattices
|
|
5536
|
+
*/
|
|
5537
|
+
clearLattices() {
|
|
5538
|
+
this.clear();
|
|
5539
|
+
}
|
|
5540
|
+
/**
|
|
5541
|
+
* Get Lattice count
|
|
5542
|
+
*/
|
|
5543
|
+
getLatticeCount() {
|
|
5544
|
+
return this.count();
|
|
5545
|
+
}
|
|
5546
|
+
/**
|
|
5547
|
+
* Get Lattice key list
|
|
5548
|
+
*/
|
|
5549
|
+
getLatticeKeys() {
|
|
5550
|
+
return this.keys();
|
|
5551
|
+
}
|
|
5552
|
+
};
|
|
5553
|
+
var loggerLatticeManager = LoggerLatticeManager.getInstance();
|
|
5554
|
+
var registerLoggerLattice = (key, config, client) => loggerLatticeManager.registerLattice(key, config, client);
|
|
5555
|
+
var getLoggerLattice = (key) => loggerLatticeManager.getLoggerLattice(key);
|
|
5556
|
+
|
|
5240
5557
|
// src/index.ts
|
|
5241
5558
|
import * as Protocols from "@axiom-lattice/protocols";
|
|
5242
5559
|
export {
|
|
@@ -5247,17 +5564,20 @@ export {
|
|
|
5247
5564
|
AgentType,
|
|
5248
5565
|
ChunkBuffer,
|
|
5249
5566
|
ChunkBufferLatticeManager,
|
|
5567
|
+
ConsoleLoggerClient,
|
|
5250
5568
|
DefaultScheduleClient,
|
|
5251
5569
|
EmbeddingsLatticeManager,
|
|
5252
5570
|
GraphBuildOptions,
|
|
5253
5571
|
InMemoryAssistantStore,
|
|
5254
5572
|
InMemoryChunkBuffer,
|
|
5255
5573
|
InMemoryThreadStore,
|
|
5574
|
+
LoggerLatticeManager,
|
|
5256
5575
|
MemoryLatticeManager,
|
|
5257
5576
|
MemoryQueueClient,
|
|
5258
5577
|
MemoryScheduleStorage,
|
|
5259
5578
|
MemoryType,
|
|
5260
5579
|
ModelLatticeManager,
|
|
5580
|
+
PinoLoggerClient,
|
|
5261
5581
|
PostgresDatabase,
|
|
5262
5582
|
Protocols,
|
|
5263
5583
|
QueueLatticeManager,
|
|
@@ -5281,6 +5601,7 @@ export {
|
|
|
5281
5601
|
getChunkBuffer,
|
|
5282
5602
|
getEmbeddingsClient,
|
|
5283
5603
|
getEmbeddingsLattice,
|
|
5604
|
+
getLoggerLattice,
|
|
5284
5605
|
getModelLattice,
|
|
5285
5606
|
getNextCronTime,
|
|
5286
5607
|
getQueueLattice,
|
|
@@ -5293,6 +5614,7 @@ export {
|
|
|
5293
5614
|
getVectorStoreLattice,
|
|
5294
5615
|
hasChunkBuffer,
|
|
5295
5616
|
isValidCronExpression,
|
|
5617
|
+
loggerLatticeManager,
|
|
5296
5618
|
modelLatticeManager,
|
|
5297
5619
|
parseCronExpression,
|
|
5298
5620
|
queueLatticeManager,
|
|
@@ -5301,6 +5623,7 @@ export {
|
|
|
5301
5623
|
registerCheckpointSaver,
|
|
5302
5624
|
registerChunkBuffer,
|
|
5303
5625
|
registerEmbeddingsLattice,
|
|
5626
|
+
registerLoggerLattice,
|
|
5304
5627
|
registerModelLattice,
|
|
5305
5628
|
registerQueueLattice,
|
|
5306
5629
|
registerScheduleLattice,
|