mirror of
https://github.com/anomalyco/opencode-sdk-python.git
synced 2026-05-17 12:42:25 +00:00
chore(internal): codegen related update
This commit is contained in:
parent
14d6c2e4a9
commit
5d19369b82
5 changed files with 344 additions and 16 deletions
|
|
@ -9,6 +9,7 @@ import asyncio
|
|||
import inspect
|
||||
import logging
|
||||
import platform
|
||||
import warnings
|
||||
import email.utils
|
||||
from types import TracebackType
|
||||
from random import random
|
||||
|
|
@ -51,9 +52,11 @@ from ._types import (
|
|||
ResponseT,
|
||||
AnyMapping,
|
||||
PostParser,
|
||||
BinaryTypes,
|
||||
RequestFiles,
|
||||
HttpxSendArgs,
|
||||
RequestOptions,
|
||||
AsyncBinaryTypes,
|
||||
HttpxRequestFiles,
|
||||
ModelBuilderProtocol,
|
||||
not_given,
|
||||
|
|
@ -477,8 +480,19 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
|||
retries_taken: int = 0,
|
||||
) -> httpx.Request:
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
log.debug("Request options: %s", model_dump(options, exclude_unset=True))
|
||||
|
||||
log.debug(
|
||||
"Request options: %s",
|
||||
model_dump(
|
||||
options,
|
||||
exclude_unset=True,
|
||||
# Pydantic v1 can't dump every type we support in content, so we exclude it for now.
|
||||
exclude={
|
||||
"content",
|
||||
}
|
||||
if PYDANTIC_V1
|
||||
else {},
|
||||
),
|
||||
)
|
||||
kwargs: dict[str, Any] = {}
|
||||
|
||||
json_data = options.json_data
|
||||
|
|
@ -532,7 +546,13 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
|||
is_body_allowed = options.method.lower() != "get"
|
||||
|
||||
if is_body_allowed:
|
||||
if isinstance(json_data, bytes):
|
||||
if options.content is not None and json_data is not None:
|
||||
raise TypeError("Passing both `content` and `json_data` is not supported")
|
||||
if options.content is not None and files is not None:
|
||||
raise TypeError("Passing both `content` and `files` is not supported")
|
||||
if options.content is not None:
|
||||
kwargs["content"] = options.content
|
||||
elif isinstance(json_data, bytes):
|
||||
kwargs["content"] = json_data
|
||||
else:
|
||||
kwargs["json"] = json_data if is_given(json_data) else None
|
||||
|
|
@ -1194,6 +1214,7 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: BinaryTypes | None = None,
|
||||
options: RequestOptions = {},
|
||||
files: RequestFiles | None = None,
|
||||
stream: Literal[False] = False,
|
||||
|
|
@ -1206,6 +1227,7 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: BinaryTypes | None = None,
|
||||
options: RequestOptions = {},
|
||||
files: RequestFiles | None = None,
|
||||
stream: Literal[True],
|
||||
|
|
@ -1219,6 +1241,7 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: BinaryTypes | None = None,
|
||||
options: RequestOptions = {},
|
||||
files: RequestFiles | None = None,
|
||||
stream: bool,
|
||||
|
|
@ -1231,13 +1254,25 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: BinaryTypes | None = None,
|
||||
options: RequestOptions = {},
|
||||
files: RequestFiles | None = None,
|
||||
stream: bool = False,
|
||||
stream_cls: type[_StreamT] | None = None,
|
||||
) -> ResponseT | _StreamT:
|
||||
if body is not None and content is not None:
|
||||
raise TypeError("Passing both `body` and `content` is not supported")
|
||||
if files is not None and content is not None:
|
||||
raise TypeError("Passing both `files` and `content` is not supported")
|
||||
if isinstance(body, bytes):
|
||||
warnings.warn(
|
||||
"Passing raw bytes as `body` is deprecated and will be removed in a future version. "
|
||||
"Please pass raw bytes via the `content` parameter instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
opts = FinalRequestOptions.construct(
|
||||
method="post", url=path, json_data=body, files=to_httpx_files(files), **options
|
||||
method="post", url=path, json_data=body, content=content, files=to_httpx_files(files), **options
|
||||
)
|
||||
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
|
||||
|
||||
|
|
@ -1247,11 +1282,23 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: BinaryTypes | None = None,
|
||||
files: RequestFiles | None = None,
|
||||
options: RequestOptions = {},
|
||||
) -> ResponseT:
|
||||
if body is not None and content is not None:
|
||||
raise TypeError("Passing both `body` and `content` is not supported")
|
||||
if files is not None and content is not None:
|
||||
raise TypeError("Passing both `files` and `content` is not supported")
|
||||
if isinstance(body, bytes):
|
||||
warnings.warn(
|
||||
"Passing raw bytes as `body` is deprecated and will be removed in a future version. "
|
||||
"Please pass raw bytes via the `content` parameter instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
opts = FinalRequestOptions.construct(
|
||||
method="patch", url=path, json_data=body, files=to_httpx_files(files), **options
|
||||
method="patch", url=path, json_data=body, content=content, files=to_httpx_files(files), **options
|
||||
)
|
||||
return self.request(cast_to, opts)
|
||||
|
||||
|
|
@ -1261,11 +1308,23 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: BinaryTypes | None = None,
|
||||
files: RequestFiles | None = None,
|
||||
options: RequestOptions = {},
|
||||
) -> ResponseT:
|
||||
if body is not None and content is not None:
|
||||
raise TypeError("Passing both `body` and `content` is not supported")
|
||||
if files is not None and content is not None:
|
||||
raise TypeError("Passing both `files` and `content` is not supported")
|
||||
if isinstance(body, bytes):
|
||||
warnings.warn(
|
||||
"Passing raw bytes as `body` is deprecated and will be removed in a future version. "
|
||||
"Please pass raw bytes via the `content` parameter instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
opts = FinalRequestOptions.construct(
|
||||
method="put", url=path, json_data=body, files=to_httpx_files(files), **options
|
||||
method="put", url=path, json_data=body, content=content, files=to_httpx_files(files), **options
|
||||
)
|
||||
return self.request(cast_to, opts)
|
||||
|
||||
|
|
@ -1275,9 +1334,19 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: BinaryTypes | None = None,
|
||||
options: RequestOptions = {},
|
||||
) -> ResponseT:
|
||||
opts = FinalRequestOptions.construct(method="delete", url=path, json_data=body, **options)
|
||||
if body is not None and content is not None:
|
||||
raise TypeError("Passing both `body` and `content` is not supported")
|
||||
if isinstance(body, bytes):
|
||||
warnings.warn(
|
||||
"Passing raw bytes as `body` is deprecated and will be removed in a future version. "
|
||||
"Please pass raw bytes via the `content` parameter instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
opts = FinalRequestOptions.construct(method="delete", url=path, json_data=body, content=content, **options)
|
||||
return self.request(cast_to, opts)
|
||||
|
||||
def get_api_list(
|
||||
|
|
@ -1717,6 +1786,7 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: AsyncBinaryTypes | None = None,
|
||||
files: RequestFiles | None = None,
|
||||
options: RequestOptions = {},
|
||||
stream: Literal[False] = False,
|
||||
|
|
@ -1729,6 +1799,7 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: AsyncBinaryTypes | None = None,
|
||||
files: RequestFiles | None = None,
|
||||
options: RequestOptions = {},
|
||||
stream: Literal[True],
|
||||
|
|
@ -1742,6 +1813,7 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: AsyncBinaryTypes | None = None,
|
||||
files: RequestFiles | None = None,
|
||||
options: RequestOptions = {},
|
||||
stream: bool,
|
||||
|
|
@ -1754,13 +1826,25 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: AsyncBinaryTypes | None = None,
|
||||
files: RequestFiles | None = None,
|
||||
options: RequestOptions = {},
|
||||
stream: bool = False,
|
||||
stream_cls: type[_AsyncStreamT] | None = None,
|
||||
) -> ResponseT | _AsyncStreamT:
|
||||
if body is not None and content is not None:
|
||||
raise TypeError("Passing both `body` and `content` is not supported")
|
||||
if files is not None and content is not None:
|
||||
raise TypeError("Passing both `files` and `content` is not supported")
|
||||
if isinstance(body, bytes):
|
||||
warnings.warn(
|
||||
"Passing raw bytes as `body` is deprecated and will be removed in a future version. "
|
||||
"Please pass raw bytes via the `content` parameter instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
opts = FinalRequestOptions.construct(
|
||||
method="post", url=path, json_data=body, files=await async_to_httpx_files(files), **options
|
||||
method="post", url=path, json_data=body, content=content, files=await async_to_httpx_files(files), **options
|
||||
)
|
||||
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
|
||||
|
||||
|
|
@ -1770,11 +1854,28 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: AsyncBinaryTypes | None = None,
|
||||
files: RequestFiles | None = None,
|
||||
options: RequestOptions = {},
|
||||
) -> ResponseT:
|
||||
if body is not None and content is not None:
|
||||
raise TypeError("Passing both `body` and `content` is not supported")
|
||||
if files is not None and content is not None:
|
||||
raise TypeError("Passing both `files` and `content` is not supported")
|
||||
if isinstance(body, bytes):
|
||||
warnings.warn(
|
||||
"Passing raw bytes as `body` is deprecated and will be removed in a future version. "
|
||||
"Please pass raw bytes via the `content` parameter instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
opts = FinalRequestOptions.construct(
|
||||
method="patch", url=path, json_data=body, files=await async_to_httpx_files(files), **options
|
||||
method="patch",
|
||||
url=path,
|
||||
json_data=body,
|
||||
content=content,
|
||||
files=await async_to_httpx_files(files),
|
||||
**options,
|
||||
)
|
||||
return await self.request(cast_to, opts)
|
||||
|
||||
|
|
@ -1784,11 +1885,23 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: AsyncBinaryTypes | None = None,
|
||||
files: RequestFiles | None = None,
|
||||
options: RequestOptions = {},
|
||||
) -> ResponseT:
|
||||
if body is not None and content is not None:
|
||||
raise TypeError("Passing both `body` and `content` is not supported")
|
||||
if files is not None and content is not None:
|
||||
raise TypeError("Passing both `files` and `content` is not supported")
|
||||
if isinstance(body, bytes):
|
||||
warnings.warn(
|
||||
"Passing raw bytes as `body` is deprecated and will be removed in a future version. "
|
||||
"Please pass raw bytes via the `content` parameter instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
opts = FinalRequestOptions.construct(
|
||||
method="put", url=path, json_data=body, files=await async_to_httpx_files(files), **options
|
||||
method="put", url=path, json_data=body, content=content, files=await async_to_httpx_files(files), **options
|
||||
)
|
||||
return await self.request(cast_to, opts)
|
||||
|
||||
|
|
@ -1798,9 +1911,19 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
|
|||
*,
|
||||
cast_to: Type[ResponseT],
|
||||
body: Body | None = None,
|
||||
content: AsyncBinaryTypes | None = None,
|
||||
options: RequestOptions = {},
|
||||
) -> ResponseT:
|
||||
opts = FinalRequestOptions.construct(method="delete", url=path, json_data=body, **options)
|
||||
if body is not None and content is not None:
|
||||
raise TypeError("Passing both `body` and `content` is not supported")
|
||||
if isinstance(body, bytes):
|
||||
warnings.warn(
|
||||
"Passing raw bytes as `body` is deprecated and will be removed in a future version. "
|
||||
"Please pass raw bytes via the `content` parameter instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
opts = FinalRequestOptions.construct(method="delete", url=path, json_data=body, content=content, **options)
|
||||
return await self.request(cast_to, opts)
|
||||
|
||||
def get_api_list(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue