life
Version:
Life.js is the first fullstack framework to build agentic web applications. It is minimal, extensible, and typesafe. Well, everything you love.
132 lines (117 loc) • 7.42 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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 _chunkBFC2WP6Qjs = require('./chunk-BFC2WP6Q.js');
var _chunk6PEHRAEPjs = require('./chunk-6PEHRAEP.js');
// telemetry/clients/browser.ts
var _uaparserjs = require('ua-parser-js');
var _helpers = require('ua-parser-js/helpers');
var _zod = require('zod'); var _zod2 = _interopRequireDefault(_zod);
var baseAgentClientAttributesSchema = _zod2.default.object({
agentName: _zod2.default.string(),
agentId: _zod2.default.string(),
agentConfig: _chunkBFC2WP6Qjs.agentClientConfig.schema.transform((c) => _chunkBFC2WP6Qjs.agentClientConfig.toTelemetry(c)),
transportProviderName: _zod2.default.string()
});
var telemetryBrowserScopesDefinition = _chunkVLUR4YNDjs.defineScopes.call(void 0, {
client: {
requiredAttributesSchema: _zod2.default.object(),
displayName: "Client"
},
"agent.client": {
requiredAttributesSchema: baseAgentClientAttributesSchema,
displayName: /* @__PURE__ */ _chunk6PEHRAEPjs.__name.call(void 0, (attributes) => `Agent (${_optionalChain([attributes, 'optionalAccess', _ => _.agentName])} - ${_optionalChain([attributes, 'optionalAccess', _2 => _2.agentId, 'access', _3 => _3.replace, 'call', _4 => _4("agent_", ""), 'access', _5 => _5.slice, 'call', _6 => _6(0, 6)])})`, "displayName")
},
"plugin.client": {
requiredAttributesSchema: baseAgentClientAttributesSchema.extend({
pluginName: _zod2.default.string(),
pluginClientConfig: _zod2.default.any()
}),
displayName: /* @__PURE__ */ _chunk6PEHRAEPjs.__name.call(void 0, (attributes) => `Plugin (${_optionalChain([attributes, 'optionalAccess', _7 => _7.pluginName])})`, "displayName")
},
react: {
requiredAttributesSchema: _zod2.default.object(),
displayName: "React"
}
});
var TelemetryBrowserClient = class extends _chunkVLUR4YNDjs.TelemetryClient {
static {
_chunk6PEHRAEPjs.__name.call(void 0, this, "TelemetryBrowserClient");
}
constructor(scope) {
super(telemetryBrowserScopesDefinition, scope);
this.#attachFlushEventListeners();
}
/**
* Attaches event listeners for best-effort flushing of telemetry data
* before the page unloads, loses visibility, or gets hibernated.
*/
#attachFlushEventListeners() {
const flush = /* @__PURE__ */ _chunk6PEHRAEPjs.__name.call(void 0, () => this.flushConsumers().catch(() => ({})), "flush");
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "hidden") flush();
});
window.addEventListener("pagehide", flush);
window.addEventListener("beforeunload", flush);
}
getResource() {
const results = new (0, _uaparserjs.UAParser)().getResult();
const parseEnvironment = /* @__PURE__ */ _chunk6PEHRAEPjs.__name.call(void 0, (_value) => {
if (!_value) return null;
const value = _value.trim().toLowerCase();
if (["development", "production", "staging", "test"].includes(value))
return value;
const alias = {
dev: "development",
prod: "production",
stage: "staging",
test: "test"
}[value];
if (alias) return alias;
return null;
}, "parseEnvironment");
const environment = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(parseEnvironment(_optionalChain([import.meta, 'access', _8 => _8.env, 'optionalAccess', _9 => _9.MODE])), () => ( parseEnvironment(_optionalChain([globalThis, 'access', _10 => _10.process, 'optionalAccess', _11 => _11.env, 'optionalAccess', _12 => _12.NODE_ENV])))), () => ( parseEnvironment(_optionalChain([globalThis, 'access', _13 => _13.process, 'optionalAccess', _14 => _14.env, 'optionalAccess', _15 => _15.NEXT_PUBLIC_ENV])))), () => ( (typeof window !== "undefined" && // biome-ignore lint/performance/useTopLevelRegex: unecessary
/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$/.test(_nullishCoalesce(_optionalChain([globalThis, 'access', _16 => _16.location, 'optionalAccess', _17 => _17.hostname]), () => ( ""))) ? "development" : "production")));
const userAgent = navigator.userAgent.toLowerCase();
return {
platform: "browser",
environment,
lifeVersion: _chunkVLUR4YNDjs.package_default.version,
deviceType: _nullishCoalesce(_optionalChain([results, 'optionalAccess', _18 => _18.device, 'optionalAccess', _19 => _19.type]), () => ( "unknown")),
deviceBrand: _optionalChain([results, 'optionalAccess', _20 => _20.device, 'optionalAccess', _21 => _21.vendor]) || "unknown",
deviceModel: _optionalChain([results, 'optionalAccess', _22 => _22.device, 'optionalAccess', _23 => _23.model]) || "unknown",
osName: _optionalChain([results, 'optionalAccess', _24 => _24.os, 'optionalAccess', _25 => _25.name]) || "unknown",
osVersion: _optionalChain([results, 'optionalAccess', _26 => _26.os, 'optionalAccess', _27 => _27.version]) || "unknown",
cpuArchitecture: _nullishCoalesce(_optionalChain([results, 'optionalAccess', _28 => _28.cpu, 'optionalAccess', _29 => _29.architecture]), () => ( "unknown")),
browserUserAgent: navigator.userAgent,
browserName: _optionalChain([results, 'optionalAccess', _30 => _30.browser, 'optionalAccess', _31 => _31.name]) || "unknown",
browserVersion: _optionalChain([results, 'optionalAccess', _32 => _32.browser, 'optionalAccess', _33 => _33.version]) || "unknown",
browserEngine: _optionalChain([results, 'optionalAccess', _34 => _34.engine, 'optionalAccess', _35 => _35.name]) || "unknown",
isBot: _helpers.isBot.call(void 0, userAgent),
isAiBot: _helpers.isAIBot.call(void 0, userAgent),
schemaVersion: "1"
};
}
getCurrentSpanData() {
return;
}
runWithSpanData(_spanData, fn) {
return fn();
}
};
function createTelemetryClient(scope, requiredAttributes) {
const client = new TelemetryBrowserClient(scope);
for (const [key, value] of Object.entries(requiredAttributes)) client.setAttribute(key, value);
return client;
}
_chunk6PEHRAEPjs.__name.call(void 0, createTelemetryClient, "createTelemetryClient");
// telemetry/helpers/log-level-priority.ts
function logLevelPriority(level) {
if (level === "fatal") return 4;
if (level === "error") return 3;
if (level === "warn") return 2;
if (level === "info") return 1;
else return 0;
}
_chunk6PEHRAEPjs.__name.call(void 0, logLevelPriority, "logLevelPriority");
exports.telemetryBrowserScopesDefinition = telemetryBrowserScopesDefinition; exports.TelemetryBrowserClient = TelemetryBrowserClient; exports.createTelemetryClient = createTelemetryClient; exports.logLevelPriority = logLevelPriority;
//# sourceMappingURL=chunk-EL6AAGQA.js.map