Skip to content

Commit 8865297

Browse files
authored
feat(operator): thread ids on requests, run ids on results, and the audit run reads (#285)
## Summary Companion to RoboFinSystems/robosystems#1936 and the TypeScript twin RoboFinSystems/robosystems-typescript-client#301. Additive, so a client minor; nothing the integration template imports moves. - \`OperatorQueryRequest.thread_id\` rides the body: it groups a run with the earlier runs of one conversation, and with no \`history\` given the server seeds the run from the thread's own record. Sent only when set. - \`OperatorResult.operation_id\` names the run on every path (a sync 200, the followed stream, the status poll), so a caller can read its record back. - Regenerated against the local API: \`list_operator_threads\`, \`list_operator_runs\` and \`get_operator_run\` under the graph audit, with their models. The new request field waits on the robosystems release carrying #1936; against an older server it is ignored. ## Verified Wire-shape tests cover the body (thread field present only when set) and the run id on sync and followed results. Lint, typecheck and the full suite green. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01AZDcFWJRoqZQpZ3ZguTVzu
2 parents 234fb3c + dcc8a43 commit 8865297

20 files changed

Lines changed: 2056 additions & 5 deletions
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
from http import HTTPStatus
2+
from typing import Any
3+
from urllib.parse import quote
4+
5+
import httpx
6+
7+
from ... import errors
8+
from ...client import AuthenticatedClient, Client
9+
from ...models.error_response import ErrorResponse
10+
from ...models.http_validation_error import HTTPValidationError
11+
from ...models.operator_run_detail import OperatorRunDetail
12+
from ...types import Response
13+
14+
15+
def _get_kwargs(
16+
graph_id: str,
17+
operation_id: str,
18+
) -> dict[str, Any]:
19+
20+
_kwargs: dict[str, Any] = {
21+
"method": "get",
22+
"url": "/v1/graphs/{graph_id}/audit/runs/{operation_id}".format(
23+
graph_id=quote(str(graph_id), safe=""),
24+
operation_id=quote(str(operation_id), safe=""),
25+
),
26+
}
27+
28+
return _kwargs
29+
30+
31+
def _parse_response(
32+
*, client: AuthenticatedClient | Client, response: httpx.Response
33+
) -> ErrorResponse | HTTPValidationError | OperatorRunDetail | None:
34+
if response.status_code == 200:
35+
response_200 = OperatorRunDetail.from_dict(response.json())
36+
37+
return response_200
38+
39+
if response.status_code == 400:
40+
response_400 = ErrorResponse.from_dict(response.json())
41+
42+
return response_400
43+
44+
if response.status_code == 401:
45+
response_401 = ErrorResponse.from_dict(response.json())
46+
47+
return response_401
48+
49+
if response.status_code == 403:
50+
response_403 = ErrorResponse.from_dict(response.json())
51+
52+
return response_403
53+
54+
if response.status_code == 404:
55+
response_404 = ErrorResponse.from_dict(response.json())
56+
57+
return response_404
58+
59+
if response.status_code == 422:
60+
response_422 = HTTPValidationError.from_dict(response.json())
61+
62+
return response_422
63+
64+
if response.status_code == 429:
65+
response_429 = ErrorResponse.from_dict(response.json())
66+
67+
return response_429
68+
69+
if response.status_code == 500:
70+
response_500 = ErrorResponse.from_dict(response.json())
71+
72+
return response_500
73+
74+
if client.raise_on_unexpected_status:
75+
raise errors.UnexpectedStatus(response.status_code, response.content)
76+
else:
77+
return None
78+
79+
80+
def _build_response(
81+
*, client: AuthenticatedClient | Client, response: httpx.Response
82+
) -> Response[ErrorResponse | HTTPValidationError | OperatorRunDetail]:
83+
return Response(
84+
status_code=HTTPStatus(response.status_code),
85+
content=response.content,
86+
headers=response.headers,
87+
parsed=_parse_response(client=client, response=response),
88+
)
89+
90+
91+
def sync_detailed(
92+
graph_id: str,
93+
operation_id: str,
94+
*,
95+
client: AuthenticatedClient,
96+
) -> Response[ErrorResponse | HTTPValidationError | OperatorRunDetail]:
97+
"""Get Operator Run
98+
99+
One operator run with its full paper trail: the history it was seeded with, every model call with
100+
the tool calls it made and the results it read, the answer, and the response metadata. Readable by a
101+
graph admin or by the user who made the run.
102+
103+
Args:
104+
graph_id (str): Graph identifier
105+
operation_id (str): The run's operation id
106+
107+
Raises:
108+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
109+
httpx.TimeoutException: If the request takes longer than Client.timeout.
110+
111+
Returns:
112+
Response[ErrorResponse | HTTPValidationError | OperatorRunDetail]
113+
"""
114+
115+
kwargs = _get_kwargs(
116+
graph_id=graph_id,
117+
operation_id=operation_id,
118+
)
119+
120+
response = client.get_httpx_client().request(
121+
**kwargs,
122+
)
123+
124+
return _build_response(client=client, response=response)
125+
126+
127+
def sync(
128+
graph_id: str,
129+
operation_id: str,
130+
*,
131+
client: AuthenticatedClient,
132+
) -> ErrorResponse | HTTPValidationError | OperatorRunDetail | None:
133+
"""Get Operator Run
134+
135+
One operator run with its full paper trail: the history it was seeded with, every model call with
136+
the tool calls it made and the results it read, the answer, and the response metadata. Readable by a
137+
graph admin or by the user who made the run.
138+
139+
Args:
140+
graph_id (str): Graph identifier
141+
operation_id (str): The run's operation id
142+
143+
Raises:
144+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
145+
httpx.TimeoutException: If the request takes longer than Client.timeout.
146+
147+
Returns:
148+
ErrorResponse | HTTPValidationError | OperatorRunDetail
149+
"""
150+
151+
return sync_detailed(
152+
graph_id=graph_id,
153+
operation_id=operation_id,
154+
client=client,
155+
).parsed
156+
157+
158+
async def asyncio_detailed(
159+
graph_id: str,
160+
operation_id: str,
161+
*,
162+
client: AuthenticatedClient,
163+
) -> Response[ErrorResponse | HTTPValidationError | OperatorRunDetail]:
164+
"""Get Operator Run
165+
166+
One operator run with its full paper trail: the history it was seeded with, every model call with
167+
the tool calls it made and the results it read, the answer, and the response metadata. Readable by a
168+
graph admin or by the user who made the run.
169+
170+
Args:
171+
graph_id (str): Graph identifier
172+
operation_id (str): The run's operation id
173+
174+
Raises:
175+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
176+
httpx.TimeoutException: If the request takes longer than Client.timeout.
177+
178+
Returns:
179+
Response[ErrorResponse | HTTPValidationError | OperatorRunDetail]
180+
"""
181+
182+
kwargs = _get_kwargs(
183+
graph_id=graph_id,
184+
operation_id=operation_id,
185+
)
186+
187+
response = await client.get_async_httpx_client().request(**kwargs)
188+
189+
return _build_response(client=client, response=response)
190+
191+
192+
async def asyncio(
193+
graph_id: str,
194+
operation_id: str,
195+
*,
196+
client: AuthenticatedClient,
197+
) -> ErrorResponse | HTTPValidationError | OperatorRunDetail | None:
198+
"""Get Operator Run
199+
200+
One operator run with its full paper trail: the history it was seeded with, every model call with
201+
the tool calls it made and the results it read, the answer, and the response metadata. Readable by a
202+
graph admin or by the user who made the run.
203+
204+
Args:
205+
graph_id (str): Graph identifier
206+
operation_id (str): The run's operation id
207+
208+
Raises:
209+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
210+
httpx.TimeoutException: If the request takes longer than Client.timeout.
211+
212+
Returns:
213+
ErrorResponse | HTTPValidationError | OperatorRunDetail
214+
"""
215+
216+
return (
217+
await asyncio_detailed(
218+
graph_id=graph_id,
219+
operation_id=operation_id,
220+
client=client,
221+
)
222+
).parsed

0 commit comments

Comments
 (0)