veris-ai 1.6.0__py3-none-any.whl → 1.7.0__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 veris-ai might be problematic. Click here for more details.
- veris_ai/tool_mock.py +150 -120
- {veris_ai-1.6.0.dist-info → veris_ai-1.7.0.dist-info}/METADATA +1 -1
- {veris_ai-1.6.0.dist-info → veris_ai-1.7.0.dist-info}/RECORD +5 -5
- {veris_ai-1.6.0.dist-info → veris_ai-1.7.0.dist-info}/WHEEL +0 -0
- {veris_ai-1.6.0.dist-info → veris_ai-1.7.0.dist-info}/licenses/LICENSE +0 -0
veris_ai/tool_mock.py
CHANGED
|
@@ -172,67 +172,82 @@ class VerisSDK:
|
|
|
172
172
|
# If not in simulation mode, execute the original function
|
|
173
173
|
return await func(*args, **kwargs)
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
175
|
+
async def _execute_mock_logic(session_id: str) -> object:
|
|
176
|
+
# Handle spy mode - execute original function and log
|
|
177
|
+
if mode == "spy":
|
|
178
|
+
logger.info(f"Spying on function: {func.__name__}")
|
|
179
|
+
|
|
180
|
+
# Log the tool call
|
|
181
|
+
sig = inspect.signature(func)
|
|
182
|
+
bound_args = sig.bind(*args, **kwargs)
|
|
183
|
+
bound_args.apply_defaults()
|
|
184
|
+
_ = bound_args.arguments.pop("ctx", None)
|
|
185
|
+
_ = bound_args.arguments.pop("self", None)
|
|
186
|
+
_ = bound_args.arguments.pop("cls", None)
|
|
187
|
+
|
|
188
|
+
await log_tool_call_async(
|
|
189
|
+
session_id=session_id,
|
|
190
|
+
function_name=func.__name__,
|
|
191
|
+
parameters=bound_args.arguments,
|
|
192
|
+
docstring=inspect.getdoc(func) or "",
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
# Execute the original function
|
|
196
|
+
result = await func(*args, **kwargs)
|
|
197
|
+
|
|
198
|
+
# Log the response
|
|
199
|
+
await log_tool_response_async(session_id=session_id, response=result)
|
|
200
|
+
|
|
201
|
+
return result
|
|
202
|
+
|
|
203
|
+
# Regular mock mode
|
|
204
|
+
base_url = os.getenv("VERIS_ENDPOINT_URL")
|
|
205
|
+
if not base_url:
|
|
206
|
+
error_msg = "VERIS_ENDPOINT_URL environment variable is not set"
|
|
207
|
+
raise ValueError(error_msg)
|
|
208
|
+
endpoint = f"{base_url.rstrip('/')}/api/v2/tool_mock"
|
|
209
|
+
# Default timeout of 30 seconds
|
|
210
|
+
timeout = float(os.getenv("VERIS_MOCK_TIMEOUT", "90.0"))
|
|
211
|
+
|
|
212
|
+
logger.info(f"Simulating function: {func.__name__}")
|
|
213
|
+
payload, return_type_obj = create_mock_payload(*args, **kwargs)
|
|
214
|
+
|
|
215
|
+
# Send request to endpoint with timeout
|
|
216
|
+
# Inject current trace context headers if OpenTelemetry is available
|
|
217
|
+
headers: dict[str, str] | None = None
|
|
218
|
+
try:
|
|
219
|
+
from opentelemetry.propagate import get_global_textmap # type: ignore[import-not-found]
|
|
220
|
+
|
|
221
|
+
headers = {}
|
|
222
|
+
get_global_textmap().inject(headers)
|
|
223
|
+
except Exception: # pragma: no cover - otel optional
|
|
224
|
+
headers = None
|
|
225
|
+
|
|
226
|
+
async with httpx.AsyncClient(timeout=timeout) as client:
|
|
227
|
+
response = await client.post(endpoint, json=payload, headers=headers)
|
|
228
|
+
response.raise_for_status()
|
|
229
|
+
mock_result = response.json()
|
|
230
|
+
logger.info(f"Mock response: {mock_result}")
|
|
231
|
+
|
|
232
|
+
if isinstance(mock_result, str):
|
|
233
|
+
with suppress(json.JSONDecodeError):
|
|
234
|
+
mock_result = json.loads(mock_result)
|
|
235
|
+
return convert_to_type(mock_result, return_type_obj)
|
|
236
|
+
return convert_to_type(mock_result, return_type_obj)
|
|
237
|
+
|
|
238
|
+
# Create a top-level span for the simulated mock call if OpenTelemetry is available
|
|
217
239
|
try:
|
|
218
|
-
from opentelemetry
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
logger.info(f"Mock response: {mock_result}")
|
|
230
|
-
|
|
231
|
-
if isinstance(mock_result, str):
|
|
232
|
-
with suppress(json.JSONDecodeError):
|
|
233
|
-
mock_result = json.loads(mock_result)
|
|
234
|
-
return convert_to_type(mock_result, return_type_obj)
|
|
235
|
-
return convert_to_type(mock_result, return_type_obj)
|
|
240
|
+
from opentelemetry import trace # type: ignore[import-not-found]
|
|
241
|
+
|
|
242
|
+
tracer = trace.get_tracer("veris_ai.tool_mock")
|
|
243
|
+
span_name = f"mock.{func.__name__}"
|
|
244
|
+
with tracer.start_as_current_span(span_name) as span: # type: ignore[attr-defined]
|
|
245
|
+
span.set_attribute("veris_ai.session.id", self.session_id or "") # type: ignore[attr-defined]
|
|
246
|
+
span.set_attribute("veris_ai.mock.mode", mode) # type: ignore[attr-defined]
|
|
247
|
+
return await _execute_mock_logic(self.session_id)
|
|
248
|
+
except Exception:
|
|
249
|
+
# If OpenTelemetry is not available, run without span
|
|
250
|
+
return await _execute_mock_logic(self.session_id)
|
|
236
251
|
|
|
237
252
|
@wraps(func)
|
|
238
253
|
def sync_wrapper(
|
|
@@ -244,67 +259,82 @@ class VerisSDK:
|
|
|
244
259
|
# If not in simulation mode, execute the original function
|
|
245
260
|
return func(*args, **kwargs)
|
|
246
261
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
262
|
+
def _execute_mock_logic(session_id: str) -> object:
|
|
263
|
+
# Handle spy mode - execute original function and log
|
|
264
|
+
if mode == "spy":
|
|
265
|
+
logger.info(f"Spying on function: {func.__name__}")
|
|
266
|
+
|
|
267
|
+
# Log the tool call
|
|
268
|
+
sig = inspect.signature(func)
|
|
269
|
+
bound_args = sig.bind(*args, **kwargs)
|
|
270
|
+
bound_args.apply_defaults()
|
|
271
|
+
_ = bound_args.arguments.pop("ctx", None)
|
|
272
|
+
_ = bound_args.arguments.pop("self", None)
|
|
273
|
+
_ = bound_args.arguments.pop("cls", None)
|
|
274
|
+
|
|
275
|
+
log_tool_call_sync(
|
|
276
|
+
session_id=session_id,
|
|
277
|
+
function_name=func.__name__,
|
|
278
|
+
parameters=bound_args.arguments,
|
|
279
|
+
docstring=inspect.getdoc(func) or "",
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
# Execute the original function
|
|
283
|
+
result = func(*args, **kwargs)
|
|
284
|
+
|
|
285
|
+
# Log the response
|
|
286
|
+
log_tool_response_sync(session_id=session_id, response=result)
|
|
287
|
+
|
|
288
|
+
return result
|
|
289
|
+
|
|
290
|
+
# Regular mock mode
|
|
291
|
+
base_url = os.getenv("VERIS_ENDPOINT_URL")
|
|
292
|
+
if not base_url:
|
|
293
|
+
error_msg = "VERIS_ENDPOINT_URL environment variable is not set"
|
|
294
|
+
raise ValueError(error_msg)
|
|
295
|
+
endpoint = f"{base_url.rstrip('/')}/api/v2/tool_mock"
|
|
296
|
+
# Default timeout of 30 seconds
|
|
297
|
+
timeout = float(os.getenv("VERIS_MOCK_TIMEOUT", "90.0"))
|
|
298
|
+
|
|
299
|
+
logger.info(f"Simulating function: {func.__name__}")
|
|
300
|
+
payload, return_type_obj = create_mock_payload(*args, **kwargs)
|
|
301
|
+
|
|
302
|
+
# Send request to endpoint with timeout (synchronous)
|
|
303
|
+
# Inject current trace context headers if OpenTelemetry is available
|
|
304
|
+
headers: dict[str, str] | None = None
|
|
305
|
+
try:
|
|
306
|
+
from opentelemetry.propagate import get_global_textmap # type: ignore[import-not-found]
|
|
307
|
+
|
|
308
|
+
headers = {}
|
|
309
|
+
get_global_textmap().inject(headers)
|
|
310
|
+
except Exception: # pragma: no cover - otel optional
|
|
311
|
+
headers = None
|
|
312
|
+
|
|
313
|
+
with httpx.Client(timeout=timeout) as client:
|
|
314
|
+
response = client.post(endpoint, json=payload, headers=headers)
|
|
315
|
+
response.raise_for_status()
|
|
316
|
+
mock_result = response.json()
|
|
317
|
+
logger.info(f"Mock response: {mock_result}")
|
|
318
|
+
|
|
319
|
+
if isinstance(mock_result, str):
|
|
320
|
+
with suppress(json.JSONDecodeError):
|
|
321
|
+
mock_result = json.loads(mock_result)
|
|
322
|
+
return convert_to_type(mock_result, return_type_obj)
|
|
323
|
+
return convert_to_type(mock_result, return_type_obj)
|
|
324
|
+
|
|
325
|
+
# Create a top-level span for the simulated mock call if OpenTelemetry is available
|
|
289
326
|
try:
|
|
290
|
-
from opentelemetry
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
logger.info(f"Mock response: {mock_result}")
|
|
302
|
-
|
|
303
|
-
if isinstance(mock_result, str):
|
|
304
|
-
with suppress(json.JSONDecodeError):
|
|
305
|
-
mock_result = json.loads(mock_result)
|
|
306
|
-
return convert_to_type(mock_result, return_type_obj)
|
|
307
|
-
return convert_to_type(mock_result, return_type_obj)
|
|
327
|
+
from opentelemetry import trace # type: ignore[import-not-found]
|
|
328
|
+
|
|
329
|
+
tracer = trace.get_tracer("veris_ai.tool_mock")
|
|
330
|
+
span_name = f"mock.{func.__name__}"
|
|
331
|
+
with tracer.start_as_current_span(span_name) as span: # type: ignore[attr-defined]
|
|
332
|
+
span.set_attribute("veris_ai.session.id", self.session_id or "") # type: ignore[attr-defined]
|
|
333
|
+
span.set_attribute("veris_ai.mock.mode", mode) # type: ignore[attr-defined]
|
|
334
|
+
return _execute_mock_logic(self.session_id)
|
|
335
|
+
except Exception:
|
|
336
|
+
# If OpenTelemetry is not available, run without span
|
|
337
|
+
return _execute_mock_logic(self.session_id)
|
|
308
338
|
|
|
309
339
|
# Return the appropriate wrapper based on whether the function is async
|
|
310
340
|
return async_wrapper if is_async else sync_wrapper
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: veris-ai
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.0
|
|
4
4
|
Summary: A Python package for Veris AI tools
|
|
5
5
|
Project-URL: Homepage, https://github.com/veris-ai/veris-python-sdk
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/veris-ai/veris-python-sdk/issues
|
|
@@ -3,13 +3,13 @@ veris_ai/__init__.py,sha256=Gh52-XfFpsxX37uqp8vuX0V3Np7f-Rlf5k3MMANu6e0,425
|
|
|
3
3
|
veris_ai/logging.py,sha256=srEdVimcQSCsnwGhyzCydehD2JW1cQmwSRd3X20NQs0,5233
|
|
4
4
|
veris_ai/models.py,sha256=6HINPxNFCakCVPcyEbUswWkXwb2K4lF0A8g8EvTMal4,213
|
|
5
5
|
veris_ai/observability.py,sha256=fG5ixAiVDykLCdHUScKQNCsePLphKQ7PcaKkAGBVdF0,5113
|
|
6
|
-
veris_ai/tool_mock.py,sha256=
|
|
6
|
+
veris_ai/tool_mock.py,sha256=C1BANT3LCMKOIwJm_nOFuNdHnaO9_tbjeDTtBcI41RI,16512
|
|
7
7
|
veris_ai/utils.py,sha256=aqFFNuNiBehil6874nOHtU7G_bWHbFpVuubcz2AIx6I,9267
|
|
8
8
|
veris_ai/jaeger_interface/README.md,sha256=kd9rKcE5xf3EyNaiHu0tjn-0oES9sfaK6Ih-OhhTyCM,2821
|
|
9
9
|
veris_ai/jaeger_interface/__init__.py,sha256=KD7NSiMYRG_2uF6dOLKkGG5lNQe4K9ptEwucwMT4_aw,1128
|
|
10
10
|
veris_ai/jaeger_interface/client.py,sha256=yJrh86wRR0Dk3Gq12DId99WogcMIVbL0QQFqVSevvlE,8772
|
|
11
11
|
veris_ai/jaeger_interface/models.py,sha256=e64VV6IvOEFuzRUgvDAMQFyOZMRb56I-PUPZLBZ3rX0,1864
|
|
12
|
-
veris_ai-1.
|
|
13
|
-
veris_ai-1.
|
|
14
|
-
veris_ai-1.
|
|
15
|
-
veris_ai-1.
|
|
12
|
+
veris_ai-1.7.0.dist-info/METADATA,sha256=dmWFBpwU2MK9tjnJtlrkQdqnR9C0yn0Lhb1TMWb-XvA,8679
|
|
13
|
+
veris_ai-1.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
14
|
+
veris_ai-1.7.0.dist-info/licenses/LICENSE,sha256=2g4i20atAgtD5einaKzhQrIB-JrPhyQgD3bC0wkHcCI,1065
|
|
15
|
+
veris_ai-1.7.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|