Files
claude-code-conduit/client/conduit.mjs
mikael-lovqvists-claude-agent 62d2480cd4 Add --url flag to ccc-client and ccc-queue
Overrides CONDUIT_URL env var. Resolved through load_client_config and
threaded into create_conduit_client as base_url parameter.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 21:20:59 +00:00

44 lines
1.3 KiB
JavaScript

// 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 };
}