signalwire-agents 1.0.13__py3-none-any.whl → 1.0.14__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 +80 -58
- signalwire_agents/cli/dokku.py +945 -151
- {signalwire_agents-1.0.13.dist-info → signalwire_agents-1.0.14.dist-info}/METADATA +1 -1
- {signalwire_agents-1.0.13.dist-info → signalwire_agents-1.0.14.dist-info}/RECORD +12 -12
- {signalwire_agents-1.0.13.data → signalwire_agents-1.0.14.data}/data/share/man/man1/sw-agent-init.1 +0 -0
- {signalwire_agents-1.0.13.data → signalwire_agents-1.0.14.data}/data/share/man/man1/sw-search.1 +0 -0
- {signalwire_agents-1.0.13.data → signalwire_agents-1.0.14.data}/data/share/man/man1/swaig-test.1 +0 -0
- {signalwire_agents-1.0.13.dist-info → signalwire_agents-1.0.14.dist-info}/WHEEL +0 -0
- {signalwire_agents-1.0.13.dist-info → signalwire_agents-1.0.14.dist-info}/entry_points.txt +0 -0
- {signalwire_agents-1.0.13.dist-info → signalwire_agents-1.0.14.dist-info}/licenses/LICENSE +0 -0
- {signalwire_agents-1.0.13.dist-info → signalwire_agents-1.0.14.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.14"
|
|
22
22
|
|
|
23
23
|
# Import core classes for easier access
|
|
24
24
|
from .core.agent_base import AgentBase
|
|
@@ -550,65 +550,9 @@ class AgentServer:
|
|
|
550
550
|
if not self.agents:
|
|
551
551
|
self.logger.warning("Starting server with no registered agents")
|
|
552
552
|
|
|
553
|
-
#
|
|
554
|
-
|
|
555
|
-
@self.app.post("/{full_path:path}")
|
|
556
|
-
async def handle_all_routes(request: Request, full_path: str):
|
|
557
|
-
"""Handle requests that don't match registered routes (e.g. /matti instead of /matti/)"""
|
|
558
|
-
# Check if this path maps to one of our registered agents
|
|
559
|
-
for route, agent in self.agents.items():
|
|
560
|
-
# Check for exact match with registered route
|
|
561
|
-
if full_path == route.lstrip("/"):
|
|
562
|
-
# This is a request to an agent's root without trailing slash
|
|
563
|
-
return await agent._handle_root_request(request)
|
|
564
|
-
elif full_path.startswith(route.lstrip("/") + "/"):
|
|
565
|
-
# This is a request to an agent's sub-path
|
|
566
|
-
relative_path = full_path[len(route.lstrip("/")):]
|
|
567
|
-
relative_path = relative_path.lstrip("/")
|
|
553
|
+
# Register catch-all route handler (handles agent routing and static files)
|
|
554
|
+
self._register_catch_all_handler()
|
|
568
555
|
|
|
569
|
-
# Route to appropriate handler based on path
|
|
570
|
-
if not relative_path or relative_path == "/":
|
|
571
|
-
return await agent._handle_root_request(request)
|
|
572
|
-
|
|
573
|
-
clean_path = relative_path.rstrip("/")
|
|
574
|
-
if clean_path == "debug":
|
|
575
|
-
return await agent._handle_debug_request(request)
|
|
576
|
-
elif clean_path == "swaig":
|
|
577
|
-
from fastapi import Response
|
|
578
|
-
return await agent._handle_swaig_request(request, Response())
|
|
579
|
-
elif clean_path == "post_prompt":
|
|
580
|
-
return await agent._handle_post_prompt_request(request)
|
|
581
|
-
elif clean_path == "check_for_input":
|
|
582
|
-
return await agent._handle_check_for_input_request(request)
|
|
583
|
-
|
|
584
|
-
# Check for custom routing callbacks
|
|
585
|
-
if hasattr(agent, '_routing_callbacks'):
|
|
586
|
-
for callback_path, callback_fn in agent._routing_callbacks.items():
|
|
587
|
-
cb_path_clean = callback_path.strip("/")
|
|
588
|
-
if clean_path == cb_path_clean:
|
|
589
|
-
request.state.callback_path = callback_path
|
|
590
|
-
return await agent._handle_root_request(request)
|
|
591
|
-
|
|
592
|
-
# No matching agent - check for static files
|
|
593
|
-
if hasattr(self, '_static_directories'):
|
|
594
|
-
# Check each static directory route
|
|
595
|
-
for static_route, static_dir in self._static_directories.items():
|
|
596
|
-
# For root static route, serve any unmatched path
|
|
597
|
-
if static_route == "" or static_route == "/":
|
|
598
|
-
response = self._serve_static_file(full_path, "")
|
|
599
|
-
if response:
|
|
600
|
-
return response
|
|
601
|
-
# For prefixed static routes, check if path matches
|
|
602
|
-
elif full_path.startswith(static_route.lstrip("/") + "/") or full_path == static_route.lstrip("/"):
|
|
603
|
-
relative_path = full_path[len(static_route.lstrip("/")):].lstrip("/")
|
|
604
|
-
response = self._serve_static_file(relative_path, static_route)
|
|
605
|
-
if response:
|
|
606
|
-
return response
|
|
607
|
-
|
|
608
|
-
# No matching agent or static file found
|
|
609
|
-
from fastapi import HTTPException
|
|
610
|
-
raise HTTPException(status_code=404, detail="Not Found")
|
|
611
|
-
|
|
612
556
|
# Set host and port
|
|
613
557
|
host = host or self.host
|
|
614
558
|
port = port or self.port
|
|
@@ -738,6 +682,10 @@ class AgentServer:
|
|
|
738
682
|
|
|
739
683
|
self.logger.info(f"Serving static files from '{directory}' at route '{route or '/'}'")
|
|
740
684
|
|
|
685
|
+
# Register catch-all handler immediately so it works with gunicorn
|
|
686
|
+
# (when using server.app directly instead of server.run())
|
|
687
|
+
self._register_catch_all_handler()
|
|
688
|
+
|
|
741
689
|
def _serve_static_file(self, file_path: str, route: str = "/") -> Optional[Response]:
|
|
742
690
|
"""
|
|
743
691
|
Internal method to serve a static file.
|
|
@@ -785,3 +733,77 @@ class AgentServer:
|
|
|
785
733
|
return None
|
|
786
734
|
|
|
787
735
|
return FileResponse(full_path)
|
|
736
|
+
|
|
737
|
+
def _register_catch_all_handler(self) -> None:
|
|
738
|
+
"""
|
|
739
|
+
Register catch-all route handler for agent routing and static files.
|
|
740
|
+
|
|
741
|
+
This handler is needed for:
|
|
742
|
+
1. Routing requests without trailing slashes to agents (e.g., /santa instead of /santa/)
|
|
743
|
+
2. Serving static files from directories registered with serve_static_files()
|
|
744
|
+
|
|
745
|
+
The handler is registered once and works with both server.run() and
|
|
746
|
+
direct use of server.app with gunicorn/uvicorn.
|
|
747
|
+
"""
|
|
748
|
+
# Only register once
|
|
749
|
+
if getattr(self, '_catch_all_registered', False):
|
|
750
|
+
return
|
|
751
|
+
self._catch_all_registered = True
|
|
752
|
+
|
|
753
|
+
@self.app.get("/{full_path:path}")
|
|
754
|
+
@self.app.post("/{full_path:path}")
|
|
755
|
+
async def handle_all_routes(request: Request, full_path: str):
|
|
756
|
+
"""Handle requests that don't match registered routes (e.g. /matti instead of /matti/)"""
|
|
757
|
+
# Check if this path maps to one of our registered agents
|
|
758
|
+
for route, agent in self.agents.items():
|
|
759
|
+
# Check for exact match with registered route
|
|
760
|
+
if full_path == route.lstrip("/"):
|
|
761
|
+
# This is a request to an agent's root without trailing slash
|
|
762
|
+
return await agent._handle_root_request(request)
|
|
763
|
+
elif full_path.startswith(route.lstrip("/") + "/"):
|
|
764
|
+
# This is a request to an agent's sub-path
|
|
765
|
+
relative_path = full_path[len(route.lstrip("/")):]
|
|
766
|
+
relative_path = relative_path.lstrip("/")
|
|
767
|
+
|
|
768
|
+
# Route to appropriate handler based on path
|
|
769
|
+
if not relative_path or relative_path == "/":
|
|
770
|
+
return await agent._handle_root_request(request)
|
|
771
|
+
|
|
772
|
+
clean_path = relative_path.rstrip("/")
|
|
773
|
+
if clean_path == "debug":
|
|
774
|
+
return await agent._handle_debug_request(request)
|
|
775
|
+
elif clean_path == "swaig":
|
|
776
|
+
from fastapi import Response
|
|
777
|
+
return await agent._handle_swaig_request(request, Response())
|
|
778
|
+
elif clean_path == "post_prompt":
|
|
779
|
+
return await agent._handle_post_prompt_request(request)
|
|
780
|
+
elif clean_path == "check_for_input":
|
|
781
|
+
return await agent._handle_check_for_input_request(request)
|
|
782
|
+
|
|
783
|
+
# Check for custom routing callbacks
|
|
784
|
+
if hasattr(agent, '_routing_callbacks'):
|
|
785
|
+
for callback_path, callback_fn in agent._routing_callbacks.items():
|
|
786
|
+
cb_path_clean = callback_path.strip("/")
|
|
787
|
+
if clean_path == cb_path_clean:
|
|
788
|
+
request.state.callback_path = callback_path
|
|
789
|
+
return await agent._handle_root_request(request)
|
|
790
|
+
|
|
791
|
+
# No matching agent - check for static files
|
|
792
|
+
if hasattr(self, '_static_directories'):
|
|
793
|
+
# Check each static directory route
|
|
794
|
+
for static_route, static_dir in self._static_directories.items():
|
|
795
|
+
# For root static route, serve any unmatched path
|
|
796
|
+
if static_route == "" or static_route == "/":
|
|
797
|
+
response = self._serve_static_file(full_path, "")
|
|
798
|
+
if response:
|
|
799
|
+
return response
|
|
800
|
+
# For prefixed static routes, check if path matches
|
|
801
|
+
elif full_path.startswith(static_route.lstrip("/") + "/") or full_path == static_route.lstrip("/"):
|
|
802
|
+
relative_path = full_path[len(static_route.lstrip("/")):].lstrip("/")
|
|
803
|
+
response = self._serve_static_file(relative_path, static_route)
|
|
804
|
+
if response:
|
|
805
|
+
return response
|
|
806
|
+
|
|
807
|
+
# No matching agent or static file found
|
|
808
|
+
from fastapi import HTTPException
|
|
809
|
+
raise HTTPException(status_code=404, detail="Not Found")
|