diff --git a/pyproject.toml b/pyproject.toml index 93c6ec0..036c33c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ name = "credal" [tool.poetry] name = "credal" -version = "0.1.13" +version = "0.1.14" description = "" readme = "README.md" authors = [] diff --git a/reference.md b/reference.md index d611ac9..db46e40 100644 --- a/reference.md +++ b/reference.md @@ -837,6 +837,129 @@ client.copilots.delete_copilot( + + + + +
client.copilots.export(...) +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Export copilot configurations for backup or migration purposes. + +**IMPORTANT**: This endpoint requires: +- Admin privileges +- The 'ai-usage-analytics-log.export' scope on the API key + +Returns all deployed copilots with their full configuration including model settings, tools, and deployment details. Optional date filters can be applied to narrow down results. +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```python +import datetime + +from credal import CredalApi + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.copilots.export( + agent_created_from=datetime.datetime.fromisoformat( + "2024-01-01 00:00:00+00:00", + ), + agent_created_to=datetime.datetime.fromisoformat( + "2024-12-31 23:59:59+00:00", + ), +) + +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**agent_created_from:** `typing.Optional[dt.datetime]` — Filter copilots created on or after this datetime (ISO 8601 format). + +
+
+ +
+
+ +**agent_created_to:** `typing.Optional[dt.datetime]` — Filter copilots created before or on this datetime (ISO 8601 format). + +
+
+ +
+
+ +**version_created_from:** `typing.Optional[dt.datetime]` — Filter copilot versions created on or after this datetime (ISO 8601 format). + +
+
+ +
+
+ +**version_created_to:** `typing.Optional[dt.datetime]` — Filter copilot versions created before or on this datetime (ISO 8601 format). + +
+
+ +
+
+ +**limit:** `typing.Optional[int]` — Maximum number of copilots to return. Must be a positive integer with a maximum value of 1000. Defaults to 100. + +
+
+ +
+
+ +**cursor:** `typing.Optional[str]` — Cursor for pagination. Use the cursor returned in the previous response to fetch the next page of results. If not provided, returns the first page. + +
+
+ +
+
+ +**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration. + +
+
+
+
+ +
diff --git a/src/credal/__init__.py b/src/credal/__init__.py index 8b11245..b0d632a 100644 --- a/src/credal/__init__.py +++ b/src/credal/__init__.py @@ -35,6 +35,8 @@ EndOfMessageChunk, ErrorChunk, ErrorChunkData, + ExportCopilotsResponse, + ExportedCopilot, FeedbackEnum, Filter, Filter_Boolean, @@ -116,6 +118,8 @@ "EndOfMessageChunk": ".copilots", "ErrorChunk": ".copilots", "ErrorChunkData": ".copilots", + "ExportCopilotsResponse": ".copilots", + "ExportedCopilot": ".copilots", "ExternalResourceId": ".common", "FeedbackEnum": ".copilots", "Filter": ".copilots", @@ -221,6 +225,8 @@ def __dir__(): "EndOfMessageChunk", "ErrorChunk", "ErrorChunkData", + "ExportCopilotsResponse", + "ExportedCopilot", "ExternalResourceId", "FeedbackEnum", "Filter", diff --git a/src/credal/copilots/__init__.py b/src/credal/copilots/__init__.py index df887e7..759f57f 100644 --- a/src/credal/copilots/__init__.py +++ b/src/credal/copilots/__init__.py @@ -21,6 +21,8 @@ EndOfMessageChunk, ErrorChunk, ErrorChunkData, + ExportCopilotsResponse, + ExportedCopilot, FeedbackEnum, Filter, Filter_Boolean, @@ -66,6 +68,8 @@ "EndOfMessageChunk": ".types", "ErrorChunk": ".types", "ErrorChunkData": ".types", + "ExportCopilotsResponse": ".types", + "ExportedCopilot": ".types", "FeedbackEnum": ".types", "Filter": ".types", "Filter_Boolean": ".types", @@ -134,6 +138,8 @@ def __dir__(): "EndOfMessageChunk", "ErrorChunk", "ErrorChunkData", + "ExportCopilotsResponse", + "ExportedCopilot", "FeedbackEnum", "Filter", "Filter_Boolean", diff --git a/src/credal/copilots/client.py b/src/credal/copilots/client.py index a2de3a3..74c6302 100644 --- a/src/credal/copilots/client.py +++ b/src/credal/copilots/client.py @@ -1,5 +1,6 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing import uuid @@ -11,6 +12,7 @@ from .types.create_conversation_response import CreateConversationResponse from .types.create_copilot_response import CreateCopilotResponse from .types.delete_copilot_response import DeleteCopilotResponse +from .types.export_copilots_response import ExportCopilotsResponse from .types.input_variable import InputVariable from .types.message_feedback import MessageFeedback from .types.send_agent_message_response import SendAgentMessageResponse @@ -552,6 +554,82 @@ def delete_copilot( _response = self._raw_client.delete_copilot(id=id, request_options=request_options) return _response.data + def export( + self, + *, + agent_created_from: typing.Optional[dt.datetime] = OMIT, + agent_created_to: typing.Optional[dt.datetime] = OMIT, + version_created_from: typing.Optional[dt.datetime] = OMIT, + version_created_to: typing.Optional[dt.datetime] = OMIT, + limit: typing.Optional[int] = OMIT, + cursor: typing.Optional[str] = OMIT, + request_options: typing.Optional[RequestOptions] = None, + ) -> ExportCopilotsResponse: + """ + Export copilot configurations for backup or migration purposes. + + **IMPORTANT**: This endpoint requires: + - Admin privileges + - The 'ai-usage-analytics-log.export' scope on the API key + + Returns all deployed copilots with their full configuration including model settings, tools, and deployment details. Optional date filters can be applied to narrow down results. + + Parameters + ---------- + agent_created_from : typing.Optional[dt.datetime] + Filter copilots created on or after this datetime (ISO 8601 format). + + agent_created_to : typing.Optional[dt.datetime] + Filter copilots created before or on this datetime (ISO 8601 format). + + version_created_from : typing.Optional[dt.datetime] + Filter copilot versions created on or after this datetime (ISO 8601 format). + + version_created_to : typing.Optional[dt.datetime] + Filter copilot versions created before or on this datetime (ISO 8601 format). + + limit : typing.Optional[int] + Maximum number of copilots to return. Must be a positive integer with a maximum value of 1000. Defaults to 100. + + cursor : typing.Optional[str] + Cursor for pagination. Use the cursor returned in the previous response to fetch the next page of results. If not provided, returns the first page. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + ExportCopilotsResponse + + Examples + -------- + import datetime + + from credal import CredalApi + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.copilots.export( + agent_created_from=datetime.datetime.fromisoformat( + "2024-01-01 00:00:00+00:00", + ), + agent_created_to=datetime.datetime.fromisoformat( + "2024-12-31 23:59:59+00:00", + ), + ) + """ + _response = self._raw_client.export( + agent_created_from=agent_created_from, + agent_created_to=agent_created_to, + version_created_from=version_created_from, + version_created_to=version_created_to, + limit=limit, + cursor=cursor, + request_options=request_options, + ) + return _response.data + class AsyncCopilotsClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): @@ -1149,3 +1227,86 @@ async def main() -> None: """ _response = await self._raw_client.delete_copilot(id=id, request_options=request_options) return _response.data + + async def export( + self, + *, + agent_created_from: typing.Optional[dt.datetime] = OMIT, + agent_created_to: typing.Optional[dt.datetime] = OMIT, + version_created_from: typing.Optional[dt.datetime] = OMIT, + version_created_to: typing.Optional[dt.datetime] = OMIT, + limit: typing.Optional[int] = OMIT, + cursor: typing.Optional[str] = OMIT, + request_options: typing.Optional[RequestOptions] = None, + ) -> ExportCopilotsResponse: + """ + Export copilot configurations for backup or migration purposes. + + **IMPORTANT**: This endpoint requires: + - Admin privileges + - The 'ai-usage-analytics-log.export' scope on the API key + + Returns all deployed copilots with their full configuration including model settings, tools, and deployment details. Optional date filters can be applied to narrow down results. + + Parameters + ---------- + agent_created_from : typing.Optional[dt.datetime] + Filter copilots created on or after this datetime (ISO 8601 format). + + agent_created_to : typing.Optional[dt.datetime] + Filter copilots created before or on this datetime (ISO 8601 format). + + version_created_from : typing.Optional[dt.datetime] + Filter copilot versions created on or after this datetime (ISO 8601 format). + + version_created_to : typing.Optional[dt.datetime] + Filter copilot versions created before or on this datetime (ISO 8601 format). + + limit : typing.Optional[int] + Maximum number of copilots to return. Must be a positive integer with a maximum value of 1000. Defaults to 100. + + cursor : typing.Optional[str] + Cursor for pagination. Use the cursor returned in the previous response to fetch the next page of results. If not provided, returns the first page. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + ExportCopilotsResponse + + Examples + -------- + import asyncio + import datetime + + from credal import AsyncCredalApi + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + + async def main() -> None: + await client.copilots.export( + agent_created_from=datetime.datetime.fromisoformat( + "2024-01-01 00:00:00+00:00", + ), + agent_created_to=datetime.datetime.fromisoformat( + "2024-12-31 23:59:59+00:00", + ), + ) + + + asyncio.run(main()) + """ + _response = await self._raw_client.export( + agent_created_from=agent_created_from, + agent_created_to=agent_created_to, + version_created_from=version_created_from, + version_created_to=version_created_to, + limit=limit, + cursor=cursor, + request_options=request_options, + ) + return _response.data diff --git a/src/credal/copilots/raw_client.py b/src/credal/copilots/raw_client.py index 8595bac..ad2f702 100644 --- a/src/credal/copilots/raw_client.py +++ b/src/credal/copilots/raw_client.py @@ -1,6 +1,7 @@ # This file was auto-generated by Fern from our API Definition. import contextlib +import datetime as dt import typing import uuid from json.decoder import JSONDecodeError @@ -18,6 +19,7 @@ from .types.create_conversation_response import CreateConversationResponse from .types.create_copilot_response import CreateCopilotResponse from .types.delete_copilot_response import DeleteCopilotResponse +from .types.export_copilots_response import ExportCopilotsResponse from .types.input_variable import InputVariable from .types.message_feedback import MessageFeedback from .types.send_agent_message_response import SendAgentMessageResponse @@ -517,6 +519,82 @@ def delete_copilot( raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + def export( + self, + *, + agent_created_from: typing.Optional[dt.datetime] = OMIT, + agent_created_to: typing.Optional[dt.datetime] = OMIT, + version_created_from: typing.Optional[dt.datetime] = OMIT, + version_created_to: typing.Optional[dt.datetime] = OMIT, + limit: typing.Optional[int] = OMIT, + cursor: typing.Optional[str] = OMIT, + request_options: typing.Optional[RequestOptions] = None, + ) -> HttpResponse[ExportCopilotsResponse]: + """ + Export copilot configurations for backup or migration purposes. + + **IMPORTANT**: This endpoint requires: + - Admin privileges + - The 'ai-usage-analytics-log.export' scope on the API key + + Returns all deployed copilots with their full configuration including model settings, tools, and deployment details. Optional date filters can be applied to narrow down results. + + Parameters + ---------- + agent_created_from : typing.Optional[dt.datetime] + Filter copilots created on or after this datetime (ISO 8601 format). + + agent_created_to : typing.Optional[dt.datetime] + Filter copilots created before or on this datetime (ISO 8601 format). + + version_created_from : typing.Optional[dt.datetime] + Filter copilot versions created on or after this datetime (ISO 8601 format). + + version_created_to : typing.Optional[dt.datetime] + Filter copilot versions created before or on this datetime (ISO 8601 format). + + limit : typing.Optional[int] + Maximum number of copilots to return. Must be a positive integer with a maximum value of 1000. Defaults to 100. + + cursor : typing.Optional[str] + Cursor for pagination. Use the cursor returned in the previous response to fetch the next page of results. If not provided, returns the first page. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + HttpResponse[ExportCopilotsResponse] + """ + _response = self._client_wrapper.httpx_client.request( + "v0/copilots/export", + method="POST", + json={ + "agentCreatedFrom": agent_created_from, + "agentCreatedTo": agent_created_to, + "versionCreatedFrom": version_created_from, + "versionCreatedTo": version_created_to, + "limit": limit, + "cursor": cursor, + }, + request_options=request_options, + omit=OMIT, + ) + try: + if 200 <= _response.status_code < 300: + _data = typing.cast( + ExportCopilotsResponse, + parse_obj_as( + type_=ExportCopilotsResponse, # type: ignore + object_=_response.json(), + ), + ) + return HttpResponse(response=_response, data=_data) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + class AsyncRawCopilotsClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): @@ -1007,3 +1085,79 @@ async def delete_copilot( except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + + async def export( + self, + *, + agent_created_from: typing.Optional[dt.datetime] = OMIT, + agent_created_to: typing.Optional[dt.datetime] = OMIT, + version_created_from: typing.Optional[dt.datetime] = OMIT, + version_created_to: typing.Optional[dt.datetime] = OMIT, + limit: typing.Optional[int] = OMIT, + cursor: typing.Optional[str] = OMIT, + request_options: typing.Optional[RequestOptions] = None, + ) -> AsyncHttpResponse[ExportCopilotsResponse]: + """ + Export copilot configurations for backup or migration purposes. + + **IMPORTANT**: This endpoint requires: + - Admin privileges + - The 'ai-usage-analytics-log.export' scope on the API key + + Returns all deployed copilots with their full configuration including model settings, tools, and deployment details. Optional date filters can be applied to narrow down results. + + Parameters + ---------- + agent_created_from : typing.Optional[dt.datetime] + Filter copilots created on or after this datetime (ISO 8601 format). + + agent_created_to : typing.Optional[dt.datetime] + Filter copilots created before or on this datetime (ISO 8601 format). + + version_created_from : typing.Optional[dt.datetime] + Filter copilot versions created on or after this datetime (ISO 8601 format). + + version_created_to : typing.Optional[dt.datetime] + Filter copilot versions created before or on this datetime (ISO 8601 format). + + limit : typing.Optional[int] + Maximum number of copilots to return. Must be a positive integer with a maximum value of 1000. Defaults to 100. + + cursor : typing.Optional[str] + Cursor for pagination. Use the cursor returned in the previous response to fetch the next page of results. If not provided, returns the first page. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + AsyncHttpResponse[ExportCopilotsResponse] + """ + _response = await self._client_wrapper.httpx_client.request( + "v0/copilots/export", + method="POST", + json={ + "agentCreatedFrom": agent_created_from, + "agentCreatedTo": agent_created_to, + "versionCreatedFrom": version_created_from, + "versionCreatedTo": version_created_to, + "limit": limit, + "cursor": cursor, + }, + request_options=request_options, + omit=OMIT, + ) + try: + if 200 <= _response.status_code < 300: + _data = typing.cast( + ExportCopilotsResponse, + parse_obj_as( + type_=ExportCopilotsResponse, # type: ignore + object_=_response.json(), + ), + ) + return AsyncHttpResponse(response=_response, data=_data) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) diff --git a/src/credal/copilots/types/__init__.py b/src/credal/copilots/types/__init__.py index 6a6cf4c..df2984b 100644 --- a/src/credal/copilots/types/__init__.py +++ b/src/credal/copilots/types/__init__.py @@ -20,6 +20,8 @@ from .end_of_message_chunk import EndOfMessageChunk from .error_chunk import ErrorChunk from .error_chunk_data import ErrorChunkData + from .export_copilots_response import ExportCopilotsResponse + from .exported_copilot import ExportedCopilot from .feedback_enum import FeedbackEnum from .filter import Filter, Filter_Boolean, Filter_Datetime, Filter_Number, Filter_String from .final_chunk import FinalChunk @@ -64,6 +66,8 @@ "EndOfMessageChunk": ".end_of_message_chunk", "ErrorChunk": ".error_chunk", "ErrorChunkData": ".error_chunk_data", + "ExportCopilotsResponse": ".export_copilots_response", + "ExportedCopilot": ".exported_copilot", "FeedbackEnum": ".feedback_enum", "Filter": ".filter", "Filter_Boolean": ".filter", @@ -132,6 +136,8 @@ def __dir__(): "EndOfMessageChunk", "ErrorChunk", "ErrorChunkData", + "ExportCopilotsResponse", + "ExportedCopilot", "FeedbackEnum", "Filter", "Filter_Boolean", diff --git a/src/credal/copilots/types/export_copilots_response.py b/src/credal/copilots/types/export_copilots_response.py new file mode 100644 index 0000000..46921a3 --- /dev/null +++ b/src/credal/copilots/types/export_copilots_response.py @@ -0,0 +1,37 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +import pydantic +import typing_extensions +from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel +from ...core.serialization import FieldMetadata +from .exported_copilot import ExportedCopilot + + +class ExportCopilotsResponse(UniversalBaseModel): + data: typing.List[ExportedCopilot] = pydantic.Field() + """ + List of exported copilots matching the query filters. + """ + + has_more: typing_extensions.Annotated[bool, FieldMetadata(alias="hasMore")] = pydantic.Field() + """ + Indicates whether there are more results available for pagination. + """ + + next_cursor: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="nextCursor")] = pydantic.Field( + default=None + ) + """ + Cursor to use for fetching the next page of results. This is a UUID string. If null or not present, there are no more results. + """ + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/src/credal/copilots/types/exported_copilot.py b/src/credal/copilots/types/exported_copilot.py new file mode 100644 index 0000000..38f51c7 --- /dev/null +++ b/src/credal/copilots/types/exported_copilot.py @@ -0,0 +1,88 @@ +# This file was auto-generated by Fern from our API Definition. + +import datetime as dt +import typing +import uuid + +import pydantic +import typing_extensions +from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel +from ...core.serialization import FieldMetadata + + +class ExportedCopilot(UniversalBaseModel): + id: uuid.UUID = pydantic.Field() + """ + The unique identifier of the copilot. + """ + + name: str = pydantic.Field() + """ + The name of the deployed copilot version. + """ + + description: str = pydantic.Field() + """ + The description of the deployed copilot version. + """ + + model_configuration: typing_extensions.Annotated[typing.Any, FieldMetadata(alias="modelConfiguration")] = ( + pydantic.Field() + ) + """ + Model configuration including provider, model name, temperature, and other settings. + """ + + ai_endpoint_configuration: typing_extensions.Annotated[ + typing.Any, FieldMetadata(alias="aiEndpointConfiguration") + ] = pydantic.Field() + """ + AI endpoint configuration including base URL and authentication details. + """ + + tool_configurations: typing_extensions.Annotated[typing.Any, FieldMetadata(alias="toolConfigurations")] = ( + pydantic.Field() + ) + """ + List of tool configurations available to the copilot. + """ + + inputs: typing.Any = pydantic.Field() + """ + Input variable configurations for the copilot. + """ + + deployment_configuration: typing_extensions.Annotated[ + typing.Any, FieldMetadata(alias="deploymentConfiguration") + ] = pydantic.Field() + """ + Deployment settings and configuration. + """ + + agent_created_datetime: typing_extensions.Annotated[dt.datetime, FieldMetadata(alias="agentCreatedDatetime")] = ( + pydantic.Field() + ) + """ + ISO 8601 timestamp when the copilot was originally created. + """ + + version_created_datetime: typing_extensions.Annotated[ + dt.datetime, FieldMetadata(alias="versionCreatedDatetime") + ] = pydantic.Field() + """ + ISO 8601 timestamp when the deployed version was created. + """ + + is_deployed: typing_extensions.Annotated[bool, FieldMetadata(alias="isDeployed")] = pydantic.Field() + """ + Indicates if the copilot is currently deployed (always true for export results). + """ + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/src/credal/core/client_wrapper.py b/src/credal/core/client_wrapper.py index 18604bf..fd8227d 100644 --- a/src/credal/core/client_wrapper.py +++ b/src/credal/core/client_wrapper.py @@ -22,10 +22,10 @@ def __init__( def get_headers(self) -> typing.Dict[str, str]: headers: typing.Dict[str, str] = { - "User-Agent": "credal/0.1.13", + "User-Agent": "credal/0.1.14", "X-Fern-Language": "Python", "X-Fern-SDK-Name": "credal", - "X-Fern-SDK-Version": "0.1.13", + "X-Fern-SDK-Version": "0.1.14", **(self.get_custom_headers() or {}), } headers["Authorization"] = f"Bearer {self._get_api_key()}"