naas-abi-core 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. naas_abi_core-1.0.0/.gitignore +96 -0
  2. naas_abi_core-1.0.0/=0.9.13 +6 -0
  3. naas_abi_core-1.0.0/CHANGELOG.md +67 -0
  4. naas_abi_core-1.0.0/PKG-INFO +75 -0
  5. naas_abi_core-1.0.0/README.md +45 -0
  6. naas_abi_core-1.0.0/naas_abi_core/__init__.py +1 -0
  7. naas_abi_core-1.0.0/naas_abi_core/apps/api/api.py +242 -0
  8. naas_abi_core-1.0.0/naas_abi_core/apps/api/api_test.py +281 -0
  9. naas_abi_core-1.0.0/naas_abi_core/apps/api/openapi_doc.py +307 -0
  10. naas_abi_core-1.0.0/naas_abi_core/apps/mcp/mcp_server.py +243 -0
  11. naas_abi_core-1.0.0/naas_abi_core/apps/mcp/mcp_server_test.py +163 -0
  12. naas_abi_core-1.0.0/naas_abi_core/apps/terminal_agent/main.py +555 -0
  13. naas_abi_core-1.0.0/naas_abi_core/apps/terminal_agent/terminal_style.py +175 -0
  14. naas_abi_core-1.0.0/naas_abi_core/cli/__init__.py +53 -0
  15. naas_abi_core-1.0.0/naas_abi_core/cli/agent.py +30 -0
  16. naas_abi_core-1.0.0/naas_abi_core/cli/chat.py +26 -0
  17. naas_abi_core-1.0.0/naas_abi_core/cli/config.py +49 -0
  18. naas_abi_core-1.0.0/naas_abi_core/cli/init.py +13 -0
  19. naas_abi_core-1.0.0/naas_abi_core/cli/module.py +28 -0
  20. naas_abi_core-1.0.0/naas_abi_core/cli/new.py +13 -0
  21. naas_abi_core-1.0.0/naas_abi_core/cli/secret.py +79 -0
  22. naas_abi_core-1.0.0/naas_abi_core/engine/Engine.py +87 -0
  23. naas_abi_core-1.0.0/naas_abi_core/engine/EngineProxy.py +109 -0
  24. naas_abi_core-1.0.0/naas_abi_core/engine/Engine_test.py +6 -0
  25. naas_abi_core-1.0.0/naas_abi_core/engine/IEngine.py +91 -0
  26. naas_abi_core-1.0.0/naas_abi_core/engine/conftest.py +45 -0
  27. naas_abi_core-1.0.0/naas_abi_core/engine/engine_configuration/EngineConfiguration.py +160 -0
  28. naas_abi_core-1.0.0/naas_abi_core/engine/engine_configuration/EngineConfiguration_GenericLoader.py +49 -0
  29. naas_abi_core-1.0.0/naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService.py +131 -0
  30. naas_abi_core-1.0.0/naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService_test.py +26 -0
  31. naas_abi_core-1.0.0/naas_abi_core/engine/engine_configuration/EngineConfiguration_SecretService.py +116 -0
  32. naas_abi_core-1.0.0/naas_abi_core/engine/engine_configuration/EngineConfiguration_TripleStoreService.py +171 -0
  33. naas_abi_core-1.0.0/naas_abi_core/engine/engine_configuration/EngineConfiguration_VectorStoreService.py +65 -0
  34. naas_abi_core-1.0.0/naas_abi_core/engine/engine_configuration/EngineConfiguration_test.py +9 -0
  35. naas_abi_core-1.0.0/naas_abi_core/engine/engine_configuration/utils/PydanticModelValidator.py +15 -0
  36. naas_abi_core-1.0.0/naas_abi_core/engine/engine_loaders/EngineModuleLoader.py +302 -0
  37. naas_abi_core-1.0.0/naas_abi_core/engine/engine_loaders/EngineOntologyLoader.py +16 -0
  38. naas_abi_core-1.0.0/naas_abi_core/engine/engine_loaders/EngineServiceLoader.py +47 -0
  39. naas_abi_core-1.0.0/naas_abi_core/integration/__init__.py +7 -0
  40. naas_abi_core-1.0.0/naas_abi_core/integration/integration.py +28 -0
  41. naas_abi_core-1.0.0/naas_abi_core/models/Model.py +198 -0
  42. naas_abi_core-1.0.0/naas_abi_core/models/OpenRouter.py +15 -0
  43. naas_abi_core-1.0.0/naas_abi_core/models/OpenRouter_test.py +36 -0
  44. naas_abi_core-1.0.0/naas_abi_core/module/Module.py +245 -0
  45. naas_abi_core-1.0.0/naas_abi_core/module/ModuleAgentLoader.py +49 -0
  46. naas_abi_core-1.0.0/naas_abi_core/module/ModuleUtils.py +20 -0
  47. naas_abi_core-1.0.0/naas_abi_core/modules/templatablesparqlquery/README.md +196 -0
  48. naas_abi_core-1.0.0/naas_abi_core/modules/templatablesparqlquery/__init__.py +39 -0
  49. naas_abi_core-1.0.0/naas_abi_core/modules/templatablesparqlquery/ontologies/TemplatableSparqlQueryOntology.ttl +116 -0
  50. naas_abi_core-1.0.0/naas_abi_core/modules/templatablesparqlquery/workflows/GenericWorkflow.py +48 -0
  51. naas_abi_core-1.0.0/naas_abi_core/modules/templatablesparqlquery/workflows/TemplatableSparqlQueryLoader.py +192 -0
  52. naas_abi_core-1.0.0/naas_abi_core/pipeline/__init__.py +6 -0
  53. naas_abi_core-1.0.0/naas_abi_core/pipeline/pipeline.py +70 -0
  54. naas_abi_core-1.0.0/naas_abi_core/services/__init__.py +0 -0
  55. naas_abi_core-1.0.0/naas_abi_core/services/agent/Agent.py +1619 -0
  56. naas_abi_core-1.0.0/naas_abi_core/services/agent/AgentMemory_test.py +28 -0
  57. naas_abi_core-1.0.0/naas_abi_core/services/agent/Agent_test.py +214 -0
  58. naas_abi_core-1.0.0/naas_abi_core/services/agent/IntentAgent.py +1171 -0
  59. naas_abi_core-1.0.0/naas_abi_core/services/agent/IntentAgent_test.py +139 -0
  60. naas_abi_core-1.0.0/naas_abi_core/services/agent/beta/Embeddings.py +180 -0
  61. naas_abi_core-1.0.0/naas_abi_core/services/agent/beta/IntentMapper.py +119 -0
  62. naas_abi_core-1.0.0/naas_abi_core/services/agent/beta/LocalModel.py +88 -0
  63. naas_abi_core-1.0.0/naas_abi_core/services/agent/beta/VectorStore.py +89 -0
  64. naas_abi_core-1.0.0/naas_abi_core/services/agent/test_agent_memory.py +278 -0
  65. naas_abi_core-1.0.0/naas_abi_core/services/agent/test_postgres_integration.py +145 -0
  66. naas_abi_core-1.0.0/naas_abi_core/services/cache/CacheFactory.py +31 -0
  67. naas_abi_core-1.0.0/naas_abi_core/services/cache/CachePort.py +63 -0
  68. naas_abi_core-1.0.0/naas_abi_core/services/cache/CacheService.py +246 -0
  69. naas_abi_core-1.0.0/naas_abi_core/services/cache/CacheService_test.py +85 -0
  70. naas_abi_core-1.0.0/naas_abi_core/services/cache/adapters/secondary/CacheFSAdapter.py +39 -0
  71. naas_abi_core-1.0.0/naas_abi_core/services/object_storage/ObjectStorageFactory.py +57 -0
  72. naas_abi_core-1.0.0/naas_abi_core/services/object_storage/ObjectStoragePort.py +47 -0
  73. naas_abi_core-1.0.0/naas_abi_core/services/object_storage/ObjectStorageService.py +41 -0
  74. naas_abi_core-1.0.0/naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterFS.py +52 -0
  75. naas_abi_core-1.0.0/naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterNaas.py +131 -0
  76. naas_abi_core-1.0.0/naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterS3.py +171 -0
  77. naas_abi_core-1.0.0/naas_abi_core/services/ontology/OntologyPorts.py +36 -0
  78. naas_abi_core-1.0.0/naas_abi_core/services/ontology/OntologyService.py +17 -0
  79. naas_abi_core-1.0.0/naas_abi_core/services/ontology/adaptors/secondary/OntologyService_SecondaryAdaptor_NERPort.py +37 -0
  80. naas_abi_core-1.0.0/naas_abi_core/services/secret/Secret.py +138 -0
  81. naas_abi_core-1.0.0/naas_abi_core/services/secret/SecretPorts.py +40 -0
  82. naas_abi_core-1.0.0/naas_abi_core/services/secret/Secret_test.py +65 -0
  83. naas_abi_core-1.0.0/naas_abi_core/services/secret/adaptors/secondary/Base64Secret.py +57 -0
  84. naas_abi_core-1.0.0/naas_abi_core/services/secret/adaptors/secondary/Base64Secret_test.py +39 -0
  85. naas_abi_core-1.0.0/naas_abi_core/services/secret/adaptors/secondary/NaasSecret.py +81 -0
  86. naas_abi_core-1.0.0/naas_abi_core/services/secret/adaptors/secondary/NaasSecret_test.py +25 -0
  87. naas_abi_core-1.0.0/naas_abi_core/services/secret/adaptors/secondary/dotenv_secret_secondaryadaptor.py +26 -0
  88. naas_abi_core-1.0.0/naas_abi_core/services/triple_store/TripleStoreFactory.py +116 -0
  89. naas_abi_core-1.0.0/naas_abi_core/services/triple_store/TripleStorePorts.py +223 -0
  90. naas_abi_core-1.0.0/naas_abi_core/services/triple_store/TripleStoreService.py +419 -0
  91. naas_abi_core-1.0.0/naas_abi_core/services/triple_store/adaptors/secondary/AWSNeptune.py +1284 -0
  92. naas_abi_core-1.0.0/naas_abi_core/services/triple_store/adaptors/secondary/AWSNeptune_test.py +284 -0
  93. naas_abi_core-1.0.0/naas_abi_core/services/triple_store/adaptors/secondary/Oxigraph.py +597 -0
  94. naas_abi_core-1.0.0/naas_abi_core/services/triple_store/adaptors/secondary/Oxigraph_test.py +1474 -0
  95. naas_abi_core-1.0.0/naas_abi_core/services/triple_store/adaptors/secondary/TripleStoreService__SecondaryAdaptor__Filesystem.py +223 -0
  96. naas_abi_core-1.0.0/naas_abi_core/services/triple_store/adaptors/secondary/TripleStoreService__SecondaryAdaptor__ObjectStorage.py +234 -0
  97. naas_abi_core-1.0.0/naas_abi_core/services/triple_store/adaptors/secondary/base/TripleStoreService__SecondaryAdaptor__FileBase.py +18 -0
  98. naas_abi_core-1.0.0/naas_abi_core/services/vector_store/IVectorStorePort.py +101 -0
  99. naas_abi_core-1.0.0/naas_abi_core/services/vector_store/IVectorStorePort_test.py +189 -0
  100. naas_abi_core-1.0.0/naas_abi_core/services/vector_store/VectorStoreFactory.py +47 -0
  101. naas_abi_core-1.0.0/naas_abi_core/services/vector_store/VectorStoreService.py +171 -0
  102. naas_abi_core-1.0.0/naas_abi_core/services/vector_store/VectorStoreService_test.py +185 -0
  103. naas_abi_core-1.0.0/naas_abi_core/services/vector_store/__init__.py +13 -0
  104. naas_abi_core-1.0.0/naas_abi_core/services/vector_store/adapters/QdrantAdapter.py +251 -0
  105. naas_abi_core-1.0.0/naas_abi_core/services/vector_store/adapters/QdrantAdapter_test.py +57 -0
  106. naas_abi_core-1.0.0/naas_abi_core/utils/Expose.py +53 -0
  107. naas_abi_core-1.0.0/naas_abi_core/utils/Graph.py +182 -0
  108. naas_abi_core-1.0.0/naas_abi_core/utils/JSON.py +49 -0
  109. naas_abi_core-1.0.0/naas_abi_core/utils/LazyLoader.py +44 -0
  110. naas_abi_core-1.0.0/naas_abi_core/utils/Logger.py +12 -0
  111. naas_abi_core-1.0.0/naas_abi_core/utils/OntologyReasoner.py +141 -0
  112. naas_abi_core-1.0.0/naas_abi_core/utils/OntologyYaml.disabled.py +679 -0
  113. naas_abi_core-1.0.0/naas_abi_core/utils/SPARQL.py +256 -0
  114. naas_abi_core-1.0.0/naas_abi_core/utils/Storage.py +33 -0
  115. naas_abi_core-1.0.0/naas_abi_core/utils/StorageUtils.py +398 -0
  116. naas_abi_core-1.0.0/naas_abi_core/utils/String.py +52 -0
  117. naas_abi_core-1.0.0/naas_abi_core/utils/Workers.py +114 -0
  118. naas_abi_core-1.0.0/naas_abi_core/utils/__init__.py +0 -0
  119. naas_abi_core-1.0.0/naas_abi_core/utils/onto2py/README.md +0 -0
  120. naas_abi_core-1.0.0/naas_abi_core/utils/onto2py/__init__.py +10 -0
  121. naas_abi_core-1.0.0/naas_abi_core/utils/onto2py/__main__.py +29 -0
  122. naas_abi_core-1.0.0/naas_abi_core/utils/onto2py/onto2py.py +611 -0
  123. naas_abi_core-1.0.0/naas_abi_core/utils/onto2py/tests/ttl2py_test.py +271 -0
  124. naas_abi_core-1.0.0/naas_abi_core/workflow/__init__.py +5 -0
  125. naas_abi_core-1.0.0/naas_abi_core/workflow/workflow.py +48 -0
  126. naas_abi_core-1.0.0/pyproject.toml +81 -0
