veris-ai 1.14.0__tar.gz → 1.14.2__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 veris-ai might be problematic. Click here for more details.
- {veris_ai-1.14.0 → veris_ai-1.14.2}/PKG-INFO +1 -1
- {veris_ai-1.14.0 → veris_ai-1.14.2}/pyproject.toml +1 -1
- {veris_ai-1.14.0 → veris_ai-1.14.2}/src/veris_ai/api_client.py +31 -9
- {veris_ai-1.14.0 → veris_ai-1.14.2}/src/veris_ai/tool_mock.py +6 -3
- veris_ai-1.14.2/tests/test_api_client.py +78 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/uv.lock +1 -1
- {veris_ai-1.14.0 → veris_ai-1.14.2}/.cursor/rules/documentation-management.mdc +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/.github/workflows/release.yml +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/.github/workflows/test.yml +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/.gitignore +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/.pre-commit-config.yaml +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/CHANGELOG.md +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/CLAUDE.md +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/LICENSE +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/README.md +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/examples/README.md +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/examples/__init__.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/examples/import_options.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/examples/openai_agents_example.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/src/veris_ai/README.md +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/src/veris_ai/__init__.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/src/veris_ai/agents_wrapper.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/src/veris_ai/jaeger_interface/README.md +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/src/veris_ai/jaeger_interface/__init__.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/src/veris_ai/jaeger_interface/client.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/src/veris_ai/jaeger_interface/models.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/src/veris_ai/models.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/src/veris_ai/observability.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/src/veris_ai/utils.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/README.md +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/__init__.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/conftest.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/fixtures/__init__.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/fixtures/http_server.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/fixtures/simple_app.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/test_agents_wrapper_extract.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/test_agents_wrapper_simple.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/test_helpers.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/test_mcp_protocol_server_mocked.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/test_side_effects.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/test_token_decoding.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/test_tool_mock.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/test_utils.py +0 -0
- {veris_ai-1.14.0 → veris_ai-1.14.2}/tests/test_veris_runner_tool_options.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: veris-ai
|
|
3
|
-
Version: 1.14.
|
|
3
|
+
Version: 1.14.2
|
|
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
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
4
|
import os
|
|
5
|
+
from contextvars import ContextVar
|
|
5
6
|
from typing import Any
|
|
6
7
|
|
|
7
8
|
import httpx
|
|
@@ -9,6 +10,9 @@ from urllib.parse import urljoin
|
|
|
9
10
|
|
|
10
11
|
logger = logging.getLogger(__name__)
|
|
11
12
|
|
|
13
|
+
# Context variable to store base_url for per-request multi-tenant scenarios
|
|
14
|
+
_base_url_context: ContextVar[str | None] = ContextVar("veris_base_url", default=None)
|
|
15
|
+
|
|
12
16
|
|
|
13
17
|
class SimulatorAPIClient:
|
|
14
18
|
"""Centralized client for making requests to VERIS simulation endpoints.
|
|
@@ -20,12 +24,22 @@ class SimulatorAPIClient:
|
|
|
20
24
|
changes reflected without recreating the singleton.
|
|
21
25
|
"""
|
|
22
26
|
|
|
23
|
-
def __init__(self) -> None:
|
|
27
|
+
def __init__(self, timeout: float | None = None) -> None:
|
|
24
28
|
"""Initialize the API client with static timeout configuration."""
|
|
25
|
-
self.
|
|
29
|
+
self._timeout = timeout or float(os.getenv("VERIS_MOCK_TIMEOUT", "300.0"))
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def base_url(self) -> str:
|
|
33
|
+
"""Get the resolved base URL."""
|
|
34
|
+
return self._get_base_url()
|
|
26
35
|
|
|
27
36
|
def _get_base_url(self) -> str:
|
|
28
|
-
"""Resolve the base URL from environment.
|
|
37
|
+
"""Resolve the base URL from context, environment, or default.
|
|
38
|
+
|
|
39
|
+
Priority order:
|
|
40
|
+
1. Context variable (for per-request multi-tenant scenarios)
|
|
41
|
+
2. VERIS_API_URL environment variable
|
|
42
|
+
3. Default production URL
|
|
29
43
|
|
|
30
44
|
Behavior:
|
|
31
45
|
- If VERIS_API_URL is unset, default to the dev simulator URL.
|
|
@@ -33,7 +47,9 @@ class SimulatorAPIClient:
|
|
|
33
47
|
(do not fall back). This supports tests expecting connection
|
|
34
48
|
failures when an invalid endpoint is provided.
|
|
35
49
|
"""
|
|
36
|
-
|
|
50
|
+
# Priority: context > env var > default
|
|
51
|
+
context_url = _base_url_context.get()
|
|
52
|
+
return context_url or os.getenv("VERIS_API_URL") or "https://simulator.api.veris.ai"
|
|
37
53
|
|
|
38
54
|
def _build_headers(self) -> dict[str, str] | None:
|
|
39
55
|
"""Build headers including OpenTelemetry tracing and API key."""
|
|
@@ -55,7 +71,7 @@ class SimulatorAPIClient:
|
|
|
55
71
|
if not endpoint.startswith(("http://", "https://")):
|
|
56
72
|
raise httpx.ConnectError("Invalid endpoint URL (not absolute): {endpoint}")
|
|
57
73
|
|
|
58
|
-
with httpx.Client(timeout=self.
|
|
74
|
+
with httpx.Client(timeout=self._timeout) as client:
|
|
59
75
|
response = client.post(endpoint, json=payload, headers=headers)
|
|
60
76
|
response.raise_for_status()
|
|
61
77
|
return response.json() if response.content else None
|
|
@@ -73,7 +89,7 @@ class SimulatorAPIClient:
|
|
|
73
89
|
error_msg = f"Invalid endpoint URL (not absolute): {endpoint}"
|
|
74
90
|
raise httpx.ConnectError(error_msg)
|
|
75
91
|
|
|
76
|
-
async with httpx.AsyncClient(timeout=self.
|
|
92
|
+
async with httpx.AsyncClient(timeout=self._timeout) as client:
|
|
77
93
|
response = await client.post(endpoint, json=payload, headers=headers)
|
|
78
94
|
response.raise_for_status()
|
|
79
95
|
return response.json() if response.content else None
|
|
@@ -81,15 +97,15 @@ class SimulatorAPIClient:
|
|
|
81
97
|
@property
|
|
82
98
|
def tool_mock_endpoint(self) -> str:
|
|
83
99
|
"""Get the tool mock endpoint URL."""
|
|
84
|
-
return urljoin(self.
|
|
100
|
+
return urljoin(self.base_url, "v3/tool_mock")
|
|
85
101
|
|
|
86
102
|
def get_log_tool_call_endpoint(self, session_id: str) -> str:
|
|
87
103
|
"""Get the log tool call endpoint URL."""
|
|
88
|
-
return urljoin(self.
|
|
104
|
+
return urljoin(self.base_url, f"v3/log_tool_call?session_id={session_id}")
|
|
89
105
|
|
|
90
106
|
def get_log_tool_response_endpoint(self, session_id: str) -> str:
|
|
91
107
|
"""Get the log tool response endpoint URL."""
|
|
92
|
-
return urljoin(self.
|
|
108
|
+
return urljoin(self.base_url, f"v3/log_tool_response?session_id={session_id}")
|
|
93
109
|
|
|
94
110
|
|
|
95
111
|
# Global singleton instance
|
|
@@ -99,3 +115,9 @@ _api_client = SimulatorAPIClient()
|
|
|
99
115
|
def get_api_client() -> SimulatorAPIClient:
|
|
100
116
|
"""Get the global API client instance."""
|
|
101
117
|
return _api_client
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def set_api_client_params(timeout: float | None = None) -> None:
|
|
121
|
+
"""Set the global API client instance for testing purposes."""
|
|
122
|
+
global _api_client # noqa: PLW0603
|
|
123
|
+
_api_client = SimulatorAPIClient(timeout=timeout)
|
|
@@ -16,7 +16,7 @@ from typing import (
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
from veris_ai.models import ResponseExpectation, ToolCallOptions
|
|
19
|
-
from veris_ai.api_client import get_api_client
|
|
19
|
+
from veris_ai.api_client import _base_url_context, get_api_client
|
|
20
20
|
from veris_ai.utils import (
|
|
21
21
|
convert_to_type,
|
|
22
22
|
execute_callback,
|
|
@@ -92,6 +92,8 @@ class VerisSDK:
|
|
|
92
92
|
|
|
93
93
|
self._set_session_id(token_data["session_id"])
|
|
94
94
|
self._set_thread_id(token_data["thread_id"])
|
|
95
|
+
if token_data.get("api_url"):
|
|
96
|
+
_base_url_context.set(token_data["api_url"])
|
|
95
97
|
logger.info(
|
|
96
98
|
f"Session ID set to {token_data['session_id']}, "
|
|
97
99
|
f"Thread ID set to {token_data['thread_id']} - mocking enabled"
|
|
@@ -142,10 +144,11 @@ class VerisSDK:
|
|
|
142
144
|
_thread_id_context.set(None)
|
|
143
145
|
|
|
144
146
|
def clear_context(self) -> None:
|
|
145
|
-
"""Clear the session_id and
|
|
147
|
+
"""Clear the session_id, thread_id, and base_url from context variables."""
|
|
146
148
|
self._clear_session_id()
|
|
147
149
|
self._clear_thread_id()
|
|
148
|
-
|
|
150
|
+
_base_url_context.set(None)
|
|
151
|
+
logger.info("Session ID, Thread ID, and Base URL cleared - mocking disabled")
|
|
149
152
|
|
|
150
153
|
def clear_session_id(self) -> None:
|
|
151
154
|
"""DEPRECATED: Use clear_context() instead."""
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Tests for SimulatorAPIClient endpoint URL generation and configuration."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from unittest.mock import patch
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from veris_ai.api_client import SimulatorAPIClient, get_api_client, set_api_client_params
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_tool_mock_endpoint_default():
|
|
12
|
+
"""Test that tool_mock_endpoint property returns correct URL with default base_url."""
|
|
13
|
+
client = SimulatorAPIClient()
|
|
14
|
+
endpoint = client.tool_mock_endpoint
|
|
15
|
+
|
|
16
|
+
# Should use default base URL
|
|
17
|
+
assert endpoint == "https://simulator.api.veris.ai/v3/tool_mock"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_tool_mock_endpoint_with_env_var():
|
|
21
|
+
"""Test that tool_mock_endpoint respects VERIS_API_URL environment variable."""
|
|
22
|
+
with patch.dict(os.environ, {"VERIS_API_URL": "https://test.api.veris.ai"}):
|
|
23
|
+
client = SimulatorAPIClient()
|
|
24
|
+
endpoint = client.tool_mock_endpoint
|
|
25
|
+
|
|
26
|
+
assert endpoint == "https://test.api.veris.ai/v3/tool_mock"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_log_tool_call_endpoint():
|
|
30
|
+
"""Test get_log_tool_call_endpoint generates correct URL."""
|
|
31
|
+
with patch.dict(os.environ, {"VERIS_API_URL": "https://test.api.com"}):
|
|
32
|
+
client = SimulatorAPIClient()
|
|
33
|
+
endpoint = client.get_log_tool_call_endpoint("session-123")
|
|
34
|
+
|
|
35
|
+
assert endpoint == "https://test.api.com/v3/log_tool_call?session_id=session-123"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_log_tool_response_endpoint():
|
|
39
|
+
"""Test get_log_tool_response_endpoint generates correct URL."""
|
|
40
|
+
with patch.dict(os.environ, {"VERIS_API_URL": "https://test.api.com"}):
|
|
41
|
+
client = SimulatorAPIClient()
|
|
42
|
+
endpoint = client.get_log_tool_response_endpoint("session-456")
|
|
43
|
+
|
|
44
|
+
assert endpoint == "https://test.api.com/v3/log_tool_response?session_id=session-456"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_custom_timeout():
|
|
48
|
+
"""Test that custom timeout is set correctly."""
|
|
49
|
+
client = SimulatorAPIClient(timeout=30.0)
|
|
50
|
+
assert client._timeout == 30.0
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_default_timeout():
|
|
54
|
+
"""Test that default timeout is used when not specified."""
|
|
55
|
+
with patch.dict(os.environ, {"VERIS_MOCK_TIMEOUT": "120.0"}):
|
|
56
|
+
client = SimulatorAPIClient()
|
|
57
|
+
assert client._timeout == 120.0
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_set_api_client_params_timeout():
|
|
61
|
+
"""Test that set_api_client_params reconfigures the global client timeout."""
|
|
62
|
+
# Reconfigure with custom timeout
|
|
63
|
+
set_api_client_params(timeout=60.0)
|
|
64
|
+
|
|
65
|
+
# Get client and verify timeout has been updated
|
|
66
|
+
client = get_api_client()
|
|
67
|
+
assert client._timeout == 60.0
|
|
68
|
+
|
|
69
|
+
# Restore original client
|
|
70
|
+
set_api_client_params()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_empty_env_var_uses_default():
|
|
74
|
+
"""Test that empty VERIS_API_URL falls back to default."""
|
|
75
|
+
with patch.dict(os.environ, {"VERIS_API_URL": ""}, clear=True):
|
|
76
|
+
client = SimulatorAPIClient()
|
|
77
|
+
# Empty string should NOT be used, should fall back to default
|
|
78
|
+
assert client._get_base_url() == "https://simulator.api.veris.ai"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|