langchain-trigger-server 0.1.1__tar.gz → 0.1.3__tar.gz

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.

Potentially problematic release.


This version of langchain-trigger-server might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langchain-trigger-server
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Generic event-driven triggers framework
5
5
  Project-URL: Homepage, https://github.com/langchain-ai/open-agent-platform
6
6
  Project-URL: Repository, https://github.com/langchain-ai/open-agent-platform
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.12
18
18
  Requires-Python: >=3.9
19
19
  Requires-Dist: fastapi>=0.100.0
20
20
  Requires-Dist: httpx>=0.24.0
21
+ Requires-Dist: langgraph-sdk>=0.2.6
21
22
  Requires-Dist: pydantic>=2.0.0
22
23
  Requires-Dist: python-jose[cryptography]>=3.3.0
23
24
  Requires-Dist: python-multipart>=0.0.6
@@ -9,7 +9,7 @@ from typing import Any, Callable, Dict, List, Optional
9
9
  import httpx
10
10
 
11
11
  from fastapi import FastAPI, HTTPException, Request, Depends
12
- from fastapi.middleware.cors import CORSMiddleware
12
+ from langgraph_sdk import get_client
13
13
  from starlette.middleware.base import BaseHTTPMiddleware
14
14
  from starlette.responses import Response
15
15
 
@@ -72,8 +72,7 @@ class TriggerServer:
72
72
  def __init__(
73
73
  self,
74
74
  auth_handler: Callable,
75
- cors_origins: Optional[List[str]] = None,
76
- database: Optional[TriggerDatabaseInterface] = None,
75
+ langgraph_headers_builder: Callable,
77
76
  ):
78
77
  self.app = FastAPI(
79
78
  title="Triggers Server",
@@ -81,8 +80,9 @@ class TriggerServer:
81
80
  version="0.1.0"
82
81
  )
83
82
 
84
- self.database = database or create_database() # Default to Supabase
83
+ self.database = create_database()
85
84
  self.auth_handler = auth_handler
85
+ self.langgraph_headers_builder = langgraph_headers_builder
86
86
 
87
87
  # LangGraph configuration
88
88
  self.langgraph_api_url = os.getenv("LANGGRAPH_API_URL")
@@ -93,6 +93,9 @@ class TriggerServer:
93
93
 
94
94
  self.langgraph_api_url = self.langgraph_api_url.rstrip("/")
95
95
 
96
+ # Initialize LangGraph SDK client
97
+ self.langgraph_client = get_client(url=self.langgraph_api_url)
98
+
96
99
  self.langchain_auth_client = None
97
100
  try:
98
101
  from langchain_auth import Client
@@ -107,18 +110,6 @@ class TriggerServer:
107
110
 
108
111
  self.triggers: List[TriggerTemplate] = []
109
112
 
110
- # Setup CORS
111
- if cors_origins is None:
112
- cors_origins = ["*"] # Allow all origins by default
113
-
114
- self.app.add_middleware(
115
- CORSMiddleware,
116
- allow_origins=cors_origins,
117
- allow_credentials=True,
118
- allow_methods=["*"],
119
- allow_headers=["*"],
120
- )
121
-
122
113
  # Setup authentication middleware
123
114
  self.app.add_middleware(AuthenticationMiddleware, auth_handler=auth_handler)
124
115
 
@@ -282,7 +273,7 @@ class TriggerServer:
282
273
  except Exception as e:
283
274
  raise HTTPException(
284
275
  status_code=400,
285
- detail=f"Invalid payload for trigger {trigger_type}: {str(e)}"
276
+ detail=f"Invalid payload for trigger: {str(e)}"
286
277
  )
287
278
 
288
279
  # Call the trigger's registration handler with parsed registration model
@@ -568,54 +559,35 @@ class TriggerServer:
568
559
  user_id: str,
569
560
  input_data: Dict[str, Any],
570
561
  ) -> Dict[str, Any]:
571
- """Invoke LangGraph agent directly."""
572
- headers = {
573
- "Content-Type": "application/json",
574
- "x-auth-scheme": "langchain-trigger-server-event",
575
- }
576
-
577
- # Add API key if provided
578
- if self.langgraph_api_key:
579
- headers["Authorization"] = f"Bearer {self.langgraph_api_key}"
580
-
581
- # Add user-specific headers
582
- if user_id:
583
- headers["x-supabase-user-id"] = user_id
584
-
585
- payload = {
586
- "input": input_data,
587
- "assistant_id": agent_id,
588
- "metadata": {
589
- "triggered_by": "langchain-triggers",
590
- "user_id": user_id,
591
- },
592
- }
593
-
594
- # Let LangGraph create a new thread automatically
595
- url = f"{self.langgraph_api_url}/runs"
596
-
562
+ """Invoke LangGraph agent using the SDK."""
597
563
  logger.info(f"Invoking LangGraph agent {agent_id} for user {user_id}")
598
564
 
599
- async with httpx.AsyncClient() as client:
600
- try:
601
- response = await client.post(
602
- url,
603
- json=payload,
604
- headers=headers,
605
- timeout=30.0,
606
- )
607
- response.raise_for_status()
608
-
609
- result = response.json()
610
- logger.info(f"Successfully invoked agent {agent_id}")
611
- return result
612
-
613
- except httpx.HTTPStatusError as e:
614
- logger.error(f"HTTP error invoking agent: {e.response.status_code} - {e.response.text}")
615
- raise
616
- except Exception as e:
617
- logger.error(f"Error invoking agent {agent_id}: {e}")
618
- raise
565
+ try:
566
+ # Build headers using the custom function
567
+ headers = await self.langgraph_headers_builder(
568
+ user_id=user_id,
569
+ api_key=self.langgraph_api_key,
570
+ agent_id=agent_id
571
+ )
572
+
573
+ # Create a background run using the SDK
574
+ run = await self.langgraph_client.runs.create(
575
+ thread_id=None, # Let LangGraph create a new thread
576
+ assistant_id=agent_id,
577
+ input=input_data,
578
+ metadata={
579
+ "triggered_by": "langchain-triggers",
580
+ "user_id": user_id,
581
+ },
582
+ headers=headers,
583
+ )
584
+
585
+ logger.info(f"Successfully invoked agent {agent_id}, run_id: {run['run_id']}")
586
+ return run
587
+
588
+ except Exception as e:
589
+ logger.error(f"Error invoking agent {agent_id}: {e}")
590
+ raise
619
591
 
620
592
  async def _get_authenticated_user(self, trigger: TriggerTemplate, user_id: str) -> UserAuthInfo:
621
593
  """Get authenticated user with OAuth tokens for the trigger's required providers."""
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "langchain-trigger-server"
7
- version = "0.1.1"
7
+ version = "0.1.3"
8
8
  description = "Generic event-driven triggers framework"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -30,6 +30,7 @@ dependencies = [
30
30
  "httpx>=0.24.0",
31
31
  "python-multipart>=0.0.6",
32
32
  "python-jose[cryptography]>=3.3.0",
33
+ "langgraph-sdk>=0.2.6",
33
34
  ]
34
35
 
35
36
  [project.optional-dependencies]