voxevolv 0.1.0__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.
- voxevolv-0.1.0/LICENSE +21 -0
- voxevolv-0.1.0/PKG-INFO +46 -0
- voxevolv-0.1.0/README.md +26 -0
- voxevolv-0.1.0/pyproject.toml +33 -0
- voxevolv-0.1.0/setup.cfg +4 -0
- voxevolv-0.1.0/src/voxevolv/__init__.py +17 -0
- voxevolv-0.1.0/src/voxevolv/client.py +250 -0
- voxevolv-0.1.0/src/voxevolv/py.typed +1 -0
- voxevolv-0.1.0/src/voxevolv.egg-info/PKG-INFO +46 -0
- voxevolv-0.1.0/src/voxevolv.egg-info/SOURCES.txt +11 -0
- voxevolv-0.1.0/src/voxevolv.egg-info/dependency_links.txt +1 -0
- voxevolv-0.1.0/src/voxevolv.egg-info/top_level.txt +1 -0
- voxevolv-0.1.0/tests/test_client.py +129 -0
voxevolv-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 VoxEvolv contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
voxevolv-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: voxevolv
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python server SDK for the VoxEvolv Voice Session API
|
|
5
|
+
Author: VoxEvolv contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/shobhansuri/VoxEvolv
|
|
8
|
+
Project-URL: Issues, https://github.com/shobhansuri/VoxEvolv/issues
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# VoxEvolv Python SDK
|
|
22
|
+
|
|
23
|
+
Server-only Python client for creating and managing VoxEvolv sessions.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import os
|
|
27
|
+
from voxevolv import VoxEvolv
|
|
28
|
+
|
|
29
|
+
client = VoxEvolv(
|
|
30
|
+
api_key=os.environ["VOXEVOLV_API_KEY"],
|
|
31
|
+
base_url=os.environ["VOXEVOLV_API_BASE"],
|
|
32
|
+
)
|
|
33
|
+
session = client.sessions.create(
|
|
34
|
+
intent_id=interview_session_id,
|
|
35
|
+
profile="live-interviewer",
|
|
36
|
+
participant={"identity": user_id, "display_name": display_name},
|
|
37
|
+
instructions=instructions,
|
|
38
|
+
greeting=greeting,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return session.browser_credentials()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The SDK derives one deterministic idempotency key from `intent_id`, preserves it
|
|
45
|
+
across bounded 429/5xx/network retries, and raises `VoxEvolvError` with typed API
|
|
46
|
+
failure information.
|
voxevolv-0.1.0/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# VoxEvolv Python SDK
|
|
2
|
+
|
|
3
|
+
Server-only Python client for creating and managing VoxEvolv sessions.
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
import os
|
|
7
|
+
from voxevolv import VoxEvolv
|
|
8
|
+
|
|
9
|
+
client = VoxEvolv(
|
|
10
|
+
api_key=os.environ["VOXEVOLV_API_KEY"],
|
|
11
|
+
base_url=os.environ["VOXEVOLV_API_BASE"],
|
|
12
|
+
)
|
|
13
|
+
session = client.sessions.create(
|
|
14
|
+
intent_id=interview_session_id,
|
|
15
|
+
profile="live-interviewer",
|
|
16
|
+
participant={"identity": user_id, "display_name": display_name},
|
|
17
|
+
instructions=instructions,
|
|
18
|
+
greeting=greeting,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
return session.browser_credentials()
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The SDK derives one deterministic idempotency key from `intent_id`, preserves it
|
|
25
|
+
across bounded 429/5xx/network retries, and raises `VoxEvolvError` with typed API
|
|
26
|
+
failure information.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "voxevolv"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python server SDK for the VoxEvolv Voice Session API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "VoxEvolv contributors" }]
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
dependencies = []
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Repository = "https://github.com/shobhansuri/VoxEvolv"
|
|
27
|
+
Issues = "https://github.com/shobhansuri/VoxEvolv/issues"
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.packages.find]
|
|
30
|
+
where = ["src"]
|
|
31
|
+
|
|
32
|
+
[tool.setuptools.package-data]
|
|
33
|
+
voxevolv = ["py.typed"]
|
voxevolv-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from .client import (
|
|
2
|
+
BrowserCredentials,
|
|
3
|
+
Session,
|
|
4
|
+
SessionsResource,
|
|
5
|
+
VoxEvolv,
|
|
6
|
+
VoxEvolvError,
|
|
7
|
+
idempotency_key_for,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"BrowserCredentials",
|
|
12
|
+
"Session",
|
|
13
|
+
"SessionsResource",
|
|
14
|
+
"VoxEvolv",
|
|
15
|
+
"VoxEvolvError",
|
|
16
|
+
"idempotency_key_for",
|
|
17
|
+
]
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import time
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from email.utils import parsedate_to_datetime
|
|
8
|
+
from typing import Any, Callable, Mapping, TypedDict
|
|
9
|
+
from urllib.error import HTTPError, URLError
|
|
10
|
+
from urllib.request import Request, urlopen
|
|
11
|
+
|
|
12
|
+
Transport = Callable[[Request, float], Any]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class VoxEvolvError(Exception):
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
message: str,
|
|
19
|
+
*,
|
|
20
|
+
status: int,
|
|
21
|
+
code: str | None = None,
|
|
22
|
+
request_id: str | None = None,
|
|
23
|
+
details: list[Any] | None = None,
|
|
24
|
+
retryable: bool = False,
|
|
25
|
+
) -> None:
|
|
26
|
+
super().__init__(message)
|
|
27
|
+
self.status = status
|
|
28
|
+
self.code = code
|
|
29
|
+
self.request_id = request_id
|
|
30
|
+
self.details = details or []
|
|
31
|
+
self.retryable = retryable
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class BrowserCredentials(TypedDict):
|
|
35
|
+
id: str
|
|
36
|
+
connection: Mapping[str, str]
|
|
37
|
+
access_token: str
|
|
38
|
+
access_token_expires_at: str
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass(frozen=True)
|
|
42
|
+
class Session:
|
|
43
|
+
payload: Mapping[str, Any]
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def id(self) -> str:
|
|
47
|
+
return str(self.payload["id"])
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def profile_revision(self) -> str:
|
|
51
|
+
return str(self.payload["profile_revision"])
|
|
52
|
+
|
|
53
|
+
def browser_credentials(self) -> BrowserCredentials:
|
|
54
|
+
return {
|
|
55
|
+
"id": self.id,
|
|
56
|
+
"connection": self.payload["connection"],
|
|
57
|
+
"access_token": str(self.payload["access_token"]),
|
|
58
|
+
"access_token_expires_at": str(self.payload["access_token_expires_at"]),
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class SessionsResource:
|
|
63
|
+
def __init__(self, client: VoxEvolv) -> None:
|
|
64
|
+
self._client = client
|
|
65
|
+
|
|
66
|
+
def create(
|
|
67
|
+
self,
|
|
68
|
+
*,
|
|
69
|
+
intent_id: str,
|
|
70
|
+
profile: str,
|
|
71
|
+
participant: Mapping[str, str],
|
|
72
|
+
instructions: str = "",
|
|
73
|
+
greeting: str = "",
|
|
74
|
+
language: str | None = None,
|
|
75
|
+
voice: str | None = None,
|
|
76
|
+
require: Mapping[str, Any] | None = None,
|
|
77
|
+
media: Mapping[str, Any] | None = None,
|
|
78
|
+
max_duration_seconds: int | None = None,
|
|
79
|
+
media_idle_timeout_seconds: int | None = None,
|
|
80
|
+
metadata: Mapping[str, Any] | None = None,
|
|
81
|
+
) -> Session:
|
|
82
|
+
_validate_create(intent_id=intent_id, profile=profile, participant=participant)
|
|
83
|
+
identity = participant["identity"]
|
|
84
|
+
body: dict[str, Any] = {
|
|
85
|
+
"protocol_version": 1,
|
|
86
|
+
"client_reference_id": intent_id,
|
|
87
|
+
"profile": profile,
|
|
88
|
+
"participant": {
|
|
89
|
+
"identity": identity,
|
|
90
|
+
**(
|
|
91
|
+
{"display_name": participant["display_name"]}
|
|
92
|
+
if "display_name" in participant
|
|
93
|
+
else {}
|
|
94
|
+
),
|
|
95
|
+
},
|
|
96
|
+
"instructions": instructions,
|
|
97
|
+
"greeting": greeting,
|
|
98
|
+
"metadata": dict(metadata or {}),
|
|
99
|
+
}
|
|
100
|
+
optional = {
|
|
101
|
+
"language": language,
|
|
102
|
+
"voice": voice,
|
|
103
|
+
"require": dict(require) if require is not None else None,
|
|
104
|
+
"media": dict(media) if media is not None else None,
|
|
105
|
+
"max_duration_seconds": max_duration_seconds,
|
|
106
|
+
"media_idle_timeout_seconds": media_idle_timeout_seconds,
|
|
107
|
+
}
|
|
108
|
+
body.update({key: value for key, value in optional.items() if value is not None})
|
|
109
|
+
payload = self._client._request(
|
|
110
|
+
"sessions/",
|
|
111
|
+
method="POST",
|
|
112
|
+
body=body,
|
|
113
|
+
headers={"Idempotency-Key": idempotency_key_for(intent_id)},
|
|
114
|
+
)
|
|
115
|
+
return Session(payload)
|
|
116
|
+
|
|
117
|
+
def get(self, session_id: str) -> Mapping[str, Any]:
|
|
118
|
+
return self._client._request(f"sessions/{session_id}")
|
|
119
|
+
|
|
120
|
+
def end(self, session_id: str) -> None:
|
|
121
|
+
self._client._request(f"sessions/{session_id}", method="DELETE")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class VoxEvolv:
|
|
125
|
+
def __init__(
|
|
126
|
+
self,
|
|
127
|
+
*,
|
|
128
|
+
api_key: str,
|
|
129
|
+
base_url: str,
|
|
130
|
+
max_retries: int = 2,
|
|
131
|
+
retry_base_seconds: float = 0.25,
|
|
132
|
+
timeout_seconds: float = 30.0,
|
|
133
|
+
transport: Transport | None = None,
|
|
134
|
+
sleep: Callable[[float], None] = time.sleep,
|
|
135
|
+
) -> None:
|
|
136
|
+
if not api_key.startswith("sk_"):
|
|
137
|
+
raise TypeError("api_key must be a VoxEvolv server API key")
|
|
138
|
+
if max_retries < 0:
|
|
139
|
+
raise ValueError("max_retries cannot be negative")
|
|
140
|
+
self._api_key = api_key
|
|
141
|
+
self._base_url = base_url.rstrip("/")
|
|
142
|
+
self._max_retries = max_retries
|
|
143
|
+
self._retry_base_seconds = retry_base_seconds
|
|
144
|
+
self._timeout_seconds = timeout_seconds
|
|
145
|
+
self._transport = transport or _urlopen
|
|
146
|
+
self._sleep = sleep
|
|
147
|
+
self.sessions = SessionsResource(self)
|
|
148
|
+
|
|
149
|
+
def _request(
|
|
150
|
+
self,
|
|
151
|
+
path: str,
|
|
152
|
+
*,
|
|
153
|
+
method: str = "GET",
|
|
154
|
+
body: Mapping[str, Any] | None = None,
|
|
155
|
+
headers: Mapping[str, str] | None = None,
|
|
156
|
+
) -> Mapping[str, Any]:
|
|
157
|
+
encoded = None if body is None else json.dumps(body).encode("utf-8")
|
|
158
|
+
request_headers = {
|
|
159
|
+
"Authorization": f"Bearer {self._api_key}",
|
|
160
|
+
"Accept": "application/json",
|
|
161
|
+
**({"Content-Type": "application/json"} if encoded is not None else {}),
|
|
162
|
+
**dict(headers or {}),
|
|
163
|
+
}
|
|
164
|
+
request = Request(
|
|
165
|
+
f"{self._base_url}/{path.lstrip('/')}",
|
|
166
|
+
data=encoded,
|
|
167
|
+
headers=request_headers,
|
|
168
|
+
method=method,
|
|
169
|
+
)
|
|
170
|
+
attempt = 0
|
|
171
|
+
while True:
|
|
172
|
+
try:
|
|
173
|
+
response = self._transport(request, self._timeout_seconds)
|
|
174
|
+
raw = response.read()
|
|
175
|
+
return {} if not raw else json.loads(raw)
|
|
176
|
+
except HTTPError as error:
|
|
177
|
+
retryable = error.code == 429 or error.code >= 500
|
|
178
|
+
if not retryable or attempt >= self._max_retries:
|
|
179
|
+
raise _api_error(error, retryable=retryable) from error
|
|
180
|
+
delay = _retry_after_seconds(error.headers.get("Retry-After"))
|
|
181
|
+
self._sleep(
|
|
182
|
+
delay
|
|
183
|
+
if delay is not None
|
|
184
|
+
else self._retry_base_seconds * (2**attempt)
|
|
185
|
+
)
|
|
186
|
+
attempt += 1
|
|
187
|
+
except URLError as error:
|
|
188
|
+
if attempt >= self._max_retries:
|
|
189
|
+
raise VoxEvolvError(
|
|
190
|
+
f"Could not reach VoxEvolv: {error.reason}",
|
|
191
|
+
status=0,
|
|
192
|
+
code="network_error",
|
|
193
|
+
retryable=True,
|
|
194
|
+
) from error
|
|
195
|
+
self._sleep(self._retry_base_seconds * (2**attempt))
|
|
196
|
+
attempt += 1
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def idempotency_key_for(intent_id: str) -> str:
|
|
200
|
+
if not intent_id or len(intent_id) > 200:
|
|
201
|
+
raise TypeError("intent_id must be between 1 and 200 characters")
|
|
202
|
+
digest = hashlib.sha256(intent_id.encode("utf-8")).hexdigest()
|
|
203
|
+
return f"intent_{digest}"
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _validate_create(
|
|
207
|
+
*,
|
|
208
|
+
intent_id: str,
|
|
209
|
+
profile: str,
|
|
210
|
+
participant: Mapping[str, str],
|
|
211
|
+
) -> None:
|
|
212
|
+
import re
|
|
213
|
+
|
|
214
|
+
idempotency_key_for(intent_id)
|
|
215
|
+
if re.fullmatch(r"[a-z][a-z0-9-]{1,62}[a-z0-9]", profile) is None:
|
|
216
|
+
raise TypeError("profile must be a valid published profile name")
|
|
217
|
+
identity = participant.get("identity", "")
|
|
218
|
+
if re.fullmatch(r"[A-Za-z0-9_.:@-]{1,120}", identity) is None:
|
|
219
|
+
raise TypeError("participant identity is invalid")
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def _urlopen(request: Request, timeout: float) -> Any:
|
|
223
|
+
return urlopen(request, timeout=timeout)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _api_error(error: HTTPError, *, retryable: bool) -> VoxEvolvError:
|
|
227
|
+
try:
|
|
228
|
+
payload = json.loads(error.read())
|
|
229
|
+
except (json.JSONDecodeError, UnicodeDecodeError):
|
|
230
|
+
payload = {}
|
|
231
|
+
return VoxEvolvError(
|
|
232
|
+
payload.get("message", f"VoxEvolv request failed ({error.code})"),
|
|
233
|
+
status=error.code,
|
|
234
|
+
code=payload.get("error"),
|
|
235
|
+
request_id=payload.get("request_id"),
|
|
236
|
+
details=payload.get("details", []),
|
|
237
|
+
retryable=retryable,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _retry_after_seconds(value: str | None) -> float | None:
|
|
242
|
+
if not value:
|
|
243
|
+
return None
|
|
244
|
+
try:
|
|
245
|
+
return max(0.0, float(value))
|
|
246
|
+
except ValueError:
|
|
247
|
+
try:
|
|
248
|
+
return max(0.0, parsedate_to_datetime(value).timestamp() - time.time())
|
|
249
|
+
except (TypeError, ValueError, OverflowError):
|
|
250
|
+
return None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: voxevolv
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python server SDK for the VoxEvolv Voice Session API
|
|
5
|
+
Author: VoxEvolv contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/shobhansuri/VoxEvolv
|
|
8
|
+
Project-URL: Issues, https://github.com/shobhansuri/VoxEvolv/issues
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# VoxEvolv Python SDK
|
|
22
|
+
|
|
23
|
+
Server-only Python client for creating and managing VoxEvolv sessions.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import os
|
|
27
|
+
from voxevolv import VoxEvolv
|
|
28
|
+
|
|
29
|
+
client = VoxEvolv(
|
|
30
|
+
api_key=os.environ["VOXEVOLV_API_KEY"],
|
|
31
|
+
base_url=os.environ["VOXEVOLV_API_BASE"],
|
|
32
|
+
)
|
|
33
|
+
session = client.sessions.create(
|
|
34
|
+
intent_id=interview_session_id,
|
|
35
|
+
profile="live-interviewer",
|
|
36
|
+
participant={"identity": user_id, "display_name": display_name},
|
|
37
|
+
instructions=instructions,
|
|
38
|
+
greeting=greeting,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return session.browser_credentials()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The SDK derives one deterministic idempotency key from `intent_id`, preserves it
|
|
45
|
+
across bounded 429/5xx/network retries, and raises `VoxEvolvError` with typed API
|
|
46
|
+
failure information.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/voxevolv/__init__.py
|
|
5
|
+
src/voxevolv/client.py
|
|
6
|
+
src/voxevolv/py.typed
|
|
7
|
+
src/voxevolv.egg-info/PKG-INFO
|
|
8
|
+
src/voxevolv.egg-info/SOURCES.txt
|
|
9
|
+
src/voxevolv.egg-info/dependency_links.txt
|
|
10
|
+
src/voxevolv.egg-info/top_level.txt
|
|
11
|
+
tests/test_client.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
voxevolv
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
import unittest
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from urllib.error import HTTPError
|
|
7
|
+
|
|
8
|
+
sys.path.insert(0, str(Path(__file__).parents[1] / "src"))
|
|
9
|
+
|
|
10
|
+
from voxevolv import VoxEvolv, VoxEvolvError, idempotency_key_for # noqa: E402
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Response:
|
|
14
|
+
def __init__(self, payload):
|
|
15
|
+
self.payload = payload
|
|
16
|
+
|
|
17
|
+
def read(self):
|
|
18
|
+
return json.dumps(self.payload).encode("utf-8")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ClientTests(unittest.TestCase):
|
|
22
|
+
def test_create_projects_browser_credentials_and_uses_stable_key(self):
|
|
23
|
+
calls = []
|
|
24
|
+
|
|
25
|
+
def transport(request, timeout):
|
|
26
|
+
calls.append((request, timeout))
|
|
27
|
+
return Response(
|
|
28
|
+
{
|
|
29
|
+
"id": "session-1",
|
|
30
|
+
"status": "created",
|
|
31
|
+
"profile_revision": "live-interviewer@1",
|
|
32
|
+
"connection": {
|
|
33
|
+
"url": "wss://rtc.example",
|
|
34
|
+
"token": "room-token",
|
|
35
|
+
"room_name": "room-1",
|
|
36
|
+
},
|
|
37
|
+
"access_token": "vsa_browser",
|
|
38
|
+
"access_token_expires_at": "2026-07-18T12:00:00Z",
|
|
39
|
+
"created_at": "2026-07-18T11:00:00Z",
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
client = VoxEvolv(
|
|
44
|
+
api_key="sk_test_server",
|
|
45
|
+
base_url="https://api.example.test/v1",
|
|
46
|
+
transport=transport,
|
|
47
|
+
)
|
|
48
|
+
session = client.sessions.create(
|
|
49
|
+
intent_id="interview:123",
|
|
50
|
+
profile="live-interviewer",
|
|
51
|
+
participant={"identity": "candidate_123", "display_name": "Candidate"},
|
|
52
|
+
)
|
|
53
|
+
self.assertEqual(session.id, "session-1")
|
|
54
|
+
self.assertEqual(calls[0][0].full_url, "https://api.example.test/v1/sessions/")
|
|
55
|
+
self.assertEqual(session.browser_credentials()["access_token"], "vsa_browser")
|
|
56
|
+
self.assertEqual(
|
|
57
|
+
calls[0][0].get_header("Idempotency-key"),
|
|
58
|
+
idempotency_key_for("interview:123"),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def test_retry_preserves_idempotency_key(self):
|
|
62
|
+
keys = []
|
|
63
|
+
|
|
64
|
+
def transport(request, _timeout):
|
|
65
|
+
keys.append(request.get_header("Idempotency-key"))
|
|
66
|
+
if len(keys) == 1:
|
|
67
|
+
raise HTTPError(
|
|
68
|
+
request.full_url,
|
|
69
|
+
503,
|
|
70
|
+
"Unavailable",
|
|
71
|
+
{},
|
|
72
|
+
io.BytesIO(b"{}"),
|
|
73
|
+
)
|
|
74
|
+
return Response(
|
|
75
|
+
{
|
|
76
|
+
"id": "session-1",
|
|
77
|
+
"profile_revision": "profile@1",
|
|
78
|
+
"connection": {},
|
|
79
|
+
"access_token": "vsa",
|
|
80
|
+
"access_token_expires_at": "later",
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
client = VoxEvolv(
|
|
85
|
+
api_key="sk_test_server",
|
|
86
|
+
base_url="https://api.example.test/v1",
|
|
87
|
+
transport=transport,
|
|
88
|
+
max_retries=1,
|
|
89
|
+
retry_base_seconds=0,
|
|
90
|
+
sleep=lambda _seconds: None,
|
|
91
|
+
)
|
|
92
|
+
client.sessions.create(
|
|
93
|
+
intent_id="retry-me",
|
|
94
|
+
profile="live-interviewer",
|
|
95
|
+
participant={"identity": "candidate"},
|
|
96
|
+
)
|
|
97
|
+
self.assertEqual(keys[0], keys[1])
|
|
98
|
+
|
|
99
|
+
def test_api_errors_are_typed(self):
|
|
100
|
+
def transport(request, _timeout):
|
|
101
|
+
raise HTTPError(
|
|
102
|
+
request.full_url,
|
|
103
|
+
409,
|
|
104
|
+
"Conflict",
|
|
105
|
+
{},
|
|
106
|
+
io.BytesIO(
|
|
107
|
+
json.dumps(
|
|
108
|
+
{"error": "invalid_profile", "message": "Profile is not published"}
|
|
109
|
+
).encode("utf-8")
|
|
110
|
+
),
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
client = VoxEvolv(
|
|
114
|
+
api_key="sk_test_server",
|
|
115
|
+
base_url="https://api.example.test/v1",
|
|
116
|
+
transport=transport,
|
|
117
|
+
)
|
|
118
|
+
with self.assertRaises(VoxEvolvError) as raised:
|
|
119
|
+
client.sessions.create(
|
|
120
|
+
intent_id="invalid",
|
|
121
|
+
profile="live-interviewer",
|
|
122
|
+
participant={"identity": "candidate"},
|
|
123
|
+
)
|
|
124
|
+
self.assertEqual(raised.exception.status, 409)
|
|
125
|
+
self.assertEqual(raised.exception.code, "invalid_profile")
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
if __name__ == "__main__":
|
|
129
|
+
unittest.main()
|