CLI migration: - Migrate 11 CLI files from old import pattern to centralized aitbc imports - wallet.py, exchange.py, gpu_marketplace.py, exchange_island.py, monitor.py, cross_chain.py - aitbc_cli.py, handlers (account.py, bridge.py, pool_hub.py), utils (wallet_daemon_client.py) - Replace 'from aitbc.aitbc_logging import' with 'from aitbc import get_logger' - Replace 'from aitbc.http_client import' with 'from aitbc import AITBCHTTPClient' - Replace 'from aitbc.exceptions import' with 'from aitbc import NetworkError' Packages migration: - aitbc-sdk: receipts.py - migrate from httpx to AITBCHTTPClient - aitbc-agent-sdk: 5 files - migrate logging to get_logger - agent.py, compute_provider.py, compute_consumer.py, swarm_coordinator.py, platform_builder.py
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
"""
|
|
Platform Builder - factory for constructing AITBC agent platform configurations
|
|
"""
|
|
|
|
from typing import Dict, List, Any, Optional
|
|
from .agent import Agent, AgentCapabilities, AgentIdentity
|
|
from .compute_provider import ComputeProvider
|
|
from .compute_consumer import ComputeConsumer
|
|
from .swarm_coordinator import SwarmCoordinator
|
|
|
|
from aitbc import get_logger
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
class PlatformBuilder:
|
|
"""Builder pattern for constructing AITBC agent platforms"""
|
|
|
|
def __init__(self, platform_name: str = "default") -> None:
|
|
self.platform_name = platform_name
|
|
self.agents: List[Agent] = []
|
|
self.config: Dict[str, Any] = {}
|
|
|
|
def with_config(self, config: Dict[str, Any]) -> "PlatformBuilder":
|
|
"""Set platform configuration"""
|
|
self.config.update(config)
|
|
return self
|
|
|
|
def add_provider(
|
|
self, name: str, capabilities: Dict[str, Any]
|
|
) -> "PlatformBuilder":
|
|
"""Add a compute provider agent"""
|
|
agent = Agent.create(name, "compute_provider", capabilities)
|
|
self.agents.append(agent)
|
|
logger.info(f"Added provider: {name}")
|
|
return self
|
|
|
|
def add_consumer(
|
|
self, name: str, capabilities: Dict[str, Any]
|
|
) -> "PlatformBuilder":
|
|
"""Add a compute consumer agent"""
|
|
agent = Agent.create(name, "compute_consumer", capabilities)
|
|
self.agents.append(agent)
|
|
logger.info(f"Added consumer: {name}")
|
|
return self
|
|
|
|
def build(self) -> Dict[str, Any]:
|
|
"""Build and return the platform configuration"""
|
|
return {
|
|
"platform_name": self.platform_name,
|
|
"agents": [a.to_dict() for a in self.agents],
|
|
"config": self.config,
|
|
"agent_count": len(self.agents),
|
|
}
|