// Conduit client module — import this when using conduit programmatically. // Usage: const client = create_conduit_client("agent", secret); await client.call_action("list-actions"); import { sign_request } from "./auth.mjs"; const DEFAULT_URL = 'http://localhost:3015'; export function create_conduit_client(username, secret, base_url = process.env.CONDUIT_URL || DEFAULT_URL) { function auth_headers(body_string) { return sign_request(secret, username, body_string); } async function call_action(action, params = {}) { const body_string = JSON.stringify({ action, ...params }); const res = await fetch(`${base_url}/action`, { method: "POST", headers: { "Content-Type": "application/json", ...auth_headers(body_string) }, body: body_string, }); return res.json(); } async function list_actions() { return call_action("list-actions"); } async function get_queue() { const res = await fetch(`${base_url}/queue`, { headers: auth_headers(''), }); return res.json(); } async function resolve_queue_item(id, decision) { const res = await fetch(`${base_url}/queue/${id}/${decision}`, { method: 'POST', headers: auth_headers(''), }); return res.json(); } return { call_action, list_actions, get_queue, resolve_queue_item }; }