fix: remove /v1 prefix from agent API endpoints and resolve variable naming conflicts

- Update all agent command endpoints to remove /v1 prefix for API consistency
- Rename `success` variable to `is_success` in chain.py to avoid conflict with success() function
- Rename `output` parameter to `output_file` in genesis.py for clarity
- Add admin command help tests to verify command structure
- Update blockchain status endpoint from /status to /v1/health in tests
- Mark admin help command as working
This commit is contained in:
oib
2026-03-05 09:13:11 +01:00
parent d0fc3174f3
commit 5273b1866f
13 changed files with 587 additions and 29 deletions

View File

@@ -50,7 +50,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}/v1/agents/workflows",
f"{config.coordinator_url}/agents/workflows",
headers={"X-Api-Key": config.api_key or ""},
json=workflow_data
)
@@ -94,7 +94,7 @@ def list(ctx, agent_type: Optional[str], status: Optional[str],
try:
with httpx.Client() as client:
response = client.get(
f"{config.coordinator_url}/v1/agents/workflows",
f"{config.coordinator_url}/agents/workflows",
headers={"X-Api-Key": config.api_key or ""},
params=params
)
@@ -141,7 +141,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/{agent_id}/execute",
f"{config.coordinator_url}/agents/{agent_id}/execute",
headers={"X-Api-Key": config.api_key or ""},
json=execution_data
)
@@ -173,7 +173,7 @@ def status(ctx, execution_id: str, watch: bool, interval: int):
try:
with httpx.Client() as client:
response = client.get(
f"{config.coordinator_url}/v1/agents/executions/{execution_id}",
f"{config.coordinator_url}/agents/executions/{execution_id}",
headers={"X-Api-Key": config.api_key or ""}
)
@@ -219,7 +219,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}/v1/agents/executions/{execution_id}/receipt",
f"{config.coordinator_url}/agents/executions/{execution_id}/receipt",
headers={"X-Api-Key": config.api_key or ""}
)
@@ -229,7 +229,7 @@ def receipt(ctx, execution_id: str, verify: bool, download: Optional[str]):
if verify:
# Verify receipt
verify_response = client.post(
f"{config.coordinator_url}/v1/agents/receipts/verify",
f"{config.coordinator_url}/agents/receipts/verify",
headers={"X-Api-Key": config.api_key or ""},
json={"receipt": receipt_data}
)
@@ -292,7 +292,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}/v1/agents/networks",
f"{config.coordinator_url}/agents/networks",
headers={"X-Api-Key": config.api_key or ""},
json=network_data
)
@@ -335,7 +335,7 @@ def execute(ctx, network_id: str, task, priority: str):
try:
with httpx.Client() as client:
response = client.post(
f"{config.coordinator_url}/v1/agents/networks/{network_id}/execute",
f"{config.coordinator_url}/agents/networks/{network_id}/execute",
headers={"X-Api-Key": config.api_key or ""},
json=execution_data
)
@@ -370,7 +370,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}/v1/agents/networks/{network_id}/status",
f"{config.coordinator_url}/agents/networks/{network_id}/status",
headers={"X-Api-Key": config.api_key or ""},
params=params
)
@@ -401,7 +401,7 @@ def optimize(ctx, network_id: str, objective: str):
try:
with httpx.Client() as client:
response = client.post(
f"{config.coordinator_url}/v1/agents/networks/{network_id}/optimize",
f"{config.coordinator_url}/agents/networks/{network_id}/optimize",
headers={"X-Api-Key": config.api_key or ""},
json=optimization_data
)
@@ -452,7 +452,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}/v1/agents/{agent_id}/learning/enable",
f"{config.coordinator_url}/agents/{agent_id}/learning/enable",
headers={"X-Api-Key": config.api_key or ""},
json=learning_config
)
@@ -494,7 +494,7 @@ def train(ctx, agent_id: str, feedback, epochs: int):
try:
with httpx.Client() as client:
response = client.post(
f"{config.coordinator_url}/v1/agents/{agent_id}/learning/train",
f"{config.coordinator_url}/agents/{agent_id}/learning/train",
headers={"X-Api-Key": config.api_key or ""},
json=training_data
)
@@ -526,7 +526,7 @@ def progress(ctx, agent_id: str, metrics: str):
try:
with httpx.Client() as client:
response = client.get(
f"{config.coordinator_url}/v1/agents/{agent_id}/learning/progress",
f"{config.coordinator_url}/agents/{agent_id}/learning/progress",
headers={"X-Api-Key": config.api_key or ""},
params=params
)
@@ -557,7 +557,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}/v1/agents/{agent_id}/learning/export",
f"{config.coordinator_url}/agents/{agent_id}/learning/export",
headers={"X-Api-Key": config.api_key or ""},
params=params
)
@@ -605,7 +605,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}/v1/agents/contributions",
f"{config.coordinator_url}/agents/contributions",
headers={"X-Api-Key": config.api_key or ""},
json=contribution_data
)

View File

@@ -215,9 +215,9 @@ def delete(ctx, chain_id, force, confirm):
raise click.Abort()
# Delete chain
success = chain_manager.delete_chain(chain_id, force)
is_success = chain_manager.delete_chain(chain_id, force)
if success:
if is_success:
success(f"Chain {chain_id} deleted successfully!")
else:
error(f"Failed to delete chain {chain_id}")
@@ -240,9 +240,9 @@ def add(ctx, chain_id, node_id):
config = load_multichain_config()
chain_manager = ChainManager(config)
success = chain_manager.add_chain_to_node(chain_id, node_id)
is_success = chain_manager.add_chain_to_node(chain_id, node_id)
if success:
if is_success:
success(f"Chain {chain_id} added to node {node_id} successfully!")
else:
error(f"Failed to add chain {chain_id} to node {node_id}")
@@ -263,9 +263,9 @@ def remove(ctx, chain_id, node_id, migrate):
config = load_multichain_config()
chain_manager = ChainManager(config)
success = chain_manager.remove_chain_from_node(chain_id, node_id, migrate)
is_success = chain_manager.remove_chain_from_node(chain_id, node_id, migrate)
if success:
if is_success:
success(f"Chain {chain_id} removed from node {node_id} successfully!")
else:
error(f"Failed to remove chain {chain_id} from node {node_id}")

View File

@@ -17,11 +17,11 @@ def genesis():
@genesis.command()
@click.argument('config_file', type=click.Path(exists=True))
@click.option('--output', '-o', help='Output file path')
@click.option('--output', '-o', 'output_file', help='Output file path')
@click.option('--template', help='Use predefined template')
@click.option('--format', type=click.Choice(['json', 'yaml']), default='json', help='Output format')
@click.pass_context
def create(ctx, config_file, output, template, format):
def create(ctx, config_file, output_file, template, format):
"""Create genesis block from configuration"""
try:
config = load_multichain_config()
@@ -39,13 +39,13 @@ def create(ctx, config_file, output, template, format):
genesis_block = generator.create_genesis(genesis_config)
# Determine output file
if output is None:
if output_file is None:
chain_id = genesis_block.chain_id
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
output = f"genesis_{chain_id}_{timestamp}.{format}"
output_file = f"genesis_{chain_id}_{timestamp}.{format}"
# Save genesis block
output_path = Path(output)
output_path = Path(output_file)
output_path.parent.mkdir(parents=True, exist_ok=True)
if format == 'yaml':
@@ -62,7 +62,7 @@ def create(ctx, config_file, output, template, format):
"Purpose": genesis_block.purpose,
"Name": genesis_block.name,
"Genesis Hash": genesis_block.hash,
"Output File": output,
"Output File": output_file,
"Format": format
}