karrio-cli 2025.5rc3__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 (68) hide show
  1. karrio_cli/__init__.py +0 -0
  2. karrio_cli/__main__.py +105 -0
  3. karrio_cli/ai/README.md +335 -0
  4. karrio_cli/ai/__init__.py +0 -0
  5. karrio_cli/ai/commands.py +102 -0
  6. karrio_cli/ai/karrio_ai/__init__.py +1 -0
  7. karrio_cli/ai/karrio_ai/agent.py +972 -0
  8. karrio_cli/ai/karrio_ai/architecture/INTEGRATION_AGENT_PROMPT.md +497 -0
  9. karrio_cli/ai/karrio_ai/architecture/MAPPING_AGENT_PROMPT.md +355 -0
  10. karrio_cli/ai/karrio_ai/architecture/REAL_WORLD_TESTING.md +305 -0
  11. karrio_cli/ai/karrio_ai/architecture/SCHEMA_AGENT_PROMPT.md +183 -0
  12. karrio_cli/ai/karrio_ai/architecture/TESTING_AGENT_PROMPT.md +448 -0
  13. karrio_cli/ai/karrio_ai/architecture/TESTING_GUIDE.md +271 -0
  14. karrio_cli/ai/karrio_ai/enhanced_tools.py +943 -0
  15. karrio_cli/ai/karrio_ai/rag_system.py +503 -0
  16. karrio_cli/ai/karrio_ai/tests/test_agent.py +350 -0
  17. karrio_cli/ai/karrio_ai/tests/test_real_integration.py +360 -0
  18. karrio_cli/ai/karrio_ai/tests/test_real_world_scenarios.py +513 -0
  19. karrio_cli/commands/__init__.py +0 -0
  20. karrio_cli/commands/codegen.py +336 -0
  21. karrio_cli/commands/login.py +139 -0
  22. karrio_cli/commands/plugins.py +168 -0
  23. karrio_cli/commands/sdk.py +870 -0
  24. karrio_cli/common/queries.py +101 -0
  25. karrio_cli/common/utils.py +368 -0
  26. karrio_cli/resources/__init__.py +0 -0
  27. karrio_cli/resources/carriers.py +91 -0
  28. karrio_cli/resources/connections.py +207 -0
  29. karrio_cli/resources/events.py +151 -0
  30. karrio_cli/resources/logs.py +151 -0
  31. karrio_cli/resources/orders.py +144 -0
  32. karrio_cli/resources/shipments.py +210 -0
  33. karrio_cli/resources/trackers.py +287 -0
  34. karrio_cli/templates/__init__.py +9 -0
  35. karrio_cli/templates/__pycache__/__init__.cpython-311.pyc +0 -0
  36. karrio_cli/templates/__pycache__/__init__.cpython-312.pyc +0 -0
  37. karrio_cli/templates/__pycache__/address.cpython-311.pyc +0 -0
  38. karrio_cli/templates/__pycache__/address.cpython-312.pyc +0 -0
  39. karrio_cli/templates/__pycache__/docs.cpython-311.pyc +0 -0
  40. karrio_cli/templates/__pycache__/docs.cpython-312.pyc +0 -0
  41. karrio_cli/templates/__pycache__/documents.cpython-311.pyc +0 -0
  42. karrio_cli/templates/__pycache__/documents.cpython-312.pyc +0 -0
  43. karrio_cli/templates/__pycache__/manifest.cpython-311.pyc +0 -0
  44. karrio_cli/templates/__pycache__/manifest.cpython-312.pyc +0 -0
  45. karrio_cli/templates/__pycache__/pickup.cpython-311.pyc +0 -0
  46. karrio_cli/templates/__pycache__/pickup.cpython-312.pyc +0 -0
  47. karrio_cli/templates/__pycache__/rates.cpython-311.pyc +0 -0
  48. karrio_cli/templates/__pycache__/rates.cpython-312.pyc +0 -0
  49. karrio_cli/templates/__pycache__/sdk.cpython-311.pyc +0 -0
  50. karrio_cli/templates/__pycache__/sdk.cpython-312.pyc +0 -0
  51. karrio_cli/templates/__pycache__/shipments.cpython-311.pyc +0 -0
  52. karrio_cli/templates/__pycache__/shipments.cpython-312.pyc +0 -0
  53. karrio_cli/templates/__pycache__/tracking.cpython-311.pyc +0 -0
  54. karrio_cli/templates/__pycache__/tracking.cpython-312.pyc +0 -0
  55. karrio_cli/templates/address.py +308 -0
  56. karrio_cli/templates/docs.py +150 -0
  57. karrio_cli/templates/documents.py +428 -0
  58. karrio_cli/templates/manifest.py +396 -0
  59. karrio_cli/templates/pickup.py +839 -0
  60. karrio_cli/templates/rates.py +638 -0
  61. karrio_cli/templates/sdk.py +947 -0
  62. karrio_cli/templates/shipments.py +892 -0
  63. karrio_cli/templates/tracking.py +437 -0
  64. karrio_cli-2025.5rc3.dist-info/METADATA +165 -0
  65. karrio_cli-2025.5rc3.dist-info/RECORD +68 -0
  66. karrio_cli-2025.5rc3.dist-info/WHEEL +5 -0
  67. karrio_cli-2025.5rc3.dist-info/entry_points.txt +2 -0
  68. karrio_cli-2025.5rc3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,350 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test script for the enhanced Karrio ADK agent with RAG capabilities.
