phenoml 0.0.1__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 phenoml might be problematic. Click here for more details.

Files changed (143) hide show
  1. phenoml/__init__.py +30 -0
  2. phenoml/agent/__init__.py +58 -0
  3. phenoml/agent/client.py +820 -0
  4. phenoml/agent/errors/__init__.py +11 -0
  5. phenoml/agent/errors/bad_request_error.py +10 -0
  6. phenoml/agent/errors/forbidden_error.py +10 -0
  7. phenoml/agent/errors/internal_server_error.py +10 -0
  8. phenoml/agent/errors/not_found_error.py +10 -0
  9. phenoml/agent/errors/unauthorized_error.py +10 -0
  10. phenoml/agent/prompts/__init__.py +7 -0
  11. phenoml/agent/prompts/client.py +707 -0
  12. phenoml/agent/prompts/raw_client.py +1345 -0
  13. phenoml/agent/prompts/types/__init__.py +8 -0
  14. phenoml/agent/prompts/types/prompts_delete_response.py +20 -0
  15. phenoml/agent/prompts/types/prompts_list_response.py +22 -0
  16. phenoml/agent/raw_client.py +1501 -0
  17. phenoml/agent/types/__init__.py +45 -0
  18. phenoml/agent/types/agent_chat_response.py +33 -0
  19. phenoml/agent/types/agent_create_request_provider.py +13 -0
  20. phenoml/agent/types/agent_create_request_provider_item.py +7 -0
  21. phenoml/agent/types/agent_delete_response.py +20 -0
  22. phenoml/agent/types/agent_fhir_config.py +31 -0
  23. phenoml/agent/types/agent_list_response.py +22 -0
  24. phenoml/agent/types/agent_prompts_response.py +22 -0
  25. phenoml/agent/types/agent_response.py +22 -0
  26. phenoml/agent/types/agent_template.py +56 -0
  27. phenoml/agent/types/agent_template_provider.py +13 -0
  28. phenoml/agent/types/agent_template_provider_item.py +5 -0
  29. phenoml/agent/types/agent_update_request_provider.py +13 -0
  30. phenoml/agent/types/agent_update_request_provider_item.py +7 -0
  31. phenoml/agent/types/chat_fhir_client_config.py +31 -0
  32. phenoml/agent/types/json_patch.py +7 -0
  33. phenoml/agent/types/json_patch_operation.py +36 -0
  34. phenoml/agent/types/json_patch_operation_op.py +5 -0
  35. phenoml/agent/types/prompt_template.py +52 -0
  36. phenoml/agent/types/success_response.py +20 -0
  37. phenoml/authtoken/__init__.py +17 -0
  38. phenoml/authtoken/auth/__init__.py +7 -0
  39. phenoml/authtoken/auth/client.py +129 -0
  40. phenoml/authtoken/auth/raw_client.py +173 -0
  41. phenoml/authtoken/auth/types/__init__.py +7 -0
  42. phenoml/authtoken/auth/types/auth_generate_token_response.py +22 -0
  43. phenoml/authtoken/client.py +39 -0
  44. phenoml/authtoken/errors/__init__.py +8 -0
  45. phenoml/authtoken/errors/bad_request_error.py +10 -0
  46. phenoml/authtoken/errors/unauthorized_error.py +10 -0
  47. phenoml/authtoken/raw_client.py +13 -0
  48. phenoml/authtoken/types/__init__.py +8 -0
  49. phenoml/authtoken/types/bad_request_error_body.py +21 -0
  50. phenoml/authtoken/types/unauthorized_error_body.py +21 -0
  51. phenoml/client.py +168 -0
  52. phenoml/cohort/__init__.py +8 -0
  53. phenoml/cohort/client.py +113 -0
  54. phenoml/cohort/errors/__init__.py +9 -0
  55. phenoml/cohort/errors/bad_request_error.py +10 -0
  56. phenoml/cohort/errors/internal_server_error.py +10 -0
  57. phenoml/cohort/errors/unauthorized_error.py +10 -0
  58. phenoml/cohort/raw_client.py +185 -0
  59. phenoml/cohort/types/__init__.py +8 -0
  60. phenoml/cohort/types/cohort_response.py +33 -0
  61. phenoml/cohort/types/search_concept.py +37 -0
  62. phenoml/construe/__init__.py +45 -0
  63. phenoml/construe/client.py +399 -0
  64. phenoml/construe/errors/__init__.py +11 -0
  65. phenoml/construe/errors/bad_request_error.py +10 -0
  66. phenoml/construe/errors/conflict_error.py +10 -0
  67. phenoml/construe/errors/failed_dependency_error.py +10 -0
  68. phenoml/construe/errors/internal_server_error.py +10 -0
  69. phenoml/construe/errors/unauthorized_error.py +10 -0
  70. phenoml/construe/raw_client.py +706 -0
  71. phenoml/construe/types/__init__.py +41 -0
  72. phenoml/construe/types/bad_request_error_body.py +27 -0
  73. phenoml/construe/types/construe_cohort_request_config.py +37 -0
  74. phenoml/construe/types/construe_cohort_response.py +33 -0
  75. phenoml/construe/types/construe_cohort_response_queries_item.py +49 -0
  76. phenoml/construe/types/construe_cohort_response_queries_item_code_extract_results_item.py +31 -0
  77. phenoml/construe/types/construe_cohort_response_queries_item_code_extract_results_item_codes_item.py +32 -0
  78. phenoml/construe/types/construe_upload_code_system_response.py +19 -0
  79. phenoml/construe/types/extract_codes_result.py +22 -0
  80. phenoml/construe/types/extract_request_config.py +23 -0
  81. phenoml/construe/types/extract_request_config_chunking_method.py +5 -0
  82. phenoml/construe/types/extract_request_system.py +37 -0
  83. phenoml/construe/types/extracted_code_result.py +41 -0
  84. phenoml/construe/types/internal_server_error_body.py +27 -0
  85. phenoml/construe/types/unauthorized_error_body.py +27 -0
  86. phenoml/construe/types/upload_request_format.py +5 -0
  87. phenoml/core/__init__.py +52 -0
  88. phenoml/core/api_error.py +23 -0
  89. phenoml/core/client_wrapper.py +85 -0
  90. phenoml/core/datetime_utils.py +28 -0
  91. phenoml/core/file.py +67 -0
  92. phenoml/core/force_multipart.py +16 -0
  93. phenoml/core/http_client.py +543 -0
  94. phenoml/core/http_response.py +55 -0
  95. phenoml/core/jsonable_encoder.py +100 -0
  96. phenoml/core/pydantic_utilities.py +255 -0
  97. phenoml/core/query_encoder.py +58 -0
  98. phenoml/core/remove_none_from_dict.py +11 -0
  99. phenoml/core/request_options.py +35 -0
  100. phenoml/core/serialization.py +276 -0
  101. phenoml/environment.py +7 -0
  102. phenoml/lang2fhir/__init__.py +27 -0
  103. phenoml/lang2fhir/client.py +430 -0
  104. phenoml/lang2fhir/errors/__init__.py +11 -0
  105. phenoml/lang2fhir/errors/bad_request_error.py +10 -0
  106. phenoml/lang2fhir/errors/failed_dependency_error.py +10 -0
  107. phenoml/lang2fhir/errors/forbidden_error.py +10 -0
  108. phenoml/lang2fhir/errors/internal_server_error.py +10 -0
  109. phenoml/lang2fhir/errors/unauthorized_error.py +10 -0
  110. phenoml/lang2fhir/raw_client.py +788 -0
  111. phenoml/lang2fhir/types/__init__.py +19 -0
  112. phenoml/lang2fhir/types/create_request_resource.py +25 -0
  113. phenoml/lang2fhir/types/document_request_file_type.py +7 -0
  114. phenoml/lang2fhir/types/document_request_resource.py +5 -0
  115. phenoml/lang2fhir/types/fhir_resource.py +5 -0
  116. phenoml/lang2fhir/types/lang2fhir_upload_profile_response.py +23 -0
  117. phenoml/lang2fhir/types/search_response.py +33 -0
  118. phenoml/py.typed +0 -0
  119. phenoml/tools/__init__.py +33 -0
  120. phenoml/tools/client.py +392 -0
  121. phenoml/tools/errors/__init__.py +11 -0
  122. phenoml/tools/errors/bad_request_error.py +10 -0
  123. phenoml/tools/errors/failed_dependency_error.py +10 -0
  124. phenoml/tools/errors/forbidden_error.py +10 -0
  125. phenoml/tools/errors/internal_server_error.py +10 -0
  126. phenoml/tools/errors/unauthorized_error.py +10 -0
  127. phenoml/tools/raw_client.py +745 -0
  128. phenoml/tools/types/__init__.py +25 -0
  129. phenoml/tools/types/cohort_request_provider.py +5 -0
  130. phenoml/tools/types/cohort_response.py +49 -0
  131. phenoml/tools/types/fhir_client_config.py +31 -0
  132. phenoml/tools/types/lang2fhir_and_create_request_provider.py +7 -0
  133. phenoml/tools/types/lang2fhir_and_create_request_resource.py +25 -0
  134. phenoml/tools/types/lang2fhir_and_create_response.py +33 -0
  135. phenoml/tools/types/lang2fhir_and_search_request_provider.py +7 -0
  136. phenoml/tools/types/lang2fhir_and_search_response.py +40 -0
  137. phenoml/tools/types/search_concept.py +41 -0
  138. phenoml/version.py +3 -0
  139. phenoml/wrapper_client.py +123 -0
  140. phenoml-0.0.1.dist-info/LICENSE +21 -0
  141. phenoml-0.0.1.dist-info/METADATA +192 -0
  142. phenoml-0.0.1.dist-info/RECORD +143 -0
  143. phenoml-0.0.1.dist-info/WHEEL +4 -0
@@ -0,0 +1,1501 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+ from json.decoder import JSONDecodeError
5
+
6
+ from ..core.api_error import ApiError
7
+ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8
+ from ..core.http_response import AsyncHttpResponse, HttpResponse
9
+ from ..core.jsonable_encoder import jsonable_encoder
10
+ from ..core.pydantic_utilities import parse_obj_as
11
+ from ..core.request_options import RequestOptions
12
+ from ..core.serialization import convert_and_respect_annotation_metadata
13
+ from .errors.bad_request_error import BadRequestError
14
+ from .errors.forbidden_error import ForbiddenError
15
+ from .errors.internal_server_error import InternalServerError
16
+ from .errors.not_found_error import NotFoundError
17
+ from .errors.unauthorized_error import UnauthorizedError
18
+ from .types.agent_chat_response import AgentChatResponse
19
+ from .types.agent_create_request_provider import AgentCreateRequestProvider
20
+ from .types.agent_delete_response import AgentDeleteResponse
21
+ from .types.agent_fhir_config import AgentFhirConfig
22
+ from .types.agent_list_response import AgentListResponse
23
+ from .types.agent_response import AgentResponse
24
+ from .types.agent_update_request_provider import AgentUpdateRequestProvider
25
+ from .types.chat_fhir_client_config import ChatFhirClientConfig
26
+ from .types.json_patch import JsonPatch
27
+
28
+ # this is used as the default value for optional parameters
29
+ OMIT = typing.cast(typing.Any, ...)
30
+
31
+
32
+ class RawAgentClient:
33
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
34
+ self._client_wrapper = client_wrapper
35
+
36
+ def create(
37
+ self,
38
+ *,
39
+ name: str,
40
+ prompts: typing.Sequence[str],
41
+ is_active: bool,
42
+ description: typing.Optional[str] = OMIT,
43
+ tags: typing.Optional[typing.Sequence[str]] = OMIT,
44
+ provider: typing.Optional[AgentCreateRequestProvider] = OMIT,
45
+ meta: typing.Optional[AgentFhirConfig] = OMIT,
46
+ request_options: typing.Optional[RequestOptions] = None,
47
+ ) -> HttpResponse[AgentResponse]:
48
+ """
49
+ Creates a new PhenoAgent with specified configuration
50
+
51
+ Parameters
52
+ ----------
53
+ name : str
54
+ Agent name
55
+
56
+ prompts : typing.Sequence[str]
57
+ Array of prompt IDs to use for this agent
58
+
59
+ is_active : bool
60
+ Whether the agent is active
61
+
62
+ description : typing.Optional[str]
63
+ Agent description
64
+
65
+ tags : typing.Optional[typing.Sequence[str]]
66
+ Tags for categorizing the agent
67
+
68
+ provider : typing.Optional[AgentCreateRequestProvider]
69
+ FHIR provider type - can be a single provider or array of providers
70
+
71
+ meta : typing.Optional[AgentFhirConfig]
72
+
73
+ request_options : typing.Optional[RequestOptions]
74
+ Request-specific configuration.
75
+
76
+ Returns
77
+ -------
78
+ HttpResponse[AgentResponse]
79
+ Agent created successfully
80
+ """
81
+ _response = self._client_wrapper.httpx_client.request(
82
+ "agent/create",
83
+ method="POST",
84
+ json={
85
+ "name": name,
86
+ "description": description,
87
+ "prompts": prompts,
88
+ "is_active": is_active,
89
+ "tags": tags,
90
+ "provider": convert_and_respect_annotation_metadata(
91
+ object_=provider, annotation=AgentCreateRequestProvider, direction="write"
92
+ ),
93
+ "meta": convert_and_respect_annotation_metadata(
94
+ object_=meta, annotation=AgentFhirConfig, direction="write"
95
+ ),
96
+ },
97
+ headers={
98
+ "content-type": "application/json",
99
+ },
100
+ request_options=request_options,
101
+ omit=OMIT,
102
+ )
103
+ try:
104
+ if 200 <= _response.status_code < 300:
105
+ _data = typing.cast(
106
+ AgentResponse,
107
+ parse_obj_as(
108
+ type_=AgentResponse, # type: ignore
109
+ object_=_response.json(),
110
+ ),
111
+ )
112
+ return HttpResponse(response=_response, data=_data)
113
+ if _response.status_code == 400:
114
+ raise BadRequestError(
115
+ headers=dict(_response.headers),
116
+ body=typing.cast(
117
+ typing.Optional[typing.Any],
118
+ parse_obj_as(
119
+ type_=typing.Optional[typing.Any], # type: ignore
120
+ object_=_response.json(),
121
+ ),
122
+ ),
123
+ )
124
+ if _response.status_code == 401:
125
+ raise UnauthorizedError(
126
+ headers=dict(_response.headers),
127
+ body=typing.cast(
128
+ typing.Optional[typing.Any],
129
+ parse_obj_as(
130
+ type_=typing.Optional[typing.Any], # type: ignore
131
+ object_=_response.json(),
132
+ ),
133
+ ),
134
+ )
135
+ if _response.status_code == 403:
136
+ raise ForbiddenError(
137
+ headers=dict(_response.headers),
138
+ body=typing.cast(
139
+ typing.Optional[typing.Any],
140
+ parse_obj_as(
141
+ type_=typing.Optional[typing.Any], # type: ignore
142
+ object_=_response.json(),
143
+ ),
144
+ ),
145
+ )
146
+ if _response.status_code == 500:
147
+ raise InternalServerError(
148
+ headers=dict(_response.headers),
149
+ body=typing.cast(
150
+ typing.Optional[typing.Any],
151
+ parse_obj_as(
152
+ type_=typing.Optional[typing.Any], # type: ignore
153
+ object_=_response.json(),
154
+ ),
155
+ ),
156
+ )
157
+ _response_json = _response.json()
158
+ except JSONDecodeError:
159
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
160
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
161
+
162
+ def list(
163
+ self,
164
+ *,
165
+ is_active: typing.Optional[bool] = None,
166
+ tags: typing.Optional[str] = None,
167
+ request_options: typing.Optional[RequestOptions] = None,
168
+ ) -> HttpResponse[AgentListResponse]:
169
+ """
170
+ Retrieves a list of PhenoAgents belonging to the authenticated user
171
+
172
+ Parameters
173
+ ----------
174
+ is_active : typing.Optional[bool]
175
+ Filter by active status
176
+
177
+ tags : typing.Optional[str]
178
+ Filter by tags
179
+
180
+ request_options : typing.Optional[RequestOptions]
181
+ Request-specific configuration.
182
+
183
+ Returns
184
+ -------
185
+ HttpResponse[AgentListResponse]
186
+ Agents retrieved successfully
187
+ """
188
+ _response = self._client_wrapper.httpx_client.request(
189
+ "agent/list",
190
+ method="GET",
191
+ params={
192
+ "is_active": is_active,
193
+ "tags": tags,
194
+ },
195
+ request_options=request_options,
196
+ )
197
+ try:
198
+ if 200 <= _response.status_code < 300:
199
+ _data = typing.cast(
200
+ AgentListResponse,
201
+ parse_obj_as(
202
+ type_=AgentListResponse, # type: ignore
203
+ object_=_response.json(),
204
+ ),
205
+ )
206
+ return HttpResponse(response=_response, data=_data)
207
+ if _response.status_code == 401:
208
+ raise UnauthorizedError(
209
+ headers=dict(_response.headers),
210
+ body=typing.cast(
211
+ typing.Optional[typing.Any],
212
+ parse_obj_as(
213
+ type_=typing.Optional[typing.Any], # type: ignore
214
+ object_=_response.json(),
215
+ ),
216
+ ),
217
+ )
218
+ if _response.status_code == 403:
219
+ raise ForbiddenError(
220
+ headers=dict(_response.headers),
221
+ body=typing.cast(
222
+ typing.Optional[typing.Any],
223
+ parse_obj_as(
224
+ type_=typing.Optional[typing.Any], # type: ignore
225
+ object_=_response.json(),
226
+ ),
227
+ ),
228
+ )
229
+ if _response.status_code == 500:
230
+ raise InternalServerError(
231
+ headers=dict(_response.headers),
232
+ body=typing.cast(
233
+ typing.Optional[typing.Any],
234
+ parse_obj_as(
235
+ type_=typing.Optional[typing.Any], # type: ignore
236
+ object_=_response.json(),
237
+ ),
238
+ ),
239
+ )
240
+ _response_json = _response.json()
241
+ except JSONDecodeError:
242
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
243
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
244
+
245
+ def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[AgentResponse]:
246
+ """
247
+ Retrieves a specific agent by its ID
248
+
249
+ Parameters
250
+ ----------
251
+ id : str
252
+ Agent ID
253
+
254
+ request_options : typing.Optional[RequestOptions]
255
+ Request-specific configuration.
256
+
257
+ Returns
258
+ -------
259
+ HttpResponse[AgentResponse]
260
+ Agent retrieved successfully
261
+ """
262
+ _response = self._client_wrapper.httpx_client.request(
263
+ f"agent/{jsonable_encoder(id)}",
264
+ method="GET",
265
+ request_options=request_options,
266
+ )
267
+ try:
268
+ if 200 <= _response.status_code < 300:
269
+ _data = typing.cast(
270
+ AgentResponse,
271
+ parse_obj_as(
272
+ type_=AgentResponse, # type: ignore
273
+ object_=_response.json(),
274
+ ),
275
+ )
276
+ return HttpResponse(response=_response, data=_data)
277
+ if _response.status_code == 401:
278
+ raise UnauthorizedError(
279
+ headers=dict(_response.headers),
280
+ body=typing.cast(
281
+ typing.Optional[typing.Any],
282
+ parse_obj_as(
283
+ type_=typing.Optional[typing.Any], # type: ignore
284
+ object_=_response.json(),
285
+ ),
286
+ ),
287
+ )
288
+ if _response.status_code == 403:
289
+ raise ForbiddenError(
290
+ headers=dict(_response.headers),
291
+ body=typing.cast(
292
+ typing.Optional[typing.Any],
293
+ parse_obj_as(
294
+ type_=typing.Optional[typing.Any], # type: ignore
295
+ object_=_response.json(),
296
+ ),
297
+ ),
298
+ )
299
+ if _response.status_code == 404:
300
+ raise NotFoundError(
301
+ headers=dict(_response.headers),
302
+ body=typing.cast(
303
+ typing.Optional[typing.Any],
304
+ parse_obj_as(
305
+ type_=typing.Optional[typing.Any], # type: ignore
306
+ object_=_response.json(),
307
+ ),
308
+ ),
309
+ )
310
+ if _response.status_code == 500:
311
+ raise InternalServerError(
312
+ headers=dict(_response.headers),
313
+ body=typing.cast(
314
+ typing.Optional[typing.Any],
315
+ parse_obj_as(
316
+ type_=typing.Optional[typing.Any], # type: ignore
317
+ object_=_response.json(),
318
+ ),
319
+ ),
320
+ )
321
+ _response_json = _response.json()
322
+ except JSONDecodeError:
323
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
324
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
325
+
326
+ def update(
327
+ self,
328
+ id: str,
329
+ *,
330
+ name: typing.Optional[str] = OMIT,
331
+ description: typing.Optional[str] = OMIT,
332
+ prompts: typing.Optional[typing.Sequence[str]] = OMIT,
333
+ is_active: typing.Optional[bool] = OMIT,
334
+ tags: typing.Optional[typing.Sequence[str]] = OMIT,
335
+ provider: typing.Optional[AgentUpdateRequestProvider] = OMIT,
336
+ meta: typing.Optional[AgentFhirConfig] = OMIT,
337
+ request_options: typing.Optional[RequestOptions] = None,
338
+ ) -> HttpResponse[AgentResponse]:
339
+ """
340
+ Updates an existing agent's configuration
341
+
342
+ Parameters
343
+ ----------
344
+ id : str
345
+ Agent ID
346
+
347
+ name : typing.Optional[str]
348
+ Agent name
349
+
350
+ description : typing.Optional[str]
351
+ Agent description
352
+
353
+ prompts : typing.Optional[typing.Sequence[str]]
354
+ Array of prompt IDs to use for this agent
355
+
356
+ is_active : typing.Optional[bool]
357
+ Whether the agent is active
358
+
359
+ tags : typing.Optional[typing.Sequence[str]]
360
+ Tags for categorizing the agent
361
+
362
+ provider : typing.Optional[AgentUpdateRequestProvider]
363
+ FHIR provider type - can be a single provider or array of providers
364
+
365
+ meta : typing.Optional[AgentFhirConfig]
366
+
367
+ request_options : typing.Optional[RequestOptions]
368
+ Request-specific configuration.
369
+
370
+ Returns
371
+ -------
372
+ HttpResponse[AgentResponse]
373
+ Agent updated successfully
374
+ """
375
+ _response = self._client_wrapper.httpx_client.request(
376
+ f"agent/{jsonable_encoder(id)}",
377
+ method="PUT",
378
+ json={
379
+ "name": name,
380
+ "description": description,
381
+ "prompts": prompts,
382
+ "is_active": is_active,
383
+ "tags": tags,
384
+ "provider": convert_and_respect_annotation_metadata(
385
+ object_=provider, annotation=AgentUpdateRequestProvider, direction="write"
386
+ ),
387
+ "meta": convert_and_respect_annotation_metadata(
388
+ object_=meta, annotation=AgentFhirConfig, direction="write"
389
+ ),
390
+ },
391
+ headers={
392
+ "content-type": "application/json",
393
+ },
394
+ request_options=request_options,
395
+ omit=OMIT,
396
+ )
397
+ try:
398
+ if 200 <= _response.status_code < 300:
399
+ _data = typing.cast(
400
+ AgentResponse,
401
+ parse_obj_as(
402
+ type_=AgentResponse, # type: ignore
403
+ object_=_response.json(),
404
+ ),
405
+ )
406
+ return HttpResponse(response=_response, data=_data)
407
+ if _response.status_code == 400:
408
+ raise BadRequestError(
409
+ headers=dict(_response.headers),
410
+ body=typing.cast(
411
+ typing.Optional[typing.Any],
412
+ parse_obj_as(
413
+ type_=typing.Optional[typing.Any], # type: ignore
414
+ object_=_response.json(),
415
+ ),
416
+ ),
417
+ )
418
+ if _response.status_code == 401:
419
+ raise UnauthorizedError(
420
+ headers=dict(_response.headers),
421
+ body=typing.cast(
422
+ typing.Optional[typing.Any],
423
+ parse_obj_as(
424
+ type_=typing.Optional[typing.Any], # type: ignore
425
+ object_=_response.json(),
426
+ ),
427
+ ),
428
+ )
429
+ if _response.status_code == 403:
430
+ raise ForbiddenError(
431
+ headers=dict(_response.headers),
432
+ body=typing.cast(
433
+ typing.Optional[typing.Any],
434
+ parse_obj_as(
435
+ type_=typing.Optional[typing.Any], # type: ignore
436
+ object_=_response.json(),
437
+ ),
438
+ ),
439
+ )
440
+ if _response.status_code == 404:
441
+ raise NotFoundError(
442
+ headers=dict(_response.headers),
443
+ body=typing.cast(
444
+ typing.Optional[typing.Any],
445
+ parse_obj_as(
446
+ type_=typing.Optional[typing.Any], # type: ignore
447
+ object_=_response.json(),
448
+ ),
449
+ ),
450
+ )
451
+ if _response.status_code == 500:
452
+ raise InternalServerError(
453
+ headers=dict(_response.headers),
454
+ body=typing.cast(
455
+ typing.Optional[typing.Any],
456
+ parse_obj_as(
457
+ type_=typing.Optional[typing.Any], # type: ignore
458
+ object_=_response.json(),
459
+ ),
460
+ ),
461
+ )
462
+ _response_json = _response.json()
463
+ except JSONDecodeError:
464
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
465
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
466
+
467
+ def delete(
468
+ self, id: str, *, request_options: typing.Optional[RequestOptions] = None
469
+ ) -> HttpResponse[AgentDeleteResponse]:
470
+ """
471
+ Deletes an existing agent
472
+
473
+ Parameters
474
+ ----------
475
+ id : str
476
+ Agent ID
477
+
478
+ request_options : typing.Optional[RequestOptions]
479
+ Request-specific configuration.
480
+
481
+ Returns
482
+ -------
483
+ HttpResponse[AgentDeleteResponse]
484
+ Agent deleted successfully
485
+ """
486
+ _response = self._client_wrapper.httpx_client.request(
487
+ f"agent/{jsonable_encoder(id)}",
488
+ method="DELETE",
489
+ request_options=request_options,
490
+ )
491
+ try:
492
+ if 200 <= _response.status_code < 300:
493
+ _data = typing.cast(
494
+ AgentDeleteResponse,
495
+ parse_obj_as(
496
+ type_=AgentDeleteResponse, # type: ignore
497
+ object_=_response.json(),
498
+ ),
499
+ )
500
+ return HttpResponse(response=_response, data=_data)
501
+ if _response.status_code == 401:
502
+ raise UnauthorizedError(
503
+ headers=dict(_response.headers),
504
+ body=typing.cast(
505
+ typing.Optional[typing.Any],
506
+ parse_obj_as(
507
+ type_=typing.Optional[typing.Any], # type: ignore
508
+ object_=_response.json(),
509
+ ),
510
+ ),
511
+ )
512
+ if _response.status_code == 403:
513
+ raise ForbiddenError(
514
+ headers=dict(_response.headers),
515
+ body=typing.cast(
516
+ typing.Optional[typing.Any],
517
+ parse_obj_as(
518
+ type_=typing.Optional[typing.Any], # type: ignore
519
+ object_=_response.json(),
520
+ ),
521
+ ),
522
+ )
523
+ if _response.status_code == 404:
524
+ raise NotFoundError(
525
+ headers=dict(_response.headers),
526
+ body=typing.cast(
527
+ typing.Optional[typing.Any],
528
+ parse_obj_as(
529
+ type_=typing.Optional[typing.Any], # type: ignore
530
+ object_=_response.json(),
531
+ ),
532
+ ),
533
+ )
534
+ if _response.status_code == 500:
535
+ raise InternalServerError(
536
+ headers=dict(_response.headers),
537
+ body=typing.cast(
538
+ typing.Optional[typing.Any],
539
+ parse_obj_as(
540
+ type_=typing.Optional[typing.Any], # type: ignore
541
+ object_=_response.json(),
542
+ ),
543
+ ),
544
+ )
545
+ _response_json = _response.json()
546
+ except JSONDecodeError:
547
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
548
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
549
+
550
+ def patch(
551
+ self, id: str, *, request: JsonPatch, request_options: typing.Optional[RequestOptions] = None
552
+ ) -> HttpResponse[AgentResponse]:
553
+ """
554
+ Patches an existing agent's configuration
555
+
556
+ Parameters
557
+ ----------
558
+ id : str
559
+ Agent ID
560
+
561
+ request : JsonPatch
562
+
563
+ request_options : typing.Optional[RequestOptions]
564
+ Request-specific configuration.
565
+
566
+ Returns
567
+ -------
568
+ HttpResponse[AgentResponse]
569
+ Agent patched successfully
570
+ """
571
+ _response = self._client_wrapper.httpx_client.request(
572
+ f"agent/{jsonable_encoder(id)}",
573
+ method="PATCH",
574
+ json=convert_and_respect_annotation_metadata(object_=request, annotation=JsonPatch, direction="write"),
575
+ headers={
576
+ "content-type": "application/json+patch",
577
+ },
578
+ request_options=request_options,
579
+ omit=OMIT,
580
+ )
581
+ try:
582
+ if 200 <= _response.status_code < 300:
583
+ _data = typing.cast(
584
+ AgentResponse,
585
+ parse_obj_as(
586
+ type_=AgentResponse, # type: ignore
587
+ object_=_response.json(),
588
+ ),
589
+ )
590
+ return HttpResponse(response=_response, data=_data)
591
+ if _response.status_code == 400:
592
+ raise BadRequestError(
593
+ headers=dict(_response.headers),
594
+ body=typing.cast(
595
+ typing.Optional[typing.Any],
596
+ parse_obj_as(
597
+ type_=typing.Optional[typing.Any], # type: ignore
598
+ object_=_response.json(),
599
+ ),
600
+ ),
601
+ )
602
+ if _response.status_code == 401:
603
+ raise UnauthorizedError(
604
+ headers=dict(_response.headers),
605
+ body=typing.cast(
606
+ typing.Optional[typing.Any],
607
+ parse_obj_as(
608
+ type_=typing.Optional[typing.Any], # type: ignore
609
+ object_=_response.json(),
610
+ ),
611
+ ),
612
+ )
613
+ if _response.status_code == 403:
614
+ raise ForbiddenError(
615
+ headers=dict(_response.headers),
616
+ body=typing.cast(
617
+ typing.Optional[typing.Any],
618
+ parse_obj_as(
619
+ type_=typing.Optional[typing.Any], # type: ignore
620
+ object_=_response.json(),
621
+ ),
622
+ ),
623
+ )
624
+ if _response.status_code == 404:
625
+ raise NotFoundError(
626
+ headers=dict(_response.headers),
627
+ body=typing.cast(
628
+ typing.Optional[typing.Any],
629
+ parse_obj_as(
630
+ type_=typing.Optional[typing.Any], # type: ignore
631
+ object_=_response.json(),
632
+ ),
633
+ ),
634
+ )
635
+ if _response.status_code == 500:
636
+ raise InternalServerError(
637
+ headers=dict(_response.headers),
638
+ body=typing.cast(
639
+ typing.Optional[typing.Any],
640
+ parse_obj_as(
641
+ type_=typing.Optional[typing.Any], # type: ignore
642
+ object_=_response.json(),
643
+ ),
644
+ ),
645
+ )
646
+ _response_json = _response.json()
647
+ except JSONDecodeError:
648
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
649
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
650
+
651
+ def chat(
652
+ self,
653
+ *,
654
+ message: str,
655
+ agent_id: str,
656
+ context: typing.Optional[str] = OMIT,
657
+ session_id: typing.Optional[str] = OMIT,
658
+ meta: typing.Optional[ChatFhirClientConfig] = OMIT,
659
+ request_options: typing.Optional[RequestOptions] = None,
660
+ ) -> HttpResponse[AgentChatResponse]:
661
+ """
662
+ Send a message to an agent and receive a response
663
+
664
+ Parameters
665
+ ----------
666
+ message : str
667
+ The message to send to the agent
668
+
669
+ agent_id : str
670
+ The ID of the agent to chat with
671
+
672
+ context : typing.Optional[str]
673
+ Optional context for the conversation
674
+
675
+ session_id : typing.Optional[str]
676
+ Optional session ID for conversation continuity
677
+
678
+ meta : typing.Optional[ChatFhirClientConfig]
679
+ Optional user-specific FHIR configuration overrides
680
+
681
+ request_options : typing.Optional[RequestOptions]
682
+ Request-specific configuration.
683
+
684
+ Returns
685
+ -------
686
+ HttpResponse[AgentChatResponse]
687
+ Chat response received successfully
688
+ """
689
+ _response = self._client_wrapper.httpx_client.request(
690
+ "agent/chat",
691
+ method="POST",
692
+ json={
693
+ "message": message,
694
+ "context": context,
695
+ "session_id": session_id,
696
+ "agent_id": agent_id,
697
+ "meta": convert_and_respect_annotation_metadata(
698
+ object_=meta, annotation=ChatFhirClientConfig, direction="write"
699
+ ),
700
+ },
701
+ headers={
702
+ "content-type": "application/json",
703
+ },
704
+ request_options=request_options,
705
+ omit=OMIT,
706
+ )
707
+ try:
708
+ if 200 <= _response.status_code < 300:
709
+ _data = typing.cast(
710
+ AgentChatResponse,
711
+ parse_obj_as(
712
+ type_=AgentChatResponse, # type: ignore
713
+ object_=_response.json(),
714
+ ),
715
+ )
716
+ return HttpResponse(response=_response, data=_data)
717
+ if _response.status_code == 400:
718
+ raise BadRequestError(
719
+ headers=dict(_response.headers),
720
+ body=typing.cast(
721
+ typing.Optional[typing.Any],
722
+ parse_obj_as(
723
+ type_=typing.Optional[typing.Any], # type: ignore
724
+ object_=_response.json(),
725
+ ),
726
+ ),
727
+ )
728
+ if _response.status_code == 401:
729
+ raise UnauthorizedError(
730
+ headers=dict(_response.headers),
731
+ body=typing.cast(
732
+ typing.Optional[typing.Any],
733
+ parse_obj_as(
734
+ type_=typing.Optional[typing.Any], # type: ignore
735
+ object_=_response.json(),
736
+ ),
737
+ ),
738
+ )
739
+ if _response.status_code == 403:
740
+ raise ForbiddenError(
741
+ headers=dict(_response.headers),
742
+ body=typing.cast(
743
+ typing.Optional[typing.Any],
744
+ parse_obj_as(
745
+ type_=typing.Optional[typing.Any], # type: ignore
746
+ object_=_response.json(),
747
+ ),
748
+ ),
749
+ )
750
+ if _response.status_code == 500:
751
+ raise InternalServerError(
752
+ headers=dict(_response.headers),
753
+ body=typing.cast(
754
+ typing.Optional[typing.Any],
755
+ parse_obj_as(
756
+ type_=typing.Optional[typing.Any], # type: ignore
757
+ object_=_response.json(),
758
+ ),
759
+ ),
760
+ )
761
+ _response_json = _response.json()
762
+ except JSONDecodeError:
763
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
764
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
765
+
766
+
767
+ class AsyncRawAgentClient:
768
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
769
+ self._client_wrapper = client_wrapper
770
+
771
+ async def create(
772
+ self,
773
+ *,
774
+ name: str,
775
+ prompts: typing.Sequence[str],
776
+ is_active: bool,
777
+ description: typing.Optional[str] = OMIT,
778
+ tags: typing.Optional[typing.Sequence[str]] = OMIT,
779
+ provider: typing.Optional[AgentCreateRequestProvider] = OMIT,
780
+ meta: typing.Optional[AgentFhirConfig] = OMIT,
781
+ request_options: typing.Optional[RequestOptions] = None,
782
+ ) -> AsyncHttpResponse[AgentResponse]:
783
+ """
784
+ Creates a new PhenoAgent with specified configuration
785
+
786
+ Parameters
787
+ ----------
788
+ name : str
789
+ Agent name
790
+
791
+ prompts : typing.Sequence[str]
792
+ Array of prompt IDs to use for this agent
793
+
794
+ is_active : bool
795
+ Whether the agent is active
796
+
797
+ description : typing.Optional[str]
798
+ Agent description
799
+
800
+ tags : typing.Optional[typing.Sequence[str]]
801
+ Tags for categorizing the agent
802
+
803
+ provider : typing.Optional[AgentCreateRequestProvider]
804
+ FHIR provider type - can be a single provider or array of providers
805
+
806
+ meta : typing.Optional[AgentFhirConfig]
807
+
808
+ request_options : typing.Optional[RequestOptions]
809
+ Request-specific configuration.
810
+
811
+ Returns
812
+ -------
813
+ AsyncHttpResponse[AgentResponse]
814
+ Agent created successfully
815
+ """
816
+ _response = await self._client_wrapper.httpx_client.request(
817
+ "agent/create",
818
+ method="POST",
819
+ json={
820
+ "name": name,
821
+ "description": description,
822
+ "prompts": prompts,
823
+ "is_active": is_active,
824
+ "tags": tags,
825
+ "provider": convert_and_respect_annotation_metadata(
826
+ object_=provider, annotation=AgentCreateRequestProvider, direction="write"
827
+ ),
828
+ "meta": convert_and_respect_annotation_metadata(
829
+ object_=meta, annotation=AgentFhirConfig, direction="write"
830
+ ),
831
+ },
832
+ headers={
833
+ "content-type": "application/json",
834
+ },
835
+ request_options=request_options,
836
+ omit=OMIT,
837
+ )
838
+ try:
839
+ if 200 <= _response.status_code < 300:
840
+ _data = typing.cast(
841
+ AgentResponse,
842
+ parse_obj_as(
843
+ type_=AgentResponse, # type: ignore
844
+ object_=_response.json(),
845
+ ),
846
+ )
847
+ return AsyncHttpResponse(response=_response, data=_data)
848
+ if _response.status_code == 400:
849
+ raise BadRequestError(
850
+ headers=dict(_response.headers),
851
+ body=typing.cast(
852
+ typing.Optional[typing.Any],
853
+ parse_obj_as(
854
+ type_=typing.Optional[typing.Any], # type: ignore
855
+ object_=_response.json(),
856
+ ),
857
+ ),
858
+ )
859
+ if _response.status_code == 401:
860
+ raise UnauthorizedError(
861
+ headers=dict(_response.headers),
862
+ body=typing.cast(
863
+ typing.Optional[typing.Any],
864
+ parse_obj_as(
865
+ type_=typing.Optional[typing.Any], # type: ignore
866
+ object_=_response.json(),
867
+ ),
868
+ ),
869
+ )
870
+ if _response.status_code == 403:
871
+ raise ForbiddenError(
872
+ headers=dict(_response.headers),
873
+ body=typing.cast(
874
+ typing.Optional[typing.Any],
875
+ parse_obj_as(
876
+ type_=typing.Optional[typing.Any], # type: ignore
877
+ object_=_response.json(),
878
+ ),
879
+ ),
880
+ )
881
+ if _response.status_code == 500:
882
+ raise InternalServerError(
883
+ headers=dict(_response.headers),
884
+ body=typing.cast(
885
+ typing.Optional[typing.Any],
886
+ parse_obj_as(
887
+ type_=typing.Optional[typing.Any], # type: ignore
888
+ object_=_response.json(),
889
+ ),
890
+ ),
891
+ )
892
+ _response_json = _response.json()
893
+ except JSONDecodeError:
894
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
895
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
896
+
897
+ async def list(
898
+ self,
899
+ *,
900
+ is_active: typing.Optional[bool] = None,
901
+ tags: typing.Optional[str] = None,
902
+ request_options: typing.Optional[RequestOptions] = None,
903
+ ) -> AsyncHttpResponse[AgentListResponse]:
904
+ """
905
+ Retrieves a list of PhenoAgents belonging to the authenticated user
906
+
907
+ Parameters
908
+ ----------
909
+ is_active : typing.Optional[bool]
910
+ Filter by active status
911
+
912
+ tags : typing.Optional[str]
913
+ Filter by tags
914
+
915
+ request_options : typing.Optional[RequestOptions]
916
+ Request-specific configuration.
917
+
918
+ Returns
919
+ -------
920
+ AsyncHttpResponse[AgentListResponse]
921
+ Agents retrieved successfully
922
+ """
923
+ _response = await self._client_wrapper.httpx_client.request(
924
+ "agent/list",
925
+ method="GET",
926
+ params={
927
+ "is_active": is_active,
928
+ "tags": tags,
929
+ },
930
+ request_options=request_options,
931
+ )
932
+ try:
933
+ if 200 <= _response.status_code < 300:
934
+ _data = typing.cast(
935
+ AgentListResponse,
936
+ parse_obj_as(
937
+ type_=AgentListResponse, # type: ignore
938
+ object_=_response.json(),
939
+ ),
940
+ )
941
+ return AsyncHttpResponse(response=_response, data=_data)
942
+ if _response.status_code == 401:
943
+ raise UnauthorizedError(
944
+ headers=dict(_response.headers),
945
+ body=typing.cast(
946
+ typing.Optional[typing.Any],
947
+ parse_obj_as(
948
+ type_=typing.Optional[typing.Any], # type: ignore
949
+ object_=_response.json(),
950
+ ),
951
+ ),
952
+ )
953
+ if _response.status_code == 403:
954
+ raise ForbiddenError(
955
+ headers=dict(_response.headers),
956
+ body=typing.cast(
957
+ typing.Optional[typing.Any],
958
+ parse_obj_as(
959
+ type_=typing.Optional[typing.Any], # type: ignore
960
+ object_=_response.json(),
961
+ ),
962
+ ),
963
+ )
964
+ if _response.status_code == 500:
965
+ raise InternalServerError(
966
+ headers=dict(_response.headers),
967
+ body=typing.cast(
968
+ typing.Optional[typing.Any],
969
+ parse_obj_as(
970
+ type_=typing.Optional[typing.Any], # type: ignore
971
+ object_=_response.json(),
972
+ ),
973
+ ),
974
+ )
975
+ _response_json = _response.json()
976
+ except JSONDecodeError:
977
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
978
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
979
+
980
+ async def get(
981
+ self, id: str, *, request_options: typing.Optional[RequestOptions] = None
982
+ ) -> AsyncHttpResponse[AgentResponse]:
983
+ """
984
+ Retrieves a specific agent by its ID
985
+
986
+ Parameters
987
+ ----------
988
+ id : str
989
+ Agent ID
990
+
991
+ request_options : typing.Optional[RequestOptions]
992
+ Request-specific configuration.
993
+
994
+ Returns
995
+ -------
996
+ AsyncHttpResponse[AgentResponse]
997
+ Agent retrieved successfully
998
+ """
999
+ _response = await self._client_wrapper.httpx_client.request(
1000
+ f"agent/{jsonable_encoder(id)}",
1001
+ method="GET",
1002
+ request_options=request_options,
1003
+ )
1004
+ try:
1005
+ if 200 <= _response.status_code < 300:
1006
+ _data = typing.cast(
1007
+ AgentResponse,
1008
+ parse_obj_as(
1009
+ type_=AgentResponse, # type: ignore
1010
+ object_=_response.json(),
1011
+ ),
1012
+ )
1013
+ return AsyncHttpResponse(response=_response, data=_data)
1014
+ if _response.status_code == 401:
1015
+ raise UnauthorizedError(
1016
+ headers=dict(_response.headers),
1017
+ body=typing.cast(
1018
+ typing.Optional[typing.Any],
1019
+ parse_obj_as(
1020
+ type_=typing.Optional[typing.Any], # type: ignore
1021
+ object_=_response.json(),
1022
+ ),
1023
+ ),
1024
+ )
1025
+ if _response.status_code == 403:
1026
+ raise ForbiddenError(
1027
+ headers=dict(_response.headers),
1028
+ body=typing.cast(
1029
+ typing.Optional[typing.Any],
1030
+ parse_obj_as(
1031
+ type_=typing.Optional[typing.Any], # type: ignore
1032
+ object_=_response.json(),
1033
+ ),
1034
+ ),
1035
+ )
1036
+ if _response.status_code == 404:
1037
+ raise NotFoundError(
1038
+ headers=dict(_response.headers),
1039
+ body=typing.cast(
1040
+ typing.Optional[typing.Any],
1041
+ parse_obj_as(
1042
+ type_=typing.Optional[typing.Any], # type: ignore
1043
+ object_=_response.json(),
1044
+ ),
1045
+ ),
1046
+ )
1047
+ if _response.status_code == 500:
1048
+ raise InternalServerError(
1049
+ headers=dict(_response.headers),
1050
+ body=typing.cast(
1051
+ typing.Optional[typing.Any],
1052
+ parse_obj_as(
1053
+ type_=typing.Optional[typing.Any], # type: ignore
1054
+ object_=_response.json(),
1055
+ ),
1056
+ ),
1057
+ )
1058
+ _response_json = _response.json()
1059
+ except JSONDecodeError:
1060
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1061
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1062
+
1063
+ async def update(
1064
+ self,
1065
+ id: str,
1066
+ *,
1067
+ name: typing.Optional[str] = OMIT,
1068
+ description: typing.Optional[str] = OMIT,
1069
+ prompts: typing.Optional[typing.Sequence[str]] = OMIT,
1070
+ is_active: typing.Optional[bool] = OMIT,
1071
+ tags: typing.Optional[typing.Sequence[str]] = OMIT,
1072
+ provider: typing.Optional[AgentUpdateRequestProvider] = OMIT,
1073
+ meta: typing.Optional[AgentFhirConfig] = OMIT,
1074
+ request_options: typing.Optional[RequestOptions] = None,
1075
+ ) -> AsyncHttpResponse[AgentResponse]:
1076
+ """
1077
+ Updates an existing agent's configuration
1078
+
1079
+ Parameters
1080
+ ----------
1081
+ id : str
1082
+ Agent ID
1083
+
1084
+ name : typing.Optional[str]
1085
+ Agent name
1086
+
1087
+ description : typing.Optional[str]
1088
+ Agent description
1089
+
1090
+ prompts : typing.Optional[typing.Sequence[str]]
1091
+ Array of prompt IDs to use for this agent
1092
+
1093
+ is_active : typing.Optional[bool]
1094
+ Whether the agent is active
1095
+
1096
+ tags : typing.Optional[typing.Sequence[str]]
1097
+ Tags for categorizing the agent
1098
+
1099
+ provider : typing.Optional[AgentUpdateRequestProvider]
1100
+ FHIR provider type - can be a single provider or array of providers
1101
+
1102
+ meta : typing.Optional[AgentFhirConfig]
1103
+
1104
+ request_options : typing.Optional[RequestOptions]
1105
+ Request-specific configuration.
1106
+
1107
+ Returns
1108
+ -------
1109
+ AsyncHttpResponse[AgentResponse]
1110
+ Agent updated successfully
1111
+ """
1112
+ _response = await self._client_wrapper.httpx_client.request(
1113
+ f"agent/{jsonable_encoder(id)}",
1114
+ method="PUT",
1115
+ json={
1116
+ "name": name,
1117
+ "description": description,
1118
+ "prompts": prompts,
1119
+ "is_active": is_active,
1120
+ "tags": tags,
1121
+ "provider": convert_and_respect_annotation_metadata(
1122
+ object_=provider, annotation=AgentUpdateRequestProvider, direction="write"
1123
+ ),
1124
+ "meta": convert_and_respect_annotation_metadata(
1125
+ object_=meta, annotation=AgentFhirConfig, direction="write"
1126
+ ),
1127
+ },
1128
+ headers={
1129
+ "content-type": "application/json",
1130
+ },
1131
+ request_options=request_options,
1132
+ omit=OMIT,
1133
+ )
1134
+ try:
1135
+ if 200 <= _response.status_code < 300:
1136
+ _data = typing.cast(
1137
+ AgentResponse,
1138
+ parse_obj_as(
1139
+ type_=AgentResponse, # type: ignore
1140
+ object_=_response.json(),
1141
+ ),
1142
+ )
1143
+ return AsyncHttpResponse(response=_response, data=_data)
1144
+ if _response.status_code == 400:
1145
+ raise BadRequestError(
1146
+ headers=dict(_response.headers),
1147
+ body=typing.cast(
1148
+ typing.Optional[typing.Any],
1149
+ parse_obj_as(
1150
+ type_=typing.Optional[typing.Any], # type: ignore
1151
+ object_=_response.json(),
1152
+ ),
1153
+ ),
1154
+ )
1155
+ if _response.status_code == 401:
1156
+ raise UnauthorizedError(
1157
+ headers=dict(_response.headers),
1158
+ body=typing.cast(
1159
+ typing.Optional[typing.Any],
1160
+ parse_obj_as(
1161
+ type_=typing.Optional[typing.Any], # type: ignore
1162
+ object_=_response.json(),
1163
+ ),
1164
+ ),
1165
+ )
1166
+ if _response.status_code == 403:
1167
+ raise ForbiddenError(
1168
+ headers=dict(_response.headers),
1169
+ body=typing.cast(
1170
+ typing.Optional[typing.Any],
1171
+ parse_obj_as(
1172
+ type_=typing.Optional[typing.Any], # type: ignore
1173
+ object_=_response.json(),
1174
+ ),
1175
+ ),
1176
+ )
1177
+ if _response.status_code == 404:
1178
+ raise NotFoundError(
1179
+ headers=dict(_response.headers),
1180
+ body=typing.cast(
1181
+ typing.Optional[typing.Any],
1182
+ parse_obj_as(
1183
+ type_=typing.Optional[typing.Any], # type: ignore
1184
+ object_=_response.json(),
1185
+ ),
1186
+ ),
1187
+ )
1188
+ if _response.status_code == 500:
1189
+ raise InternalServerError(
1190
+ headers=dict(_response.headers),
1191
+ body=typing.cast(
1192
+ typing.Optional[typing.Any],
1193
+ parse_obj_as(
1194
+ type_=typing.Optional[typing.Any], # type: ignore
1195
+ object_=_response.json(),
1196
+ ),
1197
+ ),
1198
+ )
1199
+ _response_json = _response.json()
1200
+ except JSONDecodeError:
1201
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1202
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1203
+
1204
+ async def delete(
1205
+ self, id: str, *, request_options: typing.Optional[RequestOptions] = None
1206
+ ) -> AsyncHttpResponse[AgentDeleteResponse]:
1207
+ """
1208
+ Deletes an existing agent
1209
+
1210
+ Parameters
1211
+ ----------
1212
+ id : str
1213
+ Agent ID
1214
+
1215
+ request_options : typing.Optional[RequestOptions]
1216
+ Request-specific configuration.
1217
+
1218
+ Returns
1219
+ -------
1220
+ AsyncHttpResponse[AgentDeleteResponse]
1221
+ Agent deleted successfully
1222
+ """
1223
+ _response = await self._client_wrapper.httpx_client.request(
1224
+ f"agent/{jsonable_encoder(id)}",
1225
+ method="DELETE",
1226
+ request_options=request_options,
1227
+ )
1228
+ try:
1229
+ if 200 <= _response.status_code < 300:
1230
+ _data = typing.cast(
1231
+ AgentDeleteResponse,
1232
+ parse_obj_as(
1233
+ type_=AgentDeleteResponse, # type: ignore
1234
+ object_=_response.json(),
1235
+ ),
1236
+ )
1237
+ return AsyncHttpResponse(response=_response, data=_data)
1238
+ if _response.status_code == 401:
1239
+ raise UnauthorizedError(
1240
+ headers=dict(_response.headers),
1241
+ body=typing.cast(
1242
+ typing.Optional[typing.Any],
1243
+ parse_obj_as(
1244
+ type_=typing.Optional[typing.Any], # type: ignore
1245
+ object_=_response.json(),
1246
+ ),
1247
+ ),
1248
+ )
1249
+ if _response.status_code == 403:
1250
+ raise ForbiddenError(
1251
+ headers=dict(_response.headers),
1252
+ body=typing.cast(
1253
+ typing.Optional[typing.Any],
1254
+ parse_obj_as(
1255
+ type_=typing.Optional[typing.Any], # type: ignore
1256
+ object_=_response.json(),
1257
+ ),
1258
+ ),
1259
+ )
1260
+ if _response.status_code == 404:
1261
+ raise NotFoundError(
1262
+ headers=dict(_response.headers),
1263
+ body=typing.cast(
1264
+ typing.Optional[typing.Any],
1265
+ parse_obj_as(
1266
+ type_=typing.Optional[typing.Any], # type: ignore
1267
+ object_=_response.json(),
1268
+ ),
1269
+ ),
1270
+ )
1271
+ if _response.status_code == 500:
1272
+ raise InternalServerError(
1273
+ headers=dict(_response.headers),
1274
+ body=typing.cast(
1275
+ typing.Optional[typing.Any],
1276
+ parse_obj_as(
1277
+ type_=typing.Optional[typing.Any], # type: ignore
1278
+ object_=_response.json(),
1279
+ ),
1280
+ ),
1281
+ )
1282
+ _response_json = _response.json()
1283
+ except JSONDecodeError:
1284
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1285
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1286
+
1287
+ async def patch(
1288
+ self, id: str, *, request: JsonPatch, request_options: typing.Optional[RequestOptions] = None
1289
+ ) -> AsyncHttpResponse[AgentResponse]:
1290
+ """
1291
+ Patches an existing agent's configuration
1292
+
1293
+ Parameters
1294
+ ----------
1295
+ id : str
1296
+ Agent ID
1297
+
1298
+ request : JsonPatch
1299
+
1300
+ request_options : typing.Optional[RequestOptions]
1301
+ Request-specific configuration.
1302
+
1303
+ Returns
1304
+ -------
1305
+ AsyncHttpResponse[AgentResponse]
1306
+ Agent patched successfully
1307
+ """
1308
+ _response = await self._client_wrapper.httpx_client.request(
1309
+ f"agent/{jsonable_encoder(id)}",
1310
+ method="PATCH",
1311
+ json=convert_and_respect_annotation_metadata(object_=request, annotation=JsonPatch, direction="write"),
1312
+ headers={
1313
+ "content-type": "application/json+patch",
1314
+ },
1315
+ request_options=request_options,
1316
+ omit=OMIT,
1317
+ )
1318
+ try:
1319
+ if 200 <= _response.status_code < 300:
1320
+ _data = typing.cast(
1321
+ AgentResponse,
1322
+ parse_obj_as(
1323
+ type_=AgentResponse, # type: ignore
1324
+ object_=_response.json(),
1325
+ ),
1326
+ )
1327
+ return AsyncHttpResponse(response=_response, data=_data)
1328
+ if _response.status_code == 400:
1329
+ raise BadRequestError(
1330
+ headers=dict(_response.headers),
1331
+ body=typing.cast(
1332
+ typing.Optional[typing.Any],
1333
+ parse_obj_as(
1334
+ type_=typing.Optional[typing.Any], # type: ignore
1335
+ object_=_response.json(),
1336
+ ),
1337
+ ),
1338
+ )
1339
+ if _response.status_code == 401:
1340
+ raise UnauthorizedError(
1341
+ headers=dict(_response.headers),
1342
+ body=typing.cast(
1343
+ typing.Optional[typing.Any],
1344
+ parse_obj_as(
1345
+ type_=typing.Optional[typing.Any], # type: ignore
1346
+ object_=_response.json(),
1347
+ ),
1348
+ ),
1349
+ )
1350
+ if _response.status_code == 403:
1351
+ raise ForbiddenError(
1352
+ headers=dict(_response.headers),
1353
+ body=typing.cast(
1354
+ typing.Optional[typing.Any],
1355
+ parse_obj_as(
1356
+ type_=typing.Optional[typing.Any], # type: ignore
1357
+ object_=_response.json(),
1358
+ ),
1359
+ ),
1360
+ )
1361
+ if _response.status_code == 404:
1362
+ raise NotFoundError(
1363
+ headers=dict(_response.headers),
1364
+ body=typing.cast(
1365
+ typing.Optional[typing.Any],
1366
+ parse_obj_as(
1367
+ type_=typing.Optional[typing.Any], # type: ignore
1368
+ object_=_response.json(),
1369
+ ),
1370
+ ),
1371
+ )
1372
+ if _response.status_code == 500:
1373
+ raise InternalServerError(
1374
+ headers=dict(_response.headers),
1375
+ body=typing.cast(
1376
+ typing.Optional[typing.Any],
1377
+ parse_obj_as(
1378
+ type_=typing.Optional[typing.Any], # type: ignore
1379
+ object_=_response.json(),
1380
+ ),
1381
+ ),
1382
+ )
1383
+ _response_json = _response.json()
1384
+ except JSONDecodeError:
1385
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1386
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1387
+
1388
+ async def chat(
1389
+ self,
1390
+ *,
1391
+ message: str,
1392
+ agent_id: str,
1393
+ context: typing.Optional[str] = OMIT,
1394
+ session_id: typing.Optional[str] = OMIT,
1395
+ meta: typing.Optional[ChatFhirClientConfig] = OMIT,
1396
+ request_options: typing.Optional[RequestOptions] = None,
1397
+ ) -> AsyncHttpResponse[AgentChatResponse]:
1398
+ """
1399
+ Send a message to an agent and receive a response
1400
+
1401
+ Parameters
1402
+ ----------
1403
+ message : str
1404
+ The message to send to the agent
1405
+
1406
+ agent_id : str
1407
+ The ID of the agent to chat with
1408
+
1409
+ context : typing.Optional[str]
1410
+ Optional context for the conversation
1411
+
1412
+ session_id : typing.Optional[str]
1413
+ Optional session ID for conversation continuity
1414
+
1415
+ meta : typing.Optional[ChatFhirClientConfig]
1416
+ Optional user-specific FHIR configuration overrides
1417
+
1418
+ request_options : typing.Optional[RequestOptions]
1419
+ Request-specific configuration.
1420
+
1421
+ Returns
1422
+ -------
1423
+ AsyncHttpResponse[AgentChatResponse]
1424
+ Chat response received successfully
1425
+ """
1426
+ _response = await self._client_wrapper.httpx_client.request(
1427
+ "agent/chat",
1428
+ method="POST",
1429
+ json={
1430
+ "message": message,
1431
+ "context": context,
1432
+ "session_id": session_id,
1433
+ "agent_id": agent_id,
1434
+ "meta": convert_and_respect_annotation_metadata(
1435
+ object_=meta, annotation=ChatFhirClientConfig, direction="write"
1436
+ ),
1437
+ },
1438
+ headers={
1439
+ "content-type": "application/json",
1440
+ },
1441
+ request_options=request_options,
1442
+ omit=OMIT,
1443
+ )
1444
+ try:
1445
+ if 200 <= _response.status_code < 300:
1446
+ _data = typing.cast(
1447
+ AgentChatResponse,
1448
+ parse_obj_as(
1449
+ type_=AgentChatResponse, # type: ignore
1450
+ object_=_response.json(),
1451
+ ),
1452
+ )
1453
+ return AsyncHttpResponse(response=_response, data=_data)
1454
+ if _response.status_code == 400:
1455
+ raise BadRequestError(
1456
+ headers=dict(_response.headers),
1457
+ body=typing.cast(
1458
+ typing.Optional[typing.Any],
1459
+ parse_obj_as(
1460
+ type_=typing.Optional[typing.Any], # type: ignore
1461
+ object_=_response.json(),
1462
+ ),
1463
+ ),
1464
+ )
1465
+ if _response.status_code == 401:
1466
+ raise UnauthorizedError(
1467
+ headers=dict(_response.headers),
1468
+ body=typing.cast(
1469
+ typing.Optional[typing.Any],
1470
+ parse_obj_as(
1471
+ type_=typing.Optional[typing.Any], # type: ignore
1472
+ object_=_response.json(),
1473
+ ),
1474
+ ),
1475
+ )
1476
+ if _response.status_code == 403:
1477
+ raise ForbiddenError(
1478
+ headers=dict(_response.headers),
1479
+ body=typing.cast(
1480
+ typing.Optional[typing.Any],
1481
+ parse_obj_as(
1482
+ type_=typing.Optional[typing.Any], # type: ignore
1483
+ object_=_response.json(),
1484
+ ),
1485
+ ),
1486
+ )
1487
+ if _response.status_code == 500:
1488
+ raise InternalServerError(
1489
+ headers=dict(_response.headers),
1490
+ body=typing.cast(
1491
+ typing.Optional[typing.Any],
1492
+ parse_obj_as(
1493
+ type_=typing.Optional[typing.Any], # type: ignore
1494
+ object_=_response.json(),
1495
+ ),
1496
+ ),
1497
+ )
1498
+ _response_json = _response.json()
1499
+ except JSONDecodeError:
1500
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1501
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)