jvserve 2.1.17__tar.gz → 2.1.18__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 jvserve might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jvserve
3
- Version: 2.1.17
3
+ Version: 2.1.18
4
4
  Summary: FastAPI webserver for loading and interaction with JIVAS agents.
5
5
  Home-page: https://github.com/TrueSelph/jvserve
6
6
  Author: TrueSelph Inc.
@@ -18,9 +18,9 @@ import pymongo
18
18
  import requests
19
19
  from bson import ObjectId
20
20
  from dotenv import load_dotenv
21
- from fastapi import FastAPI, HTTPException, Response
21
+ from fastapi import FastAPI, HTTPException, Request, Response
22
22
  from fastapi.middleware.cors import CORSMiddleware
23
- from fastapi.responses import FileResponse, StreamingResponse
23
+ from fastapi.responses import FileResponse, JSONResponse, StreamingResponse
24
24
  from jac_cloud.core.context import JaseciContext
25
25
  from jac_cloud.jaseci.main import FastAPI as JaseciFastAPI # type: ignore
26
26
  from jac_cloud.jaseci.utils import logger
@@ -244,6 +244,42 @@ def run_jivas(filename: str, host: str = "localhost", port: int = 8000) -> None:
244
244
  allow_headers=["*"],
245
245
  )
246
246
 
247
+ @app.get("/action/webhook/{namespace}/{action}/{walker}/{agent_id}/{key}")
248
+ async def webhook_exec_get(
249
+ namespace: str,
250
+ action: str,
251
+ walker: str,
252
+ agent_id: str,
253
+ key: str,
254
+ request: Request,
255
+ ) -> JSONResponse:
256
+ return await agent_interface.webhook_exec(
257
+ namespace=namespace,
258
+ action=action,
259
+ walker=walker,
260
+ agent_id=agent_id,
261
+ key=key,
262
+ request=request,
263
+ )
264
+
265
+ @app.post("/action/webhook/{namespace}/{action}/{walker}/{agent_id}/{key}")
266
+ async def webhook_exec_post(
267
+ namespace: str,
268
+ action: str,
269
+ walker: str,
270
+ agent_id: str,
271
+ key: str,
272
+ request: Request,
273
+ ) -> JSONResponse:
274
+ return await agent_interface.webhook_exec(
275
+ namespace=namespace,
276
+ action=action,
277
+ walker=walker,
278
+ agent_id=agent_id,
279
+ key=key,
280
+ request=request,
281
+ )
282
+
247
283
  # Ensure the local file directory exists if that's the interface
248
284
  if FILE_INTERFACE == "local":
249
285
  directory = os.environ.get("JIVAS_FILES_ROOT_PATH", DEFAULT_FILES_ROOT)
@@ -6,6 +6,8 @@ import traceback
6
6
  from typing import Any
7
7
 
8
8
  import requests
9
+ from fastapi import Request
10
+ from fastapi.responses import JSONResponse
9
11
 
10
12
  from jvserve.lib.jac_interface import JacInterface
11
13
 
@@ -47,6 +49,61 @@ class AgentInterface:
47
49
  self._jac.reset()
48
50
  self.logger.error(f"Init error: {e}\n{traceback.format_exc()}")
49
51
 
52
+ async def webhook_exec(
53
+ self,
54
+ agent_id: str,
55
+ key: str,
56
+ namespace: str,
57
+ action: str,
58
+ walker: str,
59
+ request: Request,
60
+ ) -> JSONResponse:
61
+ """Trigger webhook execution - async compatible"""
62
+ try:
63
+
64
+ if not self._jac.is_valid():
65
+ self.logger.warning(
66
+ "Invalid API state for webhook, attempting to reinstate it..."
67
+ )
68
+ self._jac._authenticate()
69
+
70
+ header = dict(request.headers)
71
+ try:
72
+ payload = await request.json()
73
+ if not payload:
74
+ payload = {}
75
+ except Exception:
76
+ payload = {}
77
+
78
+ walker_obj = await self._jac.spawn_walker_async(
79
+ walker_name=walker,
80
+ module_name=f"actions.{namespace}.{action}.{walker}",
81
+ attributes={
82
+ "agent_id": agent_id,
83
+ "key": key,
84
+ "header": header,
85
+ "payload": payload,
86
+ },
87
+ )
88
+ if not walker_obj:
89
+ self.logger.error("Webhook execution failed")
90
+ return JSONResponse(
91
+ content={"error": "Webhook execution failed"}, status_code=500
92
+ )
93
+
94
+ result = walker_obj.response
95
+ return JSONResponse(
96
+ status_code=result.get("status", 200),
97
+ content=result.get("message", "200 OK"),
98
+ )
99
+
100
+ except Exception as e:
101
+ self._jac.reset()
102
+ self.logger.error(f"Webhook callback error: {e}\n{traceback.format_exc()}")
103
+ return JSONResponse(
104
+ content={"error": "Internal server error"}, status_code=500
105
+ )
106
+
50
107
  def api_pulse(self, action_label: str, agent_id: str) -> dict:
51
108
  """Synchronous pulse API call"""
52
109
  if not self._jac.is_valid():
@@ -124,7 +124,7 @@ class JacInterface:
124
124
 
125
125
  try:
126
126
  if module_name not in JacMachine.list_modules():
127
- self.logger.error(f"Module {module_name} not loaded")
127
+ self.logger.error(f"Module {module_name} not found")
128
128
  return None
129
129
 
130
130
  entry_node = ctx.entry_node.archetype
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jvserve
3
- Version: 2.1.17
3
+ Version: 2.1.18
4
4
  Summary: FastAPI webserver for loading and interaction with JIVAS agents.
5
5
  Home-page: https://github.com/TrueSelph/jvserve
6
6
  Author: TrueSelph Inc.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes