|
1 | | - |
2 | 1 | """Main entry point for the Component Gallery agent.""" |
| 2 | + |
3 | 3 | import logging |
4 | 4 | import os |
5 | 5 | import sys |
|
29 | 29 |
|
30 | 30 | logger = logging.getLogger(__name__) |
31 | 31 |
|
| 32 | + |
32 | 33 | @click.command() |
33 | 34 | @click.option("--host", default="localhost") |
34 | 35 | @click.option("--port", default=10005) |
35 | 36 | def main(host, port): |
36 | | - try: |
37 | | - capabilities = AgentCapabilities( |
38 | | - streaming=True, |
39 | | - extensions=[get_a2ui_agent_extension()], |
40 | | - ) |
41 | | - |
42 | | - # Skill definition |
43 | | - skill = AgentSkill( |
44 | | - id="component_gallery", |
45 | | - name="Component Gallery", |
46 | | - description="Demonstrates A2UI components.", |
47 | | - tags=["gallery", "demo"], |
48 | | - examples=["Show me the gallery"], |
49 | | - ) |
50 | | - |
51 | | - base_url = f"http://{host}:{port}" |
52 | | - |
53 | | - agent_card = AgentCard( |
54 | | - name="Component Gallery Agent", |
55 | | - description="A2UI Component Gallery", |
56 | | - url=base_url, |
57 | | - version="0.0.1", |
58 | | - default_input_modes=["text"], |
59 | | - default_output_modes=["text"], |
60 | | - capabilities=capabilities, |
61 | | - skills=[skill], |
62 | | - ) |
63 | | - |
64 | | - agent_executor = ComponentGalleryExecutor(base_url=base_url) |
65 | | - |
66 | | - request_handler = DefaultRequestHandler( |
67 | | - agent_executor=agent_executor, |
68 | | - task_store=InMemoryTaskStore(), |
69 | | - ) |
70 | | - |
71 | | - server = A2AStarletteApplication( |
72 | | - agent_card=agent_card, http_handler=request_handler |
73 | | - ) |
74 | | - |
75 | | - app = server.build() |
76 | | - |
77 | | - app.add_middleware( |
78 | | - CORSMiddleware, |
79 | | - allow_origins=["http://localhost:5173"], |
80 | | - allow_credentials=True, |
81 | | - allow_methods=["*"], |
82 | | - allow_headers=["*"], |
83 | | - ) |
84 | | - |
85 | | - # Mount assets directory |
86 | | - assets_dir = os.path.join(os.path.dirname(__file__), "assets") |
87 | | - if os.path.exists(assets_dir): |
88 | | - app.mount("/assets", StaticFiles(directory=assets_dir), name="assets") |
89 | | - else: |
90 | | - logger.warning(f"Assets directory not found at {assets_dir}") |
91 | | - |
92 | | - print(f"Starting Component Gallery Agent on port {port}...") |
93 | | - uvicorn.run(app, host=host, port=port) |
94 | | - |
95 | | - except Exception as e: |
96 | | - logger.error(f"An error occurred during server startup: {e}") |
97 | | - exit(1) |
| 37 | + try: |
| 38 | + capabilities = AgentCapabilities( |
| 39 | + streaming=True, |
| 40 | + extensions=[get_a2ui_agent_extension()], |
| 41 | + ) |
| 42 | + |
| 43 | + # Skill definition |
| 44 | + skill = AgentSkill( |
| 45 | + id="component_gallery", |
| 46 | + name="Component Gallery", |
| 47 | + description="Demonstrates A2UI components.", |
| 48 | + tags=["gallery", "demo"], |
| 49 | + examples=["Show me the gallery"], |
| 50 | + ) |
| 51 | + |
| 52 | + base_url = f"http://{host}:{port}" |
| 53 | + |
| 54 | + agent_card = AgentCard( |
| 55 | + name="Component Gallery Agent", |
| 56 | + description="A2UI Component Gallery", |
| 57 | + url=base_url, |
| 58 | + version="0.0.1", |
| 59 | + default_input_modes=["text"], |
| 60 | + default_output_modes=["text"], |
| 61 | + capabilities=capabilities, |
| 62 | + skills=[skill], |
| 63 | + ) |
| 64 | + |
| 65 | + agent_executor = ComponentGalleryExecutor(base_url=base_url) |
| 66 | + |
| 67 | + request_handler = DefaultRequestHandler( |
| 68 | + agent_executor=agent_executor, |
| 69 | + task_store=InMemoryTaskStore(), |
| 70 | + ) |
| 71 | + |
| 72 | + server = A2AStarletteApplication( |
| 73 | + agent_card=agent_card, http_handler=request_handler |
| 74 | + ) |
| 75 | + |
| 76 | + app = server.build() |
| 77 | + |
| 78 | + app.add_middleware( |
| 79 | + CORSMiddleware, |
| 80 | + allow_origins=["http://localhost:5173"], |
| 81 | + allow_credentials=True, |
| 82 | + allow_methods=["*"], |
| 83 | + allow_headers=["*"], |
| 84 | + ) |
| 85 | + |
| 86 | + # Mount assets directory |
| 87 | + assets_dir = os.path.join(os.path.dirname(__file__), "assets") |
| 88 | + if os.path.exists(assets_dir): |
| 89 | + app.mount("/assets", StaticFiles(directory=assets_dir), name="assets") |
| 90 | + else: |
| 91 | + logger.warning(f"Assets directory not found at {assets_dir}") |
| 92 | + |
| 93 | + print(f"Starting Component Gallery Agent on port {port}...") |
| 94 | + uvicorn.run(app, host=host, port=port) |
| 95 | + |
| 96 | + except Exception as e: |
| 97 | + logger.error(f"An error occurred during server startup: {e}") |
| 98 | + exit(1) |
| 99 | + |
98 | 100 |
|
99 | 101 | if __name__ == "__main__": |
100 | | - main() |
| 102 | + main() |
0 commit comments