# TritonUtils

## Overview

The `TritonUtils` module provides utility functions for stack trace analysis, transaction management, and runtime information capture in the Triton logging framework.

## Stack Trace Analysis

### isNotTriton(stackTraceLine)

* **Description**: Checks if a stack trace line is from internal Triton files
* **Parameters**:
  * `stackTraceLine`: `{string}` Line from stack trace to check
* **Returns**: `{boolean}` True if the line is NOT from internal Triton files
* **Example**:

```javascript
const isUserCode = isNotTriton('at MyComponent.handleClick (/components/c/myComponent.js:15:10)');
```

### isLWCLine(stackTraceLine)

* **Description**: Determines if a stack trace line is from an LWC component
* **Parameters**:
  * `stackTraceLine`: `{string}` Line from stack trace to check
* **Returns**: `{boolean}` True if the line is from an LWC component
* **Example**:

```javascript
const isLWC = isLWCLine('at MyComponent.handleClick (/modules/c/myComponent.js:15:10)');
```

### isComponentLine(stackTraceLine)

* **Description**: Checks if a stack trace line is from a component (LWC or Aura)
* **Parameters**:
  * `stackTraceLine`: `{string}` Line from stack trace to check
* **Returns**: `{boolean}` True if the line is from a component
* **Example**:

```javascript
const isComponent = isComponentLine('at MyComponent.handleClick (/modules/c/myComponent.js:15:10)');
```

### isAuraLine(stackTraceLine)

* **Description**: Determines if a stack trace line is from an Aura component
* **Parameters**:
  * `stackTraceLine`: `{string}` Line from stack trace to check
* **Returns**: `{boolean}` True if the line is from an Aura component
* **Example**:

```javascript
const isAura = isAuraLine('at MyComponent.handleClick (/components/c/myComponent.js:15:10)');
```

### isAura(\[stack])

* **Description**: Determines if a stack trace is from an Aura component
* **Parameters**:
  * `stack`: `{string}` Optional stack trace to analyze. If not provided, gets current stack trace
* **Returns**: `{boolean}` True if the stack trace contains Aura component references
* **Example**:

```javascript
const isAuraComponent = isAura(new Error().stack);
```

## Transaction Management

### generateTransactionId()

* **Description**: Generates a UUID v4 (random UUID)
* **Returns**: `{string}` The generated UUID in format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
* **Example**:

```javascript
const transactionId = generateTransactionId(); // e.g. "550e8400-e29b-41d4-a716-446655440000"
```

## Runtime Information

### captureRuntimeInfo()

* **Description**: Captures comprehensive runtime information about the current environment
* **Returns**: `{Object}` Object containing:
  * Environment info (userAgent, language, platform)
  * Viewport dimensions
  * Theme settings
  * Performance metrics
  * Network info
  * Device info
* **Example**:

```javascript
const runtimeInfo = captureRuntimeInfo();
console.log(runtimeInfo.viewportWidth); // e.g. 1920
console.log(runtimeInfo.platform); // e.g. "Windows"
```

## Component Identification

### extractComponentName(componentLine)

* **Description**: Extracts the component name from a stack trace line
* **Parameters**:
  * `componentLine`: `{string}` Stack trace line containing component info
* **Returns**: `{string}` Component name or 'unknown-component' if not found
* **Example**:

```javascript
const componentName = extractComponentName('at MyComponent.handleClick (/modules/c/myComponent.js:15:10)');
// Returns: "myComponent"
```

### generateComponentId()

* **Description**: Extracts the component identifier from the current stack trace
* **Returns**: `{string}` Component identifier
* **Example**:

```javascript
const componentId = generateComponentId(); // Returns current component name
```

## Performance Metrics

The runtime information capture includes detailed performance metrics:

```javascript
{
    pageLoadTime: number,      // Total page load time
    domInteractive: number,    // Time to interactive
    domContentLoaded: number,  // DOM content loaded time
    firstByte: number,         // Time to first byte
    serverTime: number,        // Server processing time
    firstPaint: number,        // First paint timing
    firstContentfulPaint: number, // First contentful paint timing
    memoryUsage: number,       // JS heap size
    memoryLimit: number        // JS heap limit
}
```

## Network Information

The runtime information capture includes network details:

```javascript
{
    connectionType: string,    // e.g. "4g", "wifi"
    connectionSpeed: number,   // Download speed in Mbps
    connectionRtt: number,     // Round trip time
    saveData: boolean,         // Data saver enabled
    isOnline: boolean         // Online status
}
```

## Device Information

The runtime information capture includes device details:

```javascript
{
    formFactor: "SMALL" | "MEDIUM" | "LARGE",
    screenWidth: number,
    screenHeight: number,
    orientation: string,
    platform: string,
    userAgent: string
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://triton.pharos.ai/pharos-triton/methods-reference/lwc/tritonutils.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