@@ -0,0 +1,96 @@
1
+ # Environment files
2
+ .env
3
+ .env.*
4
+ !.env.example
5
+
6
+ # Virtual Environment
7
+ .venv/
8
+ venv/
9
+ ENV/
10
+ env/
11
+ uv.lock
12
+
13
+ # Config
14
+ config.yaml
15
+ config.*.yaml
16
+
17
+ # Python
18
+ __pycache__/
19
+ *.py[cod]
20
+ *$py.class
21
+ *.so
22
+ .Python
23
+ build/
24
+ develop-eggs/
25
+ dist/
26
+ downloads/
27
+ eggs/
28
+ .eggs/
29
+ #lib/
30
+ lib64/
31
+ parts/
32
+ sdist/
33
+ var/
34
+ wheels/
35
+ *.egg-info/
36
+ .installed.cfg
37
+ *.egg
38
+ .mypy_cache/
39
+ .pytest_cache/
40
+ .ruff_cache/
41
+ .pytype
42
+
43
+ # IDEs and editors
44
+ .idea/
45
+ .vscode/
46
+ *.swp
47
+ *.swo
48
+ .DS_Store
49
+
50
+ # Docker
51
+ .docker/
52
+
53
+ # Logs
54
+ *.log
55
+
56
+ # Project specific
57
+ thread_id.txt
58
+ agentic-director/
59
+
60
+ # Storage - ignore everything in storage except README files
61
+ storage/*
62
+ !storage/README.md
63
+ !storage/*/README.md
64
+ !storage/datastore/
65
+ !storage/triplestore/
66
+ !storage/vectorstore/
67
+ storage/datastore/*
68
+ storage/triplestore/*
69
+ storage/vectorstore/*
70
+
71
+ # Ignore data files globally
72
+ *.csv
73
+ *.parquet
74
+ *.json
75
+ *.pdf
76
+ *.doc
77
+ *.docx
78
+ *.ppt
79
+ *.pptx
80
+ *.xls
81
+ *.xlsx
82
+ *.jpg
83
+ *.png
84
+ *.gif
85
+ *.jpeg
86
+ *.webp
87
+ *.heic
88
+
89
+
90
+ *.pid
91
+ sandbox/
92
+
93
+ # Coverage reports
94
+ .coverage
95
+ coverage.xml
96
+ htmlcov/
@@ -0,0 +1,6 @@
1
+ Collecting uv
2
+ Downloading uv-0.9.13-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (11 kB)
3
+ Downloading uv-0.9.13-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (21.7 MB)
4
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 21.7/21.7 MB 152.8 MB/s 0:00:00
5
+ Installing collected packages: uv
6
+ Successfully installed uv-0.9.13
@@ -0,0 +1,67 @@
1
+ # CHANGELOG
2
+
3
+ <!-- version list -->
4
+
5
+ ## v1.0.0 (2025-12-01)
6
+
7
+ ### Bug Fixes
8
+
9
+ - Adding authors and removing uneeded configuration
10
+ ([`c105454`](https://github.com/jupyter-naas/abi/commit/c105454bcb1ed1da88bda6ca23a05e9e3e9c1ed1))
11
+
12
+ - Configure release on main
13
+ ([`fb32b93`](https://github.com/jupyter-naas/abi/commit/fb32b93ef0e3ce1b8bb291fda902a7a03c0f0646))
14
+
15
+
16
+ ## v1.0.0-dev.9 (2025-11-30)
17
+
18
+ ### Bug Fixes
19
+
20
+ - Working on api deployment
21
+ ([`8a803ba`](https://github.com/jupyter-naas/abi/commit/8a803bad5db9ed9d020d18245b3b6fbafda6bb2c))
22
+
23
+
24
+ ## v1.0.0-dev.8 (2025-11-30)
25
+
26
+
27
+ ## v1.0.0-dev.7 (2025-11-30)
28
+
29
+
30
+ ## v1.0.0-dev.6 (2025-11-30)
31
+
32
+
33
+ ## v1.0.0-dev.5 (2025-11-30)
34
+
35
+ ### Bug Fixes
36
+
37
+ - Working on ci/cd
38
+ ([`d65250c`](https://github.com/jupyter-naas/abi/commit/d65250c10e433595a6ecd124c33aee9ca7e69535))
39
+
40
+
41
+ ## v1.0.0-dev.4 (2025-11-30)
42
+
43
+ ### Bug Fixes
44
+
45
+ - Working on ci
46
+ ([`ba918da`](https://github.com/jupyter-naas/abi/commit/ba918da13147636ec732f2aba3e2978046b93970))
47
+
48
+
49
+ ## v1.0.0-dev.3 (2025-11-30)
50
+
51
+ ### Bug Fixes
52
+
53
+ - Uv install
54
+ ([`c268208`](https://github.com/jupyter-naas/abi/commit/c268208bdcc69223fbb68114978211de7c161956))
55
+
56
+
57
+ ## v1.0.0-dev.2 (2025-11-30)
58
+
59
+ ### Bug Fixes
60
+
61
+ - Remove scoped prefix for semantic releases
62
+ ([`c208c3f`](https://github.com/jupyter-naas/abi/commit/c208c3f12ad1cd2eb2264a166f0e683184efb2ca))
63
+
64
+
65
+ ## v1.0.0-dev.1 (2025-11-30)
66
+
67
+ - Initial Release
@@ -0,0 +1,75 @@
1
+ Metadata-Version: 2.4
2
+ Name: naas-abi-core
3
+ Version: 1.0.0
4
+ Summary: Abi framework allowing you to build your AI system.
5
+ Author-email: Maxime Jublou <maxime@naas.ai>, Florent Ravenel <florent@naas.ai>, Jeremy Ravenel <jeremy@naas.ai>
6
+ Requires-Python: <4,>=3.10
7
+ Requires-Dist: boto3<2,>=1.38.19
8
+ Requires-Dist: click<8.2,>=8.1.1
9
+ Requires-Dist: dotenv>=0.9.9
10
+ Requires-Dist: langchain-openai<0.4,>=0.3.3
11
+ Requires-Dist: langgraph-checkpoint-postgres>=2.0.21
12
+ Requires-Dist: langgraph>=0.6.6
13
+ Requires-Dist: loguru<0.8,>=0.7.2
14
+ Requires-Dist: pip>=25.1.1
15
+ Requires-Dist: psycopg[binary,pool]>=3.0.0
16
+ Requires-Dist: pydantic>=2.11.5
17
+ Requires-Dist: pydash>=8.0.5
18
+ Requires-Dist: qdrant-client>=1.14.3
19
+ Requires-Dist: rdflib<8,>=7.1.1
20
+ Requires-Dist: rich<14,>=13.9.4
21
+ Requires-Dist: spacy>=3.8.7
22
+ Requires-Dist: sparqlwrapper>=2.0.0
23
+ Requires-Dist: sse-starlette<3,>=2.1.3
24
+ Requires-Dist: starlette>=0.46.2
25
+ Requires-Dist: types-tqdm>=4.67.0.20250809
26
+ Provides-Extra: ssh
27
+ Requires-Dist: paramiko<4.0.0,>=3.5.1; extra == 'ssh'
28
+ Requires-Dist: sshtunnel>=0.4.0; extra == 'ssh'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # ABI Library
32
+
33
+ The ABI Library is the core implementation of ABI's concepts, designed to build a unified AI system. This library provides the fundamental building blocks for connecting, processing, and utilizing data across different AI components.
34
+
35
+ ## Core Concepts
36
+
37
+ ### Integration
38
+ Integrations provide standardized connections to third-party services and data sources. They handle:
39
+ - Authentication and authorization
40
+ - API communication
41
+ - Data format standardization
42
+ - Error handling and retries
43
+
44
+ ### Pipeline
45
+ Pipelines are responsible for data ingestion and transformation into the ontological layer. They:
46
+ - Utilize integrations to fetch data
47
+ - Transform raw data into semantic representations
48
+ - Maintain data consistency and quality
49
+ - Map external data models to ABI's ontology
50
+
51
+ ### Workflow
52
+ Workflows leverage the ontological layer to implement business logic and provide data to consumers. They can be used by:
53
+ - Large Language Models (LLMs)
54
+ - Remote APIs and services
55
+ - Other automated processes
56
+
57
+ ### Services
58
+ Services form the foundational layer of ABI, implementing the Hexagonal Architecture (Ports & Adapters) pattern to provide flexible and system-agnostic interfaces. This architectural approach allows ABI to seamlessly integrate with existing systems while maintaining clean separation of concerns.
59
+
60
+ Each service defines a primary port (interface) that specifies its capabilities, while multiple secondary adapters can implement this interface for different backend systems. This means you can:
61
+
62
+ - Easily swap implementations without changing business logic
63
+ - Add new integrations by implementing new adapters
64
+ - Test components in isolation using mock adapters
65
+
66
+ For example, the Secret Service could connect to various backend systems through different adapters:
67
+ - Hashicorp Vault
68
+ - AWS Secrets Manager
69
+ - Azure Key Vault
70
+ - Environment Variables
71
+ - Local File System
72
+ - Google Cloud Secret Manager
73
+ - Kubernetes Secrets
74
+
75
+ This modular approach ensures that ABI can be deployed in any environment while maintaining consistent interfaces and behavior across different infrastructure choices.
@@ -0,0 +1,45 @@
1
+ # ABI Library
2
+
3
+ The ABI Library is the core implementation of ABI's concepts, designed to build a unified AI system. This library provides the fundamental building blocks for connecting, processing, and utilizing data across different AI components.
4
+
5
+ ## Core Concepts
6
+
7
+ ### Integration
8
+ Integrations provide standardized connections to third-party services and data sources. They handle:
9
+ - Authentication and authorization
10
+ - API communication
11
+ - Data format standardization
12
+ - Error handling and retries
13
+
14
+ ### Pipeline
15
+ Pipelines are responsible for data ingestion and transformation into the ontological layer. They:
16
+ - Utilize integrations to fetch data
17
+ - Transform raw data into semantic representations
18
+ - Maintain data consistency and quality
19
+ - Map external data models to ABI's ontology
20
+
21
+ ### Workflow
22
+ Workflows leverage the ontological layer to implement business logic and provide data to consumers. They can be used by:
23
+ - Large Language Models (LLMs)
24
+ - Remote APIs and services
25
+ - Other automated processes
26
+
27
+ ### Services
28
+ Services form the foundational layer of ABI, implementing the Hexagonal Architecture (Ports & Adapters) pattern to provide flexible and system-agnostic interfaces. This architectural approach allows ABI to seamlessly integrate with existing systems while maintaining clean separation of concerns.
29
+
30
+ Each service defines a primary port (interface) that specifies its capabilities, while multiple secondary adapters can implement this interface for different backend systems. This means you can:
31
+
32
+ - Easily swap implementations without changing business logic
33
+ - Add new integrations by implementing new adapters
34
+ - Test components in isolation using mock adapters
35
+
36
+ For example, the Secret Service could connect to various backend systems through different adapters:
37
+ - Hashicorp Vault
38
+ - AWS Secrets Manager
39
+ - Azure Key Vault
40
+ - Environment Variables
41
+ - Local File System
42
+ - Google Cloud Secret Manager
43
+ - Kubernetes Secrets
44
+
45
+ This modular approach ensures that ABI can be deployed in any environment while maintaining consistent interfaces and behavior across different infrastructure choices.
@@ -0,0 +1 @@
1
+ from naas_abi_core.utils.Logger import logger as logger
@@ -0,0 +1,242 @@
1
+ import os
2
+ import subprocess
3
+ from typing import Annotated, Optional
4
+
5
+ from fastapi import APIRouter, Depends, FastAPI, HTTPException, Request, status
6
+ from fastapi.middleware.cors import CORSMiddleware
7
+ from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html
8
+ from fastapi.openapi.models import OAuthFlowPassword
9
+ from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel
10
+ from fastapi.openapi.utils import get_openapi
11
+ from fastapi.responses import HTMLResponse
12
+
13
+ # Authentication
14
+ from fastapi.security import OAuth2PasswordRequestForm
15
+ from fastapi.security.oauth2 import OAuth2
16
+ from fastapi.security.utils import get_authorization_scheme_param
17
+ from fastapi.staticfiles import StaticFiles
18
+ from naas_abi_core import logger
19
+
20
+ # Docs
21
+ from naas_abi_core.apps.api.openapi_doc import API_LANDING_HTML, TAGS_METADATA
22
+ from naas_abi_core.engine.Engine import Engine
23
+
24
+ engine = Engine()
25
+ engine.load()
26
+
27
+ # Init API
28
+ TITLE = engine.configuration.api.title
29
+ DESCRIPTION = engine.configuration.api.description
30
+ app = FastAPI(title=TITLE, docs_url=None, redoc_url=None)
31
+
32
+ # Set logo path
33
+ logo_path = engine.configuration.api.logo_path
34
+ logo_name = os.path.basename(logo_path)
35
+
36
+ # Set favicon path
37
+ favicon_path = engine.configuration.api.favicon_path
38
+ favicon_name = os.path.basename(favicon_path)
39
+
40
+ origins = engine.configuration.api.cors_origins
41
+
42
+ logger.debug(f"CORS origins: {origins}")
43
+
44
+ app.add_middleware(
45
+ CORSMiddleware,
46
+ allow_origins=origins,
47
+ allow_credentials=True,
48
+ allow_methods=["*"],
49
+ allow_headers=["*"],
50
+ )
51
+
52
+ # Mount the static directory
53
+ app.mount("/static", StaticFiles(directory="assets"), name="static")
54
+
55
+
56
+ # Custom OAuth2 class that accepts query parameter
57
+ class OAuth2QueryBearer(OAuth2):
58
+ def __init__(
59
+ self,
60
+ tokenUrl: str,
61
+ scheme_name: Optional[str] = None,
62
+ auto_error: bool = True,
63
+ ):
64
+ flows = OAuthFlowsModel(password=OAuthFlowPassword(tokenUrl=tokenUrl))
65
+ super().__init__(flows=flows, scheme_name=scheme_name, auto_error=auto_error)
66
+
67
+ async def __call__(self, request: Request) -> Optional[str]:
68
+ authorization = request.headers.get("Authorization")
69
+ # Check header first
70
+ if authorization:
71
+ scheme, header_token = get_authorization_scheme_param(authorization)
72
+ if scheme.lower() == "bearer" and header_token:
73
+ return header_token
74
+
75
+ # Then check query parameter
76
+ query_token = request.query_params.get("token")
77
+ if query_token:
78
+ return query_token
79
+
80
+ # No token found in either place
81
+ if self.auto_error:
82
+ raise HTTPException(
83
+ status_code=status.HTTP_401_UNAUTHORIZED,
84
+ detail="Not authenticated",
85
+ headers={"WWW-Authenticate": "Bearer"},
86
+ )
87
+ return None
88
+
89
+
90
+ # Replace the existing oauth2_scheme with:
91
+ oauth2_scheme = OAuth2QueryBearer(tokenUrl="token")
92
+
93
+
94
+ # Update the token validation dependency
95
+ async def is_token_valid(token: str = Depends(oauth2_scheme)):
96
+ if token != os.environ.get("ABI_API_KEY"):
97
+ raise HTTPException(
98
+ status_code=status.HTTP_401_UNAUTHORIZED,
99
+ detail="Invalid authentication credentials",
100
+ headers={"WWW-Authenticate": "Bearer"},
101
+ )
102
+ return True
103
+
104
+
105
+ @app.post("/token", include_in_schema=False)
106
+ async def login(form_data: Annotated[OAuth2PasswordRequestForm, Depends()]):
107
+ if form_data.password != "abi":
108
+ raise HTTPException(status_code=400, detail="Incorrect username or password")
109
+
110
+ return {"access_token": "abi", "token_type": "bearer"}
111
+
112
+
113
+ # Create Agents API Router
114
+ agents_router = APIRouter(
115
+ prefix="/agents",
116
+ tags=["Agents"],
117
+ responses={401: {"description": "Unauthorized"}},
118
+ dependencies=[Depends(is_token_valid)], # Apply token verification
119
+ )
120
+
121
+ # Create Pipelines API Router
122
+ pipelines_router = APIRouter(
123
+ prefix="/pipelines",
124
+ tags=["Pipelines"],
125
+ responses={401: {"description": "Unauthorized"}},
126
+ dependencies=[Depends(is_token_valid)], # Apply token verification
127
+ )
128
+
129
+ # Create Pipelines API Router
130
+ workflows_router = APIRouter(
131
+ prefix="/workflows",
132
+ tags=["Workflows"],
133
+ responses={401: {"description": "Unauthorized"}},
134
+ dependencies=[Depends(is_token_valid)], # Apply token verification
135
+ )
136
+
137
+
138
+ def get_git_tag():
139
+ try:
140
+ tag = subprocess.check_output(["git", "describe", "--tags"]).strip().decode()
141
+ except Exception as _:
142
+ # if file VERSION exists, use it
143
+ if os.path.exists("VERSION"):
144
+ with open("VERSION", "r") as f:
145
+ tag = f.read().strip()
146
+ else:
147
+ tag = "v0.0.1"
148
+ return tag
149
+
150
+
151
+ def custom_openapi():
152
+ if app.openapi_schema:
153
+ return app.openapi_schema
154
+ openapi_schema = get_openapi(
155
+ title=TITLE,
156
+ description=DESCRIPTION,
157
+ version=get_git_tag(),
158
+ routes=app.routes,
159
+ tags=TAGS_METADATA,
160
+ )
161
+ openapi_schema["info"]["x-logo"] = {
162
+ "url": f"/static/{logo_name}",
163
+ "altText": "Logo",
164
+ }
165
+ app.openapi_schema = openapi_schema
166
+ return app.openapi_schema
167
+
168
+
169
+ app.openapi = custom_openapi # type: ignore[method-assign]
170
+
171
+
172
+ @app.get("/docs", include_in_schema=False)
173
+ def overridden_swagger():
174
+ return get_swagger_ui_html(
175
+ openapi_url="/openapi.json",
176
+ title=TITLE,
177
+ swagger_favicon_url=f"/static/{favicon_name}",
178
+ )
179
+
180
+
181
+ @app.get("/redoc", include_in_schema=False)
182
+ def overridden_redoc():
183
+ return get_redoc_html(
184
+ openapi_url="/openapi.json",
185
+ title=TITLE,
186
+ redoc_favicon_url=f"/static/{favicon_name}",
187
+ )
188
+
189
+
190
+ @app.get("/", response_class=HTMLResponse, include_in_schema=False)
191
+ def root():
192
+ return API_LANDING_HTML.replace("[TITLE]", TITLE).replace("[LOGO_NAME]", logo_name)
193
+
194
+
195
+ # Add agents to the API
196
+ all_agents: list = []
197
+ for module in engine.modules.values():
198
+ for agent in module.agents:
199
+ if agent is not None:
200
+ all_agents.append(agent.New())
201
+ else:
202
+ logger.warning(f"Skipping {agent.name} agent (missing API key)")
203
+
204
+ # Sort agents by name and add to router
205
+ for agent in sorted(all_agents, key=lambda a: a.name):
206
+ logger.debug(f"Adding agent to API: {agent.name}")
207
+ agent.as_api(agents_router)
208
+
209
+ # Include routers
210
+ app.include_router(agents_router)
211
+ app.include_router(pipelines_router)
212
+ app.include_router(workflows_router)
213
+
214
+
215
+ def api():
216
+ import uvicorn
217
+
218
+ if os.environ.get("ENV") == "dev":
219
+ uvicorn.run(
220
+ "naas_abi_core.apps.api.api:app",
221
+ host="0.0.0.0",
222
+ port=9879,
223
+ reload=os.environ.get("ENV") == "dev",
224
+ reload_dirs=["src", "lib"],
225
+ log_level="debug",
226
+ )
227
+ else:
228
+ uvicorn.run(app, host="0.0.0.0", port=9879)
229
+
230
+
231
+ def test_init():
232
+ logger.info("✅ API initialization completed successfully")
233
+ print("API_INIT_TEST_PASSED")
234
+
235
+
236
+ if __name__ == "__main__":
237
+ import sys
238
+
239
+ if "--test-init" in sys.argv:
240
+ test_init()
241
+ else:
242
+ api()