import { tool } from "@opencode-ai/plugin"; import { getInternalBridgeConfig } from "../internalBridge.js"; export default tool({ description: "Query one authorized operational data source through TJWater Server. Sources are finite and task-scoped; arbitrary URLs are not supported. peripheral_work_orders contains work-order and complaint business records. peripheral_observations is point/time-window monitoring observations, not complaint text, and requires point_id, start and end. Treat origin=synthetic as synthetic evidence. If truncated=true, do not infer that the unreturned full range has no anomalies.", args: { source: tool.schema.enum([ "workbench_runtime", "scada_devices", "scada_readings", "peripheral_points", "peripheral_work_orders", "peripheral_observations", "peripheral_test_data", ]), device_ids: tool.schema.array(tool.schema.string()).optional(), point_id: tool.schema.string().optional(), start: tool.schema.string().optional(), end: tool.schema.string().optional(), }, async execute(query, context) { const { baseUrl, internalToken } = getInternalBridgeConfig(); const response = await fetch(`${baseUrl}/internal/operational-task/data-query`, { method: "POST", headers: { "Content-Type": "application/json", "x-agent-internal-token": internalToken }, body: JSON.stringify({ session_id: context.sessionID, query }), }); const text = await response.text(); if (!response.ok) throw new Error(`task data query failed (${response.status}): ${text}`); return text; }, });