signalwire-agents 1.0.7__py3-none-any.whl → 1.0.17.dev4__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.
- signalwire_agents/__init__.py +1 -1
- signalwire_agents/agent_server.py +103 -68
- signalwire_agents/cli/dokku.py +2320 -0
- signalwire_agents/cli/init_project.py +1503 -92
- signalwire_agents/core/agent_base.py +25 -5
- signalwire_agents/core/mixins/auth_mixin.py +6 -13
- signalwire_agents/core/mixins/serverless_mixin.py +204 -112
- signalwire_agents/core/mixins/web_mixin.py +14 -6
- signalwire_agents/core/swml_service.py +4 -3
- signalwire_agents/mcp_gateway/__init__.py +29 -0
- signalwire_agents/mcp_gateway/gateway_service.py +564 -0
- signalwire_agents/mcp_gateway/mcp_manager.py +513 -0
- signalwire_agents/mcp_gateway/session_manager.py +218 -0
- signalwire_agents/search/pgvector_backend.py +10 -14
- signalwire_agents/skills/__init__.py +4 -1
- {signalwire_agents-1.0.7.data → signalwire_agents-1.0.17.dev4.data}/data/share/man/man1/sw-agent-init.1 +107 -14
- {signalwire_agents-1.0.7.dist-info → signalwire_agents-1.0.17.dev4.dist-info}/METADATA +4 -1
- {signalwire_agents-1.0.7.dist-info → signalwire_agents-1.0.17.dev4.dist-info}/RECORD +24 -19
- {signalwire_agents-1.0.7.dist-info → signalwire_agents-1.0.17.dev4.dist-info}/entry_points.txt +2 -0
- {signalwire_agents-1.0.7.data → signalwire_agents-1.0.17.dev4.data}/data/share/man/man1/sw-search.1 +0 -0
- {signalwire_agents-1.0.7.data → signalwire_agents-1.0.17.dev4.data}/data/share/man/man1/swaig-test.1 +0 -0
- {signalwire_agents-1.0.7.dist-info → signalwire_agents-1.0.17.dev4.dist-info}/WHEEL +0 -0
- {signalwire_agents-1.0.7.dist-info → signalwire_agents-1.0.17.dev4.dist-info}/licenses/LICENSE +0 -0
- {signalwire_agents-1.0.7.dist-info → signalwire_agents-1.0.17.dev4.dist-info}/top_level.txt +0 -0
signalwire_agents/__init__.py
CHANGED
|
@@ -18,7 +18,7 @@ A package for building AI agents using SignalWire's AI and SWML capabilities.
|
|
|
18
18
|
from .core.logging_config import configure_logging
|
|
19
19
|
configure_logging()
|
|
20
20
|
|
|
21
|
-
__version__ = "1.0.
|
|
21
|
+
__version__ = "1.0.17.dev4"
|
|
22
22
|
|
|
23
23
|
# Import core classes for easier access
|
|
24
24
|
from .core.agent_base import AgentBase
|
|
@@ -61,17 +61,28 @@ class AgentServer:
|
|
|
61
61
|
self.app = FastAPI(
|
|
62
62
|
title="SignalWire AI Agents",
|
|
63
63
|
description="Hosted SignalWire AI Agents",
|
|
64
|
-
version="0.
|
|
64
|
+
version="1.0.17.dev4",
|
|
65
65
|
redirect_slashes=False
|
|
66
66
|
)
|
|
67
67
|
|
|
68
68
|
# Keep track of registered agents
|
|
69
69
|
self.agents: Dict[str, AgentBase] = {}
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
# Keep track of SIP routing configuration
|
|
72
72
|
self._sip_routing_enabled = False
|
|
73
73
|
self._sip_route = None
|
|
74
74
|
self._sip_username_mapping: Dict[str, str] = {} # Maps SIP usernames to routes
|
|
75
|
+
|
|
76
|
+
# Register health endpoints immediately so they're available
|
|
77
|
+
# whether using server.run() or server.app with gunicorn
|
|
78
|
+
self._register_health_endpoints()
|
|
79
|
+
|
|
80
|
+
# Register catch-all handler on startup (not in __init__) so it runs AFTER
|
|
81
|
+
# all other routes are registered. This ensures custom routes like /get_token
|
|
82
|
+
# don't get overshadowed by the catch-all /{full_path:path} route.
|
|
83
|
+
@self.app.on_event("startup")
|
|
84
|
+
async def _setup_catch_all():
|
|
85
|
+
self._register_catch_all_handler()
|
|
75
86
|
|
|
76
87
|
def register(self, agent: AgentBase, route: Optional[str] = None) -> None:
|
|
77
88
|
"""
|
|
@@ -100,12 +111,12 @@ class AgentServer:
|
|
|
100
111
|
|
|
101
112
|
# Store the agent
|
|
102
113
|
self.agents[route] = agent
|
|
103
|
-
|
|
114
|
+
|
|
104
115
|
# Get the router and register it using the standard approach
|
|
105
116
|
# The agent's router already handles both trailing slash versions properly
|
|
106
117
|
router = agent.as_router()
|
|
107
118
|
self.app.include_router(router, prefix=route)
|
|
108
|
-
|
|
119
|
+
|
|
109
120
|
self.logger.info(f"Registered agent '{agent.get_name()}' at route '{route}'")
|
|
110
121
|
|
|
111
122
|
# If SIP routing is enabled and auto-mapping is on, register SIP usernames for this agent
|
|
@@ -519,13 +530,13 @@ class AgentServer:
|
|
|
519
530
|
sys.stdout.flush()
|
|
520
531
|
|
|
521
532
|
return response
|
|
522
|
-
|
|
523
|
-
def
|
|
524
|
-
"""
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
533
|
+
|
|
534
|
+
def _register_health_endpoints(self) -> None:
|
|
535
|
+
"""Register health and readiness endpoints.
|
|
536
|
+
|
|
537
|
+
Called during __init__ so endpoints are available whether using
|
|
538
|
+
server.run() or accessing server.app directly with gunicorn.
|
|
539
|
+
"""
|
|
529
540
|
@self.app.get("/health")
|
|
530
541
|
def health_check():
|
|
531
542
|
return {
|
|
@@ -533,66 +544,19 @@ class AgentServer:
|
|
|
533
544
|
"agents": len(self.agents),
|
|
534
545
|
"routes": list(self.agents.keys())
|
|
535
546
|
}
|
|
536
|
-
|
|
537
|
-
# Add catch-all route handler to handle both trailing slash and non-trailing slash versions
|
|
538
|
-
@self.app.get("/{full_path:path}")
|
|
539
|
-
@self.app.post("/{full_path:path}")
|
|
540
|
-
async def handle_all_routes(request: Request, full_path: str):
|
|
541
|
-
"""Handle requests that don't match registered routes (e.g. /matti instead of /matti/)"""
|
|
542
|
-
# Check if this path maps to one of our registered agents
|
|
543
|
-
for route, agent in self.agents.items():
|
|
544
|
-
# Check for exact match with registered route
|
|
545
|
-
if full_path == route.lstrip("/"):
|
|
546
|
-
# This is a request to an agent's root without trailing slash
|
|
547
|
-
return await agent._handle_root_request(request)
|
|
548
|
-
elif full_path.startswith(route.lstrip("/") + "/"):
|
|
549
|
-
# This is a request to an agent's sub-path
|
|
550
|
-
relative_path = full_path[len(route.lstrip("/")):]
|
|
551
|
-
relative_path = relative_path.lstrip("/")
|
|
552
|
-
|
|
553
|
-
# Route to appropriate handler based on path
|
|
554
|
-
if not relative_path or relative_path == "/":
|
|
555
|
-
return await agent._handle_root_request(request)
|
|
556
547
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
elif clean_path == "post_prompt":
|
|
564
|
-
return await agent._handle_post_prompt_request(request)
|
|
565
|
-
elif clean_path == "check_for_input":
|
|
566
|
-
return await agent._handle_check_for_input_request(request)
|
|
567
|
-
|
|
568
|
-
# Check for custom routing callbacks
|
|
569
|
-
if hasattr(agent, '_routing_callbacks'):
|
|
570
|
-
for callback_path, callback_fn in agent._routing_callbacks.items():
|
|
571
|
-
cb_path_clean = callback_path.strip("/")
|
|
572
|
-
if clean_path == cb_path_clean:
|
|
573
|
-
request.state.callback_path = callback_path
|
|
574
|
-
return await agent._handle_root_request(request)
|
|
548
|
+
@self.app.get("/ready")
|
|
549
|
+
def readiness_check():
|
|
550
|
+
return {
|
|
551
|
+
"status": "ready",
|
|
552
|
+
"agents": len(self.agents)
|
|
553
|
+
}
|
|
575
554
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
# For root static route, serve any unmatched path
|
|
581
|
-
if static_route == "" or static_route == "/":
|
|
582
|
-
response = self._serve_static_file(full_path, "")
|
|
583
|
-
if response:
|
|
584
|
-
return response
|
|
585
|
-
# For prefixed static routes, check if path matches
|
|
586
|
-
elif full_path.startswith(static_route.lstrip("/") + "/") or full_path == static_route.lstrip("/"):
|
|
587
|
-
relative_path = full_path[len(static_route.lstrip("/")):].lstrip("/")
|
|
588
|
-
response = self._serve_static_file(relative_path, static_route)
|
|
589
|
-
if response:
|
|
590
|
-
return response
|
|
555
|
+
def _run_server(self, host: Optional[str] = None, port: Optional[int] = None) -> None:
|
|
556
|
+
"""Original server mode logic"""
|
|
557
|
+
if not self.agents:
|
|
558
|
+
self.logger.warning("Starting server with no registered agents")
|
|
591
559
|
|
|
592
|
-
# No matching agent or static file found
|
|
593
|
-
from fastapi import HTTPException
|
|
594
|
-
raise HTTPException(status_code=404, detail="Not Found")
|
|
595
|
-
|
|
596
560
|
# Set host and port
|
|
597
561
|
host = host or self.host
|
|
598
562
|
port = port or self.port
|
|
@@ -722,6 +686,7 @@ class AgentServer:
|
|
|
722
686
|
|
|
723
687
|
self.logger.info(f"Serving static files from '{directory}' at route '{route or '/'}'")
|
|
724
688
|
|
|
689
|
+
|
|
725
690
|
def _serve_static_file(self, file_path: str, route: str = "/") -> Optional[Response]:
|
|
726
691
|
"""
|
|
727
692
|
Internal method to serve a static file.
|
|
@@ -769,3 +734,73 @@ class AgentServer:
|
|
|
769
734
|
return None
|
|
770
735
|
|
|
771
736
|
return FileResponse(full_path)
|
|
737
|
+
|
|
738
|
+
def _register_catch_all_handler(self) -> None:
|
|
739
|
+
"""
|
|
740
|
+
Register catch-all route handler for agent routing and static files.
|
|
741
|
+
|
|
742
|
+
This handler is needed for:
|
|
743
|
+
1. Routing requests without trailing slashes to agents (e.g., /santa instead of /santa/)
|
|
744
|
+
2. Serving static files from directories registered with serve_static_files()
|
|
745
|
+
|
|
746
|
+
Called via startup event (not __init__) to ensure it runs AFTER all other routes
|
|
747
|
+
are registered. This prevents the catch-all from overshadowing custom routes
|
|
748
|
+
like /get_token that users may add to server.app.
|
|
749
|
+
"""
|
|
750
|
+
@self.app.get("/{full_path:path}")
|
|
751
|
+
@self.app.post("/{full_path:path}")
|
|
752
|
+
async def handle_all_routes(request: Request, full_path: str):
|
|
753
|
+
"""Handle requests that don't match registered routes (e.g. /matti instead of /matti/)"""
|
|
754
|
+
# Check if this path maps to one of our registered agents
|
|
755
|
+
for route, agent in self.agents.items():
|
|
756
|
+
# Check for exact match with registered route
|
|
757
|
+
if full_path == route.lstrip("/"):
|
|
758
|
+
# This is a request to an agent's root without trailing slash
|
|
759
|
+
return await agent._handle_root_request(request)
|
|
760
|
+
elif full_path.startswith(route.lstrip("/") + "/"):
|
|
761
|
+
# This is a request to an agent's sub-path
|
|
762
|
+
relative_path = full_path[len(route.lstrip("/")):]
|
|
763
|
+
relative_path = relative_path.lstrip("/")
|
|
764
|
+
|
|
765
|
+
# Route to appropriate handler based on path
|
|
766
|
+
if not relative_path or relative_path == "/":
|
|
767
|
+
return await agent._handle_root_request(request)
|
|
768
|
+
|
|
769
|
+
clean_path = relative_path.rstrip("/")
|
|
770
|
+
if clean_path == "debug":
|
|
771
|
+
return await agent._handle_debug_request(request)
|
|
772
|
+
elif clean_path == "swaig":
|
|
773
|
+
from fastapi import Response
|
|
774
|
+
return await agent._handle_swaig_request(request, Response())
|
|
775
|
+
elif clean_path == "post_prompt":
|
|
776
|
+
return await agent._handle_post_prompt_request(request)
|
|
777
|
+
elif clean_path == "check_for_input":
|
|
778
|
+
return await agent._handle_check_for_input_request(request)
|
|
779
|
+
|
|
780
|
+
# Check for custom routing callbacks
|
|
781
|
+
if hasattr(agent, '_routing_callbacks'):
|
|
782
|
+
for callback_path, callback_fn in agent._routing_callbacks.items():
|
|
783
|
+
cb_path_clean = callback_path.strip("/")
|
|
784
|
+
if clean_path == cb_path_clean:
|
|
785
|
+
request.state.callback_path = callback_path
|
|
786
|
+
return await agent._handle_root_request(request)
|
|
787
|
+
|
|
788
|
+
# No matching agent - check for static files
|
|
789
|
+
if hasattr(self, '_static_directories'):
|
|
790
|
+
# Check each static directory route
|
|
791
|
+
for static_route, static_dir in self._static_directories.items():
|
|
792
|
+
# For root static route, serve any unmatched path
|
|
793
|
+
if static_route == "" or static_route == "/":
|
|
794
|
+
response = self._serve_static_file(full_path, "")
|
|
795
|
+
if response:
|
|
796
|
+
return response
|
|
797
|
+
# For prefixed static routes, check if path matches
|
|
798
|
+
elif full_path.startswith(static_route.lstrip("/") + "/") or full_path == static_route.lstrip("/"):
|
|
799
|
+
relative_path = full_path[len(static_route.lstrip("/")):].lstrip("/")
|
|
800
|
+
response = self._serve_static_file(relative_path, static_route)
|
|
801
|
+
if response:
|
|
802
|
+
return response
|
|
803
|
+
|
|
804
|
+
# No matching agent or static file found
|
|
805
|
+
from fastapi import HTTPException
|
|
806
|
+
raise HTTPException(status_code=404, detail="Not Found")
|