naas-abi-core 1.0.0__py3-none-any.whl
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.
- naas_abi_core/__init__.py +1 -0
- naas_abi_core/apps/api/api.py +242 -0
- naas_abi_core/apps/api/api_test.py +281 -0
- naas_abi_core/apps/api/openapi_doc.py +307 -0
- naas_abi_core/apps/mcp/mcp_server.py +243 -0
- naas_abi_core/apps/mcp/mcp_server_test.py +163 -0
- naas_abi_core/apps/terminal_agent/main.py +555 -0
- naas_abi_core/apps/terminal_agent/terminal_style.py +175 -0
- naas_abi_core/cli/__init__.py +53 -0
- naas_abi_core/cli/agent.py +30 -0
- naas_abi_core/cli/chat.py +26 -0
- naas_abi_core/cli/config.py +49 -0
- naas_abi_core/cli/init.py +13 -0
- naas_abi_core/cli/module.py +28 -0
- naas_abi_core/cli/new.py +13 -0
- naas_abi_core/cli/secret.py +79 -0
- naas_abi_core/engine/Engine.py +87 -0
- naas_abi_core/engine/EngineProxy.py +109 -0
- naas_abi_core/engine/Engine_test.py +6 -0
- naas_abi_core/engine/IEngine.py +91 -0
- naas_abi_core/engine/conftest.py +45 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration.py +160 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_GenericLoader.py +49 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService.py +131 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService_test.py +26 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_SecretService.py +116 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_TripleStoreService.py +171 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_VectorStoreService.py +65 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_test.py +9 -0
- naas_abi_core/engine/engine_configuration/utils/PydanticModelValidator.py +15 -0
- naas_abi_core/engine/engine_loaders/EngineModuleLoader.py +302 -0
- naas_abi_core/engine/engine_loaders/EngineOntologyLoader.py +16 -0
- naas_abi_core/engine/engine_loaders/EngineServiceLoader.py +47 -0
- naas_abi_core/integration/__init__.py +7 -0
- naas_abi_core/integration/integration.py +28 -0
- naas_abi_core/models/Model.py +198 -0
- naas_abi_core/models/OpenRouter.py +15 -0
- naas_abi_core/models/OpenRouter_test.py +36 -0
- naas_abi_core/module/Module.py +245 -0
- naas_abi_core/module/ModuleAgentLoader.py +49 -0
- naas_abi_core/module/ModuleUtils.py +20 -0
- naas_abi_core/modules/templatablesparqlquery/README.md +196 -0
- naas_abi_core/modules/templatablesparqlquery/__init__.py +39 -0
- naas_abi_core/modules/templatablesparqlquery/ontologies/TemplatableSparqlQueryOntology.ttl +116 -0
- naas_abi_core/modules/templatablesparqlquery/workflows/GenericWorkflow.py +48 -0
- naas_abi_core/modules/templatablesparqlquery/workflows/TemplatableSparqlQueryLoader.py +192 -0
- naas_abi_core/pipeline/__init__.py +6 -0
- naas_abi_core/pipeline/pipeline.py +70 -0
- naas_abi_core/services/__init__.py +0 -0
- naas_abi_core/services/agent/Agent.py +1619 -0
- naas_abi_core/services/agent/AgentMemory_test.py +28 -0
- naas_abi_core/services/agent/Agent_test.py +214 -0
- naas_abi_core/services/agent/IntentAgent.py +1171 -0
- naas_abi_core/services/agent/IntentAgent_test.py +139 -0
- naas_abi_core/services/agent/beta/Embeddings.py +180 -0
- naas_abi_core/services/agent/beta/IntentMapper.py +119 -0
- naas_abi_core/services/agent/beta/LocalModel.py +88 -0
- naas_abi_core/services/agent/beta/VectorStore.py +89 -0
- naas_abi_core/services/agent/test_agent_memory.py +278 -0
- naas_abi_core/services/agent/test_postgres_integration.py +145 -0
- naas_abi_core/services/cache/CacheFactory.py +31 -0
- naas_abi_core/services/cache/CachePort.py +63 -0
- naas_abi_core/services/cache/CacheService.py +246 -0
- naas_abi_core/services/cache/CacheService_test.py +85 -0
- naas_abi_core/services/cache/adapters/secondary/CacheFSAdapter.py +39 -0
- naas_abi_core/services/object_storage/ObjectStorageFactory.py +57 -0
- naas_abi_core/services/object_storage/ObjectStoragePort.py +47 -0
- naas_abi_core/services/object_storage/ObjectStorageService.py +41 -0
- naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterFS.py +52 -0
- naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterNaas.py +131 -0
- naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterS3.py +171 -0
- naas_abi_core/services/ontology/OntologyPorts.py +36 -0
- naas_abi_core/services/ontology/OntologyService.py +17 -0
- naas_abi_core/services/ontology/adaptors/secondary/OntologyService_SecondaryAdaptor_NERPort.py +37 -0
- naas_abi_core/services/secret/Secret.py +138 -0
- naas_abi_core/services/secret/SecretPorts.py +40 -0
- naas_abi_core/services/secret/Secret_test.py +65 -0
- naas_abi_core/services/secret/adaptors/secondary/Base64Secret.py +57 -0
- naas_abi_core/services/secret/adaptors/secondary/Base64Secret_test.py +39 -0
- naas_abi_core/services/secret/adaptors/secondary/NaasSecret.py +81 -0
- naas_abi_core/services/secret/adaptors/secondary/NaasSecret_test.py +25 -0
- naas_abi_core/services/secret/adaptors/secondary/dotenv_secret_secondaryadaptor.py +26 -0
- naas_abi_core/services/triple_store/TripleStoreFactory.py +116 -0
- naas_abi_core/services/triple_store/TripleStorePorts.py +223 -0
- naas_abi_core/services/triple_store/TripleStoreService.py +419 -0
- naas_abi_core/services/triple_store/adaptors/secondary/AWSNeptune.py +1284 -0
- naas_abi_core/services/triple_store/adaptors/secondary/AWSNeptune_test.py +284 -0
- naas_abi_core/services/triple_store/adaptors/secondary/Oxigraph.py +597 -0
- naas_abi_core/services/triple_store/adaptors/secondary/Oxigraph_test.py +1474 -0
- naas_abi_core/services/triple_store/adaptors/secondary/TripleStoreService__SecondaryAdaptor__Filesystem.py +223 -0
- naas_abi_core/services/triple_store/adaptors/secondary/TripleStoreService__SecondaryAdaptor__ObjectStorage.py +234 -0
- naas_abi_core/services/triple_store/adaptors/secondary/base/TripleStoreService__SecondaryAdaptor__FileBase.py +18 -0
- naas_abi_core/services/vector_store/IVectorStorePort.py +101 -0
- naas_abi_core/services/vector_store/IVectorStorePort_test.py +189 -0
- naas_abi_core/services/vector_store/VectorStoreFactory.py +47 -0
- naas_abi_core/services/vector_store/VectorStoreService.py +171 -0
- naas_abi_core/services/vector_store/VectorStoreService_test.py +185 -0
- naas_abi_core/services/vector_store/__init__.py +13 -0
- naas_abi_core/services/vector_store/adapters/QdrantAdapter.py +251 -0
- naas_abi_core/services/vector_store/adapters/QdrantAdapter_test.py +57 -0
- naas_abi_core/utils/Expose.py +53 -0
- naas_abi_core/utils/Graph.py +182 -0
- naas_abi_core/utils/JSON.py +49 -0
- naas_abi_core/utils/LazyLoader.py +44 -0
- naas_abi_core/utils/Logger.py +12 -0
- naas_abi_core/utils/OntologyReasoner.py +141 -0
- naas_abi_core/utils/OntologyYaml.disabled.py +679 -0
- naas_abi_core/utils/SPARQL.py +256 -0
- naas_abi_core/utils/Storage.py +33 -0
- naas_abi_core/utils/StorageUtils.py +398 -0
- naas_abi_core/utils/String.py +52 -0
- naas_abi_core/utils/Workers.py +114 -0
- naas_abi_core/utils/__init__.py +0 -0
- naas_abi_core/utils/onto2py/README.md +0 -0
- naas_abi_core/utils/onto2py/__init__.py +10 -0
- naas_abi_core/utils/onto2py/__main__.py +29 -0
- naas_abi_core/utils/onto2py/onto2py.py +611 -0
- naas_abi_core/utils/onto2py/tests/ttl2py_test.py +271 -0
- naas_abi_core/workflow/__init__.py +5 -0
- naas_abi_core/workflow/workflow.py +48 -0
- naas_abi_core-1.0.0.dist-info/METADATA +75 -0
- naas_abi_core-1.0.0.dist-info/RECORD +124 -0
- naas_abi_core-1.0.0.dist-info/WHEEL +4 -0
- naas_abi_core-1.0.0.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Test script to validate MCP server functionality
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import asyncio
|
|
7
|
+
import httpx
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
from typing import Dict, Any
|
|
11
|
+
|
|
12
|
+
# Test configuration
|
|
13
|
+
API_BASE = os.environ.get("ABI_API_BASE", "http://localhost:9879")
|
|
14
|
+
API_KEY = os.environ.get("ABI_API_KEY", "")
|
|
15
|
+
|
|
16
|
+
async def test_api_health() -> bool:
|
|
17
|
+
"""Test if the API is healthy"""
|
|
18
|
+
print(f"š Testing API health at {API_BASE}...")
|
|
19
|
+
try:
|
|
20
|
+
async with httpx.AsyncClient(timeout=5.0) as client:
|
|
21
|
+
response = await client.get(f"{API_BASE}/openapi.json")
|
|
22
|
+
if response.status_code == 200:
|
|
23
|
+
print("ā
API is healthy")
|
|
24
|
+
return True
|
|
25
|
+
else:
|
|
26
|
+
print(f"ā API returned status {response.status_code}")
|
|
27
|
+
return False
|
|
28
|
+
except Exception as e:
|
|
29
|
+
print(f"ā Failed to connect to API: {e}")
|
|
30
|
+
return False
|
|
31
|
+
|
|
32
|
+
async def test_openapi_spec() -> Dict[str, Any]:
|
|
33
|
+
"""Test if OpenAPI spec is accessible and contains agents"""
|
|
34
|
+
print(f"\nš Fetching OpenAPI spec from {API_BASE}/openapi.json...")
|
|
35
|
+
try:
|
|
36
|
+
async with httpx.AsyncClient(timeout=10.0) as client:
|
|
37
|
+
response = await client.get(f"{API_BASE}/openapi.json")
|
|
38
|
+
response.raise_for_status()
|
|
39
|
+
spec = response.json()
|
|
40
|
+
print("ā
OpenAPI spec fetched successfully")
|
|
41
|
+
return spec
|
|
42
|
+
except Exception as e:
|
|
43
|
+
print(f"ā Failed to fetch OpenAPI spec: {e}")
|
|
44
|
+
return {}
|
|
45
|
+
|
|
46
|
+
def analyze_agents(openapi_spec: Dict[str, Any]) -> list:
|
|
47
|
+
"""Extract and display agent information from OpenAPI spec"""
|
|
48
|
+
print("\nš Analyzing available agents...")
|
|
49
|
+
agents = []
|
|
50
|
+
paths = openapi_spec.get("paths", {})
|
|
51
|
+
|
|
52
|
+
for path, methods in paths.items():
|
|
53
|
+
if "/agents/" in path and path.endswith("/completion"):
|
|
54
|
+
agent_name = path.split("/agents/")[1].split("/completion")[0]
|
|
55
|
+
post_method = methods.get("post", {})
|
|
56
|
+
description = post_method.get("summary", f"{agent_name} agent")
|
|
57
|
+
agents.append({
|
|
58
|
+
"name": agent_name,
|
|
59
|
+
"description": description,
|
|
60
|
+
"endpoint": path
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
if agents:
|
|
64
|
+
print(f"ā
Found {len(agents)} agents:")
|
|
65
|
+
for agent in agents:
|
|
66
|
+
print(f" ⢠{agent['name']}: {agent['description']}")
|
|
67
|
+
else:
|
|
68
|
+
print("ā No agents found in OpenAPI spec")
|
|
69
|
+
|
|
70
|
+
return agents
|
|
71
|
+
|
|
72
|
+
async def test_agent_call(agent_name: str) -> bool:
|
|
73
|
+
"""Test calling a specific agent"""
|
|
74
|
+
if not API_KEY:
|
|
75
|
+
print("\nā ļø Skipping agent call test - ABI_API_KEY not set")
|
|
76
|
+
return False
|
|
77
|
+
|
|
78
|
+
print(f"\nš Testing agent call to '{agent_name}'...")
|
|
79
|
+
try:
|
|
80
|
+
headers = {
|
|
81
|
+
"Authorization": f"Bearer {API_KEY}",
|
|
82
|
+
"Content-Type": "application/json"
|
|
83
|
+
}
|
|
84
|
+
data = {
|
|
85
|
+
"prompt": "Hello, this is a test message. Please respond briefly.",
|
|
86
|
+
"thread_id": 1
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async with httpx.AsyncClient(timeout=30.0) as client:
|
|
90
|
+
response = await client.post(
|
|
91
|
+
f"{API_BASE}/agents/{agent_name}/completion",
|
|
92
|
+
json=data,
|
|
93
|
+
headers=headers
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
if response.status_code == 200:
|
|
97
|
+
print(f"ā
Successfully called {agent_name} agent")
|
|
98
|
+
print(f" Response: {response.text[:100]}...")
|
|
99
|
+
return True
|
|
100
|
+
else:
|
|
101
|
+
print(f"ā Agent call failed with status {response.status_code}")
|
|
102
|
+
print(f" Error: {response.text}")
|
|
103
|
+
return False
|
|
104
|
+
|
|
105
|
+
except Exception as e:
|
|
106
|
+
print(f"ā Failed to call agent: {e}")
|
|
107
|
+
return False
|
|
108
|
+
|
|
109
|
+
async def test_mcp_http_server() -> bool:
|
|
110
|
+
"""Test if MCP server is running in HTTP mode"""
|
|
111
|
+
print("\nš Testing MCP HTTP server at http://localhost:3000...")
|
|
112
|
+
try:
|
|
113
|
+
async with httpx.AsyncClient(timeout=5.0) as client:
|
|
114
|
+
response = await client.get("http://localhost:3000/")
|
|
115
|
+
if response.status_code == 200:
|
|
116
|
+
print("ā
MCP HTTP server is running")
|
|
117
|
+
return True
|
|
118
|
+
else:
|
|
119
|
+
print(f"ā MCP server returned status {response.status_code}")
|
|
120
|
+
return False
|
|
121
|
+
except Exception:
|
|
122
|
+
print("ā ļø MCP HTTP server not running (this is OK if testing STDIO mode)")
|
|
123
|
+
return False
|
|
124
|
+
|
|
125
|
+
async def main():
|
|
126
|
+
"""Run all tests"""
|
|
127
|
+
print("š MCP Server Validation Tests")
|
|
128
|
+
print("=" * 50)
|
|
129
|
+
|
|
130
|
+
# Test 1: API Health
|
|
131
|
+
api_healthy = await test_api_health()
|
|
132
|
+
if not api_healthy:
|
|
133
|
+
print("\nā ļø API is not running. Please start it with: uv run api")
|
|
134
|
+
sys.exit(1)
|
|
135
|
+
|
|
136
|
+
# Test 2: OpenAPI Spec
|
|
137
|
+
openapi_spec = await test_openapi_spec()
|
|
138
|
+
if not openapi_spec:
|
|
139
|
+
sys.exit(1)
|
|
140
|
+
|
|
141
|
+
# Test 3: Analyze Agents
|
|
142
|
+
agents = analyze_agents(openapi_spec)
|
|
143
|
+
if not agents:
|
|
144
|
+
print("\nā ļø No agents found. Check your API configuration.")
|
|
145
|
+
sys.exit(1)
|
|
146
|
+
|
|
147
|
+
# Test 4: Test Agent Call (if API key is set)
|
|
148
|
+
if agents:
|
|
149
|
+
# Test the first available agent
|
|
150
|
+
await test_agent_call(agents[0]["name"])
|
|
151
|
+
|
|
152
|
+
# Test 5: MCP HTTP Server (optional)
|
|
153
|
+
await test_mcp_http_server()
|
|
154
|
+
|
|
155
|
+
print("\n" + "=" * 50)
|
|
156
|
+
print("ā
Validation complete!")
|
|
157
|
+
print("\nNext steps:")
|
|
158
|
+
print("1. Start MCP server locally: python mcp_server.py")
|
|
159
|
+
print("2. For HTTP mode: MCP_TRANSPORT=http python mcp_server.py")
|
|
160
|
+
print("3. For Claude Desktop integration, add to MCP settings")
|
|
161
|
+
|
|
162
|
+
if __name__ == "__main__":
|
|
163
|
+
asyncio.run(main())
|