home-assistant: states/call-service/config tools, emits state.changed bounded to actuator/contact domains (not attribute ticks), overridable via a watch allowlist. influxdb: health/buckets/flux-query tools — tools-only, since a time-series DB has no lifecycle event to emit here. Typecheck; manifests parse.
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
// influxdb's tools — its own code (novox/hq ADR 0044), importing its own client. They return
|
|
// structured data; the mesh serves them through the sdk's tool harness. Read-only: health, bucket
|
|
// listing, and Flux queries — no write path is exposed.
|
|
|
|
import { registerModuleTools, type ToolDefinition } from "@novox/mesh-sdk/tools";
|
|
import { InfluxDBClient } from "../client.js";
|
|
|
|
export function getInfluxDBTools(influx: InfluxDBClient): ToolDefinition[] {
|
|
return [
|
|
{
|
|
name: "influxdb_health",
|
|
description: "InfluxDB server health and version.",
|
|
input: {},
|
|
run: async () => influx.health(),
|
|
},
|
|
{
|
|
name: "influxdb_list_buckets",
|
|
description: "List InfluxDB buckets in the org, with their retention.",
|
|
input: {},
|
|
run: async () => {
|
|
const buckets = await influx.listBuckets();
|
|
return { count: buckets.length, buckets };
|
|
},
|
|
},
|
|
{
|
|
name: "influxdb_query",
|
|
description:
|
|
"Run a read-only Flux query against InfluxDB and return the parsed rows (plus raw CSV). The query is Flux, e.g. from(bucket:\"default\") |> range(start:-1h).",
|
|
input: { flux: { type: "string", description: "the Flux query to run" } },
|
|
run: async (args) => {
|
|
const { csv, rows } = await influx.query(String(args.flux));
|
|
return { rowCount: rows.length, rows, csv };
|
|
},
|
|
},
|
|
];
|
|
}
|
|
|
|
// The tools exist only when a token is configured; without one, influxdb contributes none rather
|
|
// than failing the whole runtime.
|
|
registerModuleTools("influxdb", (env) => {
|
|
try {
|
|
return getInfluxDBTools(InfluxDBClient.fromEnv(env));
|
|
} catch {
|
|
return [];
|
|
}
|
|
});
|