UNPKG

openclaw-grafana-lens

Version:

OpenClaw plugin that gives AI agents full Grafana access — 18 composable tools for PromQL/LogQL/TraceQL queries, dashboard creation, alerting, SRE investigation, security monitoring, data collection pipeline management via Grafana Alloy (29 recipes), and

73 lines (72 loc) 2.81 kB
/** * Alloy Config Builder * * Generates valid Alloy syntax (.alloy config files) from TypeScript. * Handles string escaping, identifier validation, and value rendering * to prevent injection attacks and syntax errors. * * Design choice: Template literals with type-safe escaping rather than a * full AST builder. Alloy syntax is HCL-like but NOT HCL — building a * complete TypeScript AST equivalent would be disproportionate effort. * Pipeline patterns are finite and well-structured, making templates the * right 80/20 approach. * * All user-provided values are always placed inside double-quoted string * literals — they never appear as bare identifiers or block names. This * prevents Alloy syntax injection. */ import type { AlloyValue } from "./types.js"; /** * Escape a string value for use in Alloy double-quoted strings. * Handles quotes, backslashes, newlines, and null bytes. */ export declare function escapeString(value: string): string; /** * Validate that a name is a valid Alloy identifier. * Used for component labels and attribute names. */ export declare function validateIdentifier(name: string): boolean; /** * Sanitize a user-provided name into a valid Alloy identifier. * Replaces invalid characters with underscores, ensures it starts with a letter/underscore. */ export declare function sanitizeIdentifier(name: string): string; /** * Render a TypeScript value into valid Alloy syntax. * * - Strings: double-quoted with escaping * - Numbers: bare numeric literals * - Booleans: `true` / `false` * - Arrays: `[item1, item2, ...]` * - Objects: `{ key = value, ... }` */ export declare function renderValue(value: AlloyValue, indent?: number): string; /** * Render an Alloy component target list (array of objects with __address__ keys). */ export declare function renderTargets(targets: Array<{ address: string; labels?: Record<string, string>; }>): string; /** * Builds a complete .alloy config file from component blocks. * Each pipeline is a self-contained file — no cross-file references. */ export declare class AlloyConfigBuilder { private blocks; /** * Add a raw config block. The block should be a complete Alloy component * definition (e.g., `prometheus.scrape "label" { ... }`). */ addBlock(block: string): this; /** * Build the final config file content with management header. */ build(pipelineId: string, recipe: string, pipelineName: string): string; } /** * Generate a unique component label from pipeline ID and a descriptive suffix. * All managed components use the "lens_{id}_{suffix}" naming convention * to prevent collisions with user components or other managed pipelines. */ export declare function componentLabel(pipelineId: string, suffix: string): string;