jvserve 2.0.13__py3-none-any.whl → 2.0.16__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.

Potentially problematic release.


This version of jvserve might be problematic. Click here for more details.

jvserve/__init__.py CHANGED
@@ -4,5 +4,5 @@ jvserve package initialization.
4
4
  This package provides the webserver for loading and interacting with JIVAS agents.
5
5
  """
6
6
 
7
- __version__ = "2.0.13"
7
+ __version__ = "2.0.16"
8
8
  __supported__jivas__versions__ = ["2.0.0"]
@@ -160,76 +160,146 @@ class AgentInterface:
160
160
  return response
161
161
 
162
162
  @staticmethod
163
- async def action_walker_exec(
164
- agent_id: str = Form(...), # noqa: B008
165
- module_root: str = Form(...), # noqa: B008
166
- walker: str = Form(...), # noqa: B008
163
+ def get_action_data(agent_id: str, action_label: str) -> dict:
164
+ """Retrieves the data for a specific action of an agent."""
165
+
166
+ action_data = {}
167
+ ctx = AgentInterface.load_context()
168
+
169
+ if not ctx:
170
+ return {}
171
+
172
+ # TODO : raise error in the event agent id is invalid
173
+ AgentInterface.LOGGER.debug(
174
+ f"attempting to interact with agent {agent_id} with user root {ctx.root}..."
175
+ )
176
+
177
+ try:
178
+ actions = _Jac.spawn_call(
179
+ ctx.entry_node.architype,
180
+ AgentInterface.spawn_walker(
181
+ walker_name="list_actions",
182
+ attributes={"agent_id": agent_id},
183
+ module_name="agent.action.list_actions",
184
+ ),
185
+ ).actions
186
+
187
+ if actions:
188
+ for action in actions:
189
+ if action.get("label") == action_label:
190
+ action_data = action
191
+ break
192
+
193
+ except Exception as e:
194
+ AgentInterface.EXPIRATION = None
195
+ AgentInterface.LOGGER.error(
196
+ f"an exception occurred: {e}, {traceback.format_exc()}"
197
+ )
198
+
199
+ ctx.close()
200
+ return action_data
201
+
202
+ @staticmethod
203
+ def action_walker_exec(
204
+ agent_id: Optional[str] = Form(None), # noqa: B008
205
+ module_root: Optional[str] = Form(None), # noqa: B008
206
+ walker: Optional[str] = Form(None), # noqa: B008
167
207
  args: Optional[str] = Form(None), # noqa: B008
168
208
  attachments: List[UploadFile] = File(default_factory=list), # noqa: B008
169
209
  ) -> JSONResponse:
170
- """Execute a named walker exposed by an action within context; capable of handling JSON or file data depending on request"""
171
-
172
- response = JSONResponse(status_code=500, content="unable to complete request")
173
-
210
+ """
211
+ Execute a named walker exposed by an action within context.
212
+ Capable of handling JSON or file data depending on request.
213
+
214
+ Args:
215
+ agent_id: ID of the agent
216
+ action: Name of the action
217
+ walker: Name of the walker to execute
218
+ args: JSON string of additional arguments
219
+ attachments: List of uploaded files
220
+
221
+ Returns:
222
+ JSONResponse: Response containing walker output or error message
223
+ """
224
+ ctx = None
174
225
  try:
226
+ # Validate required parameters
227
+ if walker is None or agent_id is None or module_root is None:
228
+ AgentInterface.LOGGER.error("Missing required parameters")
229
+ return JSONResponse(
230
+ status_code=400, # 400 (Bad Request)
231
+ content={"error": "Missing required parameters"},
232
+ )
233
+
234
+ # Load execution context
235
+ ctx = AgentInterface.load_context()
236
+ if not ctx:
237
+ AgentInterface.LOGGER.error(f"Unable to execute {walker}")
238
+ return JSONResponse(
239
+ status_code=500,
240
+ content={"error": "Failed to load execution context"},
241
+ )
175
242
 
176
- # add agent id as a standard
243
+ # Prepare attributes
177
244
  attributes: Dict[str, Any] = {"agent_id": agent_id}
178
245
 
179
- # add any other args
246
+ # Parse additional arguments if provided
180
247
  if args:
181
- attributes.update(json.loads(args))
248
+ try:
249
+ attributes.update(json.loads(args))
250
+ except json.JSONDecodeError as e:
251
+ AgentInterface.LOGGER.error(f"Invalid JSON in args: {e}")
252
+ return JSONResponse(
253
+ status_code=400,
254
+ content={"error": "Invalid JSON in arguments"},
255
+ )
182
256
 
183
- # Processing files if any were uploaded
257
+ # Process uploaded files
184
258
  if attachments:
185
259
  attributes["files"] = []
186
260
  for file in attachments:
187
- attributes["files"].append(
188
- {
189
- "name": file.filename,
190
- "type": file.content_type,
191
- "content": await file.read(),
192
- }
193
- )
261
+ try:
262
+ attributes["files"].append(
263
+ {
264
+ "name": file.filename,
265
+ "type": file.content_type,
266
+ "content": file.file.read(),
267
+ }
268
+ )
269
+ except Exception as e:
270
+ AgentInterface.LOGGER.error(
271
+ f"Failed to process file {file.filename}: {e}"
272
+ )
273
+ continue # Skip problematic files or return error if critical
194
274
 
195
- if not agent_id or not walker or not module_root:
196
- AgentInterface.LOGGER.error("missing parameters")
197
- return JSONResponse(
198
- status_code=401, content="missing required parameters"
199
- )
275
+ # Execute the walker
276
+ walker_response = _Jac.spawn_call(
277
+ ctx.entry_node.architype,
278
+ AgentInterface.spawn_walker(
279
+ walker_name=walker,
280
+ attributes=attributes,
281
+ module_name=f"{module_root}.{walker}",
282
+ ),
283
+ ).response
284
+ ctx.close()
285
+
286
+ return walker_response
200
287
 
201
288
  except Exception as e:
289
+ AgentInterface.EXPIRATION = None
202
290
  AgentInterface.LOGGER.error(
203
- f"an exception occurred: {e}, {traceback.format_exc()}"
291
+ f"Exception occurred: {str(e)}\n{traceback.format_exc()}"
204
292
  )
205
- return JSONResponse(status_code=500, content="internal server error")
206
-
207
- ctx = await AgentInterface.load_context_async()
208
- if ctx:
209
- # compose full module_path
210
- module = f"{module_root}.{walker}"
211
-
212
- try:
213
- response = _Jac.spawn_call(
214
- ctx.entry_node.architype,
215
- AgentInterface.spawn_walker(
216
- walker_name=walker,
217
- attributes=attributes,
218
- module_name=module,
219
- ),
220
- ).response
221
-
222
- except Exception as e:
223
- AgentInterface.EXPIRATION = None
224
- AgentInterface.LOGGER.error(
225
- f"an exception occurred: {e}, {traceback.format_exc()}"
226
- )
227
- else:
228
- AgentInterface.LOGGER.error(f"unable to execute {walker}")
229
-
230
- ctx.close()
231
-
232
- return response
293
+ return JSONResponse(
294
+ status_code=500,
295
+ content={"error": "Internal server error", "details": str(e)},
296
+ )
297
+ finally:
298
+ if ctx:
299
+ try:
300
+ ctx.close()
301
+ except Exception as e:
302
+ AgentInterface.LOGGER.error(f"Error closing context: {str(e)}")
233
303
 
234
304
  class InteractPayload(BaseModel):
235
305
  """Payload for interacting with the agent."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jvserve
