diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 647ed9ca..88e4c443 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.19.0" + ".": "4.20.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 10450956..03d2cca2 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 136 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-bff810f46da56eff8d5e189b0d1f56ac07a8289723666138549d4239cad7c2ea.yml -openapi_spec_hash: 7532ce5a6f490c8f5d1e079c76c70535 -config_hash: a1454ffd9612dee11f9d5a98e55eac9e +configured_endpoints: 147 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-47ef7e0aaa2f2052404041650c9b4d7d8c9c51c45ef2cb081548f329c3f81a6a.yml +openapi_spec_hash: 0207b30cf74121a12c1647e25463cee9 +config_hash: 8dca0f2dc2706c07cf2f8d0ed4dc062e diff --git a/CHANGELOG.md b/CHANGELOG.md index 78ee6002..fb30ec13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 4.20.0 (2026-02-10) + +Full Changelog: [v4.19.0...v4.20.0](https://github.com/openai/openai-java/compare/v4.19.0...v4.20.0) + +### Features + +* **api:** skills and hosted shell ([fcd724d](https://github.com/openai/openai-java/commit/fcd724d2822b755ef44b9de8f9b5573d82271ce7)) +* **api:** support for images in batch api ([c73908a](https://github.com/openai/openai-java/commit/c73908a19f26fa12350f7a5880401bd260420216)) + ## 4.19.0 (2026-02-09) Full Changelog: [v4.18.0...v4.19.0](https://github.com/openai/openai-java/compare/v4.18.0...v4.19.0) diff --git a/README.md b/README.md index bad6ed44..fd9f5aff 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/4.19.0) -[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/4.19.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/4.19.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/4.20.0) +[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/4.20.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/4.20.0) @@ -11,7 +11,7 @@ The OpenAI Java SDK provides convenient access to the [OpenAI REST API](https:// -The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/4.19.0). +The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/4.20.0). @@ -24,7 +24,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfor ### Gradle ```kotlin -implementation("com.openai:openai-java:4.19.0") +implementation("com.openai:openai-java:4.20.0") ``` ### Maven @@ -33,7 +33,7 @@ implementation("com.openai:openai-java:4.19.0") com.openai openai-java - 4.19.0 + 4.20.0 ``` @@ -1342,7 +1342,7 @@ If you're using Spring Boot, then you can use the SDK's [Spring Boot starter](ht #### Gradle ```kotlin -implementation("com.openai:openai-java-spring-boot-starter:4.19.0") +implementation("com.openai:openai-java-spring-boot-starter:4.20.0") ``` #### Maven @@ -1351,7 +1351,7 @@ implementation("com.openai:openai-java-spring-boot-starter:4.19.0") com.openai openai-java-spring-boot-starter - 4.19.0 + 4.20.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 1a7dcb63..5849b5ef 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.openai" - version = "4.19.0" // x-release-please-version + version = "4.20.0" // x-release-please-version } subprojects { diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt index f0489a2f..0cfaa4aa 100644 --- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt +++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt @@ -20,6 +20,7 @@ import com.openai.services.blocking.ModelService import com.openai.services.blocking.ModerationService import com.openai.services.blocking.RealtimeService import com.openai.services.blocking.ResponseService +import com.openai.services.blocking.SkillService import com.openai.services.blocking.UploadService import com.openai.services.blocking.VectorStoreService import com.openai.services.blocking.VideoService @@ -102,6 +103,8 @@ interface OpenAIClient { fun containers(): ContainerService + fun skills(): SkillService + fun videos(): VideoService /** @@ -167,6 +170,8 @@ interface OpenAIClient { fun containers(): ContainerService.WithRawResponse + fun skills(): SkillService.WithRawResponse + fun videos(): VideoService.WithRawResponse } } diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt index a3074bc1..13bf29f2 100644 --- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt @@ -20,6 +20,7 @@ import com.openai.services.async.ModelServiceAsync import com.openai.services.async.ModerationServiceAsync import com.openai.services.async.RealtimeServiceAsync import com.openai.services.async.ResponseServiceAsync +import com.openai.services.async.SkillServiceAsync import com.openai.services.async.UploadServiceAsync import com.openai.services.async.VectorStoreServiceAsync import com.openai.services.async.VideoServiceAsync @@ -102,6 +103,8 @@ interface OpenAIClientAsync { fun containers(): ContainerServiceAsync + fun skills(): SkillServiceAsync + fun videos(): VideoServiceAsync /** @@ -169,6 +172,8 @@ interface OpenAIClientAsync { fun containers(): ContainerServiceAsync.WithRawResponse + fun skills(): SkillServiceAsync.WithRawResponse + fun videos(): VideoServiceAsync.WithRawResponse } } diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt index 1424255b..74035353 100644 --- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt @@ -38,6 +38,8 @@ import com.openai.services.async.RealtimeServiceAsync import com.openai.services.async.RealtimeServiceAsyncImpl import com.openai.services.async.ResponseServiceAsync import com.openai.services.async.ResponseServiceAsyncImpl +import com.openai.services.async.SkillServiceAsync +import com.openai.services.async.SkillServiceAsyncImpl import com.openai.services.async.UploadServiceAsync import com.openai.services.async.UploadServiceAsyncImpl import com.openai.services.async.VectorStoreServiceAsync @@ -137,6 +139,10 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl ContainerServiceAsyncImpl(clientOptionsWithUserAgent) } + private val skills: SkillServiceAsync by lazy { + SkillServiceAsyncImpl(clientOptionsWithUserAgent) + } + private val videos: VideoServiceAsync by lazy { VideoServiceAsyncImpl(clientOptionsWithUserAgent) } @@ -188,6 +194,8 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl override fun containers(): ContainerServiceAsync = containers + override fun skills(): SkillServiceAsync = skills + override fun videos(): VideoServiceAsync = videos override fun close() = clientOptions.close() @@ -275,6 +283,10 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl ContainerServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val skills: SkillServiceAsync.WithRawResponse by lazy { + SkillServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + private val videos: VideoServiceAsync.WithRawResponse by lazy { VideoServiceAsyncImpl.WithRawResponseImpl(clientOptions) } @@ -326,6 +338,8 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl override fun containers(): ContainerServiceAsync.WithRawResponse = containers + override fun skills(): SkillServiceAsync.WithRawResponse = skills + override fun videos(): VideoServiceAsync.WithRawResponse = videos } } diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt index 22fa8afd..112a694d 100644 --- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt @@ -38,6 +38,8 @@ import com.openai.services.blocking.RealtimeService import com.openai.services.blocking.RealtimeServiceImpl import com.openai.services.blocking.ResponseService import com.openai.services.blocking.ResponseServiceImpl +import com.openai.services.blocking.SkillService +import com.openai.services.blocking.SkillServiceImpl import com.openai.services.blocking.UploadService import com.openai.services.blocking.UploadServiceImpl import com.openai.services.blocking.VectorStoreService @@ -123,6 +125,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient ContainerServiceImpl(clientOptionsWithUserAgent) } + private val skills: SkillService by lazy { SkillServiceImpl(clientOptionsWithUserAgent) } + private val videos: VideoService by lazy { VideoServiceImpl(clientOptionsWithUserAgent) } override fun async(): OpenAIClientAsync = async @@ -172,6 +176,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient override fun containers(): ContainerService = containers + override fun skills(): SkillService = skills + override fun videos(): VideoService = videos override fun close() = clientOptions.close() @@ -259,6 +265,10 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient ContainerServiceImpl.WithRawResponseImpl(clientOptions) } + private val skills: SkillService.WithRawResponse by lazy { + SkillServiceImpl.WithRawResponseImpl(clientOptions) + } + private val videos: VideoService.WithRawResponse by lazy { VideoServiceImpl.WithRawResponseImpl(clientOptions) } @@ -310,6 +320,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient override fun containers(): ContainerService.WithRawResponse = containers + override fun skills(): SkillService.WithRawResponse = skills + override fun videos(): VideoService.WithRawResponse = videos } } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchCreateParams.kt index 6c4be6fa..6968e467 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchCreateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchCreateParams.kt @@ -40,9 +40,10 @@ private constructor( /** * The endpoint to be used for all requests in the batch. Currently `/v1/responses`, - * `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, and `/v1/moderations` are - * supported. Note that `/v1/embeddings` batches are also restricted to a maximum of 50,000 - * embedding inputs across all requests in the batch. + * `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, `/v1/moderations`, + * `/v1/images/generations`, and `/v1/images/edits` are supported. Note that `/v1/embeddings` + * batches are also restricted to a maximum of 50,000 embedding inputs across all requests in + * the batch. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -197,9 +198,10 @@ private constructor( /** * The endpoint to be used for all requests in the batch. Currently `/v1/responses`, - * `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, and `/v1/moderations` are - * supported. Note that `/v1/embeddings` batches are also restricted to a maximum of 50,000 - * embedding inputs across all requests in the batch. + * `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, `/v1/moderations`, + * `/v1/images/generations`, and `/v1/images/edits` are supported. Note that + * `/v1/embeddings` batches are also restricted to a maximum of 50,000 embedding inputs + * across all requests in the batch. */ fun endpoint(endpoint: Endpoint) = apply { body.endpoint(endpoint) } @@ -467,9 +469,10 @@ private constructor( /** * The endpoint to be used for all requests in the batch. Currently `/v1/responses`, - * `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, and `/v1/moderations` are - * supported. Note that `/v1/embeddings` batches are also restricted to a maximum of 50,000 - * embedding inputs across all requests in the batch. + * `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, `/v1/moderations`, + * `/v1/images/generations`, and `/v1/images/edits` are supported. Note that + * `/v1/embeddings` batches are also restricted to a maximum of 50,000 embedding inputs + * across all requests in the batch. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -624,9 +627,10 @@ private constructor( /** * The endpoint to be used for all requests in the batch. Currently `/v1/responses`, - * `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, and `/v1/moderations` - * are supported. Note that `/v1/embeddings` batches are also restricted to a maximum of - * 50,000 embedding inputs across all requests in the batch. + * `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, `/v1/moderations`, + * `/v1/images/generations`, and `/v1/images/edits` are supported. Note that + * `/v1/embeddings` batches are also restricted to a maximum of 50,000 embedding inputs + * across all requests in the batch. */ fun endpoint(endpoint: Endpoint) = endpoint(JsonField.of(endpoint)) @@ -943,9 +947,10 @@ private constructor( /** * The endpoint to be used for all requests in the batch. Currently `/v1/responses`, - * `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, and `/v1/moderations` are - * supported. Note that `/v1/embeddings` batches are also restricted to a maximum of 50,000 - * embedding inputs across all requests in the batch. + * `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`, `/v1/moderations`, + * `/v1/images/generations`, and `/v1/images/edits` are supported. Note that `/v1/embeddings` + * batches are also restricted to a maximum of 50,000 embedding inputs across all requests in + * the batch. */ class Endpoint @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -971,6 +976,10 @@ private constructor( @JvmField val V1_MODERATIONS = of("/v1/moderations") + @JvmField val V1_IMAGES_GENERATIONS = of("/v1/images/generations") + + @JvmField val V1_IMAGES_EDITS = of("/v1/images/edits") + @JvmStatic fun of(value: String) = Endpoint(JsonField.of(value)) } @@ -981,6 +990,8 @@ private constructor( V1_EMBEDDINGS, V1_COMPLETIONS, V1_MODERATIONS, + V1_IMAGES_GENERATIONS, + V1_IMAGES_EDITS, } /** @@ -998,6 +1009,8 @@ private constructor( V1_EMBEDDINGS, V1_COMPLETIONS, V1_MODERATIONS, + V1_IMAGES_GENERATIONS, + V1_IMAGES_EDITS, /** An enum member indicating that [Endpoint] was instantiated with an unknown value. */ _UNKNOWN, } @@ -1016,6 +1029,8 @@ private constructor( V1_EMBEDDINGS -> Value.V1_EMBEDDINGS V1_COMPLETIONS -> Value.V1_COMPLETIONS V1_MODERATIONS -> Value.V1_MODERATIONS + V1_IMAGES_GENERATIONS -> Value.V1_IMAGES_GENERATIONS + V1_IMAGES_EDITS -> Value.V1_IMAGES_EDITS else -> Value._UNKNOWN } @@ -1035,6 +1050,8 @@ private constructor( V1_EMBEDDINGS -> Known.V1_EMBEDDINGS V1_COMPLETIONS -> Known.V1_COMPLETIONS V1_MODERATIONS -> Known.V1_MODERATIONS + V1_IMAGES_GENERATIONS -> Known.V1_IMAGES_GENERATIONS + V1_IMAGES_EDITS -> Known.V1_IMAGES_EDITS else -> throw OpenAIInvalidDataException("Unknown Endpoint: $value") } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/images/ImageEditParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/images/ImageEditParams.kt index e836c56b..c4b54c3a 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/images/ImageEditParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/images/ImageEditParams.kt @@ -33,8 +33,8 @@ import kotlin.jvm.optionals.getOrNull /** * Creates an edited or extended image given one or more source images and a prompt. This endpoint - * supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`, and `gpt-image-1-mini`) and - * `dall-e-2`. + * supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`, `gpt-image-1-mini`, and + * `chatgpt-image-latest`) and `dall-e-2`. */ class ImageEditParams private constructor( @@ -48,6 +48,7 @@ private constructor( * * For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, and `gpt-image-1.5`), each image * should be a `png`, `webp`, or `jpg` file less than 50MB. You can provide up to 16 images. + * `chatgpt-image-latest` follows the same input constraints as GPT image models. * * For `dall-e-2`, you can only provide one image, and it should be a square `png` file less * than 4MB. @@ -103,9 +104,7 @@ private constructor( fun mask(): Optional = body.mask() /** - * The model to use for image generation. Only `dall-e-2` and the GPT image models are - * supported. Defaults to `dall-e-2` unless a parameter specific to the GPT image models is - * used. + * The model to use for image generation. Defaults to `gpt-image-1.5`. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -152,9 +151,7 @@ private constructor( fun partialImages(): Optional = body.partialImages() /** - * The quality of the image that will be generated. `high`, `medium` and `low` are only - * supported for the GPT image models. `dall-e-2` only supports `standard` quality. Defaults to - * `auto`. + * The quality of the image that will be generated for GPT image models. Defaults to `auto`. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -164,7 +161,8 @@ private constructor( /** * The format in which the generated images are returned. Must be one of `url` or `b64_json`. * URLs are only valid for 60 minutes after the image has been generated. This parameter is only - * supported for `dall-e-2`, as the GPT image models always return base64-encoded images. + * supported for `dall-e-2` (default is `url` for `dall-e-2`), as GPT image models always return + * base64-encoded images. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -351,7 +349,7 @@ private constructor( * * For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, and `gpt-image-1.5`), each * image should be a `png`, `webp`, or `jpg` file less than 50MB. You can provide up to 16 - * images. + * images. `chatgpt-image-latest` follows the same input constraints as GPT image models. * * For `dall-e-2`, you can only provide one image, and it should be a square `png` file less * than 4MB. @@ -374,7 +372,7 @@ private constructor( * * For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, and `gpt-image-1.5`), each * image should be a `png`, `webp`, or `jpg` file less than 50MB. You can provide up to 16 - * images. + * images. `chatgpt-image-latest` follows the same input constraints as GPT image models. * * For `dall-e-2`, you can only provide one image, and it should be a square `png` file less * than 4MB. @@ -386,7 +384,7 @@ private constructor( * * For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, and `gpt-image-1.5`), each * image should be a `png`, `webp`, or `jpg` file less than 50MB. You can provide up to 16 - * images. + * images. `chatgpt-image-latest` follows the same input constraints as GPT image models. * * For `dall-e-2`, you can only provide one image, and it should be a square `png` file less * than 4MB. @@ -495,11 +493,7 @@ private constructor( */ fun mask(path: Path) = apply { body.mask(path) } - /** - * The model to use for image generation. Only `dall-e-2` and the GPT image models are - * supported. Defaults to `dall-e-2` unless a parameter specific to the GPT image models is - * used. - */ + /** The model to use for image generation. Defaults to `gpt-image-1.5`. */ fun model(model: ImageModel?) = apply { body.model(model) } /** Alias for calling [Builder.model] with `model.orElse(null)`. */ @@ -628,9 +622,7 @@ private constructor( } /** - * The quality of the image that will be generated. `high`, `medium` and `low` are only - * supported for the GPT image models. `dall-e-2` only supports `standard` quality. Defaults - * to `auto`. + * The quality of the image that will be generated for GPT image models. Defaults to `auto`. */ fun quality(quality: Quality?) = apply { body.quality(quality) } @@ -648,8 +640,8 @@ private constructor( /** * The format in which the generated images are returned. Must be one of `url` or * `b64_json`. URLs are only valid for 60 minutes after the image has been generated. This - * parameter is only supported for `dall-e-2`, as the GPT image models always return - * base64-encoded images. + * parameter is only supported for `dall-e-2` (default is `url` for `dall-e-2`), as GPT + * image models always return base64-encoded images. */ fun responseFormat(responseFormat: ResponseFormat?) = apply { body.responseFormat(responseFormat) @@ -884,7 +876,7 @@ private constructor( * * For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, and `gpt-image-1.5`), each * image should be a `png`, `webp`, or `jpg` file less than 50MB. You can provide up to 16 - * images. + * images. `chatgpt-image-latest` follows the same input constraints as GPT image models. * * For `dall-e-2`, you can only provide one image, and it should be a square `png` file less * than 4MB. @@ -941,9 +933,7 @@ private constructor( fun mask(): Optional = mask.value.getOptional("mask") /** - * The model to use for image generation. Only `dall-e-2` and the GPT image models are - * supported. Defaults to `dall-e-2` unless a parameter specific to the GPT image models is - * used. + * The model to use for image generation. Defaults to `gpt-image-1.5`. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -992,9 +982,7 @@ private constructor( fun partialImages(): Optional = partialImages.value.getOptional("partial_images") /** - * The quality of the image that will be generated. `high`, `medium` and `low` are only - * supported for the GPT image models. `dall-e-2` only supports `standard` quality. Defaults - * to `auto`. + * The quality of the image that will be generated for GPT image models. Defaults to `auto`. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1004,8 +992,8 @@ private constructor( /** * The format in which the generated images are returned. Must be one of `url` or * `b64_json`. URLs are only valid for 60 minutes after the image has been generated. This - * parameter is only supported for `dall-e-2`, as the GPT image models always return - * base64-encoded images. + * parameter is only supported for `dall-e-2` (default is `url` for `dall-e-2`), as GPT + * image models always return base64-encoded images. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1219,7 +1207,8 @@ private constructor( * * For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, and `gpt-image-1.5`), * each image should be a `png`, `webp`, or `jpg` file less than 50MB. You can provide - * up to 16 images. + * up to 16 images. `chatgpt-image-latest` follows the same input constraints as GPT + * image models. * * For `dall-e-2`, you can only provide one image, and it should be a square `png` file * less than 4MB. @@ -1249,7 +1238,8 @@ private constructor( * * For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, and `gpt-image-1.5`), * each image should be a `png`, `webp`, or `jpg` file less than 50MB. You can provide - * up to 16 images. + * up to 16 images. `chatgpt-image-latest` follows the same input constraints as GPT + * image models. * * For `dall-e-2`, you can only provide one image, and it should be a square `png` file * less than 4MB. @@ -1261,7 +1251,8 @@ private constructor( * * For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, and `gpt-image-1.5`), * each image should be a `png`, `webp`, or `jpg` file less than 50MB. You can provide - * up to 16 images. + * up to 16 images. `chatgpt-image-latest` follows the same input constraints as GPT + * image models. * * For `dall-e-2`, you can only provide one image, and it should be a square `png` file * less than 4MB. @@ -1382,11 +1373,7 @@ private constructor( .build() ) - /** - * The model to use for image generation. Only `dall-e-2` and the GPT image models are - * supported. Defaults to `dall-e-2` unless a parameter specific to the GPT image models - * is used. - */ + /** The model to use for image generation. Defaults to `gpt-image-1.5`. */ fun model(model: ImageModel?) = model(MultipartField.of(model)) /** Alias for calling [Builder.model] with `model.orElse(null)`. */ @@ -1522,9 +1509,8 @@ private constructor( } /** - * The quality of the image that will be generated. `high`, `medium` and `low` are only - * supported for the GPT image models. `dall-e-2` only supports `standard` quality. - * Defaults to `auto`. + * The quality of the image that will be generated for GPT image models. Defaults to + * `auto`. */ fun quality(quality: Quality?) = quality(MultipartField.of(quality)) @@ -1543,8 +1529,8 @@ private constructor( /** * The format in which the generated images are returned. Must be one of `url` or * `b64_json`. URLs are only valid for 60 minutes after the image has been generated. - * This parameter is only supported for `dall-e-2`, as the GPT image models always - * return base64-encoded images. + * This parameter is only supported for `dall-e-2` (default is `url` for `dall-e-2`), as + * GPT image models always return base64-encoded images. */ fun responseFormat(responseFormat: ResponseFormat?) = responseFormat(MultipartField.of(responseFormat)) @@ -1737,6 +1723,7 @@ private constructor( * * For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, and `gpt-image-1.5`), each image * should be a `png`, `webp`, or `jpg` file less than 50MB. You can provide up to 16 images. + * `chatgpt-image-latest` follows the same input constraints as GPT image models. * * For `dall-e-2`, you can only provide one image, and it should be a square `png` file less * than 4MB. @@ -2279,11 +2266,7 @@ private constructor( override fun toString() = value.toString() } - /** - * The quality of the image that will be generated. `high`, `medium` and `low` are only - * supported for the GPT image models. `dall-e-2` only supports `standard` quality. Defaults to - * `auto`. - */ + /** The quality of the image that will be generated for GPT image models. Defaults to `auto`. */ class Quality @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -2430,7 +2413,8 @@ private constructor( /** * The format in which the generated images are returned. Must be one of `url` or `b64_json`. * URLs are only valid for 60 minutes after the image has been generated. This parameter is only - * supported for `dall-e-2`, as the GPT image models always return base64-encoded images. + * supported for `dall-e-2` (default is `url` for `dall-e-2`), as GPT image models always return + * base64-encoded images. */ class ResponseFormat @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerAuto.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerAuto.kt new file mode 100644 index 00000000..4810d0b1 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerAuto.kt @@ -0,0 +1,892 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.getOrThrow +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class ContainerAuto +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val type: JsonValue, + private val fileIds: JsonField>, + private val memoryLimit: JsonField, + private val networkPolicy: JsonField, + private val skills: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("file_ids") + @ExcludeMissing + fileIds: JsonField> = JsonMissing.of(), + @JsonProperty("memory_limit") + @ExcludeMissing + memoryLimit: JsonField = JsonMissing.of(), + @JsonProperty("network_policy") + @ExcludeMissing + networkPolicy: JsonField = JsonMissing.of(), + @JsonProperty("skills") @ExcludeMissing skills: JsonField> = JsonMissing.of(), + ) : this(type, fileIds, memoryLimit, networkPolicy, skills, mutableMapOf()) + + /** + * Automatically creates a container for this request + * + * Expected to always return the following: + * ```java + * JsonValue.from("container_auto") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * An optional list of uploaded files to make available to your code. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fileIds(): Optional> = fileIds.getOptional("file_ids") + + /** + * The memory limit for the container. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun memoryLimit(): Optional = memoryLimit.getOptional("memory_limit") + + /** + * Network access policy for the container. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun networkPolicy(): Optional = networkPolicy.getOptional("network_policy") + + /** + * An optional list of skills referenced by id or inline data. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun skills(): Optional> = skills.getOptional("skills") + + /** + * Returns the raw JSON value of [fileIds]. + * + * Unlike [fileIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_ids") @ExcludeMissing fun _fileIds(): JsonField> = fileIds + + /** + * Returns the raw JSON value of [memoryLimit]. + * + * Unlike [memoryLimit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("memory_limit") + @ExcludeMissing + fun _memoryLimit(): JsonField = memoryLimit + + /** + * Returns the raw JSON value of [networkPolicy]. + * + * Unlike [networkPolicy], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("network_policy") + @ExcludeMissing + fun _networkPolicy(): JsonField = networkPolicy + + /** + * Returns the raw JSON value of [skills]. + * + * Unlike [skills], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("skills") @ExcludeMissing fun _skills(): JsonField> = skills + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [ContainerAuto]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ContainerAuto]. */ + class Builder internal constructor() { + + private var type: JsonValue = JsonValue.from("container_auto") + private var fileIds: JsonField>? = null + private var memoryLimit: JsonField = JsonMissing.of() + private var networkPolicy: JsonField = JsonMissing.of() + private var skills: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(containerAuto: ContainerAuto) = apply { + type = containerAuto.type + fileIds = containerAuto.fileIds.map { it.toMutableList() } + memoryLimit = containerAuto.memoryLimit + networkPolicy = containerAuto.networkPolicy + skills = containerAuto.skills.map { it.toMutableList() } + additionalProperties = containerAuto.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("container_auto") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** An optional list of uploaded files to make available to your code. */ + fun fileIds(fileIds: List) = fileIds(JsonField.of(fileIds)) + + /** + * Sets [Builder.fileIds] to an arbitrary JSON value. + * + * You should usually call [Builder.fileIds] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun fileIds(fileIds: JsonField>) = apply { + this.fileIds = fileIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [fileIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addFileId(fileId: String) = apply { + fileIds = + (fileIds ?: JsonField.of(mutableListOf())).also { + checkKnown("fileIds", it).add(fileId) + } + } + + /** The memory limit for the container. */ + fun memoryLimit(memoryLimit: MemoryLimit?) = memoryLimit(JsonField.ofNullable(memoryLimit)) + + /** Alias for calling [Builder.memoryLimit] with `memoryLimit.orElse(null)`. */ + fun memoryLimit(memoryLimit: Optional) = memoryLimit(memoryLimit.getOrNull()) + + /** + * Sets [Builder.memoryLimit] to an arbitrary JSON value. + * + * You should usually call [Builder.memoryLimit] with a well-typed [MemoryLimit] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun memoryLimit(memoryLimit: JsonField) = apply { + this.memoryLimit = memoryLimit + } + + /** Network access policy for the container. */ + fun networkPolicy(networkPolicy: NetworkPolicy) = networkPolicy(JsonField.of(networkPolicy)) + + /** + * Sets [Builder.networkPolicy] to an arbitrary JSON value. + * + * You should usually call [Builder.networkPolicy] with a well-typed [NetworkPolicy] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun networkPolicy(networkPolicy: JsonField) = apply { + this.networkPolicy = networkPolicy + } + + /** Alias for calling [networkPolicy] with `NetworkPolicy.ofDisabled(disabled)`. */ + fun networkPolicy(disabled: ContainerNetworkPolicyDisabled) = + networkPolicy(NetworkPolicy.ofDisabled(disabled)) + + /** Alias for calling [networkPolicy] with `NetworkPolicy.ofAllowlist(allowlist)`. */ + fun networkPolicy(allowlist: ContainerNetworkPolicyAllowlist) = + networkPolicy(NetworkPolicy.ofAllowlist(allowlist)) + + /** + * Alias for calling [networkPolicy] with the following: + * ```java + * ContainerNetworkPolicyAllowlist.builder() + * .allowedDomains(allowedDomains) + * .build() + * ``` + */ + fun allowlistNetworkPolicy(allowedDomains: List) = + networkPolicy( + ContainerNetworkPolicyAllowlist.builder().allowedDomains(allowedDomains).build() + ) + + /** An optional list of skills referenced by id or inline data. */ + fun skills(skills: List) = skills(JsonField.of(skills)) + + /** + * Sets [Builder.skills] to an arbitrary JSON value. + * + * You should usually call [Builder.skills] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun skills(skills: JsonField>) = apply { + this.skills = skills.map { it.toMutableList() } + } + + /** + * Adds a single [Skill] to [skills]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSkill(skill: Skill) = apply { + skills = + (skills ?: JsonField.of(mutableListOf())).also { + checkKnown("skills", it).add(skill) + } + } + + /** Alias for calling [addSkill] with `Skill.ofReference(reference)`. */ + fun addSkill(reference: SkillReference) = addSkill(Skill.ofReference(reference)) + + /** + * Alias for calling [addSkill] with the following: + * ```java + * SkillReference.builder() + * .skillId(skillId) + * .build() + * ``` + */ + fun addReferenceSkill(skillId: String) = + addSkill(SkillReference.builder().skillId(skillId).build()) + + /** Alias for calling [addSkill] with `Skill.ofInline(inline)`. */ + fun addSkill(inline: InlineSkill) = addSkill(Skill.ofInline(inline)) + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ContainerAuto]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ContainerAuto = + ContainerAuto( + type, + (fileIds ?: JsonMissing.of()).map { it.toImmutable() }, + memoryLimit, + networkPolicy, + (skills ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ContainerAuto = apply { + if (validated) { + return@apply + } + + _type().let { + if (it != JsonValue.from("container_auto")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + fileIds() + memoryLimit().ifPresent { it.validate() } + networkPolicy().ifPresent { it.validate() } + skills().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + type.let { if (it == JsonValue.from("container_auto")) 1 else 0 } + + (fileIds.asKnown().getOrNull()?.size ?: 0) + + (memoryLimit.asKnown().getOrNull()?.validity() ?: 0) + + (networkPolicy.asKnown().getOrNull()?.validity() ?: 0) + + (skills.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + /** The memory limit for the container. */ + class MemoryLimit @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val _1G = of("1g") + + @JvmField val _4G = of("4g") + + @JvmField val _16G = of("16g") + + @JvmField val _64G = of("64g") + + @JvmStatic fun of(value: String) = MemoryLimit(JsonField.of(value)) + } + + /** An enum containing [MemoryLimit]'s known values. */ + enum class Known { + _1G, + _4G, + _16G, + _64G, + } + + /** + * An enum containing [MemoryLimit]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [MemoryLimit] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + _1G, + _4G, + _16G, + _64G, + /** + * An enum member indicating that [MemoryLimit] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + _1G -> Value._1G + _4G -> Value._4G + _16G -> Value._16G + _64G -> Value._64G + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + _1G -> Known._1G + _4G -> Known._4G + _16G -> Known._16G + _64G -> Known._64G + else -> throw OpenAIInvalidDataException("Unknown MemoryLimit: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + fun validate(): MemoryLimit = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MemoryLimit && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Network access policy for the container. */ + @JsonDeserialize(using = NetworkPolicy.Deserializer::class) + @JsonSerialize(using = NetworkPolicy.Serializer::class) + class NetworkPolicy + private constructor( + private val disabled: ContainerNetworkPolicyDisabled? = null, + private val allowlist: ContainerNetworkPolicyAllowlist? = null, + private val _json: JsonValue? = null, + ) { + + fun disabled(): Optional = Optional.ofNullable(disabled) + + fun allowlist(): Optional = Optional.ofNullable(allowlist) + + fun isDisabled(): Boolean = disabled != null + + fun isAllowlist(): Boolean = allowlist != null + + fun asDisabled(): ContainerNetworkPolicyDisabled = disabled.getOrThrow("disabled") + + fun asAllowlist(): ContainerNetworkPolicyAllowlist = allowlist.getOrThrow("allowlist") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + disabled != null -> visitor.visitDisabled(disabled) + allowlist != null -> visitor.visitAllowlist(allowlist) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): NetworkPolicy = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitDisabled(disabled: ContainerNetworkPolicyDisabled) { + disabled.validate() + } + + override fun visitAllowlist(allowlist: ContainerNetworkPolicyAllowlist) { + allowlist.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitDisabled(disabled: ContainerNetworkPolicyDisabled) = + disabled.validity() + + override fun visitAllowlist(allowlist: ContainerNetworkPolicyAllowlist) = + allowlist.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NetworkPolicy && + disabled == other.disabled && + allowlist == other.allowlist + } + + override fun hashCode(): Int = Objects.hash(disabled, allowlist) + + override fun toString(): String = + when { + disabled != null -> "NetworkPolicy{disabled=$disabled}" + allowlist != null -> "NetworkPolicy{allowlist=$allowlist}" + _json != null -> "NetworkPolicy{_unknown=$_json}" + else -> throw IllegalStateException("Invalid NetworkPolicy") + } + + companion object { + + @JvmStatic + fun ofDisabled(disabled: ContainerNetworkPolicyDisabled) = + NetworkPolicy(disabled = disabled) + + @JvmStatic + fun ofAllowlist(allowlist: ContainerNetworkPolicyAllowlist) = + NetworkPolicy(allowlist = allowlist) + } + + /** + * An interface that defines how to map each variant of [NetworkPolicy] to a value of type + * [T]. + */ + interface Visitor { + + fun visitDisabled(disabled: ContainerNetworkPolicyDisabled): T + + fun visitAllowlist(allowlist: ContainerNetworkPolicyAllowlist): T + + /** + * Maps an unknown variant of [NetworkPolicy] to a value of type [T]. + * + * An instance of [NetworkPolicy] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on an + * older version than the API, then the API may respond with new variants that the SDK + * is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown NetworkPolicy: $json") + } + } + + internal class Deserializer : BaseDeserializer(NetworkPolicy::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): NetworkPolicy { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "disabled" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { NetworkPolicy(disabled = it, _json = json) } + ?: NetworkPolicy(_json = json) + } + "allowlist" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { NetworkPolicy(allowlist = it, _json = json) } + ?: NetworkPolicy(_json = json) + } + } + + return NetworkPolicy(_json = json) + } + } + + internal class Serializer : BaseSerializer(NetworkPolicy::class) { + + override fun serialize( + value: NetworkPolicy, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.disabled != null -> generator.writeObject(value.disabled) + value.allowlist != null -> generator.writeObject(value.allowlist) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid NetworkPolicy") + } + } + } + } + + @JsonDeserialize(using = Skill.Deserializer::class) + @JsonSerialize(using = Skill.Serializer::class) + class Skill + private constructor( + private val reference: SkillReference? = null, + private val inline: InlineSkill? = null, + private val _json: JsonValue? = null, + ) { + + fun reference(): Optional = Optional.ofNullable(reference) + + fun inline(): Optional = Optional.ofNullable(inline) + + fun isReference(): Boolean = reference != null + + fun isInline(): Boolean = inline != null + + fun asReference(): SkillReference = reference.getOrThrow("reference") + + fun asInline(): InlineSkill = inline.getOrThrow("inline") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + reference != null -> visitor.visitReference(reference) + inline != null -> visitor.visitInline(inline) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Skill = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitReference(reference: SkillReference) { + reference.validate() + } + + override fun visitInline(inline: InlineSkill) { + inline.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitReference(reference: SkillReference) = reference.validity() + + override fun visitInline(inline: InlineSkill) = inline.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Skill && reference == other.reference && inline == other.inline + } + + override fun hashCode(): Int = Objects.hash(reference, inline) + + override fun toString(): String = + when { + reference != null -> "Skill{reference=$reference}" + inline != null -> "Skill{inline=$inline}" + _json != null -> "Skill{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Skill") + } + + companion object { + + @JvmStatic fun ofReference(reference: SkillReference) = Skill(reference = reference) + + @JvmStatic fun ofInline(inline: InlineSkill) = Skill(inline = inline) + } + + /** An interface that defines how to map each variant of [Skill] to a value of type [T]. */ + interface Visitor { + + fun visitReference(reference: SkillReference): T + + fun visitInline(inline: InlineSkill): T + + /** + * Maps an unknown variant of [Skill] to a value of type [T]. + * + * An instance of [Skill] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Skill: $json") + } + } + + internal class Deserializer : BaseDeserializer(Skill::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Skill { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "skill_reference" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Skill(reference = it, _json = json) + } ?: Skill(_json = json) + } + "inline" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Skill(inline = it, _json = json) + } ?: Skill(_json = json) + } + } + + return Skill(_json = json) + } + } + + internal class Serializer : BaseSerializer(Skill::class) { + + override fun serialize( + value: Skill, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.reference != null -> generator.writeObject(value.reference) + value.inline != null -> generator.writeObject(value.inline) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Skill") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ContainerAuto && + type == other.type && + fileIds == other.fileIds && + memoryLimit == other.memoryLimit && + networkPolicy == other.networkPolicy && + skills == other.skills && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(type, fileIds, memoryLimit, networkPolicy, skills, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ContainerAuto{type=$type, fileIds=$fileIds, memoryLimit=$memoryLimit, networkPolicy=$networkPolicy, skills=$skills, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerNetworkPolicyAllowlist.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerNetworkPolicyAllowlist.kt new file mode 100644 index 00000000..da688261 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerNetworkPolicyAllowlist.kt @@ -0,0 +1,302 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class ContainerNetworkPolicyAllowlist +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val allowedDomains: JsonField>, + private val type: JsonValue, + private val domainSecrets: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("allowed_domains") + @ExcludeMissing + allowedDomains: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("domain_secrets") + @ExcludeMissing + domainSecrets: JsonField> = JsonMissing.of(), + ) : this(allowedDomains, type, domainSecrets, mutableMapOf()) + + /** + * A list of allowed domains when type is `allowlist`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun allowedDomains(): List = allowedDomains.getRequired("allowed_domains") + + /** + * Allow outbound network access only to specified domains. Always `allowlist`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("allowlist") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Optional domain-scoped secrets for allowlisted domains. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun domainSecrets(): Optional> = + domainSecrets.getOptional("domain_secrets") + + /** + * Returns the raw JSON value of [allowedDomains]. + * + * Unlike [allowedDomains], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_domains") + @ExcludeMissing + fun _allowedDomains(): JsonField> = allowedDomains + + /** + * Returns the raw JSON value of [domainSecrets]. + * + * Unlike [domainSecrets], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("domain_secrets") + @ExcludeMissing + fun _domainSecrets(): JsonField> = domainSecrets + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [ContainerNetworkPolicyAllowlist]. + * + * The following fields are required: + * ```java + * .allowedDomains() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ContainerNetworkPolicyAllowlist]. */ + class Builder internal constructor() { + + private var allowedDomains: JsonField>? = null + private var type: JsonValue = JsonValue.from("allowlist") + private var domainSecrets: JsonField>? = + null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(containerNetworkPolicyAllowlist: ContainerNetworkPolicyAllowlist) = + apply { + allowedDomains = + containerNetworkPolicyAllowlist.allowedDomains.map { it.toMutableList() } + type = containerNetworkPolicyAllowlist.type + domainSecrets = + containerNetworkPolicyAllowlist.domainSecrets.map { it.toMutableList() } + additionalProperties = + containerNetworkPolicyAllowlist.additionalProperties.toMutableMap() + } + + /** A list of allowed domains when type is `allowlist`. */ + fun allowedDomains(allowedDomains: List) = + allowedDomains(JsonField.of(allowedDomains)) + + /** + * Sets [Builder.allowedDomains] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedDomains] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun allowedDomains(allowedDomains: JsonField>) = apply { + this.allowedDomains = allowedDomains.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [allowedDomains]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedDomain(allowedDomain: String) = apply { + allowedDomains = + (allowedDomains ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedDomains", it).add(allowedDomain) + } + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("allowlist") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Optional domain-scoped secrets for allowlisted domains. */ + fun domainSecrets(domainSecrets: List) = + domainSecrets(JsonField.of(domainSecrets)) + + /** + * Sets [Builder.domainSecrets] to an arbitrary JSON value. + * + * You should usually call [Builder.domainSecrets] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun domainSecrets(domainSecrets: JsonField>) = + apply { + this.domainSecrets = domainSecrets.map { it.toMutableList() } + } + + /** + * Adds a single [ContainerNetworkPolicyDomainSecret] to [domainSecrets]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDomainSecret(domainSecret: ContainerNetworkPolicyDomainSecret) = apply { + domainSecrets = + (domainSecrets ?: JsonField.of(mutableListOf())).also { + checkKnown("domainSecrets", it).add(domainSecret) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ContainerNetworkPolicyAllowlist]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .allowedDomains() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ContainerNetworkPolicyAllowlist = + ContainerNetworkPolicyAllowlist( + checkRequired("allowedDomains", allowedDomains).map { it.toImmutable() }, + type, + (domainSecrets ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ContainerNetworkPolicyAllowlist = apply { + if (validated) { + return@apply + } + + allowedDomains() + _type().let { + if (it != JsonValue.from("allowlist")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + domainSecrets().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (allowedDomains.asKnown().getOrNull()?.size ?: 0) + + type.let { if (it == JsonValue.from("allowlist")) 1 else 0 } + + (domainSecrets.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ContainerNetworkPolicyAllowlist && + allowedDomains == other.allowedDomains && + type == other.type && + domainSecrets == other.domainSecrets && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(allowedDomains, type, domainSecrets, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ContainerNetworkPolicyAllowlist{allowedDomains=$allowedDomains, type=$type, domainSecrets=$domainSecrets, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerNetworkPolicyDisabled.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerNetworkPolicyDisabled.kt new file mode 100644 index 00000000..04d163f6 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerNetworkPolicyDisabled.kt @@ -0,0 +1,164 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +class ContainerNetworkPolicyDisabled +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of() + ) : this(type, mutableMapOf()) + + /** + * Disable outbound network access. Always `disabled`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("disabled") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [ContainerNetworkPolicyDisabled]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ContainerNetworkPolicyDisabled]. */ + class Builder internal constructor() { + + private var type: JsonValue = JsonValue.from("disabled") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(containerNetworkPolicyDisabled: ContainerNetworkPolicyDisabled) = apply { + type = containerNetworkPolicyDisabled.type + additionalProperties = + containerNetworkPolicyDisabled.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("disabled") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ContainerNetworkPolicyDisabled]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ContainerNetworkPolicyDisabled = + ContainerNetworkPolicyDisabled(type, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): ContainerNetworkPolicyDisabled = apply { + if (validated) { + return@apply + } + + _type().let { + if (it != JsonValue.from("disabled")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = type.let { if (it == JsonValue.from("disabled")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ContainerNetworkPolicyDisabled && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ContainerNetworkPolicyDisabled{type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerNetworkPolicyDomainSecret.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerNetworkPolicyDomainSecret.kt new file mode 100644 index 00000000..b0a646c7 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerNetworkPolicyDomainSecret.kt @@ -0,0 +1,250 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +class ContainerNetworkPolicyDomainSecret +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val domain: JsonField, + private val name: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("domain") @ExcludeMissing domain: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), + ) : this(domain, name, value, mutableMapOf()) + + /** + * The domain associated with the secret. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun domain(): String = domain.getRequired("domain") + + /** + * The name of the secret to inject for the domain. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * The secret value to inject for the domain. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun value(): String = value.getRequired("value") + + /** + * Returns the raw JSON value of [domain]. + * + * Unlike [domain], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("domain") @ExcludeMissing fun _domain(): JsonField = domain + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [value]. + * + * Unlike [value], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [ContainerNetworkPolicyDomainSecret]. + * + * The following fields are required: + * ```java + * .domain() + * .name() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ContainerNetworkPolicyDomainSecret]. */ + class Builder internal constructor() { + + private var domain: JsonField? = null + private var name: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(containerNetworkPolicyDomainSecret: ContainerNetworkPolicyDomainSecret) = + apply { + domain = containerNetworkPolicyDomainSecret.domain + name = containerNetworkPolicyDomainSecret.name + value = containerNetworkPolicyDomainSecret.value + additionalProperties = + containerNetworkPolicyDomainSecret.additionalProperties.toMutableMap() + } + + /** The domain associated with the secret. */ + fun domain(domain: String) = domain(JsonField.of(domain)) + + /** + * Sets [Builder.domain] to an arbitrary JSON value. + * + * You should usually call [Builder.domain] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun domain(domain: JsonField) = apply { this.domain = domain } + + /** The name of the secret to inject for the domain. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** The secret value to inject for the domain. */ + fun value(value: String) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun value(value: JsonField) = apply { this.value = value } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ContainerNetworkPolicyDomainSecret]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .domain() + * .name() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ContainerNetworkPolicyDomainSecret = + ContainerNetworkPolicyDomainSecret( + checkRequired("domain", domain), + checkRequired("name", name), + checkRequired("value", value), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ContainerNetworkPolicyDomainSecret = apply { + if (validated) { + return@apply + } + + domain() + name() + value() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (domain.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (value.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ContainerNetworkPolicyDomainSecret && + domain == other.domain && + name == other.name && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(domain, name, value, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ContainerNetworkPolicyDomainSecret{domain=$domain, name=$name, value=$value, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerReference.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerReference.kt new file mode 100644 index 00000000..a4c48a57 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ContainerReference.kt @@ -0,0 +1,219 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +class ContainerReference +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val containerId: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("container_id") + @ExcludeMissing + containerId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(containerId, type, mutableMapOf()) + + /** + * The ID of the referenced container. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun containerId(): String = containerId.getRequired("container_id") + + /** + * References a container created with the /v1/containers endpoint + * + * Expected to always return the following: + * ```java + * JsonValue.from("container_reference") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Returns the raw JSON value of [containerId]. + * + * Unlike [containerId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("container_id") + @ExcludeMissing + fun _containerId(): JsonField = containerId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ContainerReference]. + * + * The following fields are required: + * ```java + * .containerId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ContainerReference]. */ + class Builder internal constructor() { + + private var containerId: JsonField? = null + private var type: JsonValue = JsonValue.from("container_reference") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(containerReference: ContainerReference) = apply { + containerId = containerReference.containerId + type = containerReference.type + additionalProperties = containerReference.additionalProperties.toMutableMap() + } + + /** The ID of the referenced container. */ + fun containerId(containerId: String) = containerId(JsonField.of(containerId)) + + /** + * Sets [Builder.containerId] to an arbitrary JSON value. + * + * You should usually call [Builder.containerId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun containerId(containerId: JsonField) = apply { this.containerId = containerId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("container_reference") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ContainerReference]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .containerId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ContainerReference = + ContainerReference( + checkRequired("containerId", containerId), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ContainerReference = apply { + if (validated) { + return@apply + } + + containerId() + _type().let { + if (it != JsonValue.from("container_reference")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (containerId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("container_reference")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ContainerReference && + containerId == other.containerId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(containerId, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ContainerReference{containerId=$containerId, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/FunctionShellTool.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/FunctionShellTool.kt index 3f08c0e7..e29d6357 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/FunctionShellTool.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/FunctionShellTool.kt @@ -6,25 +6,42 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer import com.openai.core.ExcludeMissing +import com.openai.core.JsonField import com.openai.core.JsonMissing import com.openai.core.JsonValue +import com.openai.core.getOrThrow import com.openai.errors.OpenAIInvalidDataException import java.util.Collections import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** A tool that allows the model to execute shell commands. */ class FunctionShellTool @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val type: JsonValue, + private val environment: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of() - ) : this(type, mutableMapOf()) + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("environment") + @ExcludeMissing + environment: JsonField = JsonMissing.of(), + ) : this(type, environment, mutableMapOf()) /** * The type of the shell tool. Always `shell`. @@ -39,6 +56,21 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun environment(): Optional = environment.getOptional("environment") + + /** + * Returns the raw JSON value of [environment]. + * + * Unlike [environment], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("environment") + @ExcludeMissing + fun _environment(): JsonField = environment + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -61,11 +93,13 @@ private constructor( class Builder internal constructor() { private var type: JsonValue = JsonValue.from("shell") + private var environment: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(functionShellTool: FunctionShellTool) = apply { type = functionShellTool.type + environment = functionShellTool.environment additionalProperties = functionShellTool.additionalProperties.toMutableMap() } @@ -83,6 +117,47 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun environment(environment: Environment?) = environment(JsonField.ofNullable(environment)) + + /** Alias for calling [Builder.environment] with `environment.orElse(null)`. */ + fun environment(environment: Optional) = environment(environment.getOrNull()) + + /** + * Sets [Builder.environment] to an arbitrary JSON value. + * + * You should usually call [Builder.environment] with a well-typed [Environment] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun environment(environment: JsonField) = apply { + this.environment = environment + } + + /** Alias for calling [environment] with `Environment.ofContainerAuto(containerAuto)`. */ + fun environment(containerAuto: ContainerAuto) = + environment(Environment.ofContainerAuto(containerAuto)) + + /** Alias for calling [environment] with `Environment.ofLocal(local)`. */ + fun environment(local: LocalEnvironment) = environment(Environment.ofLocal(local)) + + /** + * Alias for calling [environment] with + * `Environment.ofContainerReference(containerReference)`. + */ + fun environment(containerReference: ContainerReference) = + environment(Environment.ofContainerReference(containerReference)) + + /** + * Alias for calling [environment] with the following: + * ```java + * ContainerReference.builder() + * .containerId(containerId) + * .build() + * ``` + */ + fun containerReferenceEnvironment(containerId: String) = + environment(ContainerReference.builder().containerId(containerId).build()) + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -108,7 +183,7 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): FunctionShellTool = - FunctionShellTool(type, additionalProperties.toMutableMap()) + FunctionShellTool(type, environment, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -123,6 +198,7 @@ private constructor( throw OpenAIInvalidDataException("'type' is invalid, received $it") } } + environment().ifPresent { it.validate() } validated = true } @@ -140,7 +216,213 @@ private constructor( * Used for best match union deserialization. */ @JvmSynthetic - internal fun validity(): Int = type.let { if (it == JsonValue.from("shell")) 1 else 0 } + internal fun validity(): Int = + type.let { if (it == JsonValue.from("shell")) 1 else 0 } + + (environment.asKnown().getOrNull()?.validity() ?: 0) + + @JsonDeserialize(using = Environment.Deserializer::class) + @JsonSerialize(using = Environment.Serializer::class) + class Environment + private constructor( + private val containerAuto: ContainerAuto? = null, + private val local: LocalEnvironment? = null, + private val containerReference: ContainerReference? = null, + private val _json: JsonValue? = null, + ) { + + fun containerAuto(): Optional = Optional.ofNullable(containerAuto) + + fun local(): Optional = Optional.ofNullable(local) + + fun containerReference(): Optional = + Optional.ofNullable(containerReference) + + fun isContainerAuto(): Boolean = containerAuto != null + + fun isLocal(): Boolean = local != null + + fun isContainerReference(): Boolean = containerReference != null + + fun asContainerAuto(): ContainerAuto = containerAuto.getOrThrow("containerAuto") + + fun asLocal(): LocalEnvironment = local.getOrThrow("local") + + fun asContainerReference(): ContainerReference = + containerReference.getOrThrow("containerReference") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + containerAuto != null -> visitor.visitContainerAuto(containerAuto) + local != null -> visitor.visitLocal(local) + containerReference != null -> visitor.visitContainerReference(containerReference) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Environment = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitContainerAuto(containerAuto: ContainerAuto) { + containerAuto.validate() + } + + override fun visitLocal(local: LocalEnvironment) { + local.validate() + } + + override fun visitContainerReference(containerReference: ContainerReference) { + containerReference.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitContainerAuto(containerAuto: ContainerAuto) = + containerAuto.validity() + + override fun visitLocal(local: LocalEnvironment) = local.validity() + + override fun visitContainerReference(containerReference: ContainerReference) = + containerReference.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Environment && + containerAuto == other.containerAuto && + local == other.local && + containerReference == other.containerReference + } + + override fun hashCode(): Int = Objects.hash(containerAuto, local, containerReference) + + override fun toString(): String = + when { + containerAuto != null -> "Environment{containerAuto=$containerAuto}" + local != null -> "Environment{local=$local}" + containerReference != null -> "Environment{containerReference=$containerReference}" + _json != null -> "Environment{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Environment") + } + + companion object { + + @JvmStatic + fun ofContainerAuto(containerAuto: ContainerAuto) = + Environment(containerAuto = containerAuto) + + @JvmStatic fun ofLocal(local: LocalEnvironment) = Environment(local = local) + + @JvmStatic + fun ofContainerReference(containerReference: ContainerReference) = + Environment(containerReference = containerReference) + } + + /** + * An interface that defines how to map each variant of [Environment] to a value of type + * [T]. + */ + interface Visitor { + + fun visitContainerAuto(containerAuto: ContainerAuto): T + + fun visitLocal(local: LocalEnvironment): T + + fun visitContainerReference(containerReference: ContainerReference): T + + /** + * Maps an unknown variant of [Environment] to a value of type [T]. + * + * An instance of [Environment] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on an + * older version than the API, then the API may respond with new variants that the SDK + * is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Environment: $json") + } + } + + internal class Deserializer : BaseDeserializer(Environment::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Environment { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "container_auto" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Environment(containerAuto = it, _json = json) + } ?: Environment(_json = json) + } + "local" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Environment(local = it, _json = json) + } ?: Environment(_json = json) + } + "container_reference" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Environment(containerReference = it, _json = json) + } ?: Environment(_json = json) + } + } + + return Environment(_json = json) + } + } + + internal class Serializer : BaseSerializer(Environment::class) { + + override fun serialize( + value: Environment, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.containerAuto != null -> generator.writeObject(value.containerAuto) + value.local != null -> generator.writeObject(value.local) + value.containerReference != null -> + generator.writeObject(value.containerReference) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Environment") + } + } + } + } override fun equals(other: Any?): Boolean { if (this === other) { @@ -149,13 +431,14 @@ private constructor( return other is FunctionShellTool && type == other.type && + environment == other.environment && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(type, environment, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "FunctionShellTool{type=$type, additionalProperties=$additionalProperties}" + "FunctionShellTool{type=$type, environment=$environment, additionalProperties=$additionalProperties}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/InlineSkill.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/InlineSkill.kt new file mode 100644 index 00000000..dfb4b39a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/InlineSkill.kt @@ -0,0 +1,295 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class InlineSkill +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val description: JsonField, + private val name: JsonField, + private val source: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("source") + @ExcludeMissing + source: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(description, name, source, type, mutableMapOf()) + + /** + * The description of the skill. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun description(): String = description.getRequired("description") + + /** + * The name of the skill. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * Inline skill payload + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun source(): InlineSkillSource = source.getRequired("source") + + /** + * Defines an inline skill for this request. + * + * Expected to always return the following: + * ```java + * JsonValue.from("inline") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [InlineSkill]. + * + * The following fields are required: + * ```java + * .description() + * .name() + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InlineSkill]. */ + class Builder internal constructor() { + + private var description: JsonField? = null + private var name: JsonField? = null + private var source: JsonField? = null + private var type: JsonValue = JsonValue.from("inline") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inlineSkill: InlineSkill) = apply { + description = inlineSkill.description + name = inlineSkill.name + source = inlineSkill.source + type = inlineSkill.type + additionalProperties = inlineSkill.additionalProperties.toMutableMap() + } + + /** The description of the skill. */ + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** The name of the skill. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Inline skill payload */ + fun source(source: InlineSkillSource) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [InlineSkillSource] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("inline") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InlineSkill]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .description() + * .name() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InlineSkill = + InlineSkill( + checkRequired("description", description), + checkRequired("name", name), + checkRequired("source", source), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): InlineSkill = apply { + if (validated) { + return@apply + } + + description() + name() + source().validate() + _type().let { + if (it != JsonValue.from("inline")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (description.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (source.asKnown().getOrNull()?.validity() ?: 0) + + type.let { if (it == JsonValue.from("inline")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InlineSkill && + description == other.description && + name == other.name && + source == other.source && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(description, name, source, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InlineSkill{description=$description, name=$name, source=$source, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/InlineSkillSource.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/InlineSkillSource.kt new file mode 100644 index 00000000..bf1d7c49 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/InlineSkillSource.kt @@ -0,0 +1,254 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +/** Inline skill payload */ +class InlineSkillSource +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField, + private val mediaType: JsonValue, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("media_type") @ExcludeMissing mediaType: JsonValue = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(data, mediaType, type, mutableMapOf()) + + /** + * Base64-encoded skill zip bundle. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): String = data.getRequired("data") + + /** + * The media type of the inline skill payload. Must be `application/zip`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("application/zip") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("media_type") @ExcludeMissing fun _mediaType(): JsonValue = mediaType + + /** + * The type of the inline skill source. Must be `base64`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("base64") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [InlineSkillSource]. + * + * The following fields are required: + * ```java + * .data() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InlineSkillSource]. */ + class Builder internal constructor() { + + private var data: JsonField? = null + private var mediaType: JsonValue = JsonValue.from("application/zip") + private var type: JsonValue = JsonValue.from("base64") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inlineSkillSource: InlineSkillSource) = apply { + data = inlineSkillSource.data + mediaType = inlineSkillSource.mediaType + type = inlineSkillSource.type + additionalProperties = inlineSkillSource.additionalProperties.toMutableMap() + } + + /** Base64-encoded skill zip bundle. */ + fun data(data: String) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField) = apply { this.data = data } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("application/zip") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun mediaType(mediaType: JsonValue) = apply { this.mediaType = mediaType } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("base64") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InlineSkillSource]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InlineSkillSource = + InlineSkillSource( + checkRequired("data", data), + mediaType, + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): InlineSkillSource = apply { + if (validated) { + return@apply + } + + data() + _mediaType().let { + if (it != JsonValue.from("application/zip")) { + throw OpenAIInvalidDataException("'mediaType' is invalid, received $it") + } + } + _type().let { + if (it != JsonValue.from("base64")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (data.asKnown().isPresent) 1 else 0) + + mediaType.let { if (it == JsonValue.from("application/zip")) 1 else 0 } + + type.let { if (it == JsonValue.from("base64")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InlineSkillSource && + data == other.data && + mediaType == other.mediaType && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(data, mediaType, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InlineSkillSource{data=$data, mediaType=$mediaType, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/LocalEnvironment.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/LocalEnvironment.kt new file mode 100644 index 00000000..8f475f83 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/LocalEnvironment.kt @@ -0,0 +1,220 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class LocalEnvironment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val type: JsonValue, + private val skills: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("skills") + @ExcludeMissing + skills: JsonField> = JsonMissing.of(), + ) : this(type, skills, mutableMapOf()) + + /** + * Use a local computer environment. + * + * Expected to always return the following: + * ```java + * JsonValue.from("local") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * An optional list of skills. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun skills(): Optional> = skills.getOptional("skills") + + /** + * Returns the raw JSON value of [skills]. + * + * Unlike [skills], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("skills") @ExcludeMissing fun _skills(): JsonField> = skills + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [LocalEnvironment]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [LocalEnvironment]. */ + class Builder internal constructor() { + + private var type: JsonValue = JsonValue.from("local") + private var skills: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(localEnvironment: LocalEnvironment) = apply { + type = localEnvironment.type + skills = localEnvironment.skills.map { it.toMutableList() } + additionalProperties = localEnvironment.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("local") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** An optional list of skills. */ + fun skills(skills: List) = skills(JsonField.of(skills)) + + /** + * Sets [Builder.skills] to an arbitrary JSON value. + * + * You should usually call [Builder.skills] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun skills(skills: JsonField>) = apply { + this.skills = skills.map { it.toMutableList() } + } + + /** + * Adds a single [LocalSkill] to [skills]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSkill(skill: LocalSkill) = apply { + skills = + (skills ?: JsonField.of(mutableListOf())).also { + checkKnown("skills", it).add(skill) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [LocalEnvironment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): LocalEnvironment = + LocalEnvironment( + type, + (skills ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): LocalEnvironment = apply { + if (validated) { + return@apply + } + + _type().let { + if (it != JsonValue.from("local")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + skills().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + type.let { if (it == JsonValue.from("local")) 1 else 0 } + + (skills.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is LocalEnvironment && + type == other.type && + skills == other.skills && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(type, skills, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "LocalEnvironment{type=$type, skills=$skills, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/LocalSkill.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/LocalSkill.kt new file mode 100644 index 00000000..a63f9003 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/LocalSkill.kt @@ -0,0 +1,252 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +class LocalSkill +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val description: JsonField, + private val name: JsonField, + private val path: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("path") @ExcludeMissing path: JsonField = JsonMissing.of(), + ) : this(description, name, path, mutableMapOf()) + + /** + * The description of the skill. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun description(): String = description.getRequired("description") + + /** + * The name of the skill. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * The path to the directory containing the skill. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun path(): String = path.getRequired("path") + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [path]. + * + * Unlike [path], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("path") @ExcludeMissing fun _path(): JsonField = path + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [LocalSkill]. + * + * The following fields are required: + * ```java + * .description() + * .name() + * .path() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [LocalSkill]. */ + class Builder internal constructor() { + + private var description: JsonField? = null + private var name: JsonField? = null + private var path: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(localSkill: LocalSkill) = apply { + description = localSkill.description + name = localSkill.name + path = localSkill.path + additionalProperties = localSkill.additionalProperties.toMutableMap() + } + + /** The description of the skill. */ + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** The name of the skill. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** The path to the directory containing the skill. */ + fun path(path: String) = path(JsonField.of(path)) + + /** + * Sets [Builder.path] to an arbitrary JSON value. + * + * You should usually call [Builder.path] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun path(path: JsonField) = apply { this.path = path } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [LocalSkill]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .description() + * .name() + * .path() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): LocalSkill = + LocalSkill( + checkRequired("description", description), + checkRequired("name", name), + checkRequired("path", path), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): LocalSkill = apply { + if (validated) { + return@apply + } + + description() + name() + path() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (description.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (path.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is LocalSkill && + description == other.description && + name == other.name && + path == other.path && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(description, name, path, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "LocalSkill{description=$description, name=$name, path=$path, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContainerReference.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContainerReference.kt new file mode 100644 index 00000000..5cdb5d86 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContainerReference.kt @@ -0,0 +1,217 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +/** Represents a container created with /v1/containers. */ +class ResponseContainerReference +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val containerId: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("container_id") + @ExcludeMissing + containerId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(containerId, type, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun containerId(): String = containerId.getRequired("container_id") + + /** + * The environment type. Always `container_reference`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("container_reference") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Returns the raw JSON value of [containerId]. + * + * Unlike [containerId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("container_id") + @ExcludeMissing + fun _containerId(): JsonField = containerId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ResponseContainerReference]. + * + * The following fields are required: + * ```java + * .containerId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ResponseContainerReference]. */ + class Builder internal constructor() { + + private var containerId: JsonField? = null + private var type: JsonValue = JsonValue.from("container_reference") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(responseContainerReference: ResponseContainerReference) = apply { + containerId = responseContainerReference.containerId + type = responseContainerReference.type + additionalProperties = responseContainerReference.additionalProperties.toMutableMap() + } + + fun containerId(containerId: String) = containerId(JsonField.of(containerId)) + + /** + * Sets [Builder.containerId] to an arbitrary JSON value. + * + * You should usually call [Builder.containerId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun containerId(containerId: JsonField) = apply { this.containerId = containerId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("container_reference") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ResponseContainerReference]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .containerId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ResponseContainerReference = + ResponseContainerReference( + checkRequired("containerId", containerId), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ResponseContainerReference = apply { + if (validated) { + return@apply + } + + containerId() + _type().let { + if (it != JsonValue.from("container_reference")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (containerId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("container_reference")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ResponseContainerReference && + containerId == other.containerId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(containerId, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ResponseContainerReference{containerId=$containerId, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionShellToolCall.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionShellToolCall.kt index 9111064a..132d87cf 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionShellToolCall.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionShellToolCall.kt @@ -6,6 +6,15 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer import com.openai.core.Enum import com.openai.core.ExcludeMissing import com.openai.core.JsonField @@ -13,6 +22,7 @@ import com.openai.core.JsonMissing import com.openai.core.JsonValue import com.openai.core.checkKnown import com.openai.core.checkRequired +import com.openai.core.getOrThrow import com.openai.core.toImmutable import com.openai.errors.OpenAIInvalidDataException import java.util.Collections @@ -27,6 +37,7 @@ private constructor( private val id: JsonField, private val action: JsonField, private val callId: JsonField, + private val environment: JsonField, private val status: JsonField, private val type: JsonValue, private val createdBy: JsonField, @@ -38,10 +49,13 @@ private constructor( @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), @JsonProperty("action") @ExcludeMissing action: JsonField = JsonMissing.of(), @JsonProperty("call_id") @ExcludeMissing callId: JsonField = JsonMissing.of(), + @JsonProperty("environment") + @ExcludeMissing + environment: JsonField = JsonMissing.of(), @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), @JsonProperty("created_by") @ExcludeMissing createdBy: JsonField = JsonMissing.of(), - ) : this(id, action, callId, status, type, createdBy, mutableMapOf()) + ) : this(id, action, callId, environment, status, type, createdBy, mutableMapOf()) /** * The unique ID of the shell tool call. Populated when this item is returned via API. @@ -67,6 +81,14 @@ private constructor( */ fun callId(): String = callId.getRequired("call_id") + /** + * Represents the use of a local environment to perform shell actions. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun environment(): Optional = environment.getOptional("environment") + /** * The status of the shell call. One of `in_progress`, `completed`, or `incomplete`. * @@ -117,6 +139,15 @@ private constructor( */ @JsonProperty("call_id") @ExcludeMissing fun _callId(): JsonField = callId + /** + * Returns the raw JSON value of [environment]. + * + * Unlike [environment], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("environment") + @ExcludeMissing + fun _environment(): JsonField = environment + /** * Returns the raw JSON value of [status]. * @@ -154,6 +185,7 @@ private constructor( * .id() * .action() * .callId() + * .environment() * .status() * ``` */ @@ -166,6 +198,7 @@ private constructor( private var id: JsonField? = null private var action: JsonField? = null private var callId: JsonField? = null + private var environment: JsonField? = null private var status: JsonField? = null private var type: JsonValue = JsonValue.from("shell_call") private var createdBy: JsonField = JsonMissing.of() @@ -176,6 +209,7 @@ private constructor( id = responseFunctionShellToolCall.id action = responseFunctionShellToolCall.action callId = responseFunctionShellToolCall.callId + environment = responseFunctionShellToolCall.environment status = responseFunctionShellToolCall.status type = responseFunctionShellToolCall.type createdBy = responseFunctionShellToolCall.createdBy @@ -215,6 +249,44 @@ private constructor( */ fun callId(callId: JsonField) = apply { this.callId = callId } + /** Represents the use of a local environment to perform shell actions. */ + fun environment(environment: Environment?) = environment(JsonField.ofNullable(environment)) + + /** Alias for calling [Builder.environment] with `environment.orElse(null)`. */ + fun environment(environment: Optional) = environment(environment.getOrNull()) + + /** + * Sets [Builder.environment] to an arbitrary JSON value. + * + * You should usually call [Builder.environment] with a well-typed [Environment] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun environment(environment: JsonField) = apply { + this.environment = environment + } + + /** Alias for calling [environment] with `Environment.ofLocal(local)`. */ + fun environment(local: ResponseLocalEnvironment) = environment(Environment.ofLocal(local)) + + /** + * Alias for calling [environment] with + * `Environment.ofContainerReference(containerReference)`. + */ + fun environment(containerReference: ResponseContainerReference) = + environment(Environment.ofContainerReference(containerReference)) + + /** + * Alias for calling [environment] with the following: + * ```java + * ResponseContainerReference.builder() + * .containerId(containerId) + * .build() + * ``` + */ + fun containerReferenceEnvironment(containerId: String) = + environment(ResponseContainerReference.builder().containerId(containerId).build()) + /** The status of the shell call. One of `in_progress`, `completed`, or `incomplete`. */ fun status(status: Status) = status(JsonField.of(status)) @@ -281,6 +353,7 @@ private constructor( * .id() * .action() * .callId() + * .environment() * .status() * ``` * @@ -291,6 +364,7 @@ private constructor( checkRequired("id", id), checkRequired("action", action), checkRequired("callId", callId), + checkRequired("environment", environment), checkRequired("status", status), type, createdBy, @@ -308,6 +382,7 @@ private constructor( id() action().validate() callId() + environment().ifPresent { it.validate() } status().validate() _type().let { if (it != JsonValue.from("shell_call")) { @@ -336,6 +411,7 @@ private constructor( (if (id.asKnown().isPresent) 1 else 0) + (action.asKnown().getOrNull()?.validity() ?: 0) + (if (callId.asKnown().isPresent) 1 else 0) + + (environment.asKnown().getOrNull()?.validity() ?: 0) + (status.asKnown().getOrNull()?.validity() ?: 0) + type.let { if (it == JsonValue.from("shell_call")) 1 else 0 } + (if (createdBy.asKnown().isPresent) 1 else 0) @@ -624,6 +700,193 @@ private constructor( "Action{commands=$commands, maxOutputLength=$maxOutputLength, timeoutMs=$timeoutMs, additionalProperties=$additionalProperties}" } + /** Represents the use of a local environment to perform shell actions. */ + @JsonDeserialize(using = Environment.Deserializer::class) + @JsonSerialize(using = Environment.Serializer::class) + class Environment + private constructor( + private val local: ResponseLocalEnvironment? = null, + private val containerReference: ResponseContainerReference? = null, + private val _json: JsonValue? = null, + ) { + + /** Represents the use of a local environment to perform shell actions. */ + fun local(): Optional = Optional.ofNullable(local) + + /** Represents a container created with /v1/containers. */ + fun containerReference(): Optional = + Optional.ofNullable(containerReference) + + fun isLocal(): Boolean = local != null + + fun isContainerReference(): Boolean = containerReference != null + + /** Represents the use of a local environment to perform shell actions. */ + fun asLocal(): ResponseLocalEnvironment = local.getOrThrow("local") + + /** Represents a container created with /v1/containers. */ + fun asContainerReference(): ResponseContainerReference = + containerReference.getOrThrow("containerReference") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + local != null -> visitor.visitLocal(local) + containerReference != null -> visitor.visitContainerReference(containerReference) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Environment = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitLocal(local: ResponseLocalEnvironment) { + local.validate() + } + + override fun visitContainerReference( + containerReference: ResponseContainerReference + ) { + containerReference.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitLocal(local: ResponseLocalEnvironment) = local.validity() + + override fun visitContainerReference( + containerReference: ResponseContainerReference + ) = containerReference.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Environment && + local == other.local && + containerReference == other.containerReference + } + + override fun hashCode(): Int = Objects.hash(local, containerReference) + + override fun toString(): String = + when { + local != null -> "Environment{local=$local}" + containerReference != null -> "Environment{containerReference=$containerReference}" + _json != null -> "Environment{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Environment") + } + + companion object { + + /** Represents the use of a local environment to perform shell actions. */ + @JvmStatic fun ofLocal(local: ResponseLocalEnvironment) = Environment(local = local) + + /** Represents a container created with /v1/containers. */ + @JvmStatic + fun ofContainerReference(containerReference: ResponseContainerReference) = + Environment(containerReference = containerReference) + } + + /** + * An interface that defines how to map each variant of [Environment] to a value of type + * [T]. + */ + interface Visitor { + + /** Represents the use of a local environment to perform shell actions. */ + fun visitLocal(local: ResponseLocalEnvironment): T + + /** Represents a container created with /v1/containers. */ + fun visitContainerReference(containerReference: ResponseContainerReference): T + + /** + * Maps an unknown variant of [Environment] to a value of type [T]. + * + * An instance of [Environment] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on an + * older version than the API, then the API may respond with new variants that the SDK + * is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Environment: $json") + } + } + + internal class Deserializer : BaseDeserializer(Environment::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Environment { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "local" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Environment(local = it, _json = json) } + ?: Environment(_json = json) + } + "container_reference" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Environment(containerReference = it, _json = json) } + ?: Environment(_json = json) + } + } + + return Environment(_json = json) + } + } + + internal class Serializer : BaseSerializer(Environment::class) { + + override fun serialize( + value: Environment, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.local != null -> generator.writeObject(value.local) + value.containerReference != null -> + generator.writeObject(value.containerReference) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Environment") + } + } + } + } + /** The status of the shell call. One of `in_progress`, `completed`, or `incomplete`. */ class Status @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -765,6 +1028,7 @@ private constructor( id == other.id && action == other.action && callId == other.callId && + environment == other.environment && status == other.status && type == other.type && createdBy == other.createdBy && @@ -772,11 +1036,11 @@ private constructor( } private val hashCode: Int by lazy { - Objects.hash(id, action, callId, status, type, createdBy, additionalProperties) + Objects.hash(id, action, callId, environment, status, type, createdBy, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "ResponseFunctionShellToolCall{id=$id, action=$action, callId=$callId, status=$status, type=$type, createdBy=$createdBy, additionalProperties=$additionalProperties}" + "ResponseFunctionShellToolCall{id=$id, action=$action, callId=$callId, environment=$environment, status=$status, type=$type, createdBy=$createdBy, additionalProperties=$additionalProperties}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseInputItem.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseInputItem.kt index 463c649e..74cf7df7 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseInputItem.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseInputItem.kt @@ -5254,6 +5254,7 @@ private constructor( private val callId: JsonField, private val type: JsonValue, private val id: JsonField, + private val environment: JsonField, private val status: JsonField, private val additionalProperties: MutableMap, ) { @@ -5264,8 +5265,11 @@ private constructor( @JsonProperty("call_id") @ExcludeMissing callId: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("environment") + @ExcludeMissing + environment: JsonField = JsonMissing.of(), @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), - ) : this(action, callId, type, id, status, mutableMapOf()) + ) : this(action, callId, type, id, environment, status, mutableMapOf()) /** * The shell commands and limits that describe how to run the tool call. @@ -5304,6 +5308,14 @@ private constructor( */ fun id(): Optional = id.getOptional("id") + /** + * The environment to execute the shell commands in. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun environment(): Optional = environment.getOptional("environment") + /** * The status of the shell call. One of `in_progress`, `completed`, or `incomplete`. * @@ -5333,6 +5345,15 @@ private constructor( */ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + /** + * Returns the raw JSON value of [environment]. + * + * Unlike [environment], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("environment") + @ExcludeMissing + fun _environment(): JsonField = environment + /** * Returns the raw JSON value of [status]. * @@ -5373,6 +5394,7 @@ private constructor( private var callId: JsonField? = null private var type: JsonValue = JsonValue.from("shell_call") private var id: JsonField = JsonMissing.of() + private var environment: JsonField = JsonMissing.of() private var status: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -5382,6 +5404,7 @@ private constructor( callId = shellCall.callId type = shellCall.type id = shellCall.id + environment = shellCall.environment status = shellCall.status additionalProperties = shellCall.additionalProperties.toMutableMap() } @@ -5441,6 +5464,46 @@ private constructor( */ fun id(id: JsonField) = apply { this.id = id } + /** The environment to execute the shell commands in. */ + fun environment(environment: Environment?) = + environment(JsonField.ofNullable(environment)) + + /** Alias for calling [Builder.environment] with `environment.orElse(null)`. */ + fun environment(environment: Optional) = + environment(environment.getOrNull()) + + /** + * Sets [Builder.environment] to an arbitrary JSON value. + * + * You should usually call [Builder.environment] with a well-typed [Environment] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun environment(environment: JsonField) = apply { + this.environment = environment + } + + /** Alias for calling [environment] with `Environment.ofLocal(local)`. */ + fun environment(local: LocalEnvironment) = environment(Environment.ofLocal(local)) + + /** + * Alias for calling [environment] with + * `Environment.ofContainerReference(containerReference)`. + */ + fun environment(containerReference: ContainerReference) = + environment(Environment.ofContainerReference(containerReference)) + + /** + * Alias for calling [environment] with the following: + * ```java + * ContainerReference.builder() + * .containerId(containerId) + * .build() + * ``` + */ + fun containerReferenceEnvironment(containerId: String) = + environment(ContainerReference.builder().containerId(containerId).build()) + /** The status of the shell call. One of `in_progress`, `completed`, or `incomplete`. */ fun status(status: Status?) = status(JsonField.ofNullable(status)) @@ -5494,6 +5557,7 @@ private constructor( checkRequired("callId", callId), type, id, + environment, status, additionalProperties.toMutableMap(), ) @@ -5514,6 +5578,7 @@ private constructor( } } id() + environment().ifPresent { it.validate() } status().ifPresent { it.validate() } validated = true } @@ -5538,6 +5603,7 @@ private constructor( (if (callId.asKnown().isPresent) 1 else 0) + type.let { if (it == JsonValue.from("shell_call")) 1 else 0 } + (if (id.asKnown().isPresent) 1 else 0) + + (environment.asKnown().getOrNull()?.validity() ?: 0) + (status.asKnown().getOrNull()?.validity() ?: 0) /** The shell commands and limits that describe how to run the tool call. */ @@ -5837,6 +5903,187 @@ private constructor( "Action{commands=$commands, maxOutputLength=$maxOutputLength, timeoutMs=$timeoutMs, additionalProperties=$additionalProperties}" } + /** The environment to execute the shell commands in. */ + @JsonDeserialize(using = Environment.Deserializer::class) + @JsonSerialize(using = Environment.Serializer::class) + class Environment + private constructor( + private val local: LocalEnvironment? = null, + private val containerReference: ContainerReference? = null, + private val _json: JsonValue? = null, + ) { + + fun local(): Optional = Optional.ofNullable(local) + + fun containerReference(): Optional = + Optional.ofNullable(containerReference) + + fun isLocal(): Boolean = local != null + + fun isContainerReference(): Boolean = containerReference != null + + fun asLocal(): LocalEnvironment = local.getOrThrow("local") + + fun asContainerReference(): ContainerReference = + containerReference.getOrThrow("containerReference") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + local != null -> visitor.visitLocal(local) + containerReference != null -> + visitor.visitContainerReference(containerReference) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Environment = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitLocal(local: LocalEnvironment) { + local.validate() + } + + override fun visitContainerReference( + containerReference: ContainerReference + ) { + containerReference.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitLocal(local: LocalEnvironment) = local.validity() + + override fun visitContainerReference( + containerReference: ContainerReference + ) = containerReference.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Environment && + local == other.local && + containerReference == other.containerReference + } + + override fun hashCode(): Int = Objects.hash(local, containerReference) + + override fun toString(): String = + when { + local != null -> "Environment{local=$local}" + containerReference != null -> + "Environment{containerReference=$containerReference}" + _json != null -> "Environment{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Environment") + } + + companion object { + + @JvmStatic fun ofLocal(local: LocalEnvironment) = Environment(local = local) + + @JvmStatic + fun ofContainerReference(containerReference: ContainerReference) = + Environment(containerReference = containerReference) + } + + /** + * An interface that defines how to map each variant of [Environment] to a value of type + * [T]. + */ + interface Visitor { + + fun visitLocal(local: LocalEnvironment): T + + fun visitContainerReference(containerReference: ContainerReference): T + + /** + * Maps an unknown variant of [Environment] to a value of type [T]. + * + * An instance of [Environment] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if the + * SDK is on an older version than the API, then the API may respond with new + * variants that the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Environment: $json") + } + } + + internal class Deserializer : BaseDeserializer(Environment::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Environment { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "local" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Environment(local = it, _json = json) + } ?: Environment(_json = json) + } + "container_reference" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Environment(containerReference = it, _json = json) + } ?: Environment(_json = json) + } + } + + return Environment(_json = json) + } + } + + internal class Serializer : BaseSerializer(Environment::class) { + + override fun serialize( + value: Environment, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.local != null -> generator.writeObject(value.local) + value.containerReference != null -> + generator.writeObject(value.containerReference) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Environment") + } + } + } + } + /** The status of the shell call. One of `in_progress`, `completed`, or `incomplete`. */ class Status @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -5983,18 +6230,19 @@ private constructor( callId == other.callId && type == other.type && id == other.id && + environment == other.environment && status == other.status && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(action, callId, type, id, status, additionalProperties) + Objects.hash(action, callId, type, id, environment, status, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "ShellCall{action=$action, callId=$callId, type=$type, id=$id, status=$status, additionalProperties=$additionalProperties}" + "ShellCall{action=$action, callId=$callId, type=$type, id=$id, environment=$environment, status=$status, additionalProperties=$additionalProperties}" } /** The streamed output items emitted by a shell tool call. */ diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseLocalEnvironment.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseLocalEnvironment.kt new file mode 100644 index 00000000..719aef2d --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseLocalEnvironment.kt @@ -0,0 +1,161 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +/** Represents the use of a local environment to perform shell actions. */ +class ResponseLocalEnvironment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of() + ) : this(type, mutableMapOf()) + + /** + * The environment type. Always `local`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("local") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [ResponseLocalEnvironment]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ResponseLocalEnvironment]. */ + class Builder internal constructor() { + + private var type: JsonValue = JsonValue.from("local") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(responseLocalEnvironment: ResponseLocalEnvironment) = apply { + type = responseLocalEnvironment.type + additionalProperties = responseLocalEnvironment.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("local") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ResponseLocalEnvironment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ResponseLocalEnvironment = + ResponseLocalEnvironment(type, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): ResponseLocalEnvironment = apply { + if (validated) { + return@apply + } + + _type().let { + if (it != JsonValue.from("local")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = type.let { if (it == JsonValue.from("local")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ResponseLocalEnvironment && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ResponseLocalEnvironment{type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/SkillReference.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/SkillReference.kt new file mode 100644 index 00000000..b84b877b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/SkillReference.kt @@ -0,0 +1,249 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional + +class SkillReference +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val skillId: JsonField, + private val type: JsonValue, + private val version: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("skill_id") @ExcludeMissing skillId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(skillId, type, version, mutableMapOf()) + + /** + * The ID of the referenced skill. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun skillId(): String = skillId.getRequired("skill_id") + + /** + * References a skill created with the /v1/skills endpoint. + * + * Expected to always return the following: + * ```java + * JsonValue.from("skill_reference") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Optional skill version. Use a positive integer or 'latest'. Omit for default. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun version(): Optional = version.getOptional("version") + + /** + * Returns the raw JSON value of [skillId]. + * + * Unlike [skillId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("skill_id") @ExcludeMissing fun _skillId(): JsonField = skillId + + /** + * Returns the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SkillReference]. + * + * The following fields are required: + * ```java + * .skillId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SkillReference]. */ + class Builder internal constructor() { + + private var skillId: JsonField? = null + private var type: JsonValue = JsonValue.from("skill_reference") + private var version: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(skillReference: SkillReference) = apply { + skillId = skillReference.skillId + type = skillReference.type + version = skillReference.version + additionalProperties = skillReference.additionalProperties.toMutableMap() + } + + /** The ID of the referenced skill. */ + fun skillId(skillId: String) = skillId(JsonField.of(skillId)) + + /** + * Sets [Builder.skillId] to an arbitrary JSON value. + * + * You should usually call [Builder.skillId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun skillId(skillId: JsonField) = apply { this.skillId = skillId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("skill_reference") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Optional skill version. Use a positive integer or 'latest'. Omit for default. */ + fun version(version: String) = version(JsonField.of(version)) + + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun version(version: JsonField) = apply { this.version = version } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [SkillReference]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .skillId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SkillReference = + SkillReference( + checkRequired("skillId", skillId), + type, + version, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SkillReference = apply { + if (validated) { + return@apply + } + + skillId() + _type().let { + if (it != JsonValue.from("skill_reference")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + version() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (skillId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("skill_reference")) 1 else 0 } + + (if (version.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SkillReference && + skillId == other.skillId && + type == other.type && + version == other.version && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(skillId, type, version, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SkillReference{skillId=$skillId, type=$type, version=$version, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/Tool.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/Tool.kt index 7589d318..c66219aa 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/Tool.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/Tool.kt @@ -3370,6 +3370,7 @@ private constructor( private val type: JsonValue, private val fileIds: JsonField>, private val memoryLimit: JsonField, + private val networkPolicy: JsonField, private val additionalProperties: MutableMap, ) { @@ -3382,7 +3383,10 @@ private constructor( @JsonProperty("memory_limit") @ExcludeMissing memoryLimit: JsonField = JsonMissing.of(), - ) : this(type, fileIds, memoryLimit, mutableMapOf()) + @JsonProperty("network_policy") + @ExcludeMissing + networkPolicy: JsonField = JsonMissing.of(), + ) : this(type, fileIds, memoryLimit, networkPolicy, mutableMapOf()) /** * Always `auto`. @@ -3413,6 +3417,15 @@ private constructor( */ fun memoryLimit(): Optional = memoryLimit.getOptional("memory_limit") + /** + * Network access policy for the container. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun networkPolicy(): Optional = + networkPolicy.getOptional("network_policy") + /** * Returns the raw JSON value of [fileIds]. * @@ -3433,6 +3446,16 @@ private constructor( @ExcludeMissing fun _memoryLimit(): JsonField = memoryLimit + /** + * Returns the raw JSON value of [networkPolicy]. + * + * Unlike [networkPolicy], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("network_policy") + @ExcludeMissing + fun _networkPolicy(): JsonField = networkPolicy + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -3460,6 +3483,7 @@ private constructor( private var type: JsonValue = JsonValue.from("auto") private var fileIds: JsonField>? = null private var memoryLimit: JsonField = JsonMissing.of() + private var networkPolicy: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -3467,6 +3491,7 @@ private constructor( type = codeInterpreterToolAuto.type fileIds = codeInterpreterToolAuto.fileIds.map { it.toMutableList() } memoryLimit = codeInterpreterToolAuto.memoryLimit + networkPolicy = codeInterpreterToolAuto.networkPolicy additionalProperties = codeInterpreterToolAuto.additionalProperties.toMutableMap() } @@ -3530,6 +3555,49 @@ private constructor( this.memoryLimit = memoryLimit } + /** Network access policy for the container. */ + fun networkPolicy(networkPolicy: NetworkPolicy) = + networkPolicy(JsonField.of(networkPolicy)) + + /** + * Sets [Builder.networkPolicy] to an arbitrary JSON value. + * + * You should usually call [Builder.networkPolicy] with a well-typed + * [NetworkPolicy] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun networkPolicy(networkPolicy: JsonField) = apply { + this.networkPolicy = networkPolicy + } + + /** + * Alias for calling [networkPolicy] with `NetworkPolicy.ofDisabled(disabled)`. + */ + fun networkPolicy(disabled: ContainerNetworkPolicyDisabled) = + networkPolicy(NetworkPolicy.ofDisabled(disabled)) + + /** + * Alias for calling [networkPolicy] with + * `NetworkPolicy.ofAllowlist(allowlist)`. + */ + fun networkPolicy(allowlist: ContainerNetworkPolicyAllowlist) = + networkPolicy(NetworkPolicy.ofAllowlist(allowlist)) + + /** + * Alias for calling [networkPolicy] with the following: + * ```java + * ContainerNetworkPolicyAllowlist.builder() + * .allowedDomains(allowedDomains) + * .build() + * ``` + */ + fun allowlistNetworkPolicy(allowedDomains: List) = + networkPolicy( + ContainerNetworkPolicyAllowlist.builder() + .allowedDomains(allowedDomains) + .build() + ) + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -3562,6 +3630,7 @@ private constructor( type, (fileIds ?: JsonMissing.of()).map { it.toImmutable() }, memoryLimit, + networkPolicy, additionalProperties.toMutableMap(), ) } @@ -3580,6 +3649,7 @@ private constructor( } fileIds() memoryLimit().ifPresent { it.validate() } + networkPolicy().ifPresent { it.validate() } validated = true } @@ -3601,7 +3671,8 @@ private constructor( internal fun validity(): Int = type.let { if (it == JsonValue.from("auto")) 1 else 0 } + (fileIds.asKnown().getOrNull()?.size ?: 0) + - (memoryLimit.asKnown().getOrNull()?.validity() ?: 0) + (memoryLimit.asKnown().getOrNull()?.validity() ?: 0) + + (networkPolicy.asKnown().getOrNull()?.validity() ?: 0) /** The memory limit for the code interpreter container. */ class MemoryLimit @@ -3752,6 +3823,201 @@ private constructor( override fun toString() = value.toString() } + /** Network access policy for the container. */ + @JsonDeserialize(using = NetworkPolicy.Deserializer::class) + @JsonSerialize(using = NetworkPolicy.Serializer::class) + class NetworkPolicy + private constructor( + private val disabled: ContainerNetworkPolicyDisabled? = null, + private val allowlist: ContainerNetworkPolicyAllowlist? = null, + private val _json: JsonValue? = null, + ) { + + fun disabled(): Optional = + Optional.ofNullable(disabled) + + fun allowlist(): Optional = + Optional.ofNullable(allowlist) + + fun isDisabled(): Boolean = disabled != null + + fun isAllowlist(): Boolean = allowlist != null + + fun asDisabled(): ContainerNetworkPolicyDisabled = + disabled.getOrThrow("disabled") + + fun asAllowlist(): ContainerNetworkPolicyAllowlist = + allowlist.getOrThrow("allowlist") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + disabled != null -> visitor.visitDisabled(disabled) + allowlist != null -> visitor.visitAllowlist(allowlist) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): NetworkPolicy = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitDisabled( + disabled: ContainerNetworkPolicyDisabled + ) { + disabled.validate() + } + + override fun visitAllowlist( + allowlist: ContainerNetworkPolicyAllowlist + ) { + allowlist.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitDisabled( + disabled: ContainerNetworkPolicyDisabled + ) = disabled.validity() + + override fun visitAllowlist( + allowlist: ContainerNetworkPolicyAllowlist + ) = allowlist.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is NetworkPolicy && + disabled == other.disabled && + allowlist == other.allowlist + } + + override fun hashCode(): Int = Objects.hash(disabled, allowlist) + + override fun toString(): String = + when { + disabled != null -> "NetworkPolicy{disabled=$disabled}" + allowlist != null -> "NetworkPolicy{allowlist=$allowlist}" + _json != null -> "NetworkPolicy{_unknown=$_json}" + else -> throw IllegalStateException("Invalid NetworkPolicy") + } + + companion object { + + @JvmStatic + fun ofDisabled(disabled: ContainerNetworkPolicyDisabled) = + NetworkPolicy(disabled = disabled) + + @JvmStatic + fun ofAllowlist(allowlist: ContainerNetworkPolicyAllowlist) = + NetworkPolicy(allowlist = allowlist) + } + + /** + * An interface that defines how to map each variant of [NetworkPolicy] to a + * value of type [T]. + */ + interface Visitor { + + fun visitDisabled(disabled: ContainerNetworkPolicyDisabled): T + + fun visitAllowlist(allowlist: ContainerNetworkPolicyAllowlist): T + + /** + * Maps an unknown variant of [NetworkPolicy] to a value of type [T]. + * + * An instance of [NetworkPolicy] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, + * if the SDK is on an older version than the API, then the API may respond + * with new variants that the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown NetworkPolicy: $json") + } + } + + internal class Deserializer : + BaseDeserializer(NetworkPolicy::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): NetworkPolicy { + val json = JsonValue.fromJsonNode(node) + val type = + json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "disabled" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { NetworkPolicy(disabled = it, _json = json) } + ?: NetworkPolicy(_json = json) + } + "allowlist" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { NetworkPolicy(allowlist = it, _json = json) } + ?: NetworkPolicy(_json = json) + } + } + + return NetworkPolicy(_json = json) + } + } + + internal class Serializer : + BaseSerializer(NetworkPolicy::class) { + + override fun serialize( + value: NetworkPolicy, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.disabled != null -> generator.writeObject(value.disabled) + value.allowlist != null -> generator.writeObject(value.allowlist) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid NetworkPolicy") + } + } + } + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3761,17 +4027,18 @@ private constructor( type == other.type && fileIds == other.fileIds && memoryLimit == other.memoryLimit && + networkPolicy == other.networkPolicy && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(type, fileIds, memoryLimit, additionalProperties) + Objects.hash(type, fileIds, memoryLimit, networkPolicy, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "CodeInterpreterToolAuto{type=$type, fileIds=$fileIds, memoryLimit=$memoryLimit, additionalProperties=$additionalProperties}" + "CodeInterpreterToolAuto{type=$type, fileIds=$fileIds, memoryLimit=$memoryLimit, networkPolicy=$networkPolicy, additionalProperties=$additionalProperties}" } } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/DeletedSkill.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/DeletedSkill.kt new file mode 100644 index 00000000..5ff762f9 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/DeletedSkill.kt @@ -0,0 +1,242 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +class DeletedSkill +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val deleted: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("deleted") @ExcludeMissing deleted: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(id, deleted, object_, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun deleted(): Boolean = deleted.getRequired("deleted") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("skill.deleted") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [deleted]. + * + * Unlike [deleted], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("deleted") @ExcludeMissing fun _deleted(): JsonField = deleted + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [DeletedSkill]. + * + * The following fields are required: + * ```java + * .id() + * .deleted() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DeletedSkill]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var deleted: JsonField? = null + private var object_: JsonValue = JsonValue.from("skill.deleted") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(deletedSkill: DeletedSkill) = apply { + id = deletedSkill.id + deleted = deletedSkill.deleted + object_ = deletedSkill.object_ + additionalProperties = deletedSkill.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun deleted(deleted: Boolean) = deleted(JsonField.of(deleted)) + + /** + * Sets [Builder.deleted] to an arbitrary JSON value. + * + * You should usually call [Builder.deleted] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun deleted(deleted: JsonField) = apply { this.deleted = deleted } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("skill.deleted") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [DeletedSkill]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .deleted() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DeletedSkill = + DeletedSkill( + checkRequired("id", id), + checkRequired("deleted", deleted), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): DeletedSkill = apply { + if (validated) { + return@apply + } + + id() + deleted() + _object_().let { + if (it != JsonValue.from("skill.deleted")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (deleted.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("skill.deleted")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DeletedSkill && + id == other.id && + deleted == other.deleted && + object_ == other.object_ && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, deleted, object_, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DeletedSkill{id=$id, deleted=$deleted, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/Skill.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/Skill.kt new file mode 100644 index 00000000..d68b9990 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/Skill.kt @@ -0,0 +1,431 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +class Skill +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val defaultVersion: JsonField, + private val description: JsonField, + private val latestVersion: JsonField, + private val name: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("default_version") + @ExcludeMissing + defaultVersion: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("latest_version") + @ExcludeMissing + latestVersion: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this( + id, + createdAt, + defaultVersion, + description, + latestVersion, + name, + object_, + mutableMapOf(), + ) + + /** + * Unique identifier for the skill. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * Unix timestamp (seconds) for when the skill was created. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): Long = createdAt.getRequired("created_at") + + /** + * Default version for the skill. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun defaultVersion(): String = defaultVersion.getRequired("default_version") + + /** + * Description of the skill. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun description(): String = description.getRequired("description") + + /** + * Latest version for the skill. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun latestVersion(): String = latestVersion.getRequired("latest_version") + + /** + * Name of the skill. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * The object type, which is `skill`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("skill") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [defaultVersion]. + * + * Unlike [defaultVersion], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("default_version") + @ExcludeMissing + fun _defaultVersion(): JsonField = defaultVersion + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [latestVersion]. + * + * Unlike [latestVersion], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("latest_version") + @ExcludeMissing + fun _latestVersion(): JsonField = latestVersion + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Skill]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .defaultVersion() + * .description() + * .latestVersion() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Skill]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var defaultVersion: JsonField? = null + private var description: JsonField? = null + private var latestVersion: JsonField? = null + private var name: JsonField? = null + private var object_: JsonValue = JsonValue.from("skill") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(skill: Skill) = apply { + id = skill.id + createdAt = skill.createdAt + defaultVersion = skill.defaultVersion + description = skill.description + latestVersion = skill.latestVersion + name = skill.name + object_ = skill.object_ + additionalProperties = skill.additionalProperties.toMutableMap() + } + + /** Unique identifier for the skill. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Unix timestamp (seconds) for when the skill was created. */ + fun createdAt(createdAt: Long) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Default version for the skill. */ + fun defaultVersion(defaultVersion: String) = defaultVersion(JsonField.of(defaultVersion)) + + /** + * Sets [Builder.defaultVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun defaultVersion(defaultVersion: JsonField) = apply { + this.defaultVersion = defaultVersion + } + + /** Description of the skill. */ + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** Latest version for the skill. */ + fun latestVersion(latestVersion: String) = latestVersion(JsonField.of(latestVersion)) + + /** + * Sets [Builder.latestVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.latestVersion] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun latestVersion(latestVersion: JsonField) = apply { + this.latestVersion = latestVersion + } + + /** Name of the skill. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("skill") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Skill]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .defaultVersion() + * .description() + * .latestVersion() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Skill = + Skill( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("defaultVersion", defaultVersion), + checkRequired("description", description), + checkRequired("latestVersion", latestVersion), + checkRequired("name", name), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Skill = apply { + if (validated) { + return@apply + } + + id() + createdAt() + defaultVersion() + description() + latestVersion() + name() + _object_().let { + if (it != JsonValue.from("skill")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (defaultVersion.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (latestVersion.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("skill")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Skill && + id == other.id && + createdAt == other.createdAt && + defaultVersion == other.defaultVersion && + description == other.description && + latestVersion == other.latestVersion && + name == other.name && + object_ == other.object_ && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + defaultVersion, + description, + latestVersion, + name, + object_, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Skill{id=$id, createdAt=$createdAt, defaultVersion=$defaultVersion, description=$description, latestVersion=$latestVersion, name=$name, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillCreateParams.kt new file mode 100644 index 00000000..841227b4 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillCreateParams.kt @@ -0,0 +1,557 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.openai.core.BaseSerializer +import com.openai.core.ExcludeMissing +import com.openai.core.JsonValue +import com.openai.core.MultipartField +import com.openai.core.Params +import com.openai.core.getOrThrow +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.io.InputStream +import java.nio.file.Path +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.io.path.inputStream +import kotlin.io.path.name + +/** Create Skill */ +class SkillCreateParams +private constructor( + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** + * Skill files to upload (directory upload) or a single zip file. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun files(): Optional = body.files() + + /** + * Returns the raw multipart value of [files]. + * + * Unlike [files], this method doesn't throw if the multipart field has an unexpected type. + */ + fun _files(): MultipartField = body._files() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): SkillCreateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [SkillCreateParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SkillCreateParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(skillCreateParams: SkillCreateParams) = apply { + body = skillCreateParams.body.toBuilder() + additionalHeaders = skillCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = skillCreateParams.additionalQueryParams.toBuilder() + } + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [files] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** Skill files to upload (directory upload) or a single zip file. */ + fun files(files: Files) = apply { body.files(files) } + + /** + * Sets [Builder.files] to an arbitrary multipart value. + * + * You should usually call [Builder.files] with a well-typed [Files] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun files(files: MultipartField) = apply { body.files(files) } + + /** Alias for calling [files] with `Files.ofInputStreams(inputStreams)`. */ + fun filesOfInputStreams(inputStreams: List) = apply { + body.filesOfInputStreams(inputStreams) + } + + /** Alias for calling [files] with `Files.ofInputStream(inputStream)`. */ + fun files(inputStream: InputStream) = apply { body.files(inputStream) } + + /** Skill zip file to upload. */ + fun files(inputStream: ByteArray) = apply { body.files(inputStream) } + + /** Skill zip file to upload. */ + fun files(path: Path) = apply { body.files(path) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [SkillCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): SkillCreateParams = + SkillCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Map> = + (mapOf("files" to _files()) + + _additionalBodyProperties().mapValues { (_, value) -> MultipartField.of(value) }) + .toImmutable() + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Uploads a skill either as a directory (multipart `files[]`) or as a single zip file. */ + class Body + private constructor( + private val files: MultipartField, + private val additionalProperties: MutableMap, + ) { + + /** + * Skill files to upload (directory upload) or a single zip file. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun files(): Optional = files.value.getOptional("files") + + /** + * Returns the raw multipart value of [files]. + * + * Unlike [files], this method doesn't throw if the multipart field has an unexpected type. + */ + @JsonProperty("files") @ExcludeMissing fun _files(): MultipartField = files + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var files: MultipartField = MultipartField.of(null) + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + files = body.files + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Skill files to upload (directory upload) or a single zip file. */ + fun files(files: Files) = + files( + MultipartField.builder() + .value(files) + .contentType("application/octet-stream") + .build() + ) + + /** + * Sets [Builder.files] to an arbitrary multipart value. + * + * You should usually call [Builder.files] with a well-typed [Files] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun files(files: MultipartField) = apply { this.files = files } + + /** Alias for calling [files] with `Files.ofInputStreams(inputStreams)`. */ + fun filesOfInputStreams(inputStreams: List) = + files(Files.ofInputStreams(inputStreams)) + + /** Alias for calling [files] with `Files.ofInputStream(inputStream)`. */ + fun files(inputStream: InputStream) = files(Files.ofInputStream(inputStream)) + + /** Skill zip file to upload. */ + fun files(inputStream: ByteArray) = files(inputStream.inputStream()) + + /** Skill zip file to upload. */ + fun files(path: Path) = + files( + MultipartField.builder() + .value(Files.ofInputStream(path.inputStream())) + .contentType("application/octet-stream") + .filename(path.name) + .build() + ) + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = Body(files, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + files().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + files == other.files && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(files, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Body{files=$files, additionalProperties=$additionalProperties}" + } + + /** Skill files to upload (directory upload) or a single zip file. */ + @JsonSerialize(using = Files.Serializer::class) + class Files + private constructor( + private val inputStreams: List? = null, + private val inputStream: InputStream? = null, + private val _json: JsonValue? = null, + ) { + + /** Skill files to upload (directory upload) or a single zip file. */ + fun inputStreams(): Optional> = Optional.ofNullable(inputStreams) + + /** Skill zip file to upload. */ + fun inputStream(): Optional = Optional.ofNullable(inputStream) + + fun isInputStreams(): Boolean = inputStreams != null + + fun isInputStream(): Boolean = inputStream != null + + /** Skill files to upload (directory upload) or a single zip file. */ + fun asInputStreams(): List = inputStreams.getOrThrow("inputStreams") + + /** Skill zip file to upload. */ + fun asInputStream(): InputStream = inputStream.getOrThrow("inputStream") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + inputStreams != null -> visitor.visitInputStreams(inputStreams) + inputStream != null -> visitor.visitInputStream(inputStream) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Files = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitInputStreams(inputStreams: List) {} + + override fun visitInputStream(inputStream: InputStream) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Files && + inputStreams == other.inputStreams && + inputStream == other.inputStream + } + + override fun hashCode(): Int = Objects.hash(inputStreams, inputStream) + + override fun toString(): String = + when { + inputStreams != null -> "Files{inputStreams=$inputStreams}" + inputStream != null -> "Files{inputStream=$inputStream}" + _json != null -> "Files{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Files") + } + + companion object { + + /** Skill files to upload (directory upload) or a single zip file. */ + @JvmStatic + fun ofInputStreams(inputStreams: List) = + Files(inputStreams = inputStreams.toImmutable()) + + /** Skill zip file to upload. */ + @JvmStatic + fun ofInputStream(inputStream: InputStream) = Files(inputStream = inputStream) + } + + /** An interface that defines how to map each variant of [Files] to a value of type [T]. */ + interface Visitor { + + /** Skill files to upload (directory upload) or a single zip file. */ + fun visitInputStreams(inputStreams: List): T + + /** Skill zip file to upload. */ + fun visitInputStream(inputStream: InputStream): T + + /** + * Maps an unknown variant of [Files] to a value of type [T]. + * + * An instance of [Files] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Files: $json") + } + } + + internal class Serializer : BaseSerializer(Files::class) { + + override fun serialize( + value: Files, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.inputStreams != null -> generator.writeObject(value.inputStreams) + value.inputStream != null -> generator.writeObject(value.inputStream) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Files") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SkillCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "SkillCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillDeleteParams.kt new file mode 100644 index 00000000..ab90810a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillDeleteParams.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Delete Skill */ +class SkillDeleteParams +private constructor( + private val skillId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun skillId(): Optional = Optional.ofNullable(skillId) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): SkillDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [SkillDeleteParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SkillDeleteParams]. */ + class Builder internal constructor() { + + private var skillId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(skillDeleteParams: SkillDeleteParams) = apply { + skillId = skillDeleteParams.skillId + additionalHeaders = skillDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = skillDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = skillDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun skillId(skillId: String?) = apply { this.skillId = skillId } + + /** Alias for calling [Builder.skillId] with `skillId.orElse(null)`. */ + fun skillId(skillId: Optional) = skillId(skillId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [SkillDeleteParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): SkillDeleteParams = + SkillDeleteParams( + skillId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> skillId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SkillDeleteParams && + skillId == other.skillId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash(skillId, additionalHeaders, additionalQueryParams, additionalBodyProperties) + + override fun toString() = + "SkillDeleteParams{skillId=$skillId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillList.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillList.kt new file mode 100644 index 00000000..9c323852 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillList.kt @@ -0,0 +1,349 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class SkillList +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, mutableMapOf()) + + /** + * A list of items + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * The ID of the first item in the list. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun firstId(): Optional = firstId.getOptional("first_id") + + /** + * Whether there are more items available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * The ID of the last item in the list. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastId(): Optional = lastId.getOptional("last_id") + + /** + * The type of object returned, must be `list`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SkillList]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SkillList]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(skillList: SkillList) = apply { + data = skillList.data.map { it.toMutableList() } + firstId = skillList.firstId + hasMore = skillList.hasMore + lastId = skillList.lastId + object_ = skillList.object_ + additionalProperties = skillList.additionalProperties.toMutableMap() + } + + /** A list of items */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [Skill] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Skill) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** The ID of the first item in the list. */ + fun firstId(firstId: String?) = firstId(JsonField.ofNullable(firstId)) + + /** Alias for calling [Builder.firstId] with `firstId.orElse(null)`. */ + fun firstId(firstId: Optional) = firstId(firstId.getOrNull()) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + /** Whether there are more items available. */ + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** The ID of the last item in the list. */ + fun lastId(lastId: String?) = lastId(JsonField.ofNullable(lastId)) + + /** Alias for calling [Builder.lastId] with `lastId.orElse(null)`. */ + fun lastId(lastId: Optional) = lastId(lastId.getOrNull()) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [SkillList]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SkillList = + SkillList( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SkillList = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SkillList && + data == other.data && + firstId == other.firstId && + hasMore == other.hasMore && + lastId == other.lastId && + object_ == other.object_ && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SkillList{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillListPage.kt new file mode 100644 index 00000000..c7390133 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillListPage.kt @@ -0,0 +1,127 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.openai.core.AutoPager +import com.openai.core.Page +import com.openai.core.checkRequired +import com.openai.services.blocking.SkillService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see SkillService.list */ +class SkillListPage +private constructor( + private val service: SkillService, + private val params: SkillListParams, + private val response: SkillList, +) : Page { + + /** + * Delegates to [SkillList], but gracefully handles missing data. + * + * @see SkillList.data + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [SkillList], but gracefully handles missing data. + * + * @see SkillList.hasMore + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() + + fun nextPageParams(): SkillListParams = + params.toBuilder().after(items().last()._id().getOptional("id")).build() + + override fun nextPage(): SkillListPage = service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): SkillListParams = params + + /** The response that this page was parsed from. */ + fun response(): SkillList = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SkillListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SkillListPage]. */ + class Builder internal constructor() { + + private var service: SkillService? = null + private var params: SkillListParams? = null + private var response: SkillList? = null + + @JvmSynthetic + internal fun from(skillListPage: SkillListPage) = apply { + service = skillListPage.service + params = skillListPage.params + response = skillListPage.response + } + + fun service(service: SkillService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: SkillListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: SkillList) = apply { this.response = response } + + /** + * Returns an immutable instance of [SkillListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SkillListPage = + SkillListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SkillListPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = "SkillListPage{service=$service, params=$params, response=$response}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillListPageAsync.kt new file mode 100644 index 00000000..6631e3dc --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillListPageAsync.kt @@ -0,0 +1,141 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.openai.core.AutoPagerAsync +import com.openai.core.PageAsync +import com.openai.core.checkRequired +import com.openai.services.async.SkillServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see SkillServiceAsync.list */ +class SkillListPageAsync +private constructor( + private val service: SkillServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: SkillListParams, + private val response: SkillList, +) : PageAsync { + + /** + * Delegates to [SkillList], but gracefully handles missing data. + * + * @see SkillList.data + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [SkillList], but gracefully handles missing data. + * + * @see SkillList.hasMore + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() + + fun nextPageParams(): SkillListParams = + params.toBuilder().after(items().last()._id().getOptional("id")).build() + + override fun nextPage(): CompletableFuture = service.list(nextPageParams()) + + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) + + /** The parameters that were used to request this page. */ + fun params(): SkillListParams = params + + /** The response that this page was parsed from. */ + fun response(): SkillList = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SkillListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SkillListPageAsync]. */ + class Builder internal constructor() { + + private var service: SkillServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: SkillListParams? = null + private var response: SkillList? = null + + @JvmSynthetic + internal fun from(skillListPageAsync: SkillListPageAsync) = apply { + service = skillListPageAsync.service + streamHandlerExecutor = skillListPageAsync.streamHandlerExecutor + params = skillListPageAsync.params + response = skillListPageAsync.response + } + + fun service(service: SkillServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: SkillListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: SkillList) = apply { this.response = response } + + /** + * Returns an immutable instance of [SkillListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SkillListPageAsync = + SkillListPageAsync( + checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SkillListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) + + override fun toString() = + "SkillListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillListParams.kt new file mode 100644 index 00000000..ae9fde01 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillListParams.kt @@ -0,0 +1,372 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** List Skills */ +class SkillListParams +private constructor( + private val after: String?, + private val limit: Long?, + private val order: Order?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Identifier for the last item from the previous pagination request */ + fun after(): Optional = Optional.ofNullable(after) + + /** Number of items to retrieve */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** + * Sort order of results by timestamp. Use `asc` for ascending order or `desc` for descending + * order. + */ + fun order(): Optional = Optional.ofNullable(order) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): SkillListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [SkillListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SkillListParams]. */ + class Builder internal constructor() { + + private var after: String? = null + private var limit: Long? = null + private var order: Order? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(skillListParams: SkillListParams) = apply { + after = skillListParams.after + limit = skillListParams.limit + order = skillListParams.order + additionalHeaders = skillListParams.additionalHeaders.toBuilder() + additionalQueryParams = skillListParams.additionalQueryParams.toBuilder() + } + + /** Identifier for the last item from the previous pagination request */ + fun after(after: String?) = apply { this.after = after } + + /** Alias for calling [Builder.after] with `after.orElse(null)`. */ + fun after(after: Optional) = after(after.getOrNull()) + + /** Number of items to retrieve */ + fun limit(limit: Long?) = apply { this.limit = limit } + + /** + * Alias for [Builder.limit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun limit(limit: Long) = limit(limit as Long?) + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + /** + * Sort order of results by timestamp. Use `asc` for ascending order or `desc` for + * descending order. + */ + fun order(order: Order?) = apply { this.order = order } + + /** Alias for calling [Builder.order] with `order.orElse(null)`. */ + fun order(order: Optional) = order(order.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [SkillListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): SkillListParams = + SkillListParams( + after, + limit, + order, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + after?.let { put("after", it) } + limit?.let { put("limit", it.toString()) } + order?.let { put("order", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + /** + * Sort order of results by timestamp. Use `asc` for ascending order or `desc` for descending + * order. + */ + class Order @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASC = of("asc") + + @JvmField val DESC = of("desc") + + @JvmStatic fun of(value: String) = Order(JsonField.of(value)) + } + + /** An enum containing [Order]'s known values. */ + enum class Known { + ASC, + DESC, + } + + /** + * An enum containing [Order]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Order] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ASC, + DESC, + /** An enum member indicating that [Order] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ASC -> Value.ASC + DESC -> Value.DESC + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ASC -> Known.ASC + DESC -> Known.DESC + else -> throw OpenAIInvalidDataException("Unknown Order: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + fun validate(): Order = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Order && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SkillListParams && + after == other.after && + limit == other.limit && + order == other.order && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(after, limit, order, additionalHeaders, additionalQueryParams) + + override fun toString() = + "SkillListParams{after=$after, limit=$limit, order=$order, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillRetrieveParams.kt new file mode 100644 index 00000000..e4ea93ec --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillRetrieveParams.kt @@ -0,0 +1,189 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Get Skill */ +class SkillRetrieveParams +private constructor( + private val skillId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun skillId(): Optional = Optional.ofNullable(skillId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): SkillRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [SkillRetrieveParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SkillRetrieveParams]. */ + class Builder internal constructor() { + + private var skillId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(skillRetrieveParams: SkillRetrieveParams) = apply { + skillId = skillRetrieveParams.skillId + additionalHeaders = skillRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = skillRetrieveParams.additionalQueryParams.toBuilder() + } + + fun skillId(skillId: String?) = apply { this.skillId = skillId } + + /** Alias for calling [Builder.skillId] with `skillId.orElse(null)`. */ + fun skillId(skillId: Optional) = skillId(skillId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [SkillRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): SkillRetrieveParams = + SkillRetrieveParams(skillId, additionalHeaders.build(), additionalQueryParams.build()) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> skillId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SkillRetrieveParams && + skillId == other.skillId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(skillId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "SkillRetrieveParams{skillId=$skillId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillUpdateParams.kt new file mode 100644 index 00000000..3e97254e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/SkillUpdateParams.kt @@ -0,0 +1,452 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Update Skill Default Version */ +class SkillUpdateParams +private constructor( + private val skillId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun skillId(): Optional = Optional.ofNullable(skillId) + + /** + * The skill version number to set as default. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun defaultVersion(): String = body.defaultVersion() + + /** + * Returns the raw JSON value of [defaultVersion]. + * + * Unlike [defaultVersion], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _defaultVersion(): JsonField = body._defaultVersion() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SkillUpdateParams]. + * + * The following fields are required: + * ```java + * .defaultVersion() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SkillUpdateParams]. */ + class Builder internal constructor() { + + private var skillId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(skillUpdateParams: SkillUpdateParams) = apply { + skillId = skillUpdateParams.skillId + body = skillUpdateParams.body.toBuilder() + additionalHeaders = skillUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = skillUpdateParams.additionalQueryParams.toBuilder() + } + + fun skillId(skillId: String?) = apply { this.skillId = skillId } + + /** Alias for calling [Builder.skillId] with `skillId.orElse(null)`. */ + fun skillId(skillId: Optional) = skillId(skillId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [defaultVersion] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The skill version number to set as default. */ + fun defaultVersion(defaultVersion: String) = apply { body.defaultVersion(defaultVersion) } + + /** + * Sets [Builder.defaultVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun defaultVersion(defaultVersion: JsonField) = apply { + body.defaultVersion(defaultVersion) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [SkillUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .defaultVersion() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SkillUpdateParams = + SkillUpdateParams( + skillId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> skillId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Updates the default version pointer for a skill. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val defaultVersion: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("default_version") + @ExcludeMissing + defaultVersion: JsonField = JsonMissing.of() + ) : this(defaultVersion, mutableMapOf()) + + /** + * The skill version number to set as default. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun defaultVersion(): String = defaultVersion.getRequired("default_version") + + /** + * Returns the raw JSON value of [defaultVersion]. + * + * Unlike [defaultVersion], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("default_version") + @ExcludeMissing + fun _defaultVersion(): JsonField = defaultVersion + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .defaultVersion() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var defaultVersion: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + defaultVersion = body.defaultVersion + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The skill version number to set as default. */ + fun defaultVersion(defaultVersion: String) = + defaultVersion(JsonField.of(defaultVersion)) + + /** + * Sets [Builder.defaultVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun defaultVersion(defaultVersion: JsonField) = apply { + this.defaultVersion = defaultVersion + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .defaultVersion() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("defaultVersion", defaultVersion), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + defaultVersion() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (if (defaultVersion.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + defaultVersion == other.defaultVersion && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(defaultVersion, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{defaultVersion=$defaultVersion, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SkillUpdateParams && + skillId == other.skillId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(skillId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "SkillUpdateParams{skillId=$skillId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/content/ContentRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/content/ContentRetrieveParams.kt new file mode 100644 index 00000000..99930a5e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/content/ContentRetrieveParams.kt @@ -0,0 +1,189 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.content + +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Get Skill Content */ +class ContentRetrieveParams +private constructor( + private val skillId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun skillId(): Optional = Optional.ofNullable(skillId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): ContentRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ContentRetrieveParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ContentRetrieveParams]. */ + class Builder internal constructor() { + + private var skillId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(contentRetrieveParams: ContentRetrieveParams) = apply { + skillId = contentRetrieveParams.skillId + additionalHeaders = contentRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = contentRetrieveParams.additionalQueryParams.toBuilder() + } + + fun skillId(skillId: String?) = apply { this.skillId = skillId } + + /** Alias for calling [Builder.skillId] with `skillId.orElse(null)`. */ + fun skillId(skillId: Optional) = skillId(skillId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [ContentRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ContentRetrieveParams = + ContentRetrieveParams(skillId, additionalHeaders.build(), additionalQueryParams.build()) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> skillId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ContentRetrieveParams && + skillId == other.skillId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(skillId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ContentRetrieveParams{skillId=$skillId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/DeletedSkillVersion.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/DeletedSkillVersion.kt new file mode 100644 index 00000000..b382ed0f --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/DeletedSkillVersion.kt @@ -0,0 +1,280 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +class DeletedSkillVersion +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val deleted: JsonField, + private val object_: JsonValue, + private val version: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("deleted") @ExcludeMissing deleted: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(id, deleted, object_, version, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun deleted(): Boolean = deleted.getRequired("deleted") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("skill.version.deleted") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * The deleted skill version. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun version(): String = version.getRequired("version") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [deleted]. + * + * Unlike [deleted], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("deleted") @ExcludeMissing fun _deleted(): JsonField = deleted + + /** + * Returns the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [DeletedSkillVersion]. + * + * The following fields are required: + * ```java + * .id() + * .deleted() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DeletedSkillVersion]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var deleted: JsonField? = null + private var object_: JsonValue = JsonValue.from("skill.version.deleted") + private var version: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(deletedSkillVersion: DeletedSkillVersion) = apply { + id = deletedSkillVersion.id + deleted = deletedSkillVersion.deleted + object_ = deletedSkillVersion.object_ + version = deletedSkillVersion.version + additionalProperties = deletedSkillVersion.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun deleted(deleted: Boolean) = deleted(JsonField.of(deleted)) + + /** + * Sets [Builder.deleted] to an arbitrary JSON value. + * + * You should usually call [Builder.deleted] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun deleted(deleted: JsonField) = apply { this.deleted = deleted } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("skill.version.deleted") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** The deleted skill version. */ + fun version(version: String) = version(JsonField.of(version)) + + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun version(version: JsonField) = apply { this.version = version } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [DeletedSkillVersion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .deleted() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DeletedSkillVersion = + DeletedSkillVersion( + checkRequired("id", id), + checkRequired("deleted", deleted), + object_, + checkRequired("version", version), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): DeletedSkillVersion = apply { + if (validated) { + return@apply + } + + id() + deleted() + _object_().let { + if (it != JsonValue.from("skill.version.deleted")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + version() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (deleted.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("skill.version.deleted")) 1 else 0 } + + (if (version.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DeletedSkillVersion && + id == other.id && + deleted == other.deleted && + object_ == other.object_ && + version == other.version && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, deleted, object_, version, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DeletedSkillVersion{id=$id, deleted=$deleted, object_=$object_, version=$version, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/SkillVersion.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/SkillVersion.kt new file mode 100644 index 00000000..e523565f --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/SkillVersion.kt @@ -0,0 +1,408 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +class SkillVersion +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val description: JsonField, + private val name: JsonField, + private val object_: JsonValue, + private val skillId: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("skill_id") @ExcludeMissing skillId: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(id, createdAt, description, name, object_, skillId, version, mutableMapOf()) + + /** + * Unique identifier for the skill version. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * Unix timestamp (seconds) for when the version was created. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): Long = createdAt.getRequired("created_at") + + /** + * Description of the skill version. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun description(): String = description.getRequired("description") + + /** + * Name of the skill version. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * The object type, which is `skill.version`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("skill.version") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Identifier of the skill for this version. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun skillId(): String = skillId.getRequired("skill_id") + + /** + * Version number for this skill. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun version(): String = version.getRequired("version") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [skillId]. + * + * Unlike [skillId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("skill_id") @ExcludeMissing fun _skillId(): JsonField = skillId + + /** + * Returns the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SkillVersion]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .description() + * .name() + * .skillId() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SkillVersion]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var description: JsonField? = null + private var name: JsonField? = null + private var object_: JsonValue = JsonValue.from("skill.version") + private var skillId: JsonField? = null + private var version: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(skillVersion: SkillVersion) = apply { + id = skillVersion.id + createdAt = skillVersion.createdAt + description = skillVersion.description + name = skillVersion.name + object_ = skillVersion.object_ + skillId = skillVersion.skillId + version = skillVersion.version + additionalProperties = skillVersion.additionalProperties.toMutableMap() + } + + /** Unique identifier for the skill version. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Unix timestamp (seconds) for when the version was created. */ + fun createdAt(createdAt: Long) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Description of the skill version. */ + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** Name of the skill version. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("skill.version") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** Identifier of the skill for this version. */ + fun skillId(skillId: String) = skillId(JsonField.of(skillId)) + + /** + * Sets [Builder.skillId] to an arbitrary JSON value. + * + * You should usually call [Builder.skillId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun skillId(skillId: JsonField) = apply { this.skillId = skillId } + + /** Version number for this skill. */ + fun version(version: String) = version(JsonField.of(version)) + + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun version(version: JsonField) = apply { this.version = version } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [SkillVersion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .description() + * .name() + * .skillId() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SkillVersion = + SkillVersion( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("description", description), + checkRequired("name", name), + object_, + checkRequired("skillId", skillId), + checkRequired("version", version), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SkillVersion = apply { + if (validated) { + return@apply + } + + id() + createdAt() + description() + name() + _object_().let { + if (it != JsonValue.from("skill.version")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + skillId() + version() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("skill.version")) 1 else 0 } + + (if (skillId.asKnown().isPresent) 1 else 0) + + (if (version.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SkillVersion && + id == other.id && + createdAt == other.createdAt && + description == other.description && + name == other.name && + object_ == other.object_ && + skillId == other.skillId && + version == other.version && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + description, + name, + object_, + skillId, + version, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SkillVersion{id=$id, createdAt=$createdAt, description=$description, name=$name, object_=$object_, skillId=$skillId, version=$version, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/SkillVersionList.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/SkillVersionList.kt new file mode 100644 index 00000000..5200ebda --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/SkillVersionList.kt @@ -0,0 +1,351 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class SkillVersionList +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, mutableMapOf()) + + /** + * A list of items + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * The ID of the first item in the list. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun firstId(): Optional = firstId.getOptional("first_id") + + /** + * Whether there are more items available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * The ID of the last item in the list. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastId(): Optional = lastId.getOptional("last_id") + + /** + * The type of object returned, must be `list`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [SkillVersionList]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SkillVersionList]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(skillVersionList: SkillVersionList) = apply { + data = skillVersionList.data.map { it.toMutableList() } + firstId = skillVersionList.firstId + hasMore = skillVersionList.hasMore + lastId = skillVersionList.lastId + object_ = skillVersionList.object_ + additionalProperties = skillVersionList.additionalProperties.toMutableMap() + } + + /** A list of items */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [SkillVersion] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: SkillVersion) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** The ID of the first item in the list. */ + fun firstId(firstId: String?) = firstId(JsonField.ofNullable(firstId)) + + /** Alias for calling [Builder.firstId] with `firstId.orElse(null)`. */ + fun firstId(firstId: Optional) = firstId(firstId.getOrNull()) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + /** Whether there are more items available. */ + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** The ID of the last item in the list. */ + fun lastId(lastId: String?) = lastId(JsonField.ofNullable(lastId)) + + /** Alias for calling [Builder.lastId] with `lastId.orElse(null)`. */ + fun lastId(lastId: Optional) = lastId(lastId.getOrNull()) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [SkillVersionList]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SkillVersionList = + SkillVersionList( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SkillVersionList = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SkillVersionList && + data == other.data && + firstId == other.firstId && + hasMore == other.hasMore && + lastId == other.lastId && + object_ == other.object_ && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SkillVersionList{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionCreateParams.kt new file mode 100644 index 00000000..469e6afd --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionCreateParams.kt @@ -0,0 +1,639 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.openai.core.BaseSerializer +import com.openai.core.ExcludeMissing +import com.openai.core.JsonValue +import com.openai.core.MultipartField +import com.openai.core.Params +import com.openai.core.getOrThrow +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.io.InputStream +import java.nio.file.Path +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.io.path.inputStream +import kotlin.io.path.name +import kotlin.jvm.optionals.getOrNull + +/** Create Skill Version */ +class VersionCreateParams +private constructor( + private val skillId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun skillId(): Optional = Optional.ofNullable(skillId) + + /** + * Whether to set this version as the default. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun default_(): Optional = body.default_() + + /** + * Skill files to upload (directory upload) or a single zip file. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun files(): Optional = body.files() + + /** + * Returns the raw multipart value of [default_]. + * + * Unlike [default_], this method doesn't throw if the multipart field has an unexpected type. + */ + fun _default_(): MultipartField = body._default_() + + /** + * Returns the raw multipart value of [files]. + * + * Unlike [files], this method doesn't throw if the multipart field has an unexpected type. + */ + fun _files(): MultipartField = body._files() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): VersionCreateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [VersionCreateParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VersionCreateParams]. */ + class Builder internal constructor() { + + private var skillId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(versionCreateParams: VersionCreateParams) = apply { + skillId = versionCreateParams.skillId + body = versionCreateParams.body.toBuilder() + additionalHeaders = versionCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = versionCreateParams.additionalQueryParams.toBuilder() + } + + fun skillId(skillId: String?) = apply { this.skillId = skillId } + + /** Alias for calling [Builder.skillId] with `skillId.orElse(null)`. */ + fun skillId(skillId: Optional) = skillId(skillId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [default_] + * - [files] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** Whether to set this version as the default. */ + fun default_(default_: Boolean) = apply { body.default_(default_) } + + /** + * Sets [Builder.default_] to an arbitrary multipart value. + * + * You should usually call [Builder.default_] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun default_(default_: MultipartField) = apply { body.default_(default_) } + + /** Skill files to upload (directory upload) or a single zip file. */ + fun files(files: Files) = apply { body.files(files) } + + /** + * Sets [Builder.files] to an arbitrary multipart value. + * + * You should usually call [Builder.files] with a well-typed [Files] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun files(files: MultipartField) = apply { body.files(files) } + + /** Alias for calling [files] with `Files.ofInputStreams(inputStreams)`. */ + fun filesOfInputStreams(inputStreams: List) = apply { + body.filesOfInputStreams(inputStreams) + } + + /** Alias for calling [files] with `Files.ofInputStream(inputStream)`. */ + fun files(inputStream: InputStream) = apply { body.files(inputStream) } + + /** Skill zip file to upload. */ + fun files(inputStream: ByteArray) = apply { body.files(inputStream) } + + /** Skill zip file to upload. */ + fun files(path: Path) = apply { body.files(path) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [VersionCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): VersionCreateParams = + VersionCreateParams( + skillId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Map> = + (mapOf("default" to _default_(), "files" to _files()) + + _additionalBodyProperties().mapValues { (_, value) -> MultipartField.of(value) }) + .toImmutable() + + fun _pathParam(index: Int): String = + when (index) { + 0 -> skillId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Uploads a new immutable version of a skill. */ + class Body + private constructor( + private val default_: MultipartField, + private val files: MultipartField, + private val additionalProperties: MutableMap, + ) { + + /** + * Whether to set this version as the default. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun default_(): Optional = default_.value.getOptional("default") + + /** + * Skill files to upload (directory upload) or a single zip file. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun files(): Optional = files.value.getOptional("files") + + /** + * Returns the raw multipart value of [default_]. + * + * Unlike [default_], this method doesn't throw if the multipart field has an unexpected + * type. + */ + @JsonProperty("default") @ExcludeMissing fun _default_(): MultipartField = default_ + + /** + * Returns the raw multipart value of [files]. + * + * Unlike [files], this method doesn't throw if the multipart field has an unexpected type. + */ + @JsonProperty("files") @ExcludeMissing fun _files(): MultipartField = files + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var default_: MultipartField = MultipartField.of(null) + private var files: MultipartField = MultipartField.of(null) + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + default_ = body.default_ + files = body.files + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Whether to set this version as the default. */ + fun default_(default_: Boolean) = default_(MultipartField.of(default_)) + + /** + * Sets [Builder.default_] to an arbitrary multipart value. + * + * You should usually call [Builder.default_] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun default_(default_: MultipartField) = apply { this.default_ = default_ } + + /** Skill files to upload (directory upload) or a single zip file. */ + fun files(files: Files) = + files( + MultipartField.builder() + .value(files) + .contentType("application/octet-stream") + .build() + ) + + /** + * Sets [Builder.files] to an arbitrary multipart value. + * + * You should usually call [Builder.files] with a well-typed [Files] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun files(files: MultipartField) = apply { this.files = files } + + /** Alias for calling [files] with `Files.ofInputStreams(inputStreams)`. */ + fun filesOfInputStreams(inputStreams: List) = + files(Files.ofInputStreams(inputStreams)) + + /** Alias for calling [files] with `Files.ofInputStream(inputStream)`. */ + fun files(inputStream: InputStream) = files(Files.ofInputStream(inputStream)) + + /** Skill zip file to upload. */ + fun files(inputStream: ByteArray) = files(inputStream.inputStream()) + + /** Skill zip file to upload. */ + fun files(path: Path) = + files( + MultipartField.builder() + .value(Files.ofInputStream(path.inputStream())) + .contentType("application/octet-stream") + .filename(path.name) + .build() + ) + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = Body(default_, files, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + default_() + files().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + default_ == other.default_ && + files == other.files && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(default_, files, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{default_=$default_, files=$files, additionalProperties=$additionalProperties}" + } + + /** Skill files to upload (directory upload) or a single zip file. */ + @JsonSerialize(using = Files.Serializer::class) + class Files + private constructor( + private val inputStreams: List? = null, + private val inputStream: InputStream? = null, + private val _json: JsonValue? = null, + ) { + + /** Skill files to upload (directory upload) or a single zip file. */ + fun inputStreams(): Optional> = Optional.ofNullable(inputStreams) + + /** Skill zip file to upload. */ + fun inputStream(): Optional = Optional.ofNullable(inputStream) + + fun isInputStreams(): Boolean = inputStreams != null + + fun isInputStream(): Boolean = inputStream != null + + /** Skill files to upload (directory upload) or a single zip file. */ + fun asInputStreams(): List = inputStreams.getOrThrow("inputStreams") + + /** Skill zip file to upload. */ + fun asInputStream(): InputStream = inputStream.getOrThrow("inputStream") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + inputStreams != null -> visitor.visitInputStreams(inputStreams) + inputStream != null -> visitor.visitInputStream(inputStream) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Files = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitInputStreams(inputStreams: List) {} + + override fun visitInputStream(inputStream: InputStream) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Files && + inputStreams == other.inputStreams && + inputStream == other.inputStream + } + + override fun hashCode(): Int = Objects.hash(inputStreams, inputStream) + + override fun toString(): String = + when { + inputStreams != null -> "Files{inputStreams=$inputStreams}" + inputStream != null -> "Files{inputStream=$inputStream}" + _json != null -> "Files{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Files") + } + + companion object { + + /** Skill files to upload (directory upload) or a single zip file. */ + @JvmStatic + fun ofInputStreams(inputStreams: List) = + Files(inputStreams = inputStreams.toImmutable()) + + /** Skill zip file to upload. */ + @JvmStatic + fun ofInputStream(inputStream: InputStream) = Files(inputStream = inputStream) + } + + /** An interface that defines how to map each variant of [Files] to a value of type [T]. */ + interface Visitor { + + /** Skill files to upload (directory upload) or a single zip file. */ + fun visitInputStreams(inputStreams: List): T + + /** Skill zip file to upload. */ + fun visitInputStream(inputStream: InputStream): T + + /** + * Maps an unknown variant of [Files] to a value of type [T]. + * + * An instance of [Files] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Files: $json") + } + } + + internal class Serializer : BaseSerializer(Files::class) { + + override fun serialize( + value: Files, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.inputStreams != null -> generator.writeObject(value.inputStreams) + value.inputStream != null -> generator.writeObject(value.inputStream) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Files") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VersionCreateParams && + skillId == other.skillId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(skillId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "VersionCreateParams{skillId=$skillId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionDeleteParams.kt new file mode 100644 index 00000000..dc243031 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionDeleteParams.kt @@ -0,0 +1,260 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Delete Skill Version */ +class VersionDeleteParams +private constructor( + private val skillId: String, + private val version: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun skillId(): String = skillId + + /** The skill version number. */ + fun version(): Optional = Optional.ofNullable(version) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [VersionDeleteParams]. + * + * The following fields are required: + * ```java + * .skillId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VersionDeleteParams]. */ + class Builder internal constructor() { + + private var skillId: String? = null + private var version: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(versionDeleteParams: VersionDeleteParams) = apply { + skillId = versionDeleteParams.skillId + version = versionDeleteParams.version + additionalHeaders = versionDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = versionDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = versionDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun skillId(skillId: String) = apply { this.skillId = skillId } + + /** The skill version number. */ + fun version(version: String?) = apply { this.version = version } + + /** Alias for calling [Builder.version] with `version.orElse(null)`. */ + fun version(version: Optional) = version(version.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [VersionDeleteParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .skillId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VersionDeleteParams = + VersionDeleteParams( + checkRequired("skillId", skillId), + version, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> skillId + 1 -> version ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VersionDeleteParams && + skillId == other.skillId && + version == other.version && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + skillId, + version, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "VersionDeleteParams{skillId=$skillId, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionListPage.kt new file mode 100644 index 00000000..aaf2a636 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionListPage.kt @@ -0,0 +1,128 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.openai.core.AutoPager +import com.openai.core.Page +import com.openai.core.checkRequired +import com.openai.services.blocking.skills.VersionService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see VersionService.list */ +class VersionListPage +private constructor( + private val service: VersionService, + private val params: VersionListParams, + private val response: SkillVersionList, +) : Page { + + /** + * Delegates to [SkillVersionList], but gracefully handles missing data. + * + * @see SkillVersionList.data + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [SkillVersionList], but gracefully handles missing data. + * + * @see SkillVersionList.hasMore + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() + + fun nextPageParams(): VersionListParams = + params.toBuilder().after(items().last()._id().getOptional("id")).build() + + override fun nextPage(): VersionListPage = service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): VersionListParams = params + + /** The response that this page was parsed from. */ + fun response(): SkillVersionList = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [VersionListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VersionListPage]. */ + class Builder internal constructor() { + + private var service: VersionService? = null + private var params: VersionListParams? = null + private var response: SkillVersionList? = null + + @JvmSynthetic + internal fun from(versionListPage: VersionListPage) = apply { + service = versionListPage.service + params = versionListPage.params + response = versionListPage.response + } + + fun service(service: VersionService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: VersionListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: SkillVersionList) = apply { this.response = response } + + /** + * Returns an immutable instance of [VersionListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VersionListPage = + VersionListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VersionListPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = + "VersionListPage{service=$service, params=$params, response=$response}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionListPageAsync.kt new file mode 100644 index 00000000..a78c9e2a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionListPageAsync.kt @@ -0,0 +1,142 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.openai.core.AutoPagerAsync +import com.openai.core.PageAsync +import com.openai.core.checkRequired +import com.openai.services.async.skills.VersionServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see VersionServiceAsync.list */ +class VersionListPageAsync +private constructor( + private val service: VersionServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: VersionListParams, + private val response: SkillVersionList, +) : PageAsync { + + /** + * Delegates to [SkillVersionList], but gracefully handles missing data. + * + * @see SkillVersionList.data + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [SkillVersionList], but gracefully handles missing data. + * + * @see SkillVersionList.hasMore + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() + + fun nextPageParams(): VersionListParams = + params.toBuilder().after(items().last()._id().getOptional("id")).build() + + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) + + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) + + /** The parameters that were used to request this page. */ + fun params(): VersionListParams = params + + /** The response that this page was parsed from. */ + fun response(): SkillVersionList = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [VersionListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VersionListPageAsync]. */ + class Builder internal constructor() { + + private var service: VersionServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: VersionListParams? = null + private var response: SkillVersionList? = null + + @JvmSynthetic + internal fun from(versionListPageAsync: VersionListPageAsync) = apply { + service = versionListPageAsync.service + streamHandlerExecutor = versionListPageAsync.streamHandlerExecutor + params = versionListPageAsync.params + response = versionListPageAsync.response + } + + fun service(service: VersionServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: VersionListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: SkillVersionList) = apply { this.response = response } + + /** + * Returns an immutable instance of [VersionListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VersionListPageAsync = + VersionListPageAsync( + checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VersionListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) + + override fun toString() = + "VersionListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionListParams.kt new file mode 100644 index 00000000..6aeab426 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionListParams.kt @@ -0,0 +1,381 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** List Skill Versions */ +class VersionListParams +private constructor( + private val skillId: String?, + private val after: String?, + private val limit: Long?, + private val order: Order?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun skillId(): Optional = Optional.ofNullable(skillId) + + /** The skill version ID to start after. */ + fun after(): Optional = Optional.ofNullable(after) + + /** Number of versions to retrieve. */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** Sort order of results by version number. */ + fun order(): Optional = Optional.ofNullable(order) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): VersionListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [VersionListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VersionListParams]. */ + class Builder internal constructor() { + + private var skillId: String? = null + private var after: String? = null + private var limit: Long? = null + private var order: Order? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(versionListParams: VersionListParams) = apply { + skillId = versionListParams.skillId + after = versionListParams.after + limit = versionListParams.limit + order = versionListParams.order + additionalHeaders = versionListParams.additionalHeaders.toBuilder() + additionalQueryParams = versionListParams.additionalQueryParams.toBuilder() + } + + fun skillId(skillId: String?) = apply { this.skillId = skillId } + + /** Alias for calling [Builder.skillId] with `skillId.orElse(null)`. */ + fun skillId(skillId: Optional) = skillId(skillId.getOrNull()) + + /** The skill version ID to start after. */ + fun after(after: String?) = apply { this.after = after } + + /** Alias for calling [Builder.after] with `after.orElse(null)`. */ + fun after(after: Optional) = after(after.getOrNull()) + + /** Number of versions to retrieve. */ + fun limit(limit: Long?) = apply { this.limit = limit } + + /** + * Alias for [Builder.limit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun limit(limit: Long) = limit(limit as Long?) + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + /** Sort order of results by version number. */ + fun order(order: Order?) = apply { this.order = order } + + /** Alias for calling [Builder.order] with `order.orElse(null)`. */ + fun order(order: Optional) = order(order.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [VersionListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): VersionListParams = + VersionListParams( + skillId, + after, + limit, + order, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> skillId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + after?.let { put("after", it) } + limit?.let { put("limit", it.toString()) } + order?.let { put("order", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + /** Sort order of results by version number. */ + class Order @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASC = of("asc") + + @JvmField val DESC = of("desc") + + @JvmStatic fun of(value: String) = Order(JsonField.of(value)) + } + + /** An enum containing [Order]'s known values. */ + enum class Known { + ASC, + DESC, + } + + /** + * An enum containing [Order]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Order] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ASC, + DESC, + /** An enum member indicating that [Order] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ASC -> Value.ASC + DESC -> Value.DESC + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ASC -> Known.ASC + DESC -> Known.DESC + else -> throw OpenAIInvalidDataException("Unknown Order: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + fun validate(): Order = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Order && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VersionListParams && + skillId == other.skillId && + after == other.after && + limit == other.limit && + order == other.order && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(skillId, after, limit, order, additionalHeaders, additionalQueryParams) + + override fun toString() = + "VersionListParams{skillId=$skillId, after=$after, limit=$limit, order=$order, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionRetrieveParams.kt new file mode 100644 index 00000000..ca57e71a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/VersionRetrieveParams.kt @@ -0,0 +1,219 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Get Skill Version */ +class VersionRetrieveParams +private constructor( + private val skillId: String, + private val version: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun skillId(): String = skillId + + /** The version number to retrieve. */ + fun version(): Optional = Optional.ofNullable(version) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [VersionRetrieveParams]. + * + * The following fields are required: + * ```java + * .skillId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VersionRetrieveParams]. */ + class Builder internal constructor() { + + private var skillId: String? = null + private var version: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(versionRetrieveParams: VersionRetrieveParams) = apply { + skillId = versionRetrieveParams.skillId + version = versionRetrieveParams.version + additionalHeaders = versionRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = versionRetrieveParams.additionalQueryParams.toBuilder() + } + + fun skillId(skillId: String) = apply { this.skillId = skillId } + + /** The version number to retrieve. */ + fun version(version: String?) = apply { this.version = version } + + /** Alias for calling [Builder.version] with `version.orElse(null)`. */ + fun version(version: Optional) = version(version.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [VersionRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .skillId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VersionRetrieveParams = + VersionRetrieveParams( + checkRequired("skillId", skillId), + version, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> skillId + 1 -> version ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VersionRetrieveParams && + skillId == other.skillId && + version == other.version && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(skillId, version, additionalHeaders, additionalQueryParams) + + override fun toString() = + "VersionRetrieveParams{skillId=$skillId, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/content/ContentRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/content/ContentRetrieveParams.kt new file mode 100644 index 00000000..c4bce580 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/skills/versions/content/ContentRetrieveParams.kt @@ -0,0 +1,219 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions.content + +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Get Skill Version Content */ +class ContentRetrieveParams +private constructor( + private val skillId: String, + private val version: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun skillId(): String = skillId + + /** The skill version number. */ + fun version(): Optional = Optional.ofNullable(version) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ContentRetrieveParams]. + * + * The following fields are required: + * ```java + * .skillId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ContentRetrieveParams]. */ + class Builder internal constructor() { + + private var skillId: String? = null + private var version: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(contentRetrieveParams: ContentRetrieveParams) = apply { + skillId = contentRetrieveParams.skillId + version = contentRetrieveParams.version + additionalHeaders = contentRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = contentRetrieveParams.additionalQueryParams.toBuilder() + } + + fun skillId(skillId: String) = apply { this.skillId = skillId } + + /** The skill version number. */ + fun version(version: String?) = apply { this.version = version } + + /** Alias for calling [Builder.version] with `version.orElse(null)`. */ + fun version(version: Optional) = version(version.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [ContentRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .skillId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ContentRetrieveParams = + ContentRetrieveParams( + checkRequired("skillId", skillId), + version, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> skillId + 1 -> version ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ContentRetrieveParams && + skillId == other.skillId && + version == other.version && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(skillId, version, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ContentRetrieveParams{skillId=$skillId, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/ImageServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/ImageServiceAsync.kt index 42a08b7d..f2bb02e5 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/ImageServiceAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/ImageServiceAsync.kt @@ -43,8 +43,8 @@ interface ImageServiceAsync { /** * Creates an edited or extended image given one or more source images and a prompt. This - * endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`, and `gpt-image-1-mini`) - * and `dall-e-2`. + * endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`, `gpt-image-1-mini`, and + * `chatgpt-image-latest`) and `dall-e-2`. */ fun edit(params: ImageEditParams): CompletableFuture = edit(params, RequestOptions.none()) @@ -57,8 +57,8 @@ interface ImageServiceAsync { /** * Creates an edited or extended image given one or more source images and a prompt. This - * endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`, and `gpt-image-1-mini`) - * and `dall-e-2`. + * endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`, `gpt-image-1-mini`, and + * `chatgpt-image-latest`) and `dall-e-2`. */ fun editStreaming(params: ImageEditParams): AsyncStreamResponse = editStreaming(params, RequestOptions.none()) diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/SkillServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/SkillServiceAsync.kt new file mode 100644 index 00000000..33508ee2 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/SkillServiceAsync.kt @@ -0,0 +1,328 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.skills.DeletedSkill +import com.openai.models.skills.Skill +import com.openai.models.skills.SkillCreateParams +import com.openai.models.skills.SkillDeleteParams +import com.openai.models.skills.SkillListPageAsync +import com.openai.models.skills.SkillListParams +import com.openai.models.skills.SkillRetrieveParams +import com.openai.models.skills.SkillUpdateParams +import com.openai.services.async.skills.ContentServiceAsync +import com.openai.services.async.skills.VersionServiceAsync +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface SkillServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): SkillServiceAsync + + fun content(): ContentServiceAsync + + fun versions(): VersionServiceAsync + + /** Create Skill */ + fun create(): CompletableFuture = create(SkillCreateParams.none()) + + /** @see create */ + fun create( + params: SkillCreateParams = SkillCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see create */ + fun create(params: SkillCreateParams = SkillCreateParams.none()): CompletableFuture = + create(params, RequestOptions.none()) + + /** @see create */ + fun create(requestOptions: RequestOptions): CompletableFuture = + create(SkillCreateParams.none(), requestOptions) + + /** Get Skill */ + fun retrieve(skillId: String): CompletableFuture = + retrieve(skillId, SkillRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + skillId: String, + params: SkillRetrieveParams = SkillRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + skillId: String, + params: SkillRetrieveParams = SkillRetrieveParams.none(), + ): CompletableFuture = retrieve(skillId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: SkillRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve(params: SkillRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(skillId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(skillId, SkillRetrieveParams.none(), requestOptions) + + /** Update Skill Default Version */ + fun update(skillId: String, params: SkillUpdateParams): CompletableFuture = + update(skillId, params, RequestOptions.none()) + + /** @see update */ + fun update( + skillId: String, + params: SkillUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see update */ + fun update(params: SkillUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: SkillUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** List Skills */ + fun list(): CompletableFuture = list(SkillListParams.none()) + + /** @see list */ + fun list( + params: SkillListParams = SkillListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list( + params: SkillListParams = SkillListParams.none() + ): CompletableFuture = list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): CompletableFuture = + list(SkillListParams.none(), requestOptions) + + /** Delete Skill */ + fun delete(skillId: String): CompletableFuture = + delete(skillId, SkillDeleteParams.none()) + + /** @see delete */ + fun delete( + skillId: String, + params: SkillDeleteParams = SkillDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see delete */ + fun delete( + skillId: String, + params: SkillDeleteParams = SkillDeleteParams.none(), + ): CompletableFuture = delete(skillId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: SkillDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see delete */ + fun delete(params: SkillDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(skillId: String, requestOptions: RequestOptions): CompletableFuture = + delete(skillId, SkillDeleteParams.none(), requestOptions) + + /** A view of [SkillServiceAsync] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): SkillServiceAsync.WithRawResponse + + fun content(): ContentServiceAsync.WithRawResponse + + fun versions(): VersionServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /skills`, but is otherwise the same as + * [SkillServiceAsync.create]. + */ + fun create(): CompletableFuture> = create(SkillCreateParams.none()) + + /** @see create */ + fun create( + params: SkillCreateParams = SkillCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see create */ + fun create( + params: SkillCreateParams = SkillCreateParams.none() + ): CompletableFuture> = create(params, RequestOptions.none()) + + /** @see create */ + fun create(requestOptions: RequestOptions): CompletableFuture> = + create(SkillCreateParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /skills/{skill_id}`, but is otherwise the same as + * [SkillServiceAsync.retrieve]. + */ + fun retrieve(skillId: String): CompletableFuture> = + retrieve(skillId, SkillRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + skillId: String, + params: SkillRetrieveParams = SkillRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + skillId: String, + params: SkillRetrieveParams = SkillRetrieveParams.none(), + ): CompletableFuture> = + retrieve(skillId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: SkillRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve(params: SkillRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + skillId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(skillId, SkillRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /skills/{skill_id}`, but is otherwise the same as + * [SkillServiceAsync.update]. + */ + fun update( + skillId: String, + params: SkillUpdateParams, + ): CompletableFuture> = + update(skillId, params, RequestOptions.none()) + + /** @see update */ + fun update( + skillId: String, + params: SkillUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see update */ + fun update(params: SkillUpdateParams): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: SkillUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /skills`, but is otherwise the same as + * [SkillServiceAsync.list]. + */ + fun list(): CompletableFuture> = + list(SkillListParams.none()) + + /** @see list */ + fun list( + params: SkillListParams = SkillListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: SkillListParams = SkillListParams.none() + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + requestOptions: RequestOptions + ): CompletableFuture> = + list(SkillListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /skills/{skill_id}`, but is otherwise the same as + * [SkillServiceAsync.delete]. + */ + fun delete(skillId: String): CompletableFuture> = + delete(skillId, SkillDeleteParams.none()) + + /** @see delete */ + fun delete( + skillId: String, + params: SkillDeleteParams = SkillDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see delete */ + fun delete( + skillId: String, + params: SkillDeleteParams = SkillDeleteParams.none(), + ): CompletableFuture> = + delete(skillId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: SkillDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see delete */ + fun delete(params: SkillDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + skillId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(skillId, SkillDeleteParams.none(), requestOptions) + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/SkillServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/SkillServiceAsyncImpl.kt new file mode 100644 index 00000000..19d2f955 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/SkillServiceAsyncImpl.kt @@ -0,0 +1,284 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.multipartFormData +import com.openai.core.http.parseable +import com.openai.core.prepareAsync +import com.openai.models.skills.DeletedSkill +import com.openai.models.skills.Skill +import com.openai.models.skills.SkillCreateParams +import com.openai.models.skills.SkillDeleteParams +import com.openai.models.skills.SkillList +import com.openai.models.skills.SkillListPageAsync +import com.openai.models.skills.SkillListParams +import com.openai.models.skills.SkillRetrieveParams +import com.openai.models.skills.SkillUpdateParams +import com.openai.services.async.skills.ContentServiceAsync +import com.openai.services.async.skills.ContentServiceAsyncImpl +import com.openai.services.async.skills.VersionServiceAsync +import com.openai.services.async.skills.VersionServiceAsyncImpl +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class SkillServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + SkillServiceAsync { + + private val withRawResponse: SkillServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val content: ContentServiceAsync by lazy { ContentServiceAsyncImpl(clientOptions) } + + private val versions: VersionServiceAsync by lazy { VersionServiceAsyncImpl(clientOptions) } + + override fun withRawResponse(): SkillServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): SkillServiceAsync = + SkillServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun content(): ContentServiceAsync = content + + override fun versions(): VersionServiceAsync = versions + + override fun create( + params: SkillCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /skills + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun retrieve( + params: SkillRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /skills/{skill_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun update( + params: SkillUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /skills/{skill_id} + withRawResponse().update(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: SkillListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /skills + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun delete( + params: SkillDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /skills/{skill_id} + withRawResponse().delete(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + SkillServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + private val content: ContentServiceAsync.WithRawResponse by lazy { + ContentServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + private val versions: VersionServiceAsync.WithRawResponse by lazy { + VersionServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): SkillServiceAsync.WithRawResponse = + SkillServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun content(): ContentServiceAsync.WithRawResponse = content + + override fun versions(): VersionServiceAsync.WithRawResponse = versions + + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: SkillCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills") + .body(multipartFormData(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: SkillRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("skillId", params.skillId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills", params._pathParam(0)) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: SkillUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("skillId", params.skillId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills", params._pathParam(0)) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: SkillListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + SkillListPageAsync.builder() + .service(SkillServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) + .params(params) + .response(it) + .build() + } + } + } + } + + private val deleteHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun delete( + params: SkillDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("skillId", params.skillId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills", params._pathParam(0)) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { deleteHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/skills/ContentServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/skills/ContentServiceAsync.kt new file mode 100644 index 00000000..36609822 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/skills/ContentServiceAsync.kt @@ -0,0 +1,110 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.skills + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponse +import com.openai.models.skills.content.ContentRetrieveParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface ContentServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ContentServiceAsync + + /** Get Skill Content */ + fun retrieve(skillId: String): CompletableFuture = + retrieve(skillId, ContentRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + skillId: String, + params: ContentRetrieveParams = ContentRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + skillId: String, + params: ContentRetrieveParams = ContentRetrieveParams.none(), + ): CompletableFuture = retrieve(skillId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve(params: ContentRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(skillId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(skillId, ContentRetrieveParams.none(), requestOptions) + + /** + * A view of [ContentServiceAsync] that provides access to raw HTTP responses for each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ContentServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `get /skills/{skill_id}/content`, but is otherwise the + * same as [ContentServiceAsync.retrieve]. + */ + fun retrieve(skillId: String): CompletableFuture = + retrieve(skillId, ContentRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + skillId: String, + params: ContentRetrieveParams = ContentRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + skillId: String, + params: ContentRetrieveParams = ContentRetrieveParams.none(), + ): CompletableFuture = retrieve(skillId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve(params: ContentRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + skillId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(skillId, ContentRetrieveParams.none(), requestOptions) + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/skills/ContentServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/skills/ContentServiceAsyncImpl.kt new file mode 100644 index 00000000..c737c0e0 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/skills/ContentServiceAsyncImpl.kt @@ -0,0 +1,72 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.skills + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.prepareAsync +import com.openai.models.skills.content.ContentRetrieveParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class ContentServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + ContentServiceAsync { + + private val withRawResponse: ContentServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): ContentServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): ContentServiceAsync = + ContentServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /skills/{skill_id}/content + withRawResponse().retrieve(params, requestOptions) + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + ContentServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ContentServiceAsync.WithRawResponse = + ContentServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("skillId", params.skillId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills", params._pathParam(0), "content") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> errorHandler.handle(response) } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/skills/VersionServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/skills/VersionServiceAsync.kt new file mode 100644 index 00000000..84958d93 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/skills/VersionServiceAsync.kt @@ -0,0 +1,304 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.skills + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.skills.versions.DeletedSkillVersion +import com.openai.models.skills.versions.SkillVersion +import com.openai.models.skills.versions.VersionCreateParams +import com.openai.models.skills.versions.VersionDeleteParams +import com.openai.models.skills.versions.VersionListPageAsync +import com.openai.models.skills.versions.VersionListParams +import com.openai.models.skills.versions.VersionRetrieveParams +import com.openai.services.async.skills.versions.ContentServiceAsync +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface VersionServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): VersionServiceAsync + + fun content(): ContentServiceAsync + + /** Create Skill Version */ + fun create(skillId: String): CompletableFuture = + create(skillId, VersionCreateParams.none()) + + /** @see create */ + fun create( + skillId: String, + params: VersionCreateParams = VersionCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + create(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see create */ + fun create( + skillId: String, + params: VersionCreateParams = VersionCreateParams.none(), + ): CompletableFuture = create(skillId, params, RequestOptions.none()) + + /** @see create */ + fun create( + params: VersionCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see create */ + fun create(params: VersionCreateParams): CompletableFuture = + create(params, RequestOptions.none()) + + /** @see create */ + fun create(skillId: String, requestOptions: RequestOptions): CompletableFuture = + create(skillId, VersionCreateParams.none(), requestOptions) + + /** Get Skill Version */ + fun retrieve(version: String, params: VersionRetrieveParams): CompletableFuture = + retrieve(version, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + version: String, + params: VersionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().version(version).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: VersionRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: VersionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** List Skill Versions */ + fun list(skillId: String): CompletableFuture = + list(skillId, VersionListParams.none()) + + /** @see list */ + fun list( + skillId: String, + params: VersionListParams = VersionListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + list(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see list */ + fun list( + skillId: String, + params: VersionListParams = VersionListParams.none(), + ): CompletableFuture = list(skillId, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: VersionListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list(params: VersionListParams): CompletableFuture = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + skillId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + list(skillId, VersionListParams.none(), requestOptions) + + /** Delete Skill Version */ + fun delete( + version: String, + params: VersionDeleteParams, + ): CompletableFuture = delete(version, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + version: String, + params: VersionDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().version(version).build(), requestOptions) + + /** @see delete */ + fun delete(params: VersionDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: VersionDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * A view of [VersionServiceAsync] that provides access to raw HTTP responses for each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): VersionServiceAsync.WithRawResponse + + fun content(): ContentServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /skills/{skill_id}/versions`, but is otherwise the + * same as [VersionServiceAsync.create]. + */ + fun create(skillId: String): CompletableFuture> = + create(skillId, VersionCreateParams.none()) + + /** @see create */ + fun create( + skillId: String, + params: VersionCreateParams = VersionCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + create(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see create */ + fun create( + skillId: String, + params: VersionCreateParams = VersionCreateParams.none(), + ): CompletableFuture> = + create(skillId, params, RequestOptions.none()) + + /** @see create */ + fun create( + params: VersionCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see create */ + fun create(params: VersionCreateParams): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + skillId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + create(skillId, VersionCreateParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /skills/{skill_id}/versions/{version}`, but is + * otherwise the same as [VersionServiceAsync.retrieve]. + */ + fun retrieve( + version: String, + params: VersionRetrieveParams, + ): CompletableFuture> = + retrieve(version, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + version: String, + params: VersionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().version(version).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + params: VersionRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: VersionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /skills/{skill_id}/versions`, but is otherwise the + * same as [VersionServiceAsync.list]. + */ + fun list(skillId: String): CompletableFuture> = + list(skillId, VersionListParams.none()) + + /** @see list */ + fun list( + skillId: String, + params: VersionListParams = VersionListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + list(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see list */ + fun list( + skillId: String, + params: VersionListParams = VersionListParams.none(), + ): CompletableFuture> = + list(skillId, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: VersionListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: VersionListParams + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + skillId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + list(skillId, VersionListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /skills/{skill_id}/versions/{version}`, but is + * otherwise the same as [VersionServiceAsync.delete]. + */ + fun delete( + version: String, + params: VersionDeleteParams, + ): CompletableFuture> = + delete(version, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + version: String, + params: VersionDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().version(version).build(), requestOptions) + + /** @see delete */ + fun delete( + params: VersionDeleteParams + ): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: VersionDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/skills/VersionServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/skills/VersionServiceAsyncImpl.kt new file mode 100644 index 00000000..25683d9b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/skills/VersionServiceAsyncImpl.kt @@ -0,0 +1,249 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.skills + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.multipartFormData +import com.openai.core.http.parseable +import com.openai.core.prepareAsync +import com.openai.models.skills.versions.DeletedSkillVersion +import com.openai.models.skills.versions.SkillVersion +import com.openai.models.skills.versions.SkillVersionList +import com.openai.models.skills.versions.VersionCreateParams +import com.openai.models.skills.versions.VersionDeleteParams +import com.openai.models.skills.versions.VersionListPageAsync +import com.openai.models.skills.versions.VersionListParams +import com.openai.models.skills.versions.VersionRetrieveParams +import com.openai.services.async.skills.versions.ContentServiceAsync +import com.openai.services.async.skills.versions.ContentServiceAsyncImpl +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class VersionServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + VersionServiceAsync { + + private val withRawResponse: VersionServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val content: ContentServiceAsync by lazy { ContentServiceAsyncImpl(clientOptions) } + + override fun withRawResponse(): VersionServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): VersionServiceAsync = + VersionServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun content(): ContentServiceAsync = content + + override fun create( + params: VersionCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /skills/{skill_id}/versions + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun retrieve( + params: VersionRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /skills/{skill_id}/versions/{version} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: VersionListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /skills/{skill_id}/versions + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun delete( + params: VersionDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /skills/{skill_id}/versions/{version} + withRawResponse().delete(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + VersionServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + private val content: ContentServiceAsync.WithRawResponse by lazy { + ContentServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): VersionServiceAsync.WithRawResponse = + VersionServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun content(): ContentServiceAsync.WithRawResponse = content + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: VersionCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("skillId", params.skillId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills", params._pathParam(0), "versions") + .body(multipartFormData(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: VersionRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("version", params.version().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "skills", + params._pathParam(0), + "versions", + params._pathParam(1), + ) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: VersionListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("skillId", params.skillId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills", params._pathParam(0), "versions") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + VersionListPageAsync.builder() + .service(VersionServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) + .params(params) + .response(it) + .build() + } + } + } + } + + private val deleteHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun delete( + params: VersionDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("version", params.version().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "skills", + params._pathParam(0), + "versions", + params._pathParam(1), + ) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { deleteHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/skills/versions/ContentServiceAsync.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/skills/versions/ContentServiceAsync.kt new file mode 100644 index 00000000..96c8cc80 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/skills/versions/ContentServiceAsync.kt @@ -0,0 +1,89 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.skills.versions + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponse +import com.openai.models.skills.versions.content.ContentRetrieveParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface ContentServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ContentServiceAsync + + /** Get Skill Version Content */ + fun retrieve(version: String, params: ContentRetrieveParams): CompletableFuture = + retrieve(version, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + version: String, + params: ContentRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().version(version).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: ContentRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * A view of [ContentServiceAsync] that provides access to raw HTTP responses for each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ContentServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `get /skills/{skill_id}/versions/{version}/content`, but + * is otherwise the same as [ContentServiceAsync.retrieve]. + */ + fun retrieve( + version: String, + params: ContentRetrieveParams, + ): CompletableFuture = retrieve(version, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + version: String, + params: ContentRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().version(version).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: ContentRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/skills/versions/ContentServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/skills/versions/ContentServiceAsyncImpl.kt new file mode 100644 index 00000000..09314b20 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/skills/versions/ContentServiceAsyncImpl.kt @@ -0,0 +1,78 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.skills.versions + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.prepareAsync +import com.openai.models.skills.versions.content.ContentRetrieveParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class ContentServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + ContentServiceAsync { + + private val withRawResponse: ContentServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): ContentServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): ContentServiceAsync = + ContentServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /skills/{skill_id}/versions/{version}/content + withRawResponse().retrieve(params, requestOptions) + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + ContentServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ContentServiceAsync.WithRawResponse = + ContentServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("version", params.version().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "skills", + params._pathParam(0), + "versions", + params._pathParam(1), + "content", + ) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> errorHandler.handle(response) } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/ImageService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/ImageService.kt index 1cd9e749..33f1f92e 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/ImageService.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/ImageService.kt @@ -41,8 +41,8 @@ interface ImageService { /** * Creates an edited or extended image given one or more source images and a prompt. This - * endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`, and `gpt-image-1-mini`) - * and `dall-e-2`. + * endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`, `gpt-image-1-mini`, and + * `chatgpt-image-latest`) and `dall-e-2`. */ fun edit(params: ImageEditParams): ImagesResponse = edit(params, RequestOptions.none()) @@ -54,8 +54,8 @@ interface ImageService { /** * Creates an edited or extended image given one or more source images and a prompt. This - * endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`, and `gpt-image-1-mini`) - * and `dall-e-2`. + * endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`, `gpt-image-1-mini`, and + * `chatgpt-image-latest`) and `dall-e-2`. */ @MustBeClosed fun editStreaming(params: ImageEditParams): StreamResponse = diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/SkillService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/SkillService.kt new file mode 100644 index 00000000..ea62d814 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/SkillService.kt @@ -0,0 +1,320 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking + +import com.google.errorprone.annotations.MustBeClosed +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.skills.DeletedSkill +import com.openai.models.skills.Skill +import com.openai.models.skills.SkillCreateParams +import com.openai.models.skills.SkillDeleteParams +import com.openai.models.skills.SkillListPage +import com.openai.models.skills.SkillListParams +import com.openai.models.skills.SkillRetrieveParams +import com.openai.models.skills.SkillUpdateParams +import com.openai.services.blocking.skills.ContentService +import com.openai.services.blocking.skills.VersionService +import java.util.function.Consumer + +interface SkillService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): SkillService + + fun content(): ContentService + + fun versions(): VersionService + + /** Create Skill */ + fun create(): Skill = create(SkillCreateParams.none()) + + /** @see create */ + fun create( + params: SkillCreateParams = SkillCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Skill + + /** @see create */ + fun create(params: SkillCreateParams = SkillCreateParams.none()): Skill = + create(params, RequestOptions.none()) + + /** @see create */ + fun create(requestOptions: RequestOptions): Skill = + create(SkillCreateParams.none(), requestOptions) + + /** Get Skill */ + fun retrieve(skillId: String): Skill = retrieve(skillId, SkillRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + skillId: String, + params: SkillRetrieveParams = SkillRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Skill = retrieve(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(skillId: String, params: SkillRetrieveParams = SkillRetrieveParams.none()): Skill = + retrieve(skillId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: SkillRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Skill + + /** @see retrieve */ + fun retrieve(params: SkillRetrieveParams): Skill = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(skillId: String, requestOptions: RequestOptions): Skill = + retrieve(skillId, SkillRetrieveParams.none(), requestOptions) + + /** Update Skill Default Version */ + fun update(skillId: String, params: SkillUpdateParams): Skill = + update(skillId, params, RequestOptions.none()) + + /** @see update */ + fun update( + skillId: String, + params: SkillUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Skill = update(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see update */ + fun update(params: SkillUpdateParams): Skill = update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: SkillUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Skill + + /** List Skills */ + fun list(): SkillListPage = list(SkillListParams.none()) + + /** @see list */ + fun list( + params: SkillListParams = SkillListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): SkillListPage + + /** @see list */ + fun list(params: SkillListParams = SkillListParams.none()): SkillListPage = + list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): SkillListPage = + list(SkillListParams.none(), requestOptions) + + /** Delete Skill */ + fun delete(skillId: String): DeletedSkill = delete(skillId, SkillDeleteParams.none()) + + /** @see delete */ + fun delete( + skillId: String, + params: SkillDeleteParams = SkillDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): DeletedSkill = delete(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see delete */ + fun delete( + skillId: String, + params: SkillDeleteParams = SkillDeleteParams.none(), + ): DeletedSkill = delete(skillId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: SkillDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): DeletedSkill + + /** @see delete */ + fun delete(params: SkillDeleteParams): DeletedSkill = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(skillId: String, requestOptions: RequestOptions): DeletedSkill = + delete(skillId, SkillDeleteParams.none(), requestOptions) + + /** A view of [SkillService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): SkillService.WithRawResponse + + fun content(): ContentService.WithRawResponse + + fun versions(): VersionService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /skills`, but is otherwise the same as + * [SkillService.create]. + */ + @MustBeClosed fun create(): HttpResponseFor = create(SkillCreateParams.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: SkillCreateParams = SkillCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see create */ + @MustBeClosed + fun create(params: SkillCreateParams = SkillCreateParams.none()): HttpResponseFor = + create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create(requestOptions: RequestOptions): HttpResponseFor = + create(SkillCreateParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /skills/{skill_id}`, but is otherwise the same as + * [SkillService.retrieve]. + */ + @MustBeClosed + fun retrieve(skillId: String): HttpResponseFor = + retrieve(skillId, SkillRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + skillId: String, + params: SkillRetrieveParams = SkillRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + skillId: String, + params: SkillRetrieveParams = SkillRetrieveParams.none(), + ): HttpResponseFor = retrieve(skillId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: SkillRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: SkillRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(skillId: String, requestOptions: RequestOptions): HttpResponseFor = + retrieve(skillId, SkillRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /skills/{skill_id}`, but is otherwise the same as + * [SkillService.update]. + */ + @MustBeClosed + fun update(skillId: String, params: SkillUpdateParams): HttpResponseFor = + update(skillId, params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + skillId: String, + params: SkillUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update(params: SkillUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + params: SkillUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /skills`, but is otherwise the same as + * [SkillService.list]. + */ + @MustBeClosed fun list(): HttpResponseFor = list(SkillListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: SkillListParams = SkillListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list(params: SkillListParams = SkillListParams.none()): HttpResponseFor = + list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list(requestOptions: RequestOptions): HttpResponseFor = + list(SkillListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /skills/{skill_id}`, but is otherwise the same as + * [SkillService.delete]. + */ + @MustBeClosed + fun delete(skillId: String): HttpResponseFor = + delete(skillId, SkillDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + skillId: String, + params: SkillDeleteParams = SkillDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see delete */ + @MustBeClosed + fun delete( + skillId: String, + params: SkillDeleteParams = SkillDeleteParams.none(), + ): HttpResponseFor = delete(skillId, params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + params: SkillDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see delete */ + @MustBeClosed + fun delete(params: SkillDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(skillId: String, requestOptions: RequestOptions): HttpResponseFor = + delete(skillId, SkillDeleteParams.none(), requestOptions) + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/SkillServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/SkillServiceImpl.kt new file mode 100644 index 00000000..67e24b20 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/SkillServiceImpl.kt @@ -0,0 +1,252 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.multipartFormData +import com.openai.core.http.parseable +import com.openai.core.prepare +import com.openai.models.skills.DeletedSkill +import com.openai.models.skills.Skill +import com.openai.models.skills.SkillCreateParams +import com.openai.models.skills.SkillDeleteParams +import com.openai.models.skills.SkillList +import com.openai.models.skills.SkillListPage +import com.openai.models.skills.SkillListParams +import com.openai.models.skills.SkillRetrieveParams +import com.openai.models.skills.SkillUpdateParams +import com.openai.services.blocking.skills.ContentService +import com.openai.services.blocking.skills.ContentServiceImpl +import com.openai.services.blocking.skills.VersionService +import com.openai.services.blocking.skills.VersionServiceImpl +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class SkillServiceImpl internal constructor(private val clientOptions: ClientOptions) : + SkillService { + + private val withRawResponse: SkillService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val content: ContentService by lazy { ContentServiceImpl(clientOptions) } + + private val versions: VersionService by lazy { VersionServiceImpl(clientOptions) } + + override fun withRawResponse(): SkillService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): SkillService = + SkillServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun content(): ContentService = content + + override fun versions(): VersionService = versions + + override fun create(params: SkillCreateParams, requestOptions: RequestOptions): Skill = + // post /skills + withRawResponse().create(params, requestOptions).parse() + + override fun retrieve(params: SkillRetrieveParams, requestOptions: RequestOptions): Skill = + // get /skills/{skill_id} + withRawResponse().retrieve(params, requestOptions).parse() + + override fun update(params: SkillUpdateParams, requestOptions: RequestOptions): Skill = + // post /skills/{skill_id} + withRawResponse().update(params, requestOptions).parse() + + override fun list(params: SkillListParams, requestOptions: RequestOptions): SkillListPage = + // get /skills + withRawResponse().list(params, requestOptions).parse() + + override fun delete(params: SkillDeleteParams, requestOptions: RequestOptions): DeletedSkill = + // delete /skills/{skill_id} + withRawResponse().delete(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + SkillService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + private val content: ContentService.WithRawResponse by lazy { + ContentServiceImpl.WithRawResponseImpl(clientOptions) + } + + private val versions: VersionService.WithRawResponse by lazy { + VersionServiceImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): SkillService.WithRawResponse = + SkillServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun content(): ContentService.WithRawResponse = content + + override fun versions(): VersionService.WithRawResponse = versions + + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: SkillCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills") + .body(multipartFormData(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: SkillRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("skillId", params.skillId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills", params._pathParam(0)) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: SkillUpdateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("skillId", params.skillId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills", params._pathParam(0)) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: SkillListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + SkillListPage.builder() + .service(SkillServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } + } + } + + private val deleteHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun delete( + params: SkillDeleteParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("skillId", params.skillId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills", params._pathParam(0)) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { deleteHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/ContentService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/ContentService.kt new file mode 100644 index 00000000..89c1df96 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/ContentService.kt @@ -0,0 +1,112 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.skills + +import com.google.errorprone.annotations.MustBeClosed +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponse +import com.openai.models.skills.content.ContentRetrieveParams +import java.util.function.Consumer + +interface ContentService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ContentService + + /** Get Skill Content */ + @MustBeClosed + fun retrieve(skillId: String): HttpResponse = retrieve(skillId, ContentRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + skillId: String, + params: ContentRetrieveParams = ContentRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse = retrieve(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + skillId: String, + params: ContentRetrieveParams = ContentRetrieveParams.none(), + ): HttpResponse = retrieve(skillId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: ContentRetrieveParams): HttpResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(skillId: String, requestOptions: RequestOptions): HttpResponse = + retrieve(skillId, ContentRetrieveParams.none(), requestOptions) + + /** A view of [ContentService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ContentService.WithRawResponse + + /** + * Returns a raw HTTP response for `get /skills/{skill_id}/content`, but is otherwise the + * same as [ContentService.retrieve]. + */ + @MustBeClosed + fun retrieve(skillId: String): HttpResponse = + retrieve(skillId, ContentRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + skillId: String, + params: ContentRetrieveParams = ContentRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse = retrieve(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + skillId: String, + params: ContentRetrieveParams = ContentRetrieveParams.none(), + ): HttpResponse = retrieve(skillId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: ContentRetrieveParams): HttpResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(skillId: String, requestOptions: RequestOptions): HttpResponse = + retrieve(skillId, ContentRetrieveParams.none(), requestOptions) + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/ContentServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/ContentServiceImpl.kt new file mode 100644 index 00000000..88b12109 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/ContentServiceImpl.kt @@ -0,0 +1,70 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.skills + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.prepare +import com.openai.models.skills.content.ContentRetrieveParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class ContentServiceImpl internal constructor(private val clientOptions: ClientOptions) : + ContentService { + + private val withRawResponse: ContentService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): ContentService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): ContentService = + ContentServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponse = + // get /skills/{skill_id}/content + withRawResponse().retrieve(params, requestOptions) + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + ContentService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ContentService.WithRawResponse = + ContentServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponse { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("skillId", params.skillId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills", params._pathParam(0), "content") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response) + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/VersionService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/VersionService.kt new file mode 100644 index 00000000..89d7d8e1 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/VersionService.kt @@ -0,0 +1,294 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.skills + +import com.google.errorprone.annotations.MustBeClosed +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponseFor +import com.openai.models.skills.versions.DeletedSkillVersion +import com.openai.models.skills.versions.SkillVersion +import com.openai.models.skills.versions.VersionCreateParams +import com.openai.models.skills.versions.VersionDeleteParams +import com.openai.models.skills.versions.VersionListPage +import com.openai.models.skills.versions.VersionListParams +import com.openai.models.skills.versions.VersionRetrieveParams +import com.openai.services.blocking.skills.versions.ContentService +import java.util.function.Consumer + +interface VersionService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): VersionService + + fun content(): ContentService + + /** Create Skill Version */ + fun create(skillId: String): SkillVersion = create(skillId, VersionCreateParams.none()) + + /** @see create */ + fun create( + skillId: String, + params: VersionCreateParams = VersionCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): SkillVersion = create(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see create */ + fun create( + skillId: String, + params: VersionCreateParams = VersionCreateParams.none(), + ): SkillVersion = create(skillId, params, RequestOptions.none()) + + /** @see create */ + fun create( + params: VersionCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): SkillVersion + + /** @see create */ + fun create(params: VersionCreateParams): SkillVersion = create(params, RequestOptions.none()) + + /** @see create */ + fun create(skillId: String, requestOptions: RequestOptions): SkillVersion = + create(skillId, VersionCreateParams.none(), requestOptions) + + /** Get Skill Version */ + fun retrieve(version: String, params: VersionRetrieveParams): SkillVersion = + retrieve(version, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + version: String, + params: VersionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): SkillVersion = retrieve(params.toBuilder().version(version).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: VersionRetrieveParams): SkillVersion = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: VersionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): SkillVersion + + /** List Skill Versions */ + fun list(skillId: String): VersionListPage = list(skillId, VersionListParams.none()) + + /** @see list */ + fun list( + skillId: String, + params: VersionListParams = VersionListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): VersionListPage = list(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see list */ + fun list( + skillId: String, + params: VersionListParams = VersionListParams.none(), + ): VersionListPage = list(skillId, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: VersionListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): VersionListPage + + /** @see list */ + fun list(params: VersionListParams): VersionListPage = list(params, RequestOptions.none()) + + /** @see list */ + fun list(skillId: String, requestOptions: RequestOptions): VersionListPage = + list(skillId, VersionListParams.none(), requestOptions) + + /** Delete Skill Version */ + fun delete(version: String, params: VersionDeleteParams): DeletedSkillVersion = + delete(version, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + version: String, + params: VersionDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): DeletedSkillVersion = delete(params.toBuilder().version(version).build(), requestOptions) + + /** @see delete */ + fun delete(params: VersionDeleteParams): DeletedSkillVersion = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: VersionDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): DeletedSkillVersion + + /** A view of [VersionService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): VersionService.WithRawResponse + + fun content(): ContentService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /skills/{skill_id}/versions`, but is otherwise the + * same as [VersionService.create]. + */ + @MustBeClosed + fun create(skillId: String): HttpResponseFor = + create(skillId, VersionCreateParams.none()) + + /** @see create */ + @MustBeClosed + fun create( + skillId: String, + params: VersionCreateParams = VersionCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + create(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see create */ + @MustBeClosed + fun create( + skillId: String, + params: VersionCreateParams = VersionCreateParams.none(), + ): HttpResponseFor = create(skillId, params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: VersionCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see create */ + @MustBeClosed + fun create(params: VersionCreateParams): HttpResponseFor = + create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create(skillId: String, requestOptions: RequestOptions): HttpResponseFor = + create(skillId, VersionCreateParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /skills/{skill_id}/versions/{version}`, but is + * otherwise the same as [VersionService.retrieve]. + */ + @MustBeClosed + fun retrieve( + version: String, + params: VersionRetrieveParams, + ): HttpResponseFor = retrieve(version, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + version: String, + params: VersionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().version(version).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: VersionRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: VersionRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /skills/{skill_id}/versions`, but is otherwise the + * same as [VersionService.list]. + */ + @MustBeClosed + fun list(skillId: String): HttpResponseFor = + list(skillId, VersionListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + skillId: String, + params: VersionListParams = VersionListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + list(params.toBuilder().skillId(skillId).build(), requestOptions) + + /** @see list */ + @MustBeClosed + fun list( + skillId: String, + params: VersionListParams = VersionListParams.none(), + ): HttpResponseFor = list(skillId, params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: VersionListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list(params: VersionListParams): HttpResponseFor = + list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list( + skillId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + list(skillId, VersionListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /skills/{skill_id}/versions/{version}`, but is + * otherwise the same as [VersionService.delete]. + */ + @MustBeClosed + fun delete( + version: String, + params: VersionDeleteParams, + ): HttpResponseFor = delete(version, params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + version: String, + params: VersionDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().version(version).build(), requestOptions) + + /** @see delete */ + @MustBeClosed + fun delete(params: VersionDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + params: VersionDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/VersionServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/VersionServiceImpl.kt new file mode 100644 index 00000000..3d2e6a8b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/VersionServiceImpl.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.skills + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.handlers.jsonHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.http.HttpResponseFor +import com.openai.core.http.json +import com.openai.core.http.multipartFormData +import com.openai.core.http.parseable +import com.openai.core.prepare +import com.openai.models.skills.versions.DeletedSkillVersion +import com.openai.models.skills.versions.SkillVersion +import com.openai.models.skills.versions.SkillVersionList +import com.openai.models.skills.versions.VersionCreateParams +import com.openai.models.skills.versions.VersionDeleteParams +import com.openai.models.skills.versions.VersionListPage +import com.openai.models.skills.versions.VersionListParams +import com.openai.models.skills.versions.VersionRetrieveParams +import com.openai.services.blocking.skills.versions.ContentService +import com.openai.services.blocking.skills.versions.ContentServiceImpl +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class VersionServiceImpl internal constructor(private val clientOptions: ClientOptions) : + VersionService { + + private val withRawResponse: VersionService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val content: ContentService by lazy { ContentServiceImpl(clientOptions) } + + override fun withRawResponse(): VersionService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): VersionService = + VersionServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun content(): ContentService = content + + override fun create(params: VersionCreateParams, requestOptions: RequestOptions): SkillVersion = + // post /skills/{skill_id}/versions + withRawResponse().create(params, requestOptions).parse() + + override fun retrieve( + params: VersionRetrieveParams, + requestOptions: RequestOptions, + ): SkillVersion = + // get /skills/{skill_id}/versions/{version} + withRawResponse().retrieve(params, requestOptions).parse() + + override fun list(params: VersionListParams, requestOptions: RequestOptions): VersionListPage = + // get /skills/{skill_id}/versions + withRawResponse().list(params, requestOptions).parse() + + override fun delete( + params: VersionDeleteParams, + requestOptions: RequestOptions, + ): DeletedSkillVersion = + // delete /skills/{skill_id}/versions/{version} + withRawResponse().delete(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + VersionService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + private val content: ContentService.WithRawResponse by lazy { + ContentServiceImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): VersionService.WithRawResponse = + VersionServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun content(): ContentService.WithRawResponse = content + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: VersionCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("skillId", params.skillId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills", params._pathParam(0), "versions") + .body(multipartFormData(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: VersionRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("version", params.version().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "skills", + params._pathParam(0), + "versions", + params._pathParam(1), + ) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: VersionListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("skillId", params.skillId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("skills", params._pathParam(0), "versions") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + VersionListPage.builder() + .service(VersionServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } + } + } + + private val deleteHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun delete( + params: VersionDeleteParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("version", params.version().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "skills", + params._pathParam(0), + "versions", + params._pathParam(1), + ) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { deleteHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/versions/ContentService.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/versions/ContentService.kt new file mode 100644 index 00000000..7880fb3d --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/versions/ContentService.kt @@ -0,0 +1,89 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.skills.versions + +import com.google.errorprone.annotations.MustBeClosed +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.http.HttpResponse +import com.openai.models.skills.versions.content.ContentRetrieveParams +import java.util.function.Consumer + +interface ContentService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ContentService + + /** Get Skill Version Content */ + @MustBeClosed + fun retrieve(version: String, params: ContentRetrieveParams): HttpResponse = + retrieve(version, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + version: String, + params: ContentRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse = retrieve(params.toBuilder().version(version).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: ContentRetrieveParams): HttpResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse + + /** A view of [ContentService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ContentService.WithRawResponse + + /** + * Returns a raw HTTP response for `get /skills/{skill_id}/versions/{version}/content`, but + * is otherwise the same as [ContentService.retrieve]. + */ + @MustBeClosed + fun retrieve(version: String, params: ContentRetrieveParams): HttpResponse = + retrieve(version, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + version: String, + params: ContentRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse = retrieve(params.toBuilder().version(version).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: ContentRetrieveParams): HttpResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/versions/ContentServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/versions/ContentServiceImpl.kt new file mode 100644 index 00000000..53f61d93 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/skills/versions/ContentServiceImpl.kt @@ -0,0 +1,76 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.skills.versions + +import com.openai.core.ClientOptions +import com.openai.core.RequestOptions +import com.openai.core.checkRequired +import com.openai.core.handlers.errorBodyHandler +import com.openai.core.handlers.errorHandler +import com.openai.core.http.HttpMethod +import com.openai.core.http.HttpRequest +import com.openai.core.http.HttpResponse +import com.openai.core.http.HttpResponse.Handler +import com.openai.core.prepare +import com.openai.models.skills.versions.content.ContentRetrieveParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class ContentServiceImpl internal constructor(private val clientOptions: ClientOptions) : + ContentService { + + private val withRawResponse: ContentService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): ContentService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): ContentService = + ContentServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponse = + // get /skills/{skill_id}/versions/{version}/content + withRawResponse().retrieve(params, requestOptions) + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + ContentService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ContentService.WithRawResponse = + ContentServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun retrieve( + params: ContentRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponse { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("version", params.version().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "skills", + params._pathParam(0), + "versions", + params._pathParam(1), + "content", + ) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response) + } + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/conversations/items/ConversationItemTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/conversations/items/ConversationItemTest.kt index a6421f12..634a6b7e 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/conversations/items/ConversationItemTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/conversations/items/ConversationItemTest.kt @@ -22,6 +22,7 @@ import com.openai.models.responses.ResponseFunctionToolCall import com.openai.models.responses.ResponseFunctionToolCallItem import com.openai.models.responses.ResponseFunctionToolCallOutputItem import com.openai.models.responses.ResponseFunctionWebSearch +import com.openai.models.responses.ResponseLocalEnvironment import com.openai.models.responses.ResponseReasoningItem import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -860,6 +861,7 @@ internal class ConversationItemTest { .build() ) .callId("call_id") + .environment(ResponseLocalEnvironment.builder().build()) .status(ResponseFunctionShellToolCall.Status.IN_PROGRESS) .createdBy("created_by") .build() @@ -905,6 +907,7 @@ internal class ConversationItemTest { .build() ) .callId("call_id") + .environment(ResponseLocalEnvironment.builder().build()) .status(ResponseFunctionShellToolCall.Status.IN_PROGRESS) .createdBy("created_by") .build() diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerAutoTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerAutoTest.kt new file mode 100644 index 00000000..995b1395 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerAutoTest.kt @@ -0,0 +1,58 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ContainerAutoTest { + + @Test + fun create() { + val containerAuto = + ContainerAuto.builder() + .addFileId("file-123") + .memoryLimit(ContainerAuto.MemoryLimit._1G) + .networkPolicy(ContainerNetworkPolicyDisabled.builder().build()) + .addSkill(SkillReference.builder().skillId("x").version("version").build()) + .build() + + assertThat(containerAuto.fileIds().getOrNull()).containsExactly("file-123") + assertThat(containerAuto.memoryLimit()).contains(ContainerAuto.MemoryLimit._1G) + assertThat(containerAuto.networkPolicy()) + .contains( + ContainerAuto.NetworkPolicy.ofDisabled( + ContainerNetworkPolicyDisabled.builder().build() + ) + ) + assertThat(containerAuto.skills().getOrNull()) + .containsExactly( + ContainerAuto.Skill.ofReference( + SkillReference.builder().skillId("x").version("version").build() + ) + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val containerAuto = + ContainerAuto.builder() + .addFileId("file-123") + .memoryLimit(ContainerAuto.MemoryLimit._1G) + .networkPolicy(ContainerNetworkPolicyDisabled.builder().build()) + .addSkill(SkillReference.builder().skillId("x").version("version").build()) + .build() + + val roundtrippedContainerAuto = + jsonMapper.readValue( + jsonMapper.writeValueAsString(containerAuto), + jacksonTypeRef(), + ) + + assertThat(roundtrippedContainerAuto).isEqualTo(containerAuto) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerNetworkPolicyAllowlistTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerNetworkPolicyAllowlistTest.kt new file mode 100644 index 00000000..1c215e84 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerNetworkPolicyAllowlistTest.kt @@ -0,0 +1,62 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ContainerNetworkPolicyAllowlistTest { + + @Test + fun create() { + val containerNetworkPolicyAllowlist = + ContainerNetworkPolicyAllowlist.builder() + .addAllowedDomain("string") + .addDomainSecret( + ContainerNetworkPolicyDomainSecret.builder() + .domain("x") + .name("x") + .value("x") + .build() + ) + .build() + + assertThat(containerNetworkPolicyAllowlist.allowedDomains()).containsExactly("string") + assertThat(containerNetworkPolicyAllowlist.domainSecrets().getOrNull()) + .containsExactly( + ContainerNetworkPolicyDomainSecret.builder() + .domain("x") + .name("x") + .value("x") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val containerNetworkPolicyAllowlist = + ContainerNetworkPolicyAllowlist.builder() + .addAllowedDomain("string") + .addDomainSecret( + ContainerNetworkPolicyDomainSecret.builder() + .domain("x") + .name("x") + .value("x") + .build() + ) + .build() + + val roundtrippedContainerNetworkPolicyAllowlist = + jsonMapper.readValue( + jsonMapper.writeValueAsString(containerNetworkPolicyAllowlist), + jacksonTypeRef(), + ) + + assertThat(roundtrippedContainerNetworkPolicyAllowlist) + .isEqualTo(containerNetworkPolicyAllowlist) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerNetworkPolicyDisabledTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerNetworkPolicyDisabledTest.kt new file mode 100644 index 00000000..0885d285 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerNetworkPolicyDisabledTest.kt @@ -0,0 +1,31 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ContainerNetworkPolicyDisabledTest { + + @Test + fun create() { + val containerNetworkPolicyDisabled = ContainerNetworkPolicyDisabled.builder().build() + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val containerNetworkPolicyDisabled = ContainerNetworkPolicyDisabled.builder().build() + + val roundtrippedContainerNetworkPolicyDisabled = + jsonMapper.readValue( + jsonMapper.writeValueAsString(containerNetworkPolicyDisabled), + jacksonTypeRef(), + ) + + assertThat(roundtrippedContainerNetworkPolicyDisabled) + .isEqualTo(containerNetworkPolicyDisabled) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerNetworkPolicyDomainSecretTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerNetworkPolicyDomainSecretTest.kt new file mode 100644 index 00000000..408b535b --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerNetworkPolicyDomainSecretTest.kt @@ -0,0 +1,37 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ContainerNetworkPolicyDomainSecretTest { + + @Test + fun create() { + val containerNetworkPolicyDomainSecret = + ContainerNetworkPolicyDomainSecret.builder().domain("x").name("x").value("x").build() + + assertThat(containerNetworkPolicyDomainSecret.domain()).isEqualTo("x") + assertThat(containerNetworkPolicyDomainSecret.name()).isEqualTo("x") + assertThat(containerNetworkPolicyDomainSecret.value()).isEqualTo("x") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val containerNetworkPolicyDomainSecret = + ContainerNetworkPolicyDomainSecret.builder().domain("x").name("x").value("x").build() + + val roundtrippedContainerNetworkPolicyDomainSecret = + jsonMapper.readValue( + jsonMapper.writeValueAsString(containerNetworkPolicyDomainSecret), + jacksonTypeRef(), + ) + + assertThat(roundtrippedContainerNetworkPolicyDomainSecret) + .isEqualTo(containerNetworkPolicyDomainSecret) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerReferenceTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerReferenceTest.kt new file mode 100644 index 00000000..e584d734 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ContainerReferenceTest.kt @@ -0,0 +1,32 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ContainerReferenceTest { + + @Test + fun create() { + val containerReference = ContainerReference.builder().containerId("cntr_123").build() + + assertThat(containerReference.containerId()).isEqualTo("cntr_123") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val containerReference = ContainerReference.builder().containerId("cntr_123").build() + + val roundtrippedContainerReference = + jsonMapper.readValue( + jsonMapper.writeValueAsString(containerReference), + jacksonTypeRef(), + ) + + assertThat(roundtrippedContainerReference).isEqualTo(containerReference) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/FunctionShellToolTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/FunctionShellToolTest.kt index 86995c28..625d48bb 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/responses/FunctionShellToolTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/FunctionShellToolTest.kt @@ -11,13 +11,45 @@ internal class FunctionShellToolTest { @Test fun create() { - val functionShellTool = FunctionShellTool.builder().build() + val functionShellTool = + FunctionShellTool.builder() + .environment( + ContainerAuto.builder() + .addFileId("file-123") + .memoryLimit(ContainerAuto.MemoryLimit._1G) + .networkPolicy(ContainerNetworkPolicyDisabled.builder().build()) + .addSkill(SkillReference.builder().skillId("x").version("version").build()) + .build() + ) + .build() + + assertThat(functionShellTool.environment()) + .contains( + FunctionShellTool.Environment.ofContainerAuto( + ContainerAuto.builder() + .addFileId("file-123") + .memoryLimit(ContainerAuto.MemoryLimit._1G) + .networkPolicy(ContainerNetworkPolicyDisabled.builder().build()) + .addSkill(SkillReference.builder().skillId("x").version("version").build()) + .build() + ) + ) } @Test fun roundtrip() { val jsonMapper = jsonMapper() - val functionShellTool = FunctionShellTool.builder().build() + val functionShellTool = + FunctionShellTool.builder() + .environment( + ContainerAuto.builder() + .addFileId("file-123") + .memoryLimit(ContainerAuto.MemoryLimit._1G) + .networkPolicy(ContainerNetworkPolicyDisabled.builder().build()) + .addSkill(SkillReference.builder().skillId("x").version("version").build()) + .build() + ) + .build() val roundtrippedFunctionShellTool = jsonMapper.readValue( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/InlineSkillSourceTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/InlineSkillSourceTest.kt new file mode 100644 index 00000000..9b8d0360 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/InlineSkillSourceTest.kt @@ -0,0 +1,32 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class InlineSkillSourceTest { + + @Test + fun create() { + val inlineSkillSource = InlineSkillSource.builder().data("x").build() + + assertThat(inlineSkillSource.data()).isEqualTo("x") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val inlineSkillSource = InlineSkillSource.builder().data("x").build() + + val roundtrippedInlineSkillSource = + jsonMapper.readValue( + jsonMapper.writeValueAsString(inlineSkillSource), + jacksonTypeRef(), + ) + + assertThat(roundtrippedInlineSkillSource).isEqualTo(inlineSkillSource) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/InlineSkillTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/InlineSkillTest.kt new file mode 100644 index 00000000..91e925ac --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/InlineSkillTest.kt @@ -0,0 +1,44 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class InlineSkillTest { + + @Test + fun create() { + val inlineSkill = + InlineSkill.builder() + .description("description") + .name("name") + .source(InlineSkillSource.builder().data("x").build()) + .build() + + assertThat(inlineSkill.description()).isEqualTo("description") + assertThat(inlineSkill.name()).isEqualTo("name") + assertThat(inlineSkill.source()).isEqualTo(InlineSkillSource.builder().data("x").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val inlineSkill = + InlineSkill.builder() + .description("description") + .name("name") + .source(InlineSkillSource.builder().data("x").build()) + .build() + + val roundtrippedInlineSkill = + jsonMapper.readValue( + jsonMapper.writeValueAsString(inlineSkill), + jacksonTypeRef(), + ) + + assertThat(roundtrippedInlineSkill).isEqualTo(inlineSkill) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/LocalEnvironmentTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/LocalEnvironmentTest.kt new file mode 100644 index 00000000..7dd1d266 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/LocalEnvironmentTest.kt @@ -0,0 +1,54 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class LocalEnvironmentTest { + + @Test + fun create() { + val localEnvironment = + LocalEnvironment.builder() + .addSkill( + LocalSkill.builder() + .description("description") + .name("name") + .path("path") + .build() + ) + .build() + + assertThat(localEnvironment.skills().getOrNull()) + .containsExactly( + LocalSkill.builder().description("description").name("name").path("path").build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val localEnvironment = + LocalEnvironment.builder() + .addSkill( + LocalSkill.builder() + .description("description") + .name("name") + .path("path") + .build() + ) + .build() + + val roundtrippedLocalEnvironment = + jsonMapper.readValue( + jsonMapper.writeValueAsString(localEnvironment), + jacksonTypeRef(), + ) + + assertThat(roundtrippedLocalEnvironment).isEqualTo(localEnvironment) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/LocalSkillTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/LocalSkillTest.kt new file mode 100644 index 00000000..a832f5fc --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/LocalSkillTest.kt @@ -0,0 +1,36 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class LocalSkillTest { + + @Test + fun create() { + val localSkill = + LocalSkill.builder().description("description").name("name").path("path").build() + + assertThat(localSkill.description()).isEqualTo("description") + assertThat(localSkill.name()).isEqualTo("name") + assertThat(localSkill.path()).isEqualTo("path") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val localSkill = + LocalSkill.builder().description("description").name("name").path("path").build() + + val roundtrippedLocalSkill = + jsonMapper.readValue( + jsonMapper.writeValueAsString(localSkill), + jacksonTypeRef(), + ) + + assertThat(roundtrippedLocalSkill).isEqualTo(localSkill) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseContainerReferenceTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseContainerReferenceTest.kt new file mode 100644 index 00000000..87de0882 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseContainerReferenceTest.kt @@ -0,0 +1,34 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ResponseContainerReferenceTest { + + @Test + fun create() { + val responseContainerReference = + ResponseContainerReference.builder().containerId("container_id").build() + + assertThat(responseContainerReference.containerId()).isEqualTo("container_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val responseContainerReference = + ResponseContainerReference.builder().containerId("container_id").build() + + val roundtrippedResponseContainerReference = + jsonMapper.readValue( + jsonMapper.writeValueAsString(responseContainerReference), + jacksonTypeRef(), + ) + + assertThat(roundtrippedResponseContainerReference).isEqualTo(responseContainerReference) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseFunctionShellToolCallTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseFunctionShellToolCallTest.kt index 7d485ec8..960df4c2 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseFunctionShellToolCallTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseFunctionShellToolCallTest.kt @@ -22,6 +22,7 @@ internal class ResponseFunctionShellToolCallTest { .build() ) .callId("call_id") + .environment(ResponseLocalEnvironment.builder().build()) .status(ResponseFunctionShellToolCall.Status.IN_PROGRESS) .createdBy("created_by") .build() @@ -36,6 +37,12 @@ internal class ResponseFunctionShellToolCallTest { .build() ) assertThat(responseFunctionShellToolCall.callId()).isEqualTo("call_id") + assertThat(responseFunctionShellToolCall.environment()) + .contains( + ResponseFunctionShellToolCall.Environment.ofLocal( + ResponseLocalEnvironment.builder().build() + ) + ) assertThat(responseFunctionShellToolCall.status()) .isEqualTo(ResponseFunctionShellToolCall.Status.IN_PROGRESS) assertThat(responseFunctionShellToolCall.createdBy()).contains("created_by") @@ -55,6 +62,7 @@ internal class ResponseFunctionShellToolCallTest { .build() ) .callId("call_id") + .environment(ResponseLocalEnvironment.builder().build()) .status(ResponseFunctionShellToolCall.Status.IN_PROGRESS) .createdBy("created_by") .build() diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputItemTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputItemTest.kt index 651080b1..48de0fa2 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputItemTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputItemTest.kt @@ -1119,6 +1119,17 @@ internal class ResponseInputItemTest { ) .callId("x") .id("sh_123") + .environment( + LocalEnvironment.builder() + .addSkill( + LocalSkill.builder() + .description("description") + .name("name") + .path("path") + .build() + ) + .build() + ) .status(ResponseInputItem.ShellCall.Status.IN_PROGRESS) .build() @@ -1167,6 +1178,17 @@ internal class ResponseInputItemTest { ) .callId("x") .id("sh_123") + .environment( + LocalEnvironment.builder() + .addSkill( + LocalSkill.builder() + .description("description") + .name("name") + .path("path") + .build() + ) + .build() + ) .status(ResponseInputItem.ShellCall.Status.IN_PROGRESS) .build() ) diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseItemTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseItemTest.kt index 084a277a..8bcf2aaf 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseItemTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseItemTest.kt @@ -867,6 +867,7 @@ internal class ResponseItemTest { .build() ) .callId("call_id") + .environment(ResponseLocalEnvironment.builder().build()) .status(ResponseFunctionShellToolCall.Status.IN_PROGRESS) .createdBy("created_by") .build() @@ -910,6 +911,7 @@ internal class ResponseItemTest { .build() ) .callId("call_id") + .environment(ResponseLocalEnvironment.builder().build()) .status(ResponseFunctionShellToolCall.Status.IN_PROGRESS) .createdBy("created_by") .build() diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseLocalEnvironmentTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseLocalEnvironmentTest.kt new file mode 100644 index 00000000..b765e9c9 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseLocalEnvironmentTest.kt @@ -0,0 +1,30 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ResponseLocalEnvironmentTest { + + @Test + fun create() { + val responseLocalEnvironment = ResponseLocalEnvironment.builder().build() + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val responseLocalEnvironment = ResponseLocalEnvironment.builder().build() + + val roundtrippedResponseLocalEnvironment = + jsonMapper.readValue( + jsonMapper.writeValueAsString(responseLocalEnvironment), + jacksonTypeRef(), + ) + + assertThat(roundtrippedResponseLocalEnvironment).isEqualTo(responseLocalEnvironment) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseOutputItemTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseOutputItemTest.kt index eb81f399..62959dee 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseOutputItemTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseOutputItemTest.kt @@ -711,6 +711,7 @@ internal class ResponseOutputItemTest { .build() ) .callId("call_id") + .environment(ResponseLocalEnvironment.builder().build()) .status(ResponseFunctionShellToolCall.Status.IN_PROGRESS) .createdBy("created_by") .build() @@ -752,6 +753,7 @@ internal class ResponseOutputItemTest { .build() ) .callId("call_id") + .environment(ResponseLocalEnvironment.builder().build()) .status(ResponseFunctionShellToolCall.Status.IN_PROGRESS) .createdBy("created_by") .build() diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/SkillReferenceTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/SkillReferenceTest.kt new file mode 100644 index 00000000..dd31fa92 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/SkillReferenceTest.kt @@ -0,0 +1,33 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.responses + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SkillReferenceTest { + + @Test + fun create() { + val skillReference = SkillReference.builder().skillId("x").version("version").build() + + assertThat(skillReference.skillId()).isEqualTo("x") + assertThat(skillReference.version()).contains("version") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val skillReference = SkillReference.builder().skillId("x").version("version").build() + + val roundtrippedSkillReference = + jsonMapper.readValue( + jsonMapper.writeValueAsString(skillReference), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSkillReference).isEqualTo(skillReference) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/StructuredResponseOutputItemTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/StructuredResponseOutputItemTest.kt index b7bd60b9..c5c5b70c 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/responses/StructuredResponseOutputItemTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/StructuredResponseOutputItemTest.kt @@ -93,6 +93,7 @@ internal class StructuredResponseOutputItemTest { ResponseFunctionShellToolCall.builder() .id(STRING) .callId(STRING) + .environment(ResponseLocalEnvironment.builder().build()) .status(ResponseFunctionShellToolCall.Status.COMPLETED) .action( ResponseFunctionShellToolCall.Action.builder() diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ToolTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ToolTest.kt index b7ab999b..7b4cc92b 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/responses/ToolTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ToolTest.kt @@ -474,7 +474,17 @@ internal class ToolTest { @Test fun ofShell() { - val shell = FunctionShellTool.builder().build() + val shell = + FunctionShellTool.builder() + .environment( + ContainerAuto.builder() + .addFileId("file-123") + .memoryLimit(ContainerAuto.MemoryLimit._1G) + .networkPolicy(ContainerNetworkPolicyDisabled.builder().build()) + .addSkill(SkillReference.builder().skillId("x").version("version").build()) + .build() + ) + .build() val tool = Tool.ofShell(shell) @@ -495,7 +505,21 @@ internal class ToolTest { @Test fun ofShellRoundtrip() { val jsonMapper = jsonMapper() - val tool = Tool.ofShell(FunctionShellTool.builder().build()) + val tool = + Tool.ofShell( + FunctionShellTool.builder() + .environment( + ContainerAuto.builder() + .addFileId("file-123") + .memoryLimit(ContainerAuto.MemoryLimit._1G) + .networkPolicy(ContainerNetworkPolicyDisabled.builder().build()) + .addSkill( + SkillReference.builder().skillId("x").version("version").build() + ) + .build() + ) + .build() + ) val roundtrippedTool = jsonMapper.readValue(jsonMapper.writeValueAsString(tool), jacksonTypeRef()) diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/DeletedSkillTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/DeletedSkillTest.kt new file mode 100644 index 00000000..57f7fcbe --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/DeletedSkillTest.kt @@ -0,0 +1,33 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class DeletedSkillTest { + + @Test + fun create() { + val deletedSkill = DeletedSkill.builder().id("id").deleted(true).build() + + assertThat(deletedSkill.id()).isEqualTo("id") + assertThat(deletedSkill.deleted()).isEqualTo(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val deletedSkill = DeletedSkill.builder().id("id").deleted(true).build() + + val roundtrippedDeletedSkill = + jsonMapper.readValue( + jsonMapper.writeValueAsString(deletedSkill), + jacksonTypeRef(), + ) + + assertThat(roundtrippedDeletedSkill).isEqualTo(deletedSkill) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillCreateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillCreateParamsTest.kt new file mode 100644 index 00000000..5e255a60 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillCreateParamsTest.kt @@ -0,0 +1,62 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.openai.core.MultipartField +import java.io.InputStream +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SkillCreateParamsTest { + + @Test + fun create() { + SkillCreateParams.builder() + .filesOfInputStreams(listOf("some content".byteInputStream())) + .build() + } + + @Test + fun body() { + val params = + SkillCreateParams.builder() + .filesOfInputStreams(listOf("some content".byteInputStream())) + .build() + + val body = params._body() + + assertThat(body.filterValues { !it.value.isNull() }) + .usingRecursiveComparison() + // TODO(AssertJ): Replace this and the `mapValues` below with: + // https://github.com/assertj/assertj/issues/3165 + .withEqualsForType( + { a, b -> a.readBytes() contentEquals b.readBytes() }, + InputStream::class.java, + ) + .isEqualTo( + mapOf( + "files" to + MultipartField.builder() + .value( + SkillCreateParams.Files.ofInputStreams( + listOf("some content".byteInputStream()) + ) + ) + .contentType("application/octet-stream") + .build() + ) + .mapValues { (_, field) -> + field.map { (it as? ByteArray)?.inputStream() ?: it } + } + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = SkillCreateParams.builder().build() + + val body = params._body() + + assertThat(body.filterValues { !it.value.isNull() }).isEmpty() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillDeleteParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillDeleteParamsTest.kt new file mode 100644 index 00000000..cc0ea7ba --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillDeleteParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SkillDeleteParamsTest { + + @Test + fun create() { + SkillDeleteParams.builder().skillId("skill_123").build() + } + + @Test + fun pathParams() { + val params = SkillDeleteParams.builder().skillId("skill_123").build() + + assertThat(params._pathParam(0)).isEqualTo("skill_123") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillListParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillListParamsTest.kt new file mode 100644 index 00000000..857be122 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillListParamsTest.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.openai.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SkillListParamsTest { + + @Test + fun create() { + SkillListParams.builder().after("after").limit(0L).order(SkillListParams.Order.ASC).build() + } + + @Test + fun queryParams() { + val params = + SkillListParams.builder() + .after("after") + .limit(0L) + .order(SkillListParams.Order.ASC) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("after", "after") + .put("limit", "0") + .put("order", "asc") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = SkillListParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillListTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillListTest.kt new file mode 100644 index 00000000..e2b71b58 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillListTest.kt @@ -0,0 +1,75 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SkillListTest { + + @Test + fun create() { + val skillList = + SkillList.builder() + .addData( + Skill.builder() + .id("id") + .createdAt(0L) + .defaultVersion("default_version") + .description("description") + .latestVersion("latest_version") + .name("name") + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + assertThat(skillList.data()) + .containsExactly( + Skill.builder() + .id("id") + .createdAt(0L) + .defaultVersion("default_version") + .description("description") + .latestVersion("latest_version") + .name("name") + .build() + ) + assertThat(skillList.firstId()).contains("first_id") + assertThat(skillList.hasMore()).isEqualTo(true) + assertThat(skillList.lastId()).contains("last_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val skillList = + SkillList.builder() + .addData( + Skill.builder() + .id("id") + .createdAt(0L) + .defaultVersion("default_version") + .description("description") + .latestVersion("latest_version") + .name("name") + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + val roundtrippedSkillList = + jsonMapper.readValue( + jsonMapper.writeValueAsString(skillList), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSkillList).isEqualTo(skillList) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillRetrieveParamsTest.kt new file mode 100644 index 00000000..e19cae24 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillRetrieveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SkillRetrieveParamsTest { + + @Test + fun create() { + SkillRetrieveParams.builder().skillId("skill_123").build() + } + + @Test + fun pathParams() { + val params = SkillRetrieveParams.builder().skillId("skill_123").build() + + assertThat(params._pathParam(0)).isEqualTo("skill_123") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillTest.kt new file mode 100644 index 00000000..fd6c349b --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillTest.kt @@ -0,0 +1,50 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SkillTest { + + @Test + fun create() { + val skill = + Skill.builder() + .id("id") + .createdAt(0L) + .defaultVersion("default_version") + .description("description") + .latestVersion("latest_version") + .name("name") + .build() + + assertThat(skill.id()).isEqualTo("id") + assertThat(skill.createdAt()).isEqualTo(0L) + assertThat(skill.defaultVersion()).isEqualTo("default_version") + assertThat(skill.description()).isEqualTo("description") + assertThat(skill.latestVersion()).isEqualTo("latest_version") + assertThat(skill.name()).isEqualTo("name") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val skill = + Skill.builder() + .id("id") + .createdAt(0L) + .defaultVersion("default_version") + .description("description") + .latestVersion("latest_version") + .name("name") + .build() + + val roundtrippedSkill = + jsonMapper.readValue(jsonMapper.writeValueAsString(skill), jacksonTypeRef()) + + assertThat(roundtrippedSkill).isEqualTo(skill) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillUpdateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillUpdateParamsTest.kt new file mode 100644 index 00000000..e5216b37 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/SkillUpdateParamsTest.kt @@ -0,0 +1,40 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SkillUpdateParamsTest { + + @Test + fun create() { + SkillUpdateParams.builder().skillId("skill_123").defaultVersion("default_version").build() + } + + @Test + fun pathParams() { + val params = + SkillUpdateParams.builder() + .skillId("skill_123") + .defaultVersion("default_version") + .build() + + assertThat(params._pathParam(0)).isEqualTo("skill_123") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + SkillUpdateParams.builder() + .skillId("skill_123") + .defaultVersion("default_version") + .build() + + val body = params._body() + + assertThat(body.defaultVersion()).isEqualTo("default_version") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/content/ContentRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/content/ContentRetrieveParamsTest.kt new file mode 100644 index 00000000..61756a39 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/content/ContentRetrieveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.content + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ContentRetrieveParamsTest { + + @Test + fun create() { + ContentRetrieveParams.builder().skillId("skill_123").build() + } + + @Test + fun pathParams() { + val params = ContentRetrieveParams.builder().skillId("skill_123").build() + + assertThat(params._pathParam(0)).isEqualTo("skill_123") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/DeletedSkillVersionTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/DeletedSkillVersionTest.kt new file mode 100644 index 00000000..94f11edb --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/DeletedSkillVersionTest.kt @@ -0,0 +1,36 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class DeletedSkillVersionTest { + + @Test + fun create() { + val deletedSkillVersion = + DeletedSkillVersion.builder().id("id").deleted(true).version("version").build() + + assertThat(deletedSkillVersion.id()).isEqualTo("id") + assertThat(deletedSkillVersion.deleted()).isEqualTo(true) + assertThat(deletedSkillVersion.version()).isEqualTo("version") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val deletedSkillVersion = + DeletedSkillVersion.builder().id("id").deleted(true).version("version").build() + + val roundtrippedDeletedSkillVersion = + jsonMapper.readValue( + jsonMapper.writeValueAsString(deletedSkillVersion), + jacksonTypeRef(), + ) + + assertThat(roundtrippedDeletedSkillVersion).isEqualTo(deletedSkillVersion) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/SkillVersionListTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/SkillVersionListTest.kt new file mode 100644 index 00000000..a8574647 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/SkillVersionListTest.kt @@ -0,0 +1,75 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SkillVersionListTest { + + @Test + fun create() { + val skillVersionList = + SkillVersionList.builder() + .addData( + SkillVersion.builder() + .id("id") + .createdAt(0L) + .description("description") + .name("name") + .skillId("skill_id") + .version("version") + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + assertThat(skillVersionList.data()) + .containsExactly( + SkillVersion.builder() + .id("id") + .createdAt(0L) + .description("description") + .name("name") + .skillId("skill_id") + .version("version") + .build() + ) + assertThat(skillVersionList.firstId()).contains("first_id") + assertThat(skillVersionList.hasMore()).isEqualTo(true) + assertThat(skillVersionList.lastId()).contains("last_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val skillVersionList = + SkillVersionList.builder() + .addData( + SkillVersion.builder() + .id("id") + .createdAt(0L) + .description("description") + .name("name") + .skillId("skill_id") + .version("version") + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + val roundtrippedSkillVersionList = + jsonMapper.readValue( + jsonMapper.writeValueAsString(skillVersionList), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSkillVersionList).isEqualTo(skillVersionList) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/SkillVersionTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/SkillVersionTest.kt new file mode 100644 index 00000000..6e3af037 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/SkillVersionTest.kt @@ -0,0 +1,53 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SkillVersionTest { + + @Test + fun create() { + val skillVersion = + SkillVersion.builder() + .id("id") + .createdAt(0L) + .description("description") + .name("name") + .skillId("skill_id") + .version("version") + .build() + + assertThat(skillVersion.id()).isEqualTo("id") + assertThat(skillVersion.createdAt()).isEqualTo(0L) + assertThat(skillVersion.description()).isEqualTo("description") + assertThat(skillVersion.name()).isEqualTo("name") + assertThat(skillVersion.skillId()).isEqualTo("skill_id") + assertThat(skillVersion.version()).isEqualTo("version") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val skillVersion = + SkillVersion.builder() + .id("id") + .createdAt(0L) + .description("description") + .name("name") + .skillId("skill_id") + .version("version") + .build() + + val roundtrippedSkillVersion = + jsonMapper.readValue( + jsonMapper.writeValueAsString(skillVersion), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSkillVersion).isEqualTo(skillVersion) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/VersionCreateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/VersionCreateParamsTest.kt new file mode 100644 index 00000000..d79fd3b4 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/VersionCreateParamsTest.kt @@ -0,0 +1,76 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.openai.core.MultipartField +import java.io.InputStream +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VersionCreateParamsTest { + + @Test + fun create() { + VersionCreateParams.builder() + .skillId("skill_123") + .default_(true) + .filesOfInputStreams(listOf("some content".byteInputStream())) + .build() + } + + @Test + fun pathParams() { + val params = VersionCreateParams.builder().skillId("skill_123").build() + + assertThat(params._pathParam(0)).isEqualTo("skill_123") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + VersionCreateParams.builder() + .skillId("skill_123") + .default_(true) + .filesOfInputStreams(listOf("some content".byteInputStream())) + .build() + + val body = params._body() + + assertThat(body.filterValues { !it.value.isNull() }) + .usingRecursiveComparison() + // TODO(AssertJ): Replace this and the `mapValues` below with: + // https://github.com/assertj/assertj/issues/3165 + .withEqualsForType( + { a, b -> a.readBytes() contentEquals b.readBytes() }, + InputStream::class.java, + ) + .isEqualTo( + mapOf( + "default" to MultipartField.of(true), + "files" to + MultipartField.builder() + .value( + VersionCreateParams.Files.ofInputStreams( + listOf("some content".byteInputStream()) + ) + ) + .contentType("application/octet-stream") + .build(), + ) + .mapValues { (_, field) -> + field.map { (it as? ByteArray)?.inputStream() ?: it } + } + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = VersionCreateParams.builder().skillId("skill_123").build() + + val body = params._body() + + assertThat(body.filterValues { !it.value.isNull() }).isEmpty() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/VersionDeleteParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/VersionDeleteParamsTest.kt new file mode 100644 index 00000000..469d7dc3 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/VersionDeleteParamsTest.kt @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VersionDeleteParamsTest { + + @Test + fun create() { + VersionDeleteParams.builder().skillId("skill_123").version("version").build() + } + + @Test + fun pathParams() { + val params = VersionDeleteParams.builder().skillId("skill_123").version("version").build() + + assertThat(params._pathParam(0)).isEqualTo("skill_123") + assertThat(params._pathParam(1)).isEqualTo("version") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/VersionListParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/VersionListParamsTest.kt new file mode 100644 index 00000000..235c2a78 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/VersionListParamsTest.kt @@ -0,0 +1,60 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import com.openai.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VersionListParamsTest { + + @Test + fun create() { + VersionListParams.builder() + .skillId("skill_123") + .after("skillver_123") + .limit(0L) + .order(VersionListParams.Order.ASC) + .build() + } + + @Test + fun pathParams() { + val params = VersionListParams.builder().skillId("skill_123").build() + + assertThat(params._pathParam(0)).isEqualTo("skill_123") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + VersionListParams.builder() + .skillId("skill_123") + .after("skillver_123") + .limit(0L) + .order(VersionListParams.Order.ASC) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("after", "skillver_123") + .put("limit", "0") + .put("order", "asc") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = VersionListParams.builder().skillId("skill_123").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/VersionRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/VersionRetrieveParamsTest.kt new file mode 100644 index 00000000..2e775cf1 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/VersionRetrieveParamsTest.kt @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VersionRetrieveParamsTest { + + @Test + fun create() { + VersionRetrieveParams.builder().skillId("skill_123").version("version").build() + } + + @Test + fun pathParams() { + val params = VersionRetrieveParams.builder().skillId("skill_123").version("version").build() + + assertThat(params._pathParam(0)).isEqualTo("skill_123") + assertThat(params._pathParam(1)).isEqualTo("version") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/content/ContentRetrieveParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/content/ContentRetrieveParamsTest.kt new file mode 100644 index 00000000..27656861 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/skills/versions/content/ContentRetrieveParamsTest.kt @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.skills.versions.content + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ContentRetrieveParamsTest { + + @Test + fun create() { + ContentRetrieveParams.builder().skillId("skill_123").version("version").build() + } + + @Test + fun pathParams() { + val params = ContentRetrieveParams.builder().skillId("skill_123").version("version").build() + + assertThat(params._pathParam(0)).isEqualTo("skill_123") + assertThat(params._pathParam(1)).isEqualTo("version") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/SkillServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/SkillServiceAsyncTest.kt new file mode 100644 index 00000000..80380340 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/SkillServiceAsyncTest.kt @@ -0,0 +1,100 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClientAsync +import com.openai.models.skills.SkillCreateParams +import com.openai.models.skills.SkillUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class SkillServiceAsyncTest { + + @Test + fun create() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val skillServiceAsync = client.skills() + + val skillFuture = + skillServiceAsync.create( + SkillCreateParams.builder() + .filesOfInputStreams(listOf("some content".byteInputStream())) + .build() + ) + + val skill = skillFuture.get() + skill.validate() + } + + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val skillServiceAsync = client.skills() + + val skillFuture = skillServiceAsync.retrieve("skill_123") + + val skill = skillFuture.get() + skill.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val skillServiceAsync = client.skills() + + val skillFuture = + skillServiceAsync.update( + SkillUpdateParams.builder() + .skillId("skill_123") + .defaultVersion("default_version") + .build() + ) + + val skill = skillFuture.get() + skill.validate() + } + + @Test + fun list() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val skillServiceAsync = client.skills() + + val pageFuture = skillServiceAsync.list() + + val page = pageFuture.get() + page.response().validate() + } + + @Test + fun delete() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val skillServiceAsync = client.skills() + + val deletedSkillFuture = skillServiceAsync.delete("skill_123") + + val deletedSkill = deletedSkillFuture.get() + deletedSkill.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/skills/ContentServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/skills/ContentServiceAsyncTest.kt new file mode 100644 index 00000000..883e9e10 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/skills/ContentServiceAsyncTest.kt @@ -0,0 +1,38 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.skills + +import com.github.tomakehurst.wiremock.client.WireMock.anyUrl +import com.github.tomakehurst.wiremock.client.WireMock.get +import com.github.tomakehurst.wiremock.client.WireMock.ok +import com.github.tomakehurst.wiremock.client.WireMock.stubFor +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo +import com.github.tomakehurst.wiremock.junit5.WireMockTest +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClientAsync +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.parallel.ResourceLock + +@ExtendWith(TestServerExtension::class) +@WireMockTest +@ResourceLock("https://github.com/wiremock/wiremock/issues/169") +internal class ContentServiceAsyncTest { + + @Test + fun retrieve(wmRuntimeInfo: WireMockRuntimeInfo) { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(wmRuntimeInfo.httpBaseUrl) + .apiKey("My API Key") + .build() + val contentServiceAsync = client.skills().content() + stubFor(get(anyUrl()).willReturn(ok().withBody("abc"))) + + val contentFuture = contentServiceAsync.retrieve("skill_123") + + val content = contentFuture.get() + assertThat(content.body()).hasContent("abc") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/skills/VersionServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/skills/VersionServiceAsyncTest.kt new file mode 100644 index 00000000..b83f773e --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/skills/VersionServiceAsyncTest.kt @@ -0,0 +1,88 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.skills + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClientAsync +import com.openai.models.skills.versions.VersionCreateParams +import com.openai.models.skills.versions.VersionDeleteParams +import com.openai.models.skills.versions.VersionRetrieveParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class VersionServiceAsyncTest { + + @Test + fun create() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val versionServiceAsync = client.skills().versions() + + val skillVersionFuture = + versionServiceAsync.create( + VersionCreateParams.builder() + .skillId("skill_123") + .default_(true) + .filesOfInputStreams(listOf("some content".byteInputStream())) + .build() + ) + + val skillVersion = skillVersionFuture.get() + skillVersion.validate() + } + + @Test + fun retrieve() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val versionServiceAsync = client.skills().versions() + + val skillVersionFuture = + versionServiceAsync.retrieve( + VersionRetrieveParams.builder().skillId("skill_123").version("version").build() + ) + + val skillVersion = skillVersionFuture.get() + skillVersion.validate() + } + + @Test + fun list() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val versionServiceAsync = client.skills().versions() + + val pageFuture = versionServiceAsync.list("skill_123") + + val page = pageFuture.get() + page.response().validate() + } + + @Test + fun delete() { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val versionServiceAsync = client.skills().versions() + + val deletedSkillVersionFuture = + versionServiceAsync.delete( + VersionDeleteParams.builder().skillId("skill_123").version("version").build() + ) + + val deletedSkillVersion = deletedSkillVersionFuture.get() + deletedSkillVersion.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/skills/versions/ContentServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/skills/versions/ContentServiceAsyncTest.kt new file mode 100644 index 00000000..8dbe726d --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/skills/versions/ContentServiceAsyncTest.kt @@ -0,0 +1,42 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.async.skills.versions + +import com.github.tomakehurst.wiremock.client.WireMock.anyUrl +import com.github.tomakehurst.wiremock.client.WireMock.get +import com.github.tomakehurst.wiremock.client.WireMock.ok +import com.github.tomakehurst.wiremock.client.WireMock.stubFor +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo +import com.github.tomakehurst.wiremock.junit5.WireMockTest +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClientAsync +import com.openai.models.skills.versions.content.ContentRetrieveParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.parallel.ResourceLock + +@ExtendWith(TestServerExtension::class) +@WireMockTest +@ResourceLock("https://github.com/wiremock/wiremock/issues/169") +internal class ContentServiceAsyncTest { + + @Test + fun retrieve(wmRuntimeInfo: WireMockRuntimeInfo) { + val client = + OpenAIOkHttpClientAsync.builder() + .baseUrl(wmRuntimeInfo.httpBaseUrl) + .apiKey("My API Key") + .build() + val contentServiceAsync = client.skills().versions().content() + stubFor(get(anyUrl()).willReturn(ok().withBody("abc"))) + + val contentFuture = + contentServiceAsync.retrieve( + ContentRetrieveParams.builder().skillId("skill_123").version("version").build() + ) + + val content = contentFuture.get() + assertThat(content.body()).hasContent("abc") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/SkillServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/SkillServiceTest.kt new file mode 100644 index 00000000..86bc13ee --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/SkillServiceTest.kt @@ -0,0 +1,95 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClient +import com.openai.models.skills.SkillCreateParams +import com.openai.models.skills.SkillUpdateParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class SkillServiceTest { + + @Test + fun create() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val skillService = client.skills() + + val skill = + skillService.create( + SkillCreateParams.builder() + .filesOfInputStreams(listOf("some content".byteInputStream())) + .build() + ) + + skill.validate() + } + + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val skillService = client.skills() + + val skill = skillService.retrieve("skill_123") + + skill.validate() + } + + @Test + fun update() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val skillService = client.skills() + + val skill = + skillService.update( + SkillUpdateParams.builder() + .skillId("skill_123") + .defaultVersion("default_version") + .build() + ) + + skill.validate() + } + + @Test + fun list() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val skillService = client.skills() + + val page = skillService.list() + + page.response().validate() + } + + @Test + fun delete() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val skillService = client.skills() + + val deletedSkill = skillService.delete("skill_123") + + deletedSkill.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/skills/ContentServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/skills/ContentServiceTest.kt new file mode 100644 index 00000000..3c5ad03b --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/skills/ContentServiceTest.kt @@ -0,0 +1,37 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.skills + +import com.github.tomakehurst.wiremock.client.WireMock.anyUrl +import com.github.tomakehurst.wiremock.client.WireMock.get +import com.github.tomakehurst.wiremock.client.WireMock.ok +import com.github.tomakehurst.wiremock.client.WireMock.stubFor +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo +import com.github.tomakehurst.wiremock.junit5.WireMockTest +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClient +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.parallel.ResourceLock + +@ExtendWith(TestServerExtension::class) +@WireMockTest +@ResourceLock("https://github.com/wiremock/wiremock/issues/169") +internal class ContentServiceTest { + + @Test + fun retrieve(wmRuntimeInfo: WireMockRuntimeInfo) { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(wmRuntimeInfo.httpBaseUrl) + .apiKey("My API Key") + .build() + val contentService = client.skills().content() + stubFor(get(anyUrl()).willReturn(ok().withBody("abc"))) + + val content = contentService.retrieve("skill_123") + + assertThat(content.body()).hasContent("abc") + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/skills/VersionServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/skills/VersionServiceTest.kt new file mode 100644 index 00000000..73905937 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/skills/VersionServiceTest.kt @@ -0,0 +1,84 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.skills + +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClient +import com.openai.models.skills.versions.VersionCreateParams +import com.openai.models.skills.versions.VersionDeleteParams +import com.openai.models.skills.versions.VersionRetrieveParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class VersionServiceTest { + + @Test + fun create() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val versionService = client.skills().versions() + + val skillVersion = + versionService.create( + VersionCreateParams.builder() + .skillId("skill_123") + .default_(true) + .filesOfInputStreams(listOf("some content".byteInputStream())) + .build() + ) + + skillVersion.validate() + } + + @Test + fun retrieve() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val versionService = client.skills().versions() + + val skillVersion = + versionService.retrieve( + VersionRetrieveParams.builder().skillId("skill_123").version("version").build() + ) + + skillVersion.validate() + } + + @Test + fun list() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val versionService = client.skills().versions() + + val page = versionService.list("skill_123") + + page.response().validate() + } + + @Test + fun delete() { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val versionService = client.skills().versions() + + val deletedSkillVersion = + versionService.delete( + VersionDeleteParams.builder().skillId("skill_123").version("version").build() + ) + + deletedSkillVersion.validate() + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/skills/versions/ContentServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/skills/versions/ContentServiceTest.kt new file mode 100644 index 00000000..6b6563c2 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/skills/versions/ContentServiceTest.kt @@ -0,0 +1,41 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.services.blocking.skills.versions + +import com.github.tomakehurst.wiremock.client.WireMock.anyUrl +import com.github.tomakehurst.wiremock.client.WireMock.get +import com.github.tomakehurst.wiremock.client.WireMock.ok +import com.github.tomakehurst.wiremock.client.WireMock.stubFor +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo +import com.github.tomakehurst.wiremock.junit5.WireMockTest +import com.openai.TestServerExtension +import com.openai.client.okhttp.OpenAIOkHttpClient +import com.openai.models.skills.versions.content.ContentRetrieveParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.junit.jupiter.api.parallel.ResourceLock + +@ExtendWith(TestServerExtension::class) +@WireMockTest +@ResourceLock("https://github.com/wiremock/wiremock/issues/169") +internal class ContentServiceTest { + + @Test + fun retrieve(wmRuntimeInfo: WireMockRuntimeInfo) { + val client = + OpenAIOkHttpClient.builder() + .baseUrl(wmRuntimeInfo.httpBaseUrl) + .apiKey("My API Key") + .build() + val contentService = client.skills().versions().content() + stubFor(get(anyUrl()).willReturn(ok().withBody("abc"))) + + val content = + contentService.retrieve( + ContentRetrieveParams.builder().skillId("skill_123").version("version").build() + ) + + assertThat(content.body()).hasContent("abc") + } +} diff --git a/openai-java-proguard-test/src/test/kotlin/com/openai/proguard/ProGuardCompatibilityTest.kt b/openai-java-proguard-test/src/test/kotlin/com/openai/proguard/ProGuardCompatibilityTest.kt index a9e5070e..ba15aca6 100644 --- a/openai-java-proguard-test/src/test/kotlin/com/openai/proguard/ProGuardCompatibilityTest.kt +++ b/openai-java-proguard-test/src/test/kotlin/com/openai/proguard/ProGuardCompatibilityTest.kt @@ -75,6 +75,7 @@ internal class ProGuardCompatibilityTest { assertThat(client.conversations()).isNotNull() assertThat(client.evals()).isNotNull() assertThat(client.containers()).isNotNull() + assertThat(client.skills()).isNotNull() assertThat(client.videos()).isNotNull() }