life
Version:
Life.js is the first fullstack framework to build agentic web applications. It is minimal, extensible, and typesafe. Well, everything you love.
187 lines (166 loc) • 7.68 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkVLUR4YNDjs = require('./chunk-VLUR4YND.js');
var _chunkHPM3R2DVjs = require('./chunk-HPM3R2DV.js');
var _chunk22H3U7VVjs = require('./chunk-22H3U7VV.js');
var _chunk6PEHRAEPjs = require('./chunk-6PEHRAEP.js');
// telemetry/clients/node.ts
var _async_hooks = require('async_hooks');
var _os = require('os'); var _os2 = _interopRequireDefault(_os);
var _zod = require('zod'); var _zod2 = _interopRequireDefault(_zod);
var baseAgentServerAttributesSchema = _zod2.default.object({
agentName: _zod2.default.string(),
agentId: _zod2.default.string(),
agentSha: _zod2.default.string(),
agentConfig: _chunkHPM3R2DVjs.agentServerConfig.schema.transform((c) => _chunkHPM3R2DVjs.agentServerConfig.toTelemetry(c)),
transportProviderName: _zod2.default.string(),
llmProviderName: _zod2.default.string(),
sttProviderName: _zod2.default.string(),
eouProviderName: _zod2.default.string(),
ttsProviderName: _zod2.default.string(),
vadProviderName: _zod2.default.string()
});
var telemetryNodeScopesDefinition = _chunkVLUR4YNDjs.defineScopes.call(void 0, {
compiler: {
displayName: "Compiler",
requiredAttributesSchema: _zod2.default.object({
watch: _zod2.default.boolean()
})
},
cli: {
displayName: "CLI",
requiredAttributesSchema: _zod2.default.object({
command: _zod2.default.string(),
// e.g. "dev", "build", "start", "init"
args: _zod2.default.array(_zod2.default.string())
})
},
server: {
displayName: "Server",
requiredAttributesSchema: _zod2.default.object({
watch: _zod2.default.boolean()
})
},
webrtc: {
displayName: "WebRTC",
requiredAttributesSchema: _zod2.default.object()
},
"agent.process": {
displayName: /* @__PURE__ */ _chunk6PEHRAEPjs.__name.call(void 0, (attributes) => `Agent Process (${_optionalChain([attributes, 'optionalAccess', _ => _.agentId, 'optionalAccess', _2 => _2.replace, 'call', _3 => _3("agent_", ""), 'access', _4 => _4.slice, 'call', _5 => _5(0, 6)])})`, "displayName"),
requiredAttributesSchema: _zod2.default.object({
agentId: _zod2.default.string()
})
},
"agent.server": {
displayName: /* @__PURE__ */ _chunk6PEHRAEPjs.__name.call(void 0, (attributes) => `Agent (${_optionalChain([attributes, 'optionalAccess', _6 => _6.agentName])} - ${_optionalChain([attributes, 'optionalAccess', _7 => _7.agentId, 'optionalAccess', _8 => _8.replace, 'call', _9 => _9("agent_", ""), 'access', _10 => _10.slice, 'call', _11 => _11(0, 6)])})`, "displayName"),
requiredAttributesSchema: baseAgentServerAttributesSchema
},
"plugin.server": {
displayName: /* @__PURE__ */ _chunk6PEHRAEPjs.__name.call(void 0, (attributes) => `Plugin (${_optionalChain([attributes, 'optionalAccess', _12 => _12.pluginName])})`, "displayName"),
requiredAttributesSchema: baseAgentServerAttributesSchema.extend({
pluginName: _zod2.default.string(),
pluginServerConfig: _zod2.default.any()
})
}
});
var TelemetryNodeClient = class extends _chunkVLUR4YNDjs.TelemetryClient {
static {
_chunk6PEHRAEPjs.__name.call(void 0, this, "TelemetryNodeClient");
}
#spanDataContext = new (0, _async_hooks.AsyncLocalStorage)();
constructor(scope) {
super(telemetryNodeScopesDefinition, scope);
}
getResource() {
return {
platform: "node",
environment: process.env.NODE_ENV || "development",
isCi: Boolean(process.env.CI),
nodeVersion: process.version,
lifeVersion: _chunkVLUR4YNDjs.package_default.version,
osName: _os2.default.platform(),
osVersion: _os2.default.release(),
cpuCount: _os2.default.cpus().length,
cpuArchitecture: _os2.default.arch(),
schemaVersion: "1"
};
}
getCurrentSpanData() {
return this.#spanDataContext.getStore();
}
runWithSpanData(spanData, fn) {
return this.#spanDataContext.run(spanData, fn);
}
};
function createTelemetryClient(scope, requiredAttributes) {
const client = new TelemetryNodeClient(scope);
for (const [key, value] of Object.entries(requiredAttributes)) client.setAttribute(key, value);
return client;
}
_chunk6PEHRAEPjs.__name.call(void 0, createTelemetryClient, "createTelemetryClient");
// telemetry/helpers/patch-console.ts
var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
var pipeConsoleToTelemetryClient = /* @__PURE__ */ _chunk6PEHRAEPjs.__name.call(void 0, (telemetry) => {
const consoleMethods = ["log", "error", "warn", "info", "debug"];
for (const method of consoleMethods) {
console[method] = (...args) => {
const logLine = args.map((arg) => String(arg)).join(" ");
let logFn;
if (method === "error") logFn = telemetry.log.error;
else if (method === "warn") logFn = telemetry.log.warn;
else if (method === "info") logFn = telemetry.log.info;
else if (method === "debug") logFn = telemetry.log.debug;
else logFn = telemetry.log.info;
logFn({ message: `${_chalk2.default.italic.gray(`(from console.${method})`)} ${logLine}` });
};
}
}, "pipeConsoleToTelemetryClient");
// shared/process-stats.ts
var ProcessStats = class {
static {
_chunk6PEHRAEPjs.__name.call(void 0, this, "ProcessStats");
}
#lastCpuUsage = process.cpuUsage();
#lastSampleTime = Date.now();
#cpu = {
usedPercent: 0,
usedNs: 0
};
constructor() {
this.#updateCpuStats();
const interval = setInterval(() => this.#updateCpuStats(), 1e3);
interval.unref();
}
#updateCpuStats() {
const currentCpuUsage = process.cpuUsage();
const currentTime = Date.now();
const deltaTime = currentTime - this.#lastSampleTime;
if (deltaTime > 0) {
const deltaCpu = currentCpuUsage.user - this.#lastCpuUsage.user + (currentCpuUsage.system - this.#lastCpuUsage.system);
const cpuPercent = deltaCpu / (deltaTime * 1e3) * 100;
this.#cpu.usedPercent = Math.min(100, Math.max(0, cpuPercent));
}
this.#cpu.usedNs = (currentCpuUsage.user + currentCpuUsage.system) * 1e3;
this.#lastCpuUsage = currentCpuUsage;
this.#lastSampleTime = currentTime;
}
get() {
try {
const memoryUsed = process.memoryUsage().rss;
const totalMemory = _os2.default.totalmem();
const freeMemory = _os2.default.freemem();
return _chunk22H3U7VVjs.success.call(void 0, {
cpu: this.#cpu,
memory: {
usedPercent: memoryUsed / totalMemory * 100,
totalBytes: totalMemory,
freeBytes: freeMemory,
usedBytes: memoryUsed
}
});
} catch (error) {
return _chunk22H3U7VVjs.failure.call(void 0, { code: "Unknown", cause: error });
}
}
};
exports.telemetryNodeScopesDefinition = telemetryNodeScopesDefinition; exports.TelemetryNodeClient = TelemetryNodeClient; exports.createTelemetryClient = createTelemetryClient; exports.pipeConsoleToTelemetryClient = pipeConsoleToTelemetryClient; exports.ProcessStats = ProcessStats;
//# sourceMappingURL=chunk-5EKUVSA3.js.map