3
- Version: 2.0.13
3
+ Version: 2.0.16
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.
@@ -0,0 +1,13 @@
1
+ jvserve/__init__.py,sha256=pq6aKUL15KaEDAIo2zlj2RtTFVdN-vXUx3UVdOZxOeM,191
2
+ jvserve/cli.py,sha256=NJD4ehtKnhOvsz-vrFh9lz3P4bnxqz-uqTr8QItljZc,8897
3
+ jvserve/lib/__init__.py,sha256=cnzfSHLoTWG9Ygut2nOpDys5aPlQz-m0BSkB-nd7OMs,31
4
+ jvserve/lib/agent_interface.py,sha256=-uewEL_M4cZpZVl0rIOXnVpZI-3O9aGKLljoCgKSW0M,34955
5
+ jvserve/lib/agent_pulse.py,sha256=6hBF6KQYr6Z9Mi_yoWKGfdnW7gg84kK20Slu-bLR_m8,2067
6
+ jvserve/lib/file_interface.py,sha256=sqwTmBnZsVFQUGt7mE1EWA-jHnZlRtBAFeb4Rb_QgQ8,6079
7
+ jvserve/lib/jvlogger.py,sha256=RNiB9PHuBzTvNIQWhxoDgrDlNYA0PYm1SVpvzlqu8mE,4180
8
+ jvserve-2.0.16.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
9
+ jvserve-2.0.16.dist-info/METADATA,sha256=kRy2uTRK7zZBau0hAOt5BunMHO0m2OHHQPUzY9BGUOY,4791
10
+ jvserve-2.0.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ jvserve-2.0.16.dist-info/entry_points.txt,sha256=HYyg1QXoLs0JRb004L300VeLOZyDLY27ynD1tnTnEN4,35
12
+ jvserve-2.0.16.dist-info/top_level.txt,sha256=afoCXZv-zXNBuhVIvfJGjafXKEiJl_ooy4BtgQwAG4Q,8
13
+ jvserve-2.0.16.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- jvserve/__init__.py,sha256=AHR-iejuKB2C8u25HZ1ccXlh6tCaB3MuKVTJz-LZzig,191
2
- jvserve/cli.py,sha256=NJD4ehtKnhOvsz-vrFh9lz3P4bnxqz-uqTr8QItljZc,8897
3
- jvserve/lib/__init__.py,sha256=cnzfSHLoTWG9Ygut2nOpDys5aPlQz-m0BSkB-nd7OMs,31
4
- jvserve/lib/agent_interface.py,sha256=4SHqvySxu08dK2cPoe2TjMKlm11VqM0qDalOKp-tma4,32347
5
- jvserve/lib/agent_pulse.py,sha256=6hBF6KQYr6Z9Mi_yoWKGfdnW7gg84kK20Slu-bLR_m8,2067
6
- jvserve/lib/file_interface.py,sha256=sqwTmBnZsVFQUGt7mE1EWA-jHnZlRtBAFeb4Rb_QgQ8,6079
7
- jvserve/lib/jvlogger.py,sha256=RNiB9PHuBzTvNIQWhxoDgrDlNYA0PYm1SVpvzlqu8mE,4180
8
- jvserve-2.0.13.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
9
- jvserve-2.0.13.dist-info/METADATA,sha256=8gyJ1EnRbjZDZnOU3F-Y4lq9loXHIGLNCXn3YpPiUzg,4791
10
- jvserve-2.0.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- jvserve-2.0.13.dist-info/entry_points.txt,sha256=HYyg1QXoLs0JRb004L300VeLOZyDLY27ynD1tnTnEN4,35
12
- jvserve-2.0.13.dist-info/top_level.txt,sha256=afoCXZv-zXNBuhVIvfJGjafXKEiJl_ooy4BtgQwAG4Q,8
13
- jvserve-2.0.13.dist-info/RECORD,,