Files
claude-code-conduit/client/conduit.mjs
mikael-lovqvists-claude-agent 507eb7584d Fix ccc-queue triggering client main() on import
Move resolve_queue_item into conduit.mjs factory and have ccc-queue
import from there instead of index.mjs, which auto-executes main().

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

44 lines
1.2 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 BASE_URL = process.env.CONDUIT_URL || "http://localhost:3015";
export function create_conduit_client(username, secret) {
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 };
}