naas_abi.cli
What it is
A small interactive CLI module that scaffolds ABI modules and components by copying from src/core/__templates__, performing string substitutions, and (for modules) enabling the new module in YAML config.
Public API
-
format_module_name(name: str) -> str
Normalize a module name to lowercase, underscore-separated, and alphanumeric/underscore only. -
get_component_selection() -> dict
Interactive prompt to choose which template components to include in a new module. Ifagentsis selected,modelsis automatically included. -
enable_module_in_config(module_path: str) -> None
Attempts to enable a module in a YAML config by adding/updating an entry inmodules: [{path, enabled}]. Choosesconfig.{ENV}.yamlwhen possible, otherwiseconfig.yaml. -
create_new_module() -> None
Interactive scaffolding:- asks for module name and destination (one of predefined
src/...roots) - copies template base files and selected component directories
- rewrites references in
.py,.md,.ttlfiles - renames files containing
Template - calls
enable_module_in_config(...)
- asks for module name and destination (one of predefined
-
create_agent() -> None
Interactive agent scaffolding:- copies
TemplateAgent.pyandTemplateAgent_test.pyinto a target.../agentsfolder - adjusts some import strings based on relative path
- creates/copies a
models/folder from templates if missing (required for agents)
- copies
-
create_component(component_type: str, template_files: list[str], file_suffix: str) -> None
Generic interactive scaffolding for:- integrations, workflows, pipelines (Python + pytest file)
- ontologies (two
.ttlfiles)
Copies template files, replacesTemplate/templatetokens, and rewrites some import strings for Python files.
-
create_integration() -> None
Wrapper forcreate_component("integration", ["TemplateIntegration.py", "TemplateIntegration_test.py"], "Integration"). -
create_workflow() -> None
Wrapper forcreate_component("workflow", ["TemplateWorkflow.py", "TemplateWorkflow_test.py"], "Workflow"). -
create_pipeline() -> None
Wrapper forcreate_component("pipeline", ["TemplatePipeline.py", "TemplatePipeline_test.py"], "Pipeline"). -
create_ontology() -> None
Wrapper forcreate_component("ontology", ["TemplateOntology.ttl", "TemplateSparqlQueries.ttl"], "Ontology"). -
main() -> None
Dispatches onsys.argv[1]:create-module,create-agent,create-integration,create-workflow,create-pipeline,create-ontology
Configuration/Dependencies
- Runtime dependencies:
rich(Console,Prompt) for interactive I/OPyYAML(yaml.safe_load,yaml.dump) for config updates
- Filesystem expectations:
- Templates are read from
src/core/__templates__/... - Module creation targets one of:
src/core/<module_name>src/custom/<module_name>src/marketplace/applications/<module_name>src/marketplace/domains/<module_name>
- Templates are read from
- Config update behavior (
enable_module_in_config):- Uses
ENVenvironment variable when set - Otherwise may read
config.yamland, if configured with adotenvsecret adapter, attempts to resolveENVfrom that.envvia:naas_abi_core.services.secret.adaptors.secondary.dotenv_secret_secondaryadaptor.DotenvSecretSecondaryAdaptor - Updates
config.{ENV}.yamlif resolved and present; falls back toconfig.yaml
- Uses
Usage
Run as a module script (command dispatch)
import sys
from naas_abi import cli
sys.argv = ["naas-abi", "create-module"]
cli.main()
Call a specific interactive scaffolder
from naas_abi.cli import create_integration
create_integration()
Caveats
- This CLI is interactive (uses
Prompt.ask); it is not suitable for non-interactive automation without additional wrapping/mocking. - Scaffolding relies on the presence and structure of
src/core/__templates__. Missing templates will raise filesystem errors during creation. - Config updates are best-effort; failures are caught and reported to the console (module creation proceeds unless earlier steps fail).
- Name validation differs by scaffold:
- module names are normalized via
format_module_nameand must match^[a-z][a-z0-9_\-\.]*$after formatting - component/agent names must match
^[a-zA-Z][a-zA-Z0-9_]*$(no hyphens/dots)
- module names are normalized via