4
+
5
+ This script tests the multi-agent architecture, RAG system integration,
6
+ and tool functions for carrier integration generation.
7
+ """
8
+
9
+ import sys
10
+ import os
11
+ import json
12
+ from pathlib import Path
13
+
14
+ # Add the ai module to the path
15
+ sys.path.insert(0, str(Path(__file__).parent))
16
+
17
+ from karrio_ai.agent import (
18
+ root_agent,
19
+ analyze_existing_connector,
20
+ extract_carrier_patterns,
21
+ generate_carrier_schema,
22
+ generate_carrier_mappings,
23
+ generate_integration_tests,
24
+ assemble_complete_integration,
25
+ RAG_SYSTEM
26
+ )
27
+
28
+
29
+ def test_rag_system():
30
+ """Test the RAG system functionality."""
31
+ print("=== Testing RAG System ===")
32
+
33
+ try:
34
+ # Test pattern search
35
+ auth_patterns = RAG_SYSTEM.search_patterns("auth", limit=3)
36
+ print(f"Found {len(auth_patterns)} authentication patterns")
37
+
38
+ mapping_patterns = RAG_SYSTEM.search_patterns("mapping", limit=3)
39
+ print(f"Found {len(mapping_patterns)} mapping patterns")
40
+
41
+ schema_patterns = RAG_SYSTEM.search_patterns("schema", limit=3)
42
+ print(f"Found {len(schema_patterns)} schema patterns")
43
+
44
+ # Test carrier similarity
45
+ test_carrier_info = {
46
+ 'api_type': 'REST',
47
+ 'auth_type': 'API_KEY',
48
+ 'operations': ['rates', 'shipments', 'tracking']
49
+ }
50
+ similar_carriers = RAG_SYSTEM.get_similar_carriers(test_carrier_info)
51
+ print(f"Found similar carriers: {similar_carriers}")
52
+
53
+ # Test implementation examples
54
+ rate_examples = RAG_SYSTEM.get_implementation_examples("rate")
55
+ print(f"Found {len(rate_examples)} rate implementation examples")
56
+
57
+ print("✅ RAG system tests passed")
58
+ return True
59
+
60
+ except Exception as e:
61
+ print(f"❌ RAG system test failed: {e}")
62
+ return False
63
+
64
+
65
+ def test_analyze_existing_connector():
66
+ """Test the analyze_existing_connector tool."""
67
+ print("\n=== Testing Connector Analysis ===")
68
+
69
+ try:
70
+ # Test with UPS connector
71
+ ups_analysis = analyze_existing_connector("ups", "all")
72
+
73
+ if "error" in ups_analysis:
74
+ print(f"UPS analysis error: {ups_analysis['error']}")
75
+ return False
76
+
77
+ print(f"UPS analysis completed for carrier: {ups_analysis.get('carrier_name', 'unknown')}")
78
+ print(f"Found {len(ups_analysis.get('files', []))} files")
79
+ print(f"Structure components: {ups_analysis.get('structure', {})}")
80
+
81
+ if 'mapping_patterns' in ups_analysis:
82
+ print(f"Found {len(ups_analysis['mapping_patterns'])} mapping patterns")
83
+
84
+ if 'schema_patterns' in ups_analysis:
85
+ print(f"Found {len(ups_analysis['schema_patterns'])} schema patterns")
86
+
87
+ print("✅ Connector analysis tests passed")
88
+ return True
89
+
90
+ except Exception as e:
91
+ print(f"❌ Connector analysis test failed: {e}")
92
+ return False
93
+
94
+
95
+ def test_extract_carrier_patterns():
96
+ """Test the extract_carrier_patterns tool."""
97
+ print("\n=== Testing Pattern Extraction ===")
98
+
99
+ try:
100
+ # Test pattern extraction from similar carriers
101
+ patterns = extract_carrier_patterns(
102
+ similar_carriers=["ups", "fedex", "canadapost"],
103
+ pattern_type="mapping"
104
+ )
105
+
106
+ if "error" in patterns:
107
+ print(f"Pattern extraction error: {patterns['error']}")
108
+ return False
109
+
110
+ print(f"Analyzed carriers: {patterns['analyzed_carriers']}")
111
+ print(f"Pattern type: {patterns['pattern_type']}")
112
+ print(f"Found common patterns for {len(patterns['common_patterns'])} carriers")
113
+
114
+ if 'best_practices' in patterns:
115
+ print(f"Extracted {len(patterns['best_practices'])} best practices")
116
+ for bp in patterns['best_practices'][:2]:
117
+ print(f" - {bp['description'][:50]}... (confidence: {bp['confidence']})")
118
+
119
+ print("✅ Pattern extraction tests passed")
120
+ return True
121
+
122
+ except Exception as e:
123
+ print(f"❌ Pattern extraction test failed: {e}")
124
+ return False
125
+
126
+
127
+ def test_generate_carrier_schema():
128
+ """Test the generate_carrier_schema tool."""
129
+ print("\n=== Testing Schema Generation ===")
130
+
131
+ try:
132
+ # Test with sample JSON schema
133
+ sample_json_schema = '''
134
+ {
135
+ "type": "object",
136
+ "properties": {
137
+ "rate_id": {"type": "string"},
138
+ "service_name": {"type": "string"},
139
+ "total_cost": {"type": "number"},
140
+ "currency": {"type": "string"},
141
+ "delivery_days": {"type": "integer"}
142
+ }
143
+ }
144
+ '''
145
+
146
+ schema_result = generate_carrier_schema(
147
+ carrier_name="test_carrier",
148
+ api_documentation=sample_json_schema,
149
+ schema_type="rates"
150
+ )
151
+
152
+ if "error" in schema_result:
153
+ print(f"Schema generation error: {schema_result['error']}")
154
+ return False
155
+
156
+ print(f"Generated schemas for: {schema_result['carrier']}")
157
+ print(f"Schema type: {schema_result['schema_type']}")
158
+ print(f"Found {len(schema_result['classes'])} classes")
159
+ print(f"Required imports: {len(schema_result['imports'])}")
160
+
161
+ print("✅ Schema generation tests passed")
162
+ return True
163
+
164
+ except Exception as e:
165
+ print(f"❌ Schema generation test failed: {e}")
166
+ return False
167
+
168
+
169
+ def test_generate_carrier_mappings():
170
+ """Test the generate_carrier_mappings tool."""
171
+ print("\n=== Testing Mapping Generation ===")
172
+
173
+ try:
174
+ # Test mapping generation
175
+ api_endpoints = {
176
+ "rates": "https://api.testcarrier.com/v1/rates",
177
+ "shipments": "https://api.testcarrier.com/v1/shipments",
178
+ "tracking": "https://api.testcarrier.com/v1/tracking"
179
+ }
180
+
181
+ mapping_result = generate_carrier_mappings(
182
+ carrier_name="test_carrier",
183
+ api_endpoints=api_endpoints,
184
+ operation_type="complete"
185
+ )
186
+
187
+ if "error" in mapping_result:
188
+ print(f"Mapping generation error: {mapping_result['error']}")
189
+ return False
190
+
191
+ print(f"Generated mappings for: {mapping_result['carrier']}")
192
+ print(f"Operation type: {mapping_result['operation_type']}")
193
+ print(f"Generated {len(mapping_result['generated_mappings'])} mapping types")
194
+ print(f"API endpoints: {list(mapping_result['endpoints'].keys())}")
195
+
196
+ print("✅ Mapping generation tests passed")
197
+ return True
198
+
199
+ except Exception as e:
200
+ print(f"❌ Mapping generation test failed: {e}")
201
+ return False
202
+
203
+
204
+ def test_generate_integration_tests():
205
+ """Test the generate_integration_tests tool."""
206
+ print("\n=== Testing Test Generation ===")
207
+
208
+ try:
209
+ # Test test generation
210
+ test_data = {
211
+ "operations": ["rates", "shipments", "tracking"],
212
+ "test_addresses": {
213
+ "domestic": {"country": "US", "postal_code": "10001"},
214
+ "international": {"country": "CA", "postal_code": "M5V 3A1"}
215
+ }
216
+ }
217
+
218
+ test_result = generate_integration_tests(
219
+ carrier_name="test_carrier",
220
+ test_data=test_data,
221
+ test_type="complete"
222
+ )
223
+
224
+ if "error" in test_result:
225
+ print(f"Test generation error: {test_result['error']}")
226
+ return False
227
+
228
+ print(f"Generated tests for: {test_result['carrier']}")
229
+ print(f"Test type: {test_result['test_type']}")
230
+ print(f"Generated {len(test_result['generated_tests'])} test categories")
231
+
232
+ print("✅ Test generation tests passed")
233
+ return True
234
+
235
+ except Exception as e:
236
+ print(f"❌ Test generation test failed: {e}")
237
+ return False
238
+
239
+
240
+ def test_assemble_complete_integration():
241
+ """Test the assemble_complete_integration tool."""
242
+ print("\n=== Testing Integration Assembly ===")
243
+
244
+ try:
245
+ # Test complete integration assembly
246
+ integration_config = {
247
+ "carrier_name": "test_carrier",
248
+ "operations": ["rates", "shipments", "tracking"],
249
+ "auth_type": "API_KEY",
250
+ "api_base_url": "https://api.testcarrier.com/v1",
251
+ "test_mode": True
252
+ }
253
+
254
+ assembly_result = assemble_complete_integration(
255
+ carrier_name="test_carrier",
256
+ integration_config=integration_config
257
+ )
258
+
259
+ if "error" in assembly_result:
260
+ print(f"Integration assembly error: {assembly_result['error']}")
261
+ return False
262
+
263
+ print(f"Assembled integration for: {assembly_result['carrier']}")
264
+ print(f"Integration complete: {assembly_result['integration_complete']}")
265
+ print(f"Generated {len(assembly_result['generated_files'])} file types")
266
+ print(f"Project structure: {assembly_result['project_structure']['root']}")
267
+ print(f"Next steps: {len(assembly_result['next_steps'])} items")
268
+
269
+ for step in assembly_result['next_steps']:
270
+ print(f" - {step}")
271
+
272
+ print("✅ Integration assembly tests passed")
273
+ return True
274
+
275
+ except Exception as e:
276
+ print(f"❌ Integration assembly test failed: {e}")
277
+ return False
278
+
279
+
280
+ def test_agent_integration():
281
+ """Test the complete agent integration."""
282
+ print("\n=== Testing Agent Integration ===")
283
+
284
+ try:
285
+ # Test that all agents are properly configured
286
+ print(f"Root agent: {root_agent.name}")
287
+ print(f"Sub-agents: {len(root_agent.sub_agents)}")
288
+
289
+ # Verify agent names
290
+ agent_names = [agent.name for agent in root_agent.sub_agents]
291
+ expected_agents = ["schema_agent", "mapping_agent", "integration_agent", "testing_agent"]
292
+
293
+ for expected in expected_agents:
294
+ if expected in agent_names:
295
+ print(f"✅ {expected} is configured")
296
+ else:
297
+ print(f"❌ {expected} is missing")
298
+ return False
299
+
300
+ print("✅ Agent integration tests passed")
301
+ return True
302
+
303
+ except Exception as e:
304
+ print(f"❌ Agent integration test failed: {e}")
305
+ return False
306
+
307
+
308
+ def run_all_tests():
309
+ """Run all test functions."""
310
+ print("🚀 Starting Karrio ADK Agent Tests")
311
+ print("=" * 50)
312
+
313
+ tests = [
314
+ test_rag_system,
315
+ test_analyze_existing_connector,
316
+ test_extract_carrier_patterns,
317
+ test_generate_carrier_schema,
318
+ test_generate_carrier_mappings,
319
+ test_generate_integration_tests,
320
+ test_assemble_complete_integration,
321
+ test_agent_integration
322
+ ]
323
+
324
+ passed = 0
325
+ failed = 0
326
+
327
+ for test_func in tests:
328
+ try:
329
+ if test_func():
330
+ passed += 1
331
+ else:
332
+ failed += 1
333
+ except Exception as e:
334
+ print(f"❌ Test {test_func.__name__} crashed: {e}")
335
+ failed += 1
336
+
337
+ print("\n" + "=" * 50)
338
+ print(f"📊 Test Results: {passed} passed, {failed} failed")
339
+
340
+ if failed == 0:
341
+ print("🎉 All tests passed! The ADK agent is ready for use.")
342
+ else:
343
+ print("⚠️ Some tests failed. Please review the errors above.")
344
+
345
+ return failed == 0
346
+
347
+
348
+ if __name__ == "__main__":
349
+ success = run_all_tests()
350
+ sys.exit(0 if success else 1)