fix: standardize all agent API endpoints to use /api/v1 prefix and update blockchain commands to use local node

- Change all agent endpoints from /agents/* and /v1/agents/* to /api/v1/agents/* for consistency
- Update client job submission endpoint from /v1/jobs to /api/v1/jobs
- Fix blockchain blocks command to query local node at /rpc/blocks-range instead of coordinator
- Fix blockchain peers command to query local node at /rpc/peers with RPC-only mode fallback
- Add proper error handling for blockchain
This commit is contained in:
oib
2026-03-05 10:06:42 +01:00
parent d82600a953
commit 3f3850cbc0
5 changed files with 376 additions and 55 deletions

View File

@@ -52,7 +52,7 @@ def create(ctx, name: str, description: str, workflow_file, verification: str,
try:
with httpx.Client() as client:
response = client.post(
f"{config.coordinator_url}/agents/workflows",
f"{config.coordinator_url}/api/v1/agents/workflows",
headers={"X-Api-Key": config.api_key or ""},
json=workflow_data
)
@@ -96,7 +96,7 @@ def list(ctx, agent_type: Optional[str], status: Optional[str],
try:
with httpx.Client() as client:
response = client.get(
f"{config.coordinator_url}/agents/workflows",
f"{config.coordinator_url}/api/v1/agents/workflows",
headers={"X-Api-Key": config.api_key or ""},
params=params
)
@@ -145,7 +145,7 @@ def execute(ctx, agent_id: str, inputs, verification: str, priority: str, timeou
try:
with httpx.Client() as client:
response = client.post(
f"{config.coordinator_url}/v1/agents/workflows/{agent_id}/execute",
f"{config.coordinator_url}/api/v1/agents/workflows/{agent_id}/execute",
headers={"X-Api-Key": config.api_key or ""},
json=execution_data
)
@@ -177,7 +177,7 @@ def status(ctx, execution_id: str, watch: bool, interval: int):
try:
with httpx.Client() as client:
response = client.get(
f"{config.coordinator_url}/agents/executions/{execution_id}",
f"{config.coordinator_url}/api/v1/agents/executions/{execution_id}",
headers={"X-Api-Key": config.api_key or ""}
)
@@ -223,7 +223,7 @@ def receipt(ctx, execution_id: str, verify: bool, download: Optional[str]):
try:
with httpx.Client() as client:
response = client.get(
f"{config.coordinator_url}/agents/executions/{execution_id}/receipt",
f"{config.coordinator_url}/api/v1/agents/executions/{execution_id}/receipt",
headers={"X-Api-Key": config.api_key or ""}
)
@@ -233,7 +233,7 @@ def receipt(ctx, execution_id: str, verify: bool, download: Optional[str]):
if verify:
# Verify receipt
verify_response = client.post(
f"{config.coordinator_url}/agents/receipts/verify",
f"{config.coordinator_url}/api/v1/agents/receipts/verify",
headers={"X-Api-Key": config.api_key or ""},
json={"receipt": receipt_data}
)
@@ -296,7 +296,7 @@ def create(ctx, name: str, agents: str, description: str, coordination: str):
try:
with httpx.Client() as client:
response = client.post(
f"{config.coordinator_url}/agents/networks",
f"{config.coordinator_url}/api/v1/agents/networks",
headers={"X-Api-Key": config.api_key or ""},
json=network_data
)
@@ -339,7 +339,7 @@ def execute(ctx, network_id: str, task, priority: str):
try:
with httpx.Client() as client:
response = client.post(
f"{config.coordinator_url}/agents/networks/{network_id}/execute",
f"{config.coordinator_url}/api/v1/agents/networks/{network_id}/execute",
headers={"X-Api-Key": config.api_key or ""},
json=execution_data
)
@@ -374,7 +374,7 @@ def status(ctx, network_id: str, metrics: str, real_time: bool):
try:
with httpx.Client() as client:
response = client.get(
f"{config.coordinator_url}/agents/networks/{network_id}/status",
f"{config.coordinator_url}/api/v1/agents/networks/{network_id}/status",
headers={"X-Api-Key": config.api_key or ""},
params=params
)
@@ -405,7 +405,7 @@ def optimize(ctx, network_id: str, objective: str):
try:
with httpx.Client() as client:
response = client.post(
f"{config.coordinator_url}/agents/networks/{network_id}/optimize",
f"{config.coordinator_url}/api/v1/agents/networks/{network_id}/optimize",
headers={"X-Api-Key": config.api_key or ""},
json=optimization_data
)
@@ -456,7 +456,7 @@ def enable(ctx, agent_id: str, mode: str, feedback_source: Optional[str], learni
try:
with httpx.Client() as client:
response = client.post(
f"{config.coordinator_url}/agents/{agent_id}/learning/enable",
f"{config.coordinator_url}/api/v1/agents/{agent_id}/learning/enable",
headers={"X-Api-Key": config.api_key or ""},
json=learning_config
)
@@ -498,7 +498,7 @@ def train(ctx, agent_id: str, feedback, epochs: int):
try:
with httpx.Client() as client:
response = client.post(
f"{config.coordinator_url}/agents/{agent_id}/learning/train",
f"{config.coordinator_url}/api/v1/agents/{agent_id}/learning/train",
headers={"X-Api-Key": config.api_key or ""},
json=training_data
)
@@ -530,7 +530,7 @@ def progress(ctx, agent_id: str, metrics: str):
try:
with httpx.Client() as client:
response = client.get(
f"{config.coordinator_url}/agents/{agent_id}/learning/progress",
f"{config.coordinator_url}/api/v1/agents/{agent_id}/learning/progress",
headers={"X-Api-Key": config.api_key or ""},
params=params
)
@@ -561,7 +561,7 @@ def export(ctx, agent_id: str, format: str, output_path: Optional[str]):
try:
with httpx.Client() as client:
response = client.get(
f"{config.coordinator_url}/agents/{agent_id}/learning/export",
f"{config.coordinator_url}/api/v1/agents/{agent_id}/learning/export",
headers={"X-Api-Key": config.api_key or ""},
params=params
)
@@ -609,7 +609,7 @@ def submit_contribution(ctx, type: str, description: str, github_repo: str, bran
try:
with httpx.Client() as client:
response = client.post(
f"{config.coordinator_url}/agents/contributions",
f"{config.coordinator_url}/api/v1/agents/contributions",
headers={"X-Api-Key": config.api_key or ""},
json=contribution_data
)

View File

@@ -30,25 +30,45 @@ def blockchain():
@click.pass_context
def blocks(ctx, limit: int, from_height: Optional[int]):
"""List recent blocks"""
config = ctx.obj['config']
try:
params = {"limit": limit}
if from_height:
params["from_height"] = from_height
from ..core.config import load_multichain_config
config = load_multichain_config()
if not config.nodes:
node_url = "http://127.0.0.1:8082"
else:
node_url = list(config.nodes.values())[0].endpoint
# Get blocks from the local blockchain node
with httpx.Client() as client:
response = client.get(
f"{config.coordinator_url}/explorer/blocks",
params=params,
headers={"X-Api-Key": config.api_key or ""}
)
if from_height:
# Get blocks range
response = client.get(
f"{node_url}/rpc/blocks-range",
params={"from_height": from_height, "limit": limit},
timeout=5
)
else:
# Get recent blocks starting from head
response = client.get(
f"{node_url}/rpc/blocks-range",
params={"limit": limit},
timeout=5
)
if response.status_code == 200:
data = response.json()
output(data, ctx.obj['output_format'])
blocks_data = response.json()
output(blocks_data, ctx.obj['output_format'])
else:
error(f"Failed to fetch blocks: {response.status_code}")
# Fallback to getting head block if range not available
head_response = client.get(f"{node_url}/rpc/head", timeout=5)
if head_response.status_code == 200:
head_data = head_response.json()
output({
"blocks": [head_data],
"message": f"Showing head block only (height {head_data.get('height', 'unknown')})"
}, ctx.obj['output_format'])
else:
error(f"Failed to get blocks: {response.status_code}")
except Exception as e:
error(f"Network error: {e}")
@@ -166,20 +186,32 @@ def sync_status(ctx):
@click.pass_context
def peers(ctx):
"""List connected peers"""
config = ctx.obj['config']
try:
from ..core.config import load_multichain_config
config = load_multichain_config()
if not config.nodes:
node_url = "http://127.0.0.1:8082"
else:
node_url = list(config.nodes.values())[0].endpoint
# Try to get peers from the local blockchain node
with httpx.Client() as client:
# First try the RPC endpoint for peers
response = client.get(
f"{config.coordinator_url}/v1/health",
headers={"X-Api-Key": config.api_key or ""}
f"{node_url}/rpc/peers",
timeout=5
)
if response.status_code == 200:
peers_data = response.json()
output(peers_data, ctx.obj['output_format'])
else:
error(f"Failed to get peers: {response.status_code}")
# If no peers endpoint, return meaningful message
output({
"peers": [],
"message": "No P2P peers available - node running in RPC-only mode",
"node_url": node_url
}, ctx.obj['output_format'])
except Exception as e:
error(f"Network error: {e}")

View File

@@ -48,7 +48,7 @@ def submit(ctx, job_type: str, prompt: Optional[str], model: Optional[str],
try:
with httpx.Client() as client:
response = client.post(
f"{config.coordinator_url}/v1/jobs",
f"{config.coordinator_url}/api/v1/jobs",
headers={
"Content-Type": "application/json",
"X-Api-Key": config.api_key or ""