Пример #1
0
def publish_agent(ctx: Context):
    """Publish an agent."""
    try_to_load_agent_config(ctx)
    check_is_author_logged_in(ctx.agent_config.author)

    name = ctx.agent_config.agent_name
    agent_config_path = os.path.join(ctx.cwd, DEFAULT_AEA_CONFIG_FILE)
    output_tar = os.path.join(ctx.cwd, "{}.tar.gz".format(name))
    _compress(output_tar, agent_config_path)

    data = {
        "name": name,
        "description": ctx.agent_config.description,
        "version": ctx.agent_config.version,
        "connections": ctx.agent_config.connections,
        "protocols": ctx.agent_config.protocols,
        "skills": ctx.agent_config.skills,
    }

    path = "/agents/create"
    logger.debug("Publishing agent {} to Registry ...".format(name))
    resp = request_api("POST",
                       path,
                       data=data,
                       is_auth=True,
                       filepath=output_tar)
    click.echo(
        "Successfully published agent {} to the Registry. Public ID: {}".
        format(name, resp["public_id"]))
Пример #2
0
def freeze(ctx: Context):
    """Get the dependencies."""
    try_to_load_agent_config(ctx)
    for dependency_name, dependency_data in sorted(
        ctx.get_dependencies().items(), key=lambda x: x[0]
    ):
        print(dependency_name + dependency_data.get("version", ""))
Пример #3
0
def _fetch_agent_locally(ctx: Context, public_id: PublicId,
                         click_context) -> None:
    """
    Fetch Agent from local packages.

    :param ctx: Context
    :param public_id: public ID of agent to be fetched.

    :return: None
    """
    packages_path = os.path.basename(DEFAULT_REGISTRY_PATH)
    source_path = _try_get_item_source_path(packages_path, public_id.author,
                                            "agents", public_id.name)
    target_path = os.path.join(ctx.cwd, public_id.name)
    if os.path.exists(target_path):
        raise click.ClickException(
            'Item "{}" already exists in target folder.'.format(
                public_id.name))
    copy_tree(source_path, target_path)

    # add dependencies
    ctx.cwd = target_path
    try_to_load_agent_config(ctx)

    for item_type in ("skill", "connection", "contract", "protocol"):
        item_type_plural = "{}s".format(item_type)
        required_items = getattr(ctx.agent_config, item_type_plural)
        for item_id in required_items:
            try:
                _add_item(click_context, item_type, item_id)
            except SystemExit:
                continue
    click.echo("Agent {} successfully fetched.".format(public_id.name))
Пример #4
0
def search(ctx: Context, registry):
    """Search for components in the registry.

    If called from an agent directory, it will check

    E.g.

        aea search connections
        aea search --registry skills
    """
    if registry:
        ctx.set_config("is_registry", True)
    else:
        # if we are in an agent directory, try to load the configuration file.
        # otherwise, use the default path (i.e. 'packages/' in the current directory.)
        try:
            try_to_load_agent_config(ctx, is_exit_on_except=False)
            # path = Path(DEFAULT_AEA_CONFIG_FILE)
            # fp = open(str(path), mode="r", encoding="utf-8")
            # agent_config = ctx.agent_loader.load(fp)
            registry_directory = ctx.agent_config.registry_path
        except Exception:
            registry_directory = os.path.join(ctx.cwd, DEFAULT_REGISTRY_PATH)

        ctx.set_config("registry_directory", registry_directory)
        logger.debug("Using registry {}".format(registry_directory))
Пример #5
0
def _validate_aea(ctx: Context) -> None:
    """
    Validate aea project.

    :param ctx: the context
    """
    try_to_load_agent_config(ctx)
    _verify_or_create_private_keys(ctx)
Пример #6
0
def publish(ctx: Context, registry):
    """Publish Agent to Registry."""
    try_to_load_agent_config(ctx)
    if not registry:
        # TODO: check agent dependencies are available in local packages dir.
        _save_agent_locally(ctx)
    else:
        publish_agent(ctx)
Пример #7
0
def install(ctx: Context, requirement: Optional[str]):
    """Install the dependencies."""
    try_to_load_agent_config(ctx)

    if requirement:
        logger.debug(
            "Installing the dependencies in '{}'...".format(requirement))
        _install_from_requirement(requirement)
    else:
        logger.debug("Installing all the dependencies...")
        dependencies = ctx.get_dependencies()
        for name, d in dependencies.items():
            _install_dependency(name, d)
