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.
Files changed (124) hide show
  1. naas_abi_core/__init__.py +1 -0
  2. naas_abi_core/apps/api/api.py +242 -0
  3. naas_abi_core/apps/api/api_test.py +281 -0
  4. naas_abi_core/apps/api/openapi_doc.py +307 -0
  5. naas_abi_core/apps/mcp/mcp_server.py +243 -0
  6. naas_abi_core/apps/mcp/mcp_server_test.py +163 -0
  7. naas_abi_core/apps/terminal_agent/main.py +555 -0
  8. naas_abi_core/apps/terminal_agent/terminal_style.py +175 -0
  9. naas_abi_core/cli/__init__.py +53 -0
  10. naas_abi_core/cli/agent.py +30 -0
  11. naas_abi_core/cli/chat.py +26 -0
  12. naas_abi_core/cli/config.py +49 -0
  13. naas_abi_core/cli/init.py +13 -0
  14. naas_abi_core/cli/module.py +28 -0
  15. naas_abi_core/cli/new.py +13 -0
  16. naas_abi_core/cli/secret.py +79 -0
  17. naas_abi_core/engine/Engine.py +87 -0
  18. naas_abi_core/engine/EngineProxy.py +109 -0
  19. naas_abi_core/engine/Engine_test.py +6 -0
  20. naas_abi_core/engine/IEngine.py +91 -0
  21. naas_abi_core/engine/conftest.py +45 -0
  22. naas_abi_core/engine/engine_configuration/EngineConfiguration.py +160 -0
  23. naas_abi_core/engine/engine_configuration/EngineConfiguration_GenericLoader.py +49 -0
  24. naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService.py +131 -0
  25. naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService_test.py +26 -0
  26. naas_abi_core/engine/engine_configuration/EngineConfiguration_SecretService.py +116 -0
  27. naas_abi_core/engine/engine_configuration/EngineConfiguration_TripleStoreService.py +171 -0
  28. naas_abi_core/engine/engine_configuration/EngineConfiguration_VectorStoreService.py +65 -0
  29. naas_abi_core/engine/engine_configuration/EngineConfiguration_test.py +9 -0
  30. naas_abi_core/engine/engine_configuration/utils/PydanticModelValidator.py +15 -0
  31. naas_abi_core/engine/engine_loaders/EngineModuleLoader.py +302 -0
  32. naas_abi_core/engine/engine_loaders/EngineOntologyLoader.py +16 -0
  33. naas_abi_core/engine/engine_loaders/EngineServiceLoader.py +47 -0
  34. naas_abi_core/integration/__init__.py +7 -0
  35. naas_abi_core/integration/integration.py +28 -0
  36. naas_abi_core/models/Model.py +198 -0
  37. naas_abi_core/models/OpenRouter.py +15 -0
  38. naas_abi_core/models/OpenRouter_test.py +36 -0
  39. naas_abi_core/module/Module.py +245 -0
  40. naas_abi_core/module/ModuleAgentLoader.py +49 -0
  41. naas_abi_core/module/ModuleUtils.py +20 -0
  42. naas_abi_core/modules/templatablesparqlquery/README.md +196 -0
  43. naas_abi_core/modules/templatablesparqlquery/__init__.py +39 -0
  44. naas_abi_core/modules/templatablesparqlquery/ontologies/TemplatableSparqlQueryOntology.ttl +116 -0
  45. naas_abi_core/modules/templatablesparqlquery/workflows/GenericWorkflow.py +48 -0
  46. naas_abi_core/modules/templatablesparqlquery/workflows/TemplatableSparqlQueryLoader.py +192 -0
  47. naas_abi_core/pipeline/__init__.py +6 -0
  48. naas_abi_core/pipeline/pipeline.py +70 -0
  49. naas_abi_core/services/__init__.py +0 -0
  50. naas_abi_core/services/agent/Agent.py +1619 -0
  51. naas_abi_core/services/agent/AgentMemory_test.py +28 -0
  52. naas_abi_core/services/agent/Agent_test.py +214 -0
  53. naas_abi_core/services/agent/IntentAgent.py +1171 -0
  54. naas_abi_core/services/agent/IntentAgent_test.py +139 -0
  55. naas_abi_core/services/agent/beta/Embeddings.py +180 -0
  56. naas_abi_core/services/agent/beta/IntentMapper.py +119 -0
  57. naas_abi_core/services/agent/beta/LocalModel.py +88 -0
  58. naas_abi_core/services/agent/beta/VectorStore.py +89 -0
  59. naas_abi_core/services/agent/test_agent_memory.py +278 -0
  60. naas_abi_core/services/agent/test_postgres_integration.py +145 -0
  61. naas_abi_core/services/cache/CacheFactory.py +31 -0
  62. naas_abi_core/services/cache/CachePort.py +63 -0
  63. naas_abi_core/services/cache/CacheService.py +246 -0
  64. naas_abi_core/services/cache/CacheService_test.py +85 -0
  65. naas_abi_core/services/cache/adapters/secondary/CacheFSAdapter.py +39 -0
  66. naas_abi_core/services/object_storage/ObjectStorageFactory.py +57 -0
  67. naas_abi_core/services/object_storage/ObjectStoragePort.py +47 -0
  68. naas_abi_core/services/object_storage/ObjectStorageService.py +41 -0
  69. naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterFS.py +52 -0
  70. naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterNaas.py +131 -0
  71. naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterS3.py +171 -0
  72. naas_abi_core/services/ontology/OntologyPorts.py +36 -0
  73. naas_abi_core/services/ontology/OntologyService.py +17 -0
  74. naas_abi_core/services/ontology/adaptors/secondary/OntologyService_SecondaryAdaptor_NERPort.py +37 -0
  75. naas_abi_core/services/secret/Secret.py +138 -0
  76. naas_abi_core/services/secret/SecretPorts.py +40 -0
  77. naas_abi_core/services/secret/Secret_test.py +65 -0
  78. naas_abi_core/services/secret/adaptors/secondary/Base64Secret.py +57 -0
  79. naas_abi_core/services/secret/adaptors/secondary/Base64Secret_test.py +39 -0
  80. naas_abi_core/services/secret/adaptors/secondary/NaasSecret.py +81 -0
  81. naas_abi_core/services/secret/adaptors/secondary/NaasSecret_test.py +25 -0
  82. naas_abi_core/services/secret/adaptors/secondary/dotenv_secret_secondaryadaptor.py +26 -0
  83. naas_abi_core/services/triple_store/TripleStoreFactory.py +116 -0
  84. naas_abi_core/services/triple_store/TripleStorePorts.py +223 -0
  85. naas_abi_core/services/triple_store/TripleStoreService.py +419 -0
  86. naas_abi_core/services/triple_store/adaptors/secondary/AWSNeptune.py +1284 -0
  87. naas_abi_core/services/triple_store/adaptors/secondary/AWSNeptune_test.py +284 -0
  88. naas_abi_core/services/triple_store/adaptors/secondary/Oxigraph.py +597 -0
  89. naas_abi_core/services/triple_store/adaptors/secondary/Oxigraph_test.py +1474 -0
  90. naas_abi_core/services/triple_store/adaptors/secondary/TripleStoreService__SecondaryAdaptor__Filesystem.py +223 -0
  91. naas_abi_core/services/triple_store/adaptors/secondary/TripleStoreService__SecondaryAdaptor__ObjectStorage.py +234 -0
  92. naas_abi_core/services/triple_store/adaptors/secondary/base/TripleStoreService__SecondaryAdaptor__FileBase.py +18 -0
  93. naas_abi_core/services/vector_store/IVectorStorePort.py +101 -0
  94. naas_abi_core/services/vector_store/IVectorStorePort_test.py +189 -0
  95. naas_abi_core/services/vector_store/VectorStoreFactory.py +47 -0
  96. naas_abi_core/services/vector_store/VectorStoreService.py +171 -0
  97. naas_abi_core/services/vector_store/VectorStoreService_test.py +185 -0
  98. naas_abi_core/services/vector_store/__init__.py +13 -0
  99. naas_abi_core/services/vector_store/adapters/QdrantAdapter.py +251 -0
  100. naas_abi_core/services/vector_store/adapters/QdrantAdapter_test.py +57 -0
  101. naas_abi_core/utils/Expose.py +53 -0
  102. naas_abi_core/utils/Graph.py +182 -0
  103. naas_abi_core/utils/JSON.py +49 -0
  104. naas_abi_core/utils/LazyLoader.py +44 -0
  105. naas_abi_core/utils/Logger.py +12 -0
  106. naas_abi_core/utils/OntologyReasoner.py +141 -0
  107. naas_abi_core/utils/OntologyYaml.disabled.py +679 -0
  108. naas_abi_core/utils/SPARQL.py +256 -0
  109. naas_abi_core/utils/Storage.py +33 -0
  110. naas_abi_core/utils/StorageUtils.py +398 -0
  111. naas_abi_core/utils/String.py +52 -0
  112. naas_abi_core/utils/Workers.py +114 -0
  113. naas_abi_core/utils/__init__.py +0 -0
  114. naas_abi_core/utils/onto2py/README.md +0 -0
  115. naas_abi_core/utils/onto2py/__init__.py +10 -0
  116. naas_abi_core/utils/onto2py/__main__.py +29 -0
  117. naas_abi_core/utils/onto2py/onto2py.py +611 -0
  118. naas_abi_core/utils/onto2py/tests/ttl2py_test.py +271 -0
  119. naas_abi_core/workflow/__init__.py +5 -0
  120. naas_abi_core/workflow/workflow.py +48 -0
  121. naas_abi_core-1.0.0.dist-info/METADATA +75 -0
  122. naas_abi_core-1.0.0.dist-info/RECORD +124 -0
  123. naas_abi_core-1.0.0.dist-info/WHEEL +4 -0
  124. 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())