Пример #8
0
def fetch_agent(ctx: Context, public_id: PublicId, click_context) -> None:
    """
    Fetch Agent from Registry.

    :param public_id: str public ID of desirable Agent.

    :return: None
    """
    author, name, version = public_id.author, public_id.name, public_id.version
    api_path = "/agents/{}/{}/{}".format(author, name, version)
    resp = request_api("GET", api_path)
    file_url = resp["file"]

    filepath = download_file(file_url, ctx.cwd)
    extract(filepath, ctx.cwd)

    target_folder = os.path.join(ctx.cwd, name)
    ctx.cwd = target_folder
    try_to_load_agent_config(ctx)

    click.echo("Fetching dependencies...")
    for item_type in ("connection", "contract", "skill", "protocol"):
        item_type_plural = item_type + "s"

        # initialize fetched agent with empty folders for custom packages
        custom_items_folder = os.path.join(ctx.cwd, item_type_plural)
        os.makedirs(custom_items_folder)

        config = getattr(ctx.agent_config, item_type_plural)
        for item_public_id in config:
            try:
                _add_item(click_context, item_type, item_public_id)
            except Exception as e:
                rmtree(target_folder)
                raise click.ClickException(
                    'Unable to fetch dependency for agent "{}", aborting. {}'.
                    format(name, e))
    click.echo("Dependencies successfully fetched.")
    click.echo("Agent {} successfully fetched to {}.".format(
        name, target_folder))
Пример #9
0
def publish_agent(ctx: Context):
    """Publish an agent."""
    try_to_load_agent_config(ctx)
    check_is_author_logged_in(ctx.agent_config.author)

    name = ctx.agent_config.agent_name
    config_file_source_path = os.path.join(ctx.cwd, DEFAULT_AEA_CONFIG_FILE)
    output_tar = os.path.join(ctx.cwd, "{}.tar.gz".format(name))

    with tempfile.TemporaryDirectory() as temp_dir:
        package_dir = os.path.join(temp_dir, name)
        os.makedirs(package_dir)
        config_file_target_path = os.path.join(package_dir,
                                               DEFAULT_AEA_CONFIG_FILE)
        shutil.copy(config_file_source_path, config_file_target_path)

        _compress(output_tar, package_dir)

    data = {
        "name": name,
        "description": ctx.agent_config.description,
        "version": ctx.agent_config.version,
        "connections": ctx.agent_config.connections,
        "contracts": ctx.agent_config.contracts,
        "protocols": ctx.agent_config.protocols,
        "skills": ctx.agent_config.skills,
    }

    path = "/agents/create"
    logger.debug("Publishing agent {} to Registry ...".format(name))
    resp = request_api("POST",
                       path,
                       data=data,
                       is_auth=True,
                       filepath=output_tar)
    click.echo(
        "Successfully published agent {} to the Registry. Public ID: {}".
        format(name, resp["public_id"]))
Пример #10
0
def list(ctx: Context):
    """List the installed resources."""
    try_to_load_agent_config(ctx)
Пример #11
0
def get_wealth(ctx: Context, type_):
    """Get the wealth associated with the private key."""
    try_to_load_agent_config(ctx)
    _verify_or_create_private_keys(ctx)
    wealth = _try_get_wealth(ctx, type_)
    click.echo(wealth)
Пример #12
0
def get_address(ctx: Context, type_):
    """Get the address associated with the private key."""
    try_to_load_agent_config(ctx)
    _verify_or_create_private_keys(ctx)
    address = _try_get_address(ctx, type_)
    click.echo(address)
Пример #13
0
def add_key(ctx: Context, type_, file):
    """Add a private key to the wallet."""
    try_to_load_agent_config(ctx)
    _validate_private_key_path(file, type_)
    _try_add_key(ctx, type_, file)
Пример #14
0
def config(ctx: Context):
    """Read or modify a configuration."""
    try_to_load_agent_config(ctx)
Пример #15
0
def generate(ctx: Context):
    """Generate a resource for the agent."""
    try_to_load_agent_config(ctx)
Пример #16
0
def add(ctx: Context, registry):
    """Add a resource to the agent."""
    if registry:
        ctx.set_config("is_registry", True)
    try_to_load_agent_config(ctx)
Пример #17
0
def remove(ctx: Context):
    """Remove a resource from the agent."""
    try_to_load_agent_config(ctx)
Пример #18
0
def generate_wealth(ctx: Context, sync, type_):
    """Generate wealth for address on test network."""
    try_to_load_agent_config(ctx)
    _verify_or_create_private_keys(ctx)
    _try_generate_wealth(ctx, type_, sync)
Пример #19
0
def scaffold(ctx: Context):
    """Scaffold a resource for the agent."""
    try_to_load_agent_config(ctx)
Пример #20
0
def push(ctx: Context, registry):
    """Push item to Registry or save it in local packages."""
    try_to_load_agent_config(ctx)
    ctx.set_config("registry", registry)