diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e17c9c0..ab02f266 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,9 @@ jobs: uses: gradle/actions/setup-gradle@v4 - name: Build SDK + # disable gradle daemon in CI because it is flakey + env: + GRADLE_OPTS: "-Dkotlin.compiler.execution.strategy=in-process" run: ./scripts/build test: diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 3b4c2d4b..bd7f3844 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.1.0" + ".": "4.2.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 4e40d470..f7aa916f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 122 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-fadefdc7c7e30df47c09df323669b242ff90ee08e51f304175ace5274e0aab49.yml -openapi_spec_hash: 6d20f639d9ff8a097a34962da6218231 -config_hash: 902654e60f5d659f2bfcfd903e17c46d +configured_endpoints: 135 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-d64cf80d2ebddf175c5578f68226a3d5bbd3f7fd8d62ccac2205f3fc05a355ee.yml +openapi_spec_hash: d51e0d60d0c536f210b597a211bc5af0 +config_hash: e7c42016df9c6bd7bd6ff15101b9bc9b diff --git a/CHANGELOG.md b/CHANGELOG.md index 47456bf8..d4d3abe7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 4.2.0 (2025-10-06) + +Full Changelog: [v4.1.0...v4.2.0](https://github.com/openai/openai-java/compare/v4.1.0...v4.2.0) + +### Features + +* **api:** dev day 2025 launches ([d4f0999](https://github.com/openai/openai-java/commit/d4f09991051ca1554f2452dd014941b3e5b77f73)) + ## 4.1.0 (2025-10-02) Full Changelog: [v4.0.1...v4.1.0](https://github.com/openai/openai-java/compare/v4.0.1...v4.1.0) diff --git a/README.md b/README.md index ed41afcf..afcb980a 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.1.0) -[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/4.1.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/4.1.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/4.2.0) +[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/4.2.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/4.2.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.1.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.2.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.1.0") +implementation("com.openai:openai-java:4.2.0") ``` ### Maven @@ -33,7 +33,7 @@ implementation("com.openai:openai-java:4.1.0") com.openai openai-java - 4.1.0 + 4.2.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.1.0") +implementation("com.openai:openai-java-spring-boot-starter:4.2.0") ``` #### Maven @@ -1351,7 +1351,7 @@ implementation("com.openai:openai-java-spring-boot-starter:4.1.0") com.openai openai-java-spring-boot-starter - 4.1.0 + 4.2.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index d0ccf1e9..efa3545e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.openai" - version = "4.1.0" // x-release-please-version + version = "4.2.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 8ae6b6e7..f0489a2f 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 @@ -22,6 +22,7 @@ import com.openai.services.blocking.RealtimeService import com.openai.services.blocking.ResponseService import com.openai.services.blocking.UploadService import com.openai.services.blocking.VectorStoreService +import com.openai.services.blocking.VideoService import com.openai.services.blocking.WebhookService import java.util.function.Consumer @@ -101,6 +102,8 @@ interface OpenAIClient { fun containers(): ContainerService + fun videos(): VideoService + /** * Closes this client, relinquishing any underlying resources. * @@ -163,5 +166,7 @@ interface OpenAIClient { fun evals(): EvalService.WithRawResponse fun containers(): ContainerService.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 351b305b..a3074bc1 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 @@ -22,6 +22,7 @@ import com.openai.services.async.RealtimeServiceAsync import com.openai.services.async.ResponseServiceAsync import com.openai.services.async.UploadServiceAsync import com.openai.services.async.VectorStoreServiceAsync +import com.openai.services.async.VideoServiceAsync import com.openai.services.async.WebhookServiceAsync import java.util.function.Consumer @@ -101,6 +102,8 @@ interface OpenAIClientAsync { fun containers(): ContainerServiceAsync + fun videos(): VideoServiceAsync + /** * Closes this client, relinquishing any underlying resources. * @@ -165,5 +168,7 @@ interface OpenAIClientAsync { fun evals(): EvalServiceAsync.WithRawResponse fun containers(): ContainerServiceAsync.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 8d8a48b1..1424255b 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 @@ -42,6 +42,8 @@ import com.openai.services.async.UploadServiceAsync import com.openai.services.async.UploadServiceAsyncImpl import com.openai.services.async.VectorStoreServiceAsync import com.openai.services.async.VectorStoreServiceAsyncImpl +import com.openai.services.async.VideoServiceAsync +import com.openai.services.async.VideoServiceAsyncImpl import com.openai.services.async.WebhookServiceAsync import com.openai.services.async.WebhookServiceAsyncImpl import java.util.function.Consumer @@ -135,6 +137,10 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl ContainerServiceAsyncImpl(clientOptionsWithUserAgent) } + private val videos: VideoServiceAsync by lazy { + VideoServiceAsyncImpl(clientOptionsWithUserAgent) + } + override fun sync(): OpenAIClient = sync override fun withRawResponse(): OpenAIClientAsync.WithRawResponse = withRawResponse @@ -182,6 +188,8 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl override fun containers(): ContainerServiceAsync = containers + override fun videos(): VideoServiceAsync = videos + override fun close() = clientOptions.close() class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : @@ -267,6 +275,10 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl ContainerServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val videos: VideoServiceAsync.WithRawResponse by lazy { + VideoServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): OpenAIClientAsync.WithRawResponse = @@ -313,5 +325,7 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl override fun evals(): EvalServiceAsync.WithRawResponse = evals override fun containers(): ContainerServiceAsync.WithRawResponse = containers + + 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 436680a9..22fa8afd 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 @@ -42,6 +42,8 @@ import com.openai.services.blocking.UploadService import com.openai.services.blocking.UploadServiceImpl import com.openai.services.blocking.VectorStoreService import com.openai.services.blocking.VectorStoreServiceImpl +import com.openai.services.blocking.VideoService +import com.openai.services.blocking.VideoServiceImpl import com.openai.services.blocking.WebhookService import com.openai.services.blocking.WebhookServiceImpl import java.util.function.Consumer @@ -121,6 +123,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient ContainerServiceImpl(clientOptionsWithUserAgent) } + private val videos: VideoService by lazy { VideoServiceImpl(clientOptionsWithUserAgent) } + override fun async(): OpenAIClientAsync = async override fun withRawResponse(): OpenAIClient.WithRawResponse = withRawResponse @@ -168,6 +172,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient override fun containers(): ContainerService = containers + override fun videos(): VideoService = videos + override fun close() = clientOptions.close() class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : @@ -253,6 +259,10 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient ContainerServiceImpl.WithRawResponseImpl(clientOptions) } + private val videos: VideoService.WithRawResponse by lazy { + VideoServiceImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): OpenAIClient.WithRawResponse = @@ -299,5 +309,7 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient override fun evals(): EvalService.WithRawResponse = evals override fun containers(): ContainerService.WithRawResponse = containers + + override fun videos(): VideoService.WithRawResponse = videos } } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AllModels.kt b/openai-java-core/src/main/kotlin/com/openai/models/AllModels.kt index eae7234a..8862a6c6 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/AllModels.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/AllModels.kt @@ -254,6 +254,10 @@ private constructor( @JvmField val GPT_5_CODEX = of("gpt-5-codex") + @JvmField val GPT_5_PRO = of("gpt-5-pro") + + @JvmField val GPT_5_PRO_2025_10_06 = of("gpt-5-pro-2025-10-06") + @JvmStatic fun of(value: String) = ResponsesOnlyModel(JsonField.of(value)) } @@ -270,6 +274,8 @@ private constructor( COMPUTER_USE_PREVIEW, COMPUTER_USE_PREVIEW_2025_03_11, GPT_5_CODEX, + GPT_5_PRO, + GPT_5_PRO_2025_10_06, } /** @@ -293,6 +299,8 @@ private constructor( COMPUTER_USE_PREVIEW, COMPUTER_USE_PREVIEW_2025_03_11, GPT_5_CODEX, + GPT_5_PRO, + GPT_5_PRO_2025_10_06, /** * An enum member indicating that [ResponsesOnlyModel] was instantiated with an unknown * value. @@ -320,6 +328,8 @@ private constructor( COMPUTER_USE_PREVIEW -> Value.COMPUTER_USE_PREVIEW COMPUTER_USE_PREVIEW_2025_03_11 -> Value.COMPUTER_USE_PREVIEW_2025_03_11 GPT_5_CODEX -> Value.GPT_5_CODEX + GPT_5_PRO -> Value.GPT_5_PRO + GPT_5_PRO_2025_10_06 -> Value.GPT_5_PRO_2025_10_06 else -> Value._UNKNOWN } @@ -345,6 +355,8 @@ private constructor( COMPUTER_USE_PREVIEW -> Known.COMPUTER_USE_PREVIEW COMPUTER_USE_PREVIEW_2025_03_11 -> Known.COMPUTER_USE_PREVIEW_2025_03_11 GPT_5_CODEX -> Known.GPT_5_CODEX + GPT_5_PRO -> Known.GPT_5_PRO + GPT_5_PRO_2025_10_06 -> Known.GPT_5_PRO_2025_10_06 else -> throw OpenAIInvalidDataException("Unknown ResponsesOnlyModel: $value") } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ResponsesModel.kt b/openai-java-core/src/main/kotlin/com/openai/models/ResponsesModel.kt index 412519c4..bbf0eee4 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ResponsesModel.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ResponsesModel.kt @@ -253,6 +253,10 @@ private constructor( @JvmField val GPT_5_CODEX = of("gpt-5-codex") + @JvmField val GPT_5_PRO = of("gpt-5-pro") + + @JvmField val GPT_5_PRO_2025_10_06 = of("gpt-5-pro-2025-10-06") + @JvmStatic fun of(value: String) = ResponsesOnlyModel(JsonField.of(value)) } @@ -269,6 +273,8 @@ private constructor( COMPUTER_USE_PREVIEW, COMPUTER_USE_PREVIEW_2025_03_11, GPT_5_CODEX, + GPT_5_PRO, + GPT_5_PRO_2025_10_06, } /** @@ -292,6 +298,8 @@ private constructor( COMPUTER_USE_PREVIEW, COMPUTER_USE_PREVIEW_2025_03_11, GPT_5_CODEX, + GPT_5_PRO, + GPT_5_PRO_2025_10_06, /** * An enum member indicating that [ResponsesOnlyModel] was instantiated with an unknown * value. @@ -319,6 +327,8 @@ private constructor( COMPUTER_USE_PREVIEW -> Value.COMPUTER_USE_PREVIEW COMPUTER_USE_PREVIEW_2025_03_11 -> Value.COMPUTER_USE_PREVIEW_2025_03_11 GPT_5_CODEX -> Value.GPT_5_CODEX + GPT_5_PRO -> Value.GPT_5_PRO + GPT_5_PRO_2025_10_06 -> Value.GPT_5_PRO_2025_10_06 else -> Value._UNKNOWN } @@ -344,6 +354,8 @@ private constructor( COMPUTER_USE_PREVIEW -> Known.COMPUTER_USE_PREVIEW COMPUTER_USE_PREVIEW_2025_03_11 -> Known.COMPUTER_USE_PREVIEW_2025_03_11 GPT_5_CODEX -> Known.GPT_5_CODEX + GPT_5_PRO -> Known.GPT_5_PRO + GPT_5_PRO_2025_10_06 -> Known.GPT_5_PRO_2025_10_06 else -> throw OpenAIInvalidDataException("Unknown ResponsesOnlyModel: $value") } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/ChatKitUploadFileParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/ChatKitUploadFileParams.kt new file mode 100644 index 00000000..c1f77347 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/ChatKitUploadFileParams.kt @@ -0,0 +1,446 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonValue +import com.openai.core.MultipartField +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 com.openai.errors.OpenAIInvalidDataException +import java.io.InputStream +import java.nio.file.Path +import java.util.Collections +import java.util.Objects +import kotlin.io.path.inputStream +import kotlin.io.path.name + +/** Upload a ChatKit file */ +class ChatKitUploadFileParams +private constructor( + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** + * Binary file contents to store with the ChatKit session. Supports PDFs and PNG, JPG, JPEG, + * GIF, or WEBP images. + * + * @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 file(): InputStream = body.file() + + /** + * Returns the raw multipart value of [file]. + * + * Unlike [file], this method doesn't throw if the multipart field has an unexpected type. + */ + fun _file(): MultipartField = body._file() + + 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 [ChatKitUploadFileParams]. + * + * The following fields are required: + * ```java + * .file() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatKitUploadFileParams]. */ + 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(chatkitUploadFileParams: ChatKitUploadFileParams) = apply { + body = chatkitUploadFileParams.body.toBuilder() + additionalHeaders = chatkitUploadFileParams.additionalHeaders.toBuilder() + additionalQueryParams = chatkitUploadFileParams.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: + * - [file] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** + * Binary file contents to store with the ChatKit session. Supports PDFs and PNG, JPG, JPEG, + * GIF, or WEBP images. + */ + fun file(file: InputStream) = apply { body.file(file) } + + /** + * Sets [Builder.file] to an arbitrary multipart value. + * + * You should usually call [Builder.file] with a well-typed [InputStream] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun file(file: MultipartField) = apply { body.file(file) } + + /** + * Binary file contents to store with the ChatKit session. Supports PDFs and PNG, JPG, JPEG, + * GIF, or WEBP images. + */ + fun file(file: ByteArray) = apply { body.file(file) } + + /** + * Binary file contents to store with the ChatKit session. Supports PDFs and PNG, JPG, JPEG, + * GIF, or WEBP images. + */ + fun file(path: Path) = apply { body.file(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 [ChatKitUploadFileParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .file() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatKitUploadFileParams = + ChatKitUploadFileParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Map> = + (mapOf("file" to _file()) + + _additionalBodyProperties().mapValues { (_, value) -> MultipartField.of(value) }) + .toImmutable() + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Parameters for uploading an attachment to the active ChatKit session. */ + class Body + private constructor( + private val file: MultipartField, + private val additionalProperties: MutableMap, + ) { + + /** + * Binary file contents to store with the ChatKit session. Supports PDFs and PNG, JPG, JPEG, + * GIF, or WEBP images. + * + * @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 file(): InputStream = file.value.getRequired("file") + + /** + * Returns the raw multipart value of [file]. + * + * Unlike [file], this method doesn't throw if the multipart field has an unexpected type. + */ + @JsonProperty("file") @ExcludeMissing fun _file(): MultipartField = file + + @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 + * .file() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var file: MultipartField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + file = body.file + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** + * Binary file contents to store with the ChatKit session. Supports PDFs and PNG, JPG, + * JPEG, GIF, or WEBP images. + */ + fun file(file: InputStream) = file(MultipartField.of(file)) + + /** + * Sets [Builder.file] to an arbitrary multipart value. + * + * You should usually call [Builder.file] with a well-typed [InputStream] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun file(file: MultipartField) = apply { this.file = file } + + /** + * Binary file contents to store with the ChatKit session. Supports PDFs and PNG, JPG, + * JPEG, GIF, or WEBP images. + */ + fun file(file: ByteArray) = file(file.inputStream()) + + /** + * Binary file contents to store with the ChatKit session. Supports PDFs and PNG, JPG, + * JPEG, GIF, or WEBP images. + */ + fun file(path: Path) = + file( + MultipartField.builder() + .value(path.inputStream()) + .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. + * + * The following fields are required: + * ```java + * .file() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body(checkRequired("file", file), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + file() + 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 && + file == other.file && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(file, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Body{file=$file, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatKitUploadFileParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ChatKitUploadFileParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/ChatKitUploadFileResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/ChatKitUploadFileResponse.kt new file mode 100644 index 00000000..9f38aedc --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/ChatKitUploadFileResponse.kt @@ -0,0 +1,196 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit + +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.JsonValue +import com.openai.core.getOrThrow +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Represents either a file or image attachment. */ +@JsonDeserialize(using = ChatKitUploadFileResponse.Deserializer::class) +@JsonSerialize(using = ChatKitUploadFileResponse.Serializer::class) +class ChatKitUploadFileResponse +private constructor( + private val file: FilePart? = null, + private val image: ImagePart? = null, + private val _json: JsonValue? = null, +) { + + /** Metadata for a non-image file uploaded through ChatKit. */ + fun file(): Optional = Optional.ofNullable(file) + + /** Metadata for an image uploaded through ChatKit. */ + fun image(): Optional = Optional.ofNullable(image) + + fun isFile(): Boolean = file != null + + fun isImage(): Boolean = image != null + + /** Metadata for a non-image file uploaded through ChatKit. */ + fun asFile(): FilePart = file.getOrThrow("file") + + /** Metadata for an image uploaded through ChatKit. */ + fun asImage(): ImagePart = image.getOrThrow("image") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + file != null -> visitor.visitFile(file) + image != null -> visitor.visitImage(image) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): ChatKitUploadFileResponse = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitFile(file: FilePart) { + file.validate() + } + + override fun visitImage(image: ImagePart) { + image.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 visitFile(file: FilePart) = file.validity() + + override fun visitImage(image: ImagePart) = image.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatKitUploadFileResponse && file == other.file && image == other.image + } + + override fun hashCode(): Int = Objects.hash(file, image) + + override fun toString(): String = + when { + file != null -> "ChatKitUploadFileResponse{file=$file}" + image != null -> "ChatKitUploadFileResponse{image=$image}" + _json != null -> "ChatKitUploadFileResponse{_unknown=$_json}" + else -> throw IllegalStateException("Invalid ChatKitUploadFileResponse") + } + + companion object { + + /** Metadata for a non-image file uploaded through ChatKit. */ + @JvmStatic fun ofFile(file: FilePart) = ChatKitUploadFileResponse(file = file) + + /** Metadata for an image uploaded through ChatKit. */ + @JvmStatic fun ofImage(image: ImagePart) = ChatKitUploadFileResponse(image = image) + } + + /** + * An interface that defines how to map each variant of [ChatKitUploadFileResponse] to a value + * of type [T]. + */ + interface Visitor { + + /** Metadata for a non-image file uploaded through ChatKit. */ + fun visitFile(file: FilePart): T + + /** Metadata for an image uploaded through ChatKit. */ + fun visitImage(image: ImagePart): T + + /** + * Maps an unknown variant of [ChatKitUploadFileResponse] to a value of type [T]. + * + * An instance of [ChatKitUploadFileResponse] 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 ChatKitUploadFileResponse: $json") + } + } + + internal class Deserializer : + BaseDeserializer(ChatKitUploadFileResponse::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): ChatKitUploadFileResponse { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "file" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + ChatKitUploadFileResponse(file = it, _json = json) + } ?: ChatKitUploadFileResponse(_json = json) + } + "image" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + ChatKitUploadFileResponse(image = it, _json = json) + } ?: ChatKitUploadFileResponse(_json = json) + } + } + + return ChatKitUploadFileResponse(_json = json) + } + } + + internal class Serializer : + BaseSerializer(ChatKitUploadFileResponse::class) { + + override fun serialize( + value: ChatKitUploadFileResponse, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.file != null -> generator.writeObject(value.file) + value.image != null -> generator.writeObject(value.image) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid ChatKitUploadFileResponse") + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/ChatKitWorkflow.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/ChatKitWorkflow.kt new file mode 100644 index 00000000..972434f9 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/ChatKitWorkflow.kt @@ -0,0 +1,572 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit + +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.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Workflow metadata and state returned for the session. */ +class ChatKitWorkflow +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val stateVariables: JsonField, + private val tracing: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("state_variables") + @ExcludeMissing + stateVariables: JsonField = JsonMissing.of(), + @JsonProperty("tracing") @ExcludeMissing tracing: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(id, stateVariables, tracing, version, mutableMapOf()) + + /** + * Identifier of the workflow backing the session. + * + * @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") + + /** + * State variable key-value pairs applied when invoking the workflow. Defaults to null when no + * overrides were provided. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun stateVariables(): Optional = stateVariables.getOptional("state_variables") + + /** + * Tracing settings applied to the workflow. + * + * @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 tracing(): Tracing = tracing.getRequired("tracing") + + /** + * Specific workflow version used for the session. Defaults to null when using the latest + * deployment. + * + * @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 [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 [stateVariables]. + * + * Unlike [stateVariables], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("state_variables") + @ExcludeMissing + fun _stateVariables(): JsonField = stateVariables + + /** + * Returns the raw JSON value of [tracing]. + * + * Unlike [tracing], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tracing") @ExcludeMissing fun _tracing(): JsonField = tracing + + /** + * 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 [ChatKitWorkflow]. + * + * The following fields are required: + * ```java + * .id() + * .stateVariables() + * .tracing() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatKitWorkflow]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var stateVariables: JsonField? = null + private var tracing: JsonField? = null + private var version: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatkitWorkflow: ChatKitWorkflow) = apply { + id = chatkitWorkflow.id + stateVariables = chatkitWorkflow.stateVariables + tracing = chatkitWorkflow.tracing + version = chatkitWorkflow.version + additionalProperties = chatkitWorkflow.additionalProperties.toMutableMap() + } + + /** Identifier of the workflow backing the session. */ + 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 } + + /** + * State variable key-value pairs applied when invoking the workflow. Defaults to null when + * no overrides were provided. + */ + fun stateVariables(stateVariables: StateVariables?) = + stateVariables(JsonField.ofNullable(stateVariables)) + + /** Alias for calling [Builder.stateVariables] with `stateVariables.orElse(null)`. */ + fun stateVariables(stateVariables: Optional) = + stateVariables(stateVariables.getOrNull()) + + /** + * Sets [Builder.stateVariables] to an arbitrary JSON value. + * + * You should usually call [Builder.stateVariables] with a well-typed [StateVariables] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun stateVariables(stateVariables: JsonField) = apply { + this.stateVariables = stateVariables + } + + /** Tracing settings applied to the workflow. */ + fun tracing(tracing: Tracing) = tracing(JsonField.of(tracing)) + + /** + * Sets [Builder.tracing] to an arbitrary JSON value. + * + * You should usually call [Builder.tracing] with a well-typed [Tracing] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun tracing(tracing: JsonField) = apply { this.tracing = tracing } + + /** + * Specific workflow version used for the session. Defaults to null when using the latest + * deployment. + */ + fun version(version: String?) = version(JsonField.ofNullable(version)) + + /** Alias for calling [Builder.version] with `version.orElse(null)`. */ + fun version(version: Optional) = version(version.getOrNull()) + + /** + * 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 [ChatKitWorkflow]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .stateVariables() + * .tracing() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatKitWorkflow = + ChatKitWorkflow( + checkRequired("id", id), + checkRequired("stateVariables", stateVariables), + checkRequired("tracing", tracing), + checkRequired("version", version), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatKitWorkflow = apply { + if (validated) { + return@apply + } + + id() + stateVariables().ifPresent { it.validate() } + tracing().validate() + 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) + + (stateVariables.asKnown().getOrNull()?.validity() ?: 0) + + (tracing.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) + + /** + * State variable key-value pairs applied when invoking the workflow. Defaults to null when no + * overrides were provided. + */ + class StateVariables + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [StateVariables]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StateVariables]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(stateVariables: StateVariables) = apply { + additionalProperties = stateVariables.additionalProperties.toMutableMap() + } + + 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 [StateVariables]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): StateVariables = StateVariables(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): StateVariables = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StateVariables && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "StateVariables{additionalProperties=$additionalProperties}" + } + + /** Tracing settings applied to the workflow. */ + class Tracing + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Indicates whether tracing is enabled. + * + * @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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [Tracing]. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Tracing]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(tracing: Tracing) = apply { + enabled = tracing.enabled + additionalProperties = tracing.additionalProperties.toMutableMap() + } + + /** Indicates whether tracing is enabled. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [Tracing]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tracing = + Tracing(checkRequired("enabled", enabled), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Tracing = apply { + if (validated) { + return@apply + } + + enabled() + 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 (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tracing && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tracing{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatKitWorkflow && + id == other.id && + stateVariables == other.stateVariables && + tracing == other.tracing && + version == other.version && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, stateVariables, tracing, version, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatKitWorkflow{id=$id, stateVariables=$stateVariables, tracing=$tracing, version=$version, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/FilePart.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/FilePart.kt new file mode 100644 index 00000000..02fd2a27 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/FilePart.kt @@ -0,0 +1,341 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit + +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 +import kotlin.jvm.optionals.getOrNull + +/** Metadata for a non-image file uploaded through ChatKit. */ +class FilePart +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val mimeType: JsonField, + private val name: JsonField, + private val type: JsonValue, + private val uploadUrl: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("mime_type") @ExcludeMissing mimeType: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("upload_url") @ExcludeMissing uploadUrl: JsonField = JsonMissing.of(), + ) : this(id, mimeType, name, type, uploadUrl, mutableMapOf()) + + /** + * Unique identifier for the uploaded file. + * + * @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") + + /** + * MIME type reported for the uploaded file. Defaults to null when unknown. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun mimeType(): Optional = mimeType.getOptional("mime_type") + + /** + * Original filename supplied by the uploader. Defaults to null when unnamed. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * Type discriminator that is always `file`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("file") + * ``` + * + * 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 + + /** + * Signed URL for downloading the uploaded file. Defaults to null when no download link is + * available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun uploadUrl(): Optional = uploadUrl.getOptional("upload_url") + + /** + * 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 [mimeType]. + * + * Unlike [mimeType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("mime_type") @ExcludeMissing fun _mimeType(): JsonField = mimeType + + /** + * 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 [uploadUrl]. + * + * Unlike [uploadUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("upload_url") @ExcludeMissing fun _uploadUrl(): JsonField = uploadUrl + + @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 [FilePart]. + * + * The following fields are required: + * ```java + * .id() + * .mimeType() + * .name() + * .uploadUrl() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [FilePart]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var mimeType: JsonField? = null + private var name: JsonField? = null + private var type: JsonValue = JsonValue.from("file") + private var uploadUrl: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(filePart: FilePart) = apply { + id = filePart.id + mimeType = filePart.mimeType + name = filePart.name + type = filePart.type + uploadUrl = filePart.uploadUrl + additionalProperties = filePart.additionalProperties.toMutableMap() + } + + /** Unique identifier for the uploaded file. */ + 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 } + + /** MIME type reported for the uploaded file. Defaults to null when unknown. */ + fun mimeType(mimeType: String?) = mimeType(JsonField.ofNullable(mimeType)) + + /** Alias for calling [Builder.mimeType] with `mimeType.orElse(null)`. */ + fun mimeType(mimeType: Optional) = mimeType(mimeType.getOrNull()) + + /** + * Sets [Builder.mimeType] to an arbitrary JSON value. + * + * You should usually call [Builder.mimeType] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun mimeType(mimeType: JsonField) = apply { this.mimeType = mimeType } + + /** Original filename supplied by the uploader. Defaults to null when unnamed. */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * 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("file") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** + * Signed URL for downloading the uploaded file. Defaults to null when no download link is + * available. + */ + fun uploadUrl(uploadUrl: String?) = uploadUrl(JsonField.ofNullable(uploadUrl)) + + /** Alias for calling [Builder.uploadUrl] with `uploadUrl.orElse(null)`. */ + fun uploadUrl(uploadUrl: Optional) = uploadUrl(uploadUrl.getOrNull()) + + /** + * Sets [Builder.uploadUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.uploadUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun uploadUrl(uploadUrl: JsonField) = apply { this.uploadUrl = uploadUrl } + + 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 [FilePart]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .mimeType() + * .name() + * .uploadUrl() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FilePart = + FilePart( + checkRequired("id", id), + checkRequired("mimeType", mimeType), + checkRequired("name", name), + type, + checkRequired("uploadUrl", uploadUrl), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): FilePart = apply { + if (validated) { + return@apply + } + + id() + mimeType() + name() + _type().let { + if (it != JsonValue.from("file")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + uploadUrl() + 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 (mimeType.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("file")) 1 else 0 } + + (if (uploadUrl.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FilePart && + id == other.id && + mimeType == other.mimeType && + name == other.name && + type == other.type && + uploadUrl == other.uploadUrl && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, mimeType, name, type, uploadUrl, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FilePart{id=$id, mimeType=$mimeType, name=$name, type=$type, uploadUrl=$uploadUrl, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/ImagePart.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/ImagePart.kt new file mode 100644 index 00000000..148a7003 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/ImagePart.kt @@ -0,0 +1,377 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit + +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 +import kotlin.jvm.optionals.getOrNull + +/** Metadata for an image uploaded through ChatKit. */ +class ImagePart +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val mimeType: JsonField, + private val name: JsonField, + private val previewUrl: JsonField, + private val type: JsonValue, + private val uploadUrl: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("mime_type") @ExcludeMissing mimeType: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("preview_url") + @ExcludeMissing + previewUrl: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("upload_url") @ExcludeMissing uploadUrl: JsonField = JsonMissing.of(), + ) : this(id, mimeType, name, previewUrl, type, uploadUrl, mutableMapOf()) + + /** + * Unique identifier for the uploaded image. + * + * @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") + + /** + * MIME type of the uploaded image. + * + * @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 mimeType(): String = mimeType.getRequired("mime_type") + + /** + * Original filename for the uploaded image. Defaults to null when unnamed. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * Preview URL that can be rendered inline for the image. + * + * @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 previewUrl(): String = previewUrl.getRequired("preview_url") + + /** + * Type discriminator that is always `image`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("image") + * ``` + * + * 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 + + /** + * Signed URL for downloading the uploaded image. Defaults to null when no download link is + * available. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun uploadUrl(): Optional = uploadUrl.getOptional("upload_url") + + /** + * 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 [mimeType]. + * + * Unlike [mimeType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("mime_type") @ExcludeMissing fun _mimeType(): JsonField = mimeType + + /** + * 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 [previewUrl]. + * + * Unlike [previewUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("preview_url") @ExcludeMissing fun _previewUrl(): JsonField = previewUrl + + /** + * Returns the raw JSON value of [uploadUrl]. + * + * Unlike [uploadUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("upload_url") @ExcludeMissing fun _uploadUrl(): JsonField = uploadUrl + + @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 [ImagePart]. + * + * The following fields are required: + * ```java + * .id() + * .mimeType() + * .name() + * .previewUrl() + * .uploadUrl() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ImagePart]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var mimeType: JsonField? = null + private var name: JsonField? = null + private var previewUrl: JsonField? = null + private var type: JsonValue = JsonValue.from("image") + private var uploadUrl: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(imagePart: ImagePart) = apply { + id = imagePart.id + mimeType = imagePart.mimeType + name = imagePart.name + previewUrl = imagePart.previewUrl + type = imagePart.type + uploadUrl = imagePart.uploadUrl + additionalProperties = imagePart.additionalProperties.toMutableMap() + } + + /** Unique identifier for the uploaded image. */ + 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 } + + /** MIME type of the uploaded image. */ + fun mimeType(mimeType: String) = mimeType(JsonField.of(mimeType)) + + /** + * Sets [Builder.mimeType] to an arbitrary JSON value. + * + * You should usually call [Builder.mimeType] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun mimeType(mimeType: JsonField) = apply { this.mimeType = mimeType } + + /** Original filename for the uploaded image. Defaults to null when unnamed. */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * 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 } + + /** Preview URL that can be rendered inline for the image. */ + fun previewUrl(previewUrl: String) = previewUrl(JsonField.of(previewUrl)) + + /** + * Sets [Builder.previewUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.previewUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun previewUrl(previewUrl: JsonField) = apply { this.previewUrl = previewUrl } + + /** + * 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("image") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** + * Signed URL for downloading the uploaded image. Defaults to null when no download link is + * available. + */ + fun uploadUrl(uploadUrl: String?) = uploadUrl(JsonField.ofNullable(uploadUrl)) + + /** Alias for calling [Builder.uploadUrl] with `uploadUrl.orElse(null)`. */ + fun uploadUrl(uploadUrl: Optional) = uploadUrl(uploadUrl.getOrNull()) + + /** + * Sets [Builder.uploadUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.uploadUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun uploadUrl(uploadUrl: JsonField) = apply { this.uploadUrl = uploadUrl } + + 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 [ImagePart]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .mimeType() + * .name() + * .previewUrl() + * .uploadUrl() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ImagePart = + ImagePart( + checkRequired("id", id), + checkRequired("mimeType", mimeType), + checkRequired("name", name), + checkRequired("previewUrl", previewUrl), + type, + checkRequired("uploadUrl", uploadUrl), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ImagePart = apply { + if (validated) { + return@apply + } + + id() + mimeType() + name() + previewUrl() + _type().let { + if (it != JsonValue.from("image")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + uploadUrl() + 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 (mimeType.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (previewUrl.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("image")) 1 else 0 } + + (if (uploadUrl.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImagePart && + id == other.id && + mimeType == other.mimeType && + name == other.name && + previewUrl == other.previewUrl && + type == other.type && + uploadUrl == other.uploadUrl && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, mimeType, name, previewUrl, type, uploadUrl, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ImagePart{id=$id, mimeType=$mimeType, name=$name, previewUrl=$previewUrl, type=$type, uploadUrl=$uploadUrl, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/sessions/SessionCancelParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/sessions/SessionCancelParams.kt new file mode 100644 index 00000000..d5cadea1 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/sessions/SessionCancelParams.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.sessions + +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 + +/** Cancel a ChatKit session */ +class SessionCancelParams +private constructor( + private val sessionId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun sessionId(): Optional = Optional.ofNullable(sessionId) + + /** 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(): SessionCancelParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [SessionCancelParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SessionCancelParams]. */ + class Builder internal constructor() { + + private var sessionId: 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(sessionCancelParams: SessionCancelParams) = apply { + sessionId = sessionCancelParams.sessionId + additionalHeaders = sessionCancelParams.additionalHeaders.toBuilder() + additionalQueryParams = sessionCancelParams.additionalQueryParams.toBuilder() + additionalBodyProperties = sessionCancelParams.additionalBodyProperties.toMutableMap() + } + + fun sessionId(sessionId: String?) = apply { this.sessionId = sessionId } + + /** Alias for calling [Builder.sessionId] with `sessionId.orElse(null)`. */ + fun sessionId(sessionId: Optional) = sessionId(sessionId.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 [SessionCancelParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): SessionCancelParams = + SessionCancelParams( + sessionId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sessionId ?: "" + 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 SessionCancelParams && + sessionId == other.sessionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash(sessionId, additionalHeaders, additionalQueryParams, additionalBodyProperties) + + override fun toString() = + "SessionCancelParams{sessionId=$sessionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/sessions/SessionCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/sessions/SessionCreateParams.kt new file mode 100644 index 00000000..c2a9a4b1 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/sessions/SessionCreateParams.kt @@ -0,0 +1,762 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.sessions + +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 com.openai.models.beta.chatkit.threads.ChatSessionChatKitConfigurationParam +import com.openai.models.beta.chatkit.threads.ChatSessionExpiresAfterParam +import com.openai.models.beta.chatkit.threads.ChatSessionRateLimitsParam +import com.openai.models.beta.chatkit.threads.ChatSessionWorkflowParam +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Create a ChatKit session */ +class SessionCreateParams +private constructor( + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** + * A free-form string that identifies your end user; ensures this Session can access other + * objects that have the same `user` scope. + * + * @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 user(): String = body.user() + + /** + * Workflow that powers the session. + * + * @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 workflow(): ChatSessionWorkflowParam = body.workflow() + + /** + * Optional overrides for ChatKit runtime configuration features + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun chatkitConfiguration(): Optional = + body.chatkitConfiguration() + + /** + * Optional override for session expiration timing in seconds from creation. Defaults to 10 + * minutes. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun expiresAfter(): Optional = body.expiresAfter() + + /** + * Optional override for per-minute request limits. When omitted, defaults to 10. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun rateLimits(): Optional = body.rateLimits() + + /** + * Returns the raw JSON value of [user]. + * + * Unlike [user], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _user(): JsonField = body._user() + + /** + * Returns the raw JSON value of [workflow]. + * + * Unlike [workflow], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _workflow(): JsonField = body._workflow() + + /** + * Returns the raw JSON value of [chatkitConfiguration]. + * + * Unlike [chatkitConfiguration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _chatkitConfiguration(): JsonField = + body._chatkitConfiguration() + + /** + * Returns the raw JSON value of [expiresAfter]. + * + * Unlike [expiresAfter], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _expiresAfter(): JsonField = body._expiresAfter() + + /** + * Returns the raw JSON value of [rateLimits]. + * + * Unlike [rateLimits], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _rateLimits(): JsonField = body._rateLimits() + + 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 [SessionCreateParams]. + * + * The following fields are required: + * ```java + * .user() + * .workflow() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SessionCreateParams]. */ + 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(sessionCreateParams: SessionCreateParams) = apply { + body = sessionCreateParams.body.toBuilder() + additionalHeaders = sessionCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = sessionCreateParams.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: + * - [user] + * - [workflow] + * - [chatkitConfiguration] + * - [expiresAfter] + * - [rateLimits] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** + * A free-form string that identifies your end user; ensures this Session can access other + * objects that have the same `user` scope. + */ + fun user(user: String) = apply { body.user(user) } + + /** + * Sets [Builder.user] to an arbitrary JSON value. + * + * You should usually call [Builder.user] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun user(user: JsonField) = apply { body.user(user) } + + /** Workflow that powers the session. */ + fun workflow(workflow: ChatSessionWorkflowParam) = apply { body.workflow(workflow) } + + /** + * Sets [Builder.workflow] to an arbitrary JSON value. + * + * You should usually call [Builder.workflow] with a well-typed [ChatSessionWorkflowParam] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun workflow(workflow: JsonField) = apply { + body.workflow(workflow) + } + + /** Optional overrides for ChatKit runtime configuration features */ + fun chatkitConfiguration(chatkitConfiguration: ChatSessionChatKitConfigurationParam) = + apply { + body.chatkitConfiguration(chatkitConfiguration) + } + + /** + * Sets [Builder.chatkitConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.chatkitConfiguration] with a well-typed + * [ChatSessionChatKitConfigurationParam] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun chatkitConfiguration( + chatkitConfiguration: JsonField + ) = apply { body.chatkitConfiguration(chatkitConfiguration) } + + /** + * Optional override for session expiration timing in seconds from creation. Defaults to 10 + * minutes. + */ + fun expiresAfter(expiresAfter: ChatSessionExpiresAfterParam) = apply { + body.expiresAfter(expiresAfter) + } + + /** + * Sets [Builder.expiresAfter] to an arbitrary JSON value. + * + * You should usually call [Builder.expiresAfter] with a well-typed + * [ChatSessionExpiresAfterParam] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun expiresAfter(expiresAfter: JsonField) = apply { + body.expiresAfter(expiresAfter) + } + + /** Optional override for per-minute request limits. When omitted, defaults to 10. */ + fun rateLimits(rateLimits: ChatSessionRateLimitsParam) = apply { + body.rateLimits(rateLimits) + } + + /** + * Sets [Builder.rateLimits] to an arbitrary JSON value. + * + * You should usually call [Builder.rateLimits] with a well-typed + * [ChatSessionRateLimitsParam] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun rateLimits(rateLimits: JsonField) = apply { + body.rateLimits(rateLimits) + } + + 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 [SessionCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .user() + * .workflow() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SessionCreateParams = + SessionCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Parameters for provisioning a new ChatKit session. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val user: JsonField, + private val workflow: JsonField, + private val chatkitConfiguration: JsonField, + private val expiresAfter: JsonField, + private val rateLimits: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("user") @ExcludeMissing user: JsonField = JsonMissing.of(), + @JsonProperty("workflow") + @ExcludeMissing + workflow: JsonField = JsonMissing.of(), + @JsonProperty("chatkit_configuration") + @ExcludeMissing + chatkitConfiguration: JsonField = + JsonMissing.of(), + @JsonProperty("expires_after") + @ExcludeMissing + expiresAfter: JsonField = JsonMissing.of(), + @JsonProperty("rate_limits") + @ExcludeMissing + rateLimits: JsonField = JsonMissing.of(), + ) : this(user, workflow, chatkitConfiguration, expiresAfter, rateLimits, mutableMapOf()) + + /** + * A free-form string that identifies your end user; ensures this Session can access other + * objects that have the same `user` scope. + * + * @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 user(): String = user.getRequired("user") + + /** + * Workflow that powers the session. + * + * @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 workflow(): ChatSessionWorkflowParam = workflow.getRequired("workflow") + + /** + * Optional overrides for ChatKit runtime configuration features + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun chatkitConfiguration(): Optional = + chatkitConfiguration.getOptional("chatkit_configuration") + + /** + * Optional override for session expiration timing in seconds from creation. Defaults to 10 + * minutes. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun expiresAfter(): Optional = + expiresAfter.getOptional("expires_after") + + /** + * Optional override for per-minute request limits. When omitted, defaults to 10. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun rateLimits(): Optional = + rateLimits.getOptional("rate_limits") + + /** + * Returns the raw JSON value of [user]. + * + * Unlike [user], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user") @ExcludeMissing fun _user(): JsonField = user + + /** + * Returns the raw JSON value of [workflow]. + * + * Unlike [workflow], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workflow") + @ExcludeMissing + fun _workflow(): JsonField = workflow + + /** + * Returns the raw JSON value of [chatkitConfiguration]. + * + * Unlike [chatkitConfiguration], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("chatkit_configuration") + @ExcludeMissing + fun _chatkitConfiguration(): JsonField = + chatkitConfiguration + + /** + * Returns the raw JSON value of [expiresAfter]. + * + * Unlike [expiresAfter], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("expires_after") + @ExcludeMissing + fun _expiresAfter(): JsonField = expiresAfter + + /** + * Returns the raw JSON value of [rateLimits]. + * + * Unlike [rateLimits], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rate_limits") + @ExcludeMissing + fun _rateLimits(): JsonField = rateLimits + + @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 + * .user() + * .workflow() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var user: JsonField? = null + private var workflow: JsonField? = null + private var chatkitConfiguration: JsonField = + JsonMissing.of() + private var expiresAfter: JsonField = JsonMissing.of() + private var rateLimits: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + user = body.user + workflow = body.workflow + chatkitConfiguration = body.chatkitConfiguration + expiresAfter = body.expiresAfter + rateLimits = body.rateLimits + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** + * A free-form string that identifies your end user; ensures this Session can access + * other objects that have the same `user` scope. + */ + fun user(user: String) = user(JsonField.of(user)) + + /** + * Sets [Builder.user] to an arbitrary JSON value. + * + * You should usually call [Builder.user] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun user(user: JsonField) = apply { this.user = user } + + /** Workflow that powers the session. */ + fun workflow(workflow: ChatSessionWorkflowParam) = workflow(JsonField.of(workflow)) + + /** + * Sets [Builder.workflow] to an arbitrary JSON value. + * + * You should usually call [Builder.workflow] with a well-typed + * [ChatSessionWorkflowParam] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun workflow(workflow: JsonField) = apply { + this.workflow = workflow + } + + /** Optional overrides for ChatKit runtime configuration features */ + fun chatkitConfiguration(chatkitConfiguration: ChatSessionChatKitConfigurationParam) = + chatkitConfiguration(JsonField.of(chatkitConfiguration)) + + /** + * Sets [Builder.chatkitConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.chatkitConfiguration] with a well-typed + * [ChatSessionChatKitConfigurationParam] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun chatkitConfiguration( + chatkitConfiguration: JsonField + ) = apply { this.chatkitConfiguration = chatkitConfiguration } + + /** + * Optional override for session expiration timing in seconds from creation. Defaults to + * 10 minutes. + */ + fun expiresAfter(expiresAfter: ChatSessionExpiresAfterParam) = + expiresAfter(JsonField.of(expiresAfter)) + + /** + * Sets [Builder.expiresAfter] to an arbitrary JSON value. + * + * You should usually call [Builder.expiresAfter] with a well-typed + * [ChatSessionExpiresAfterParam] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun expiresAfter(expiresAfter: JsonField) = apply { + this.expiresAfter = expiresAfter + } + + /** Optional override for per-minute request limits. When omitted, defaults to 10. */ + fun rateLimits(rateLimits: ChatSessionRateLimitsParam) = + rateLimits(JsonField.of(rateLimits)) + + /** + * Sets [Builder.rateLimits] to an arbitrary JSON value. + * + * You should usually call [Builder.rateLimits] with a well-typed + * [ChatSessionRateLimitsParam] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun rateLimits(rateLimits: JsonField) = apply { + this.rateLimits = rateLimits + } + + 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 + * .user() + * .workflow() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("user", user), + checkRequired("workflow", workflow), + chatkitConfiguration, + expiresAfter, + rateLimits, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + user() + workflow().validate() + chatkitConfiguration().ifPresent { it.validate() } + expiresAfter().ifPresent { it.validate() } + rateLimits().ifPresent { 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 = + (if (user.asKnown().isPresent) 1 else 0) + + (workflow.asKnown().getOrNull()?.validity() ?: 0) + + (chatkitConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (expiresAfter.asKnown().getOrNull()?.validity() ?: 0) + + (rateLimits.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + user == other.user && + workflow == other.workflow && + chatkitConfiguration == other.chatkitConfiguration && + expiresAfter == other.expiresAfter && + rateLimits == other.rateLimits && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + user, + workflow, + chatkitConfiguration, + expiresAfter, + rateLimits, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{user=$user, workflow=$workflow, chatkitConfiguration=$chatkitConfiguration, expiresAfter=$expiresAfter, rateLimits=$rateLimits, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SessionCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "SessionCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitAttachment.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitAttachment.kt new file mode 100644 index 00000000..7ea32ab8 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitAttachment.kt @@ -0,0 +1,457 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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.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.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Attachment metadata included on thread items. */ +class ChatKitAttachment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val mimeType: JsonField, + private val name: JsonField, + private val previewUrl: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("mime_type") @ExcludeMissing mimeType: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("preview_url") + @ExcludeMissing + previewUrl: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(id, mimeType, name, previewUrl, type, mutableMapOf()) + + /** + * Identifier for the attachment. + * + * @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") + + /** + * MIME type of the attachment. + * + * @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 mimeType(): String = mimeType.getRequired("mime_type") + + /** + * Original display name for the attachment. + * + * @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") + + /** + * Preview URL for rendering the attachment inline. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun previewUrl(): Optional = previewUrl.getOptional("preview_url") + + /** + * Attachment discriminator. + * + * @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 type(): Type = type.getRequired("type") + + /** + * 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 [mimeType]. + * + * Unlike [mimeType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("mime_type") @ExcludeMissing fun _mimeType(): JsonField = mimeType + + /** + * 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 [previewUrl]. + * + * Unlike [previewUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("preview_url") @ExcludeMissing fun _previewUrl(): JsonField = previewUrl + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = 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 [ChatKitAttachment]. + * + * The following fields are required: + * ```java + * .id() + * .mimeType() + * .name() + * .previewUrl() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatKitAttachment]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var mimeType: JsonField? = null + private var name: JsonField? = null + private var previewUrl: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatkitAttachment: ChatKitAttachment) = apply { + id = chatkitAttachment.id + mimeType = chatkitAttachment.mimeType + name = chatkitAttachment.name + previewUrl = chatkitAttachment.previewUrl + type = chatkitAttachment.type + additionalProperties = chatkitAttachment.additionalProperties.toMutableMap() + } + + /** Identifier for the attachment. */ + 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 } + + /** MIME type of the attachment. */ + fun mimeType(mimeType: String) = mimeType(JsonField.of(mimeType)) + + /** + * Sets [Builder.mimeType] to an arbitrary JSON value. + * + * You should usually call [Builder.mimeType] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun mimeType(mimeType: JsonField) = apply { this.mimeType = mimeType } + + /** Original display name for the attachment. */ + 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 } + + /** Preview URL for rendering the attachment inline. */ + fun previewUrl(previewUrl: String?) = previewUrl(JsonField.ofNullable(previewUrl)) + + /** Alias for calling [Builder.previewUrl] with `previewUrl.orElse(null)`. */ + fun previewUrl(previewUrl: Optional) = previewUrl(previewUrl.getOrNull()) + + /** + * Sets [Builder.previewUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.previewUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun previewUrl(previewUrl: JsonField) = apply { this.previewUrl = previewUrl } + + /** Attachment discriminator. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = 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 [ChatKitAttachment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .mimeType() + * .name() + * .previewUrl() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatKitAttachment = + ChatKitAttachment( + checkRequired("id", id), + checkRequired("mimeType", mimeType), + checkRequired("name", name), + checkRequired("previewUrl", previewUrl), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatKitAttachment = apply { + if (validated) { + return@apply + } + + id() + mimeType() + name() + previewUrl() + type().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 = + (if (id.asKnown().isPresent) 1 else 0) + + (if (mimeType.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (previewUrl.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + /** Attachment discriminator. */ + class Type @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 IMAGE = of("image") + + @JvmField val FILE = of("file") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + IMAGE, + FILE, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] 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 { + IMAGE, + FILE, + /** An enum member indicating that [Type] 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) { + IMAGE -> Value.IMAGE + FILE -> Value.FILE + 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) { + IMAGE -> Known.IMAGE + FILE -> Known.FILE + else -> throw OpenAIInvalidDataException("Unknown Type: $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(): Type = 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 Type && 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 ChatKitAttachment && + id == other.id && + mimeType == other.mimeType && + name == other.name && + previewUrl == other.previewUrl && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, mimeType, name, previewUrl, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatKitAttachment{id=$id, mimeType=$mimeType, name=$name, previewUrl=$previewUrl, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitResponseOutputText.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitResponseOutputText.kt new file mode 100644 index 00000000..0a822a09 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitResponseOutputText.kt @@ -0,0 +1,1308 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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.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 +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Assistant response text accompanied by optional annotations. */ +class ChatKitResponseOutputText +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val annotations: JsonField>, + private val text: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("annotations") + @ExcludeMissing + annotations: JsonField> = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(annotations, text, type, mutableMapOf()) + + /** + * Ordered list of annotations attached to the response text. + * + * @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 annotations(): List = annotations.getRequired("annotations") + + /** + * Assistant generated text. + * + * @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 text(): String = text.getRequired("text") + + /** + * Type discriminator that is always `output_text`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("output_text") + * ``` + * + * 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 [annotations]. + * + * Unlike [annotations], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("annotations") + @ExcludeMissing + fun _annotations(): JsonField> = annotations + + /** + * Returns the raw JSON value of [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + @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 [ChatKitResponseOutputText]. + * + * The following fields are required: + * ```java + * .annotations() + * .text() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatKitResponseOutputText]. */ + class Builder internal constructor() { + + private var annotations: JsonField>? = null + private var text: JsonField? = null + private var type: JsonValue = JsonValue.from("output_text") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatkitResponseOutputText: ChatKitResponseOutputText) = apply { + annotations = chatkitResponseOutputText.annotations.map { it.toMutableList() } + text = chatkitResponseOutputText.text + type = chatkitResponseOutputText.type + additionalProperties = chatkitResponseOutputText.additionalProperties.toMutableMap() + } + + /** Ordered list of annotations attached to the response text. */ + fun annotations(annotations: List) = annotations(JsonField.of(annotations)) + + /** + * Sets [Builder.annotations] to an arbitrary JSON value. + * + * You should usually call [Builder.annotations] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun annotations(annotations: JsonField>) = apply { + this.annotations = annotations.map { it.toMutableList() } + } + + /** + * Adds a single [Annotation] to [annotations]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAnnotation(annotation: Annotation) = apply { + annotations = + (annotations ?: JsonField.of(mutableListOf())).also { + checkKnown("annotations", it).add(annotation) + } + } + + /** Alias for calling [addAnnotation] with `Annotation.ofFile(file)`. */ + fun addAnnotation(file: Annotation.File) = addAnnotation(Annotation.ofFile(file)) + + /** + * Alias for calling [addAnnotation] with the following: + * ```java + * Annotation.File.builder() + * .source(source) + * .build() + * ``` + */ + fun addFileAnnotation(source: Annotation.File.Source) = + addAnnotation(Annotation.File.builder().source(source).build()) + + /** Alias for calling [addAnnotation] with `Annotation.ofUrl(url)`. */ + fun addAnnotation(url: Annotation.Url) = addAnnotation(Annotation.ofUrl(url)) + + /** + * Alias for calling [addAnnotation] with the following: + * ```java + * Annotation.Url.builder() + * .source(source) + * .build() + * ``` + */ + fun addUrlAnnotation(source: Annotation.Url.Source) = + addAnnotation(Annotation.Url.builder().source(source).build()) + + /** Assistant generated text. */ + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + /** + * 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("output_text") + * ``` + * + * 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 [ChatKitResponseOutputText]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .annotations() + * .text() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatKitResponseOutputText = + ChatKitResponseOutputText( + checkRequired("annotations", annotations).map { it.toImmutable() }, + checkRequired("text", text), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatKitResponseOutputText = apply { + if (validated) { + return@apply + } + + annotations().forEach { it.validate() } + text() + _type().let { + if (it != JsonValue.from("output_text")) { + 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 = + (annotations.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (text.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("output_text")) 1 else 0 } + + /** Annotation object describing a cited source. */ + @JsonDeserialize(using = Annotation.Deserializer::class) + @JsonSerialize(using = Annotation.Serializer::class) + class Annotation + private constructor( + private val file: File? = null, + private val url: Url? = null, + private val _json: JsonValue? = null, + ) { + + /** Annotation that references an uploaded file. */ + fun file(): Optional = Optional.ofNullable(file) + + /** Annotation that references a URL. */ + fun url(): Optional = Optional.ofNullable(url) + + fun isFile(): Boolean = file != null + + fun isUrl(): Boolean = url != null + + /** Annotation that references an uploaded file. */ + fun asFile(): File = file.getOrThrow("file") + + /** Annotation that references a URL. */ + fun asUrl(): Url = url.getOrThrow("url") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + file != null -> visitor.visitFile(file) + url != null -> visitor.visitUrl(url) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Annotation = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitFile(file: File) { + file.validate() + } + + override fun visitUrl(url: Url) { + url.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 visitFile(file: File) = file.validity() + + override fun visitUrl(url: Url) = url.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Annotation && file == other.file && url == other.url + } + + override fun hashCode(): Int = Objects.hash(file, url) + + override fun toString(): String = + when { + file != null -> "Annotation{file=$file}" + url != null -> "Annotation{url=$url}" + _json != null -> "Annotation{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Annotation") + } + + companion object { + + /** Annotation that references an uploaded file. */ + @JvmStatic fun ofFile(file: File) = Annotation(file = file) + + /** Annotation that references a URL. */ + @JvmStatic fun ofUrl(url: Url) = Annotation(url = url) + } + + /** + * An interface that defines how to map each variant of [Annotation] to a value of type [T]. + */ + interface Visitor { + + /** Annotation that references an uploaded file. */ + fun visitFile(file: File): T + + /** Annotation that references a URL. */ + fun visitUrl(url: Url): T + + /** + * Maps an unknown variant of [Annotation] to a value of type [T]. + * + * An instance of [Annotation] 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 Annotation: $json") + } + } + + internal class Deserializer : BaseDeserializer(Annotation::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Annotation { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "file" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Annotation(file = it, _json = json) + } ?: Annotation(_json = json) + } + "url" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Annotation(url = it, _json = json) + } ?: Annotation(_json = json) + } + } + + return Annotation(_json = json) + } + } + + internal class Serializer : BaseSerializer(Annotation::class) { + + override fun serialize( + value: Annotation, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.file != null -> generator.writeObject(value.file) + value.url != null -> generator.writeObject(value.url) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Annotation") + } + } + } + + /** Annotation that references an uploaded file. */ + class File + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val source: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("source") + @ExcludeMissing + source: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(source, type, mutableMapOf()) + + /** + * File attachment referenced by the annotation. + * + * @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(): Source = source.getRequired("source") + + /** + * Type discriminator that is always `file` for this annotation. + * + * Expected to always return the following: + * ```java + * JsonValue.from("file") + * ``` + * + * 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 [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 [File]. + * + * The following fields are required: + * ```java + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [File]. */ + class Builder internal constructor() { + + private var source: JsonField? = null + private var type: JsonValue = JsonValue.from("file") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(file: File) = apply { + source = file.source + type = file.type + additionalProperties = file.additionalProperties.toMutableMap() + } + + /** File attachment referenced by the annotation. */ + fun source(source: Source) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [Source] 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("file") + * ``` + * + * 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 [File]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): File = + File(checkRequired("source", source), type, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): File = apply { + if (validated) { + return@apply + } + + source().validate() + _type().let { + if (it != JsonValue.from("file")) { + 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 = + (source.asKnown().getOrNull()?.validity() ?: 0) + + type.let { if (it == JsonValue.from("file")) 1 else 0 } + + /** File attachment referenced by the annotation. */ + class Source + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val filename: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("filename") + @ExcludeMissing + filename: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(filename, type, mutableMapOf()) + + /** + * Filename referenced by the annotation. + * + * @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 filename(): String = filename.getRequired("filename") + + /** + * Type discriminator that is always `file`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("file") + * ``` + * + * 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 [filename]. + * + * Unlike [filename], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("filename") + @ExcludeMissing + fun _filename(): JsonField = filename + + @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 [Source]. + * + * The following fields are required: + * ```java + * .filename() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Source]. */ + class Builder internal constructor() { + + private var filename: JsonField? = null + private var type: JsonValue = JsonValue.from("file") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(source: Source) = apply { + filename = source.filename + type = source.type + additionalProperties = source.additionalProperties.toMutableMap() + } + + /** Filename referenced by the annotation. */ + fun filename(filename: String) = filename(JsonField.of(filename)) + + /** + * Sets [Builder.filename] to an arbitrary JSON value. + * + * You should usually call [Builder.filename] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun filename(filename: JsonField) = apply { this.filename = filename } + + /** + * 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("file") + * ``` + * + * 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 [Source]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .filename() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Source = + Source( + checkRequired("filename", filename), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Source = apply { + if (validated) { + return@apply + } + + filename() + _type().let { + if (it != JsonValue.from("file")) { + 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 (filename.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("file")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Source && + filename == other.filename && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(filename, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Source{filename=$filename, type=$type, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is File && + source == other.source && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(source, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "File{source=$source, type=$type, additionalProperties=$additionalProperties}" + } + + /** Annotation that references a URL. */ + class Url + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val source: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("source") + @ExcludeMissing + source: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(source, type, mutableMapOf()) + + /** + * URL referenced by the annotation. + * + * @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(): Source = source.getRequired("source") + + /** + * Type discriminator that is always `url` for this annotation. + * + * Expected to always return the following: + * ```java + * JsonValue.from("url") + * ``` + * + * 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 [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 [Url]. + * + * The following fields are required: + * ```java + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Url]. */ + class Builder internal constructor() { + + private var source: JsonField? = null + private var type: JsonValue = JsonValue.from("url") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(url: Url) = apply { + source = url.source + type = url.type + additionalProperties = url.additionalProperties.toMutableMap() + } + + /** URL referenced by the annotation. */ + fun source(source: Source) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [Source] 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("url") + * ``` + * + * 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 [Url]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Url = + Url(checkRequired("source", source), type, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Url = apply { + if (validated) { + return@apply + } + + source().validate() + _type().let { + if (it != JsonValue.from("url")) { + 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 = + (source.asKnown().getOrNull()?.validity() ?: 0) + + type.let { if (it == JsonValue.from("url")) 1 else 0 } + + /** URL referenced by the annotation. */ + class Source + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val type: JsonValue, + private val url: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("url") @ExcludeMissing url: JsonField = JsonMissing.of(), + ) : this(type, url, mutableMapOf()) + + /** + * Type discriminator that is always `url`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("url") + * ``` + * + * 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 + + /** + * URL referenced by the annotation. + * + * @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 url(): String = url.getRequired("url") + + /** + * Returns the raw JSON value of [url]. + * + * Unlike [url], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url + + @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 [Source]. + * + * The following fields are required: + * ```java + * .url() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Source]. */ + class Builder internal constructor() { + + private var type: JsonValue = JsonValue.from("url") + private var url: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(source: Source) = apply { + type = source.type + url = source.url + additionalProperties = source.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("url") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** URL referenced by the annotation. */ + fun url(url: String) = url(JsonField.of(url)) + + /** + * Sets [Builder.url] to an arbitrary JSON value. + * + * You should usually call [Builder.url] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun url(url: JsonField) = apply { this.url = url } + + 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 [Source]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .url() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Source = + Source(type, checkRequired("url", url), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Source = apply { + if (validated) { + return@apply + } + + _type().let { + if (it != JsonValue.from("url")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + url() + 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("url")) 1 else 0 } + + (if (url.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Source && + type == other.type && + url == other.url && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(type, url, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Source{type=$type, url=$url, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Url && + source == other.source && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(source, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Url{source=$source, type=$type, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatKitResponseOutputText && + annotations == other.annotations && + text == other.text && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(annotations, text, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatKitResponseOutputText{annotations=$annotations, text=$text, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitThread.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitThread.kt new file mode 100644 index 00000000..e5e68503 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitThread.kt @@ -0,0 +1,1049 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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.checkRequired +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 + +/** Represents a ChatKit thread and its current status. */ +class ChatKitThread +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val object_: JsonValue, + private val status: JsonField, + private val title: JsonField, + private val user: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("title") @ExcludeMissing title: JsonField = JsonMissing.of(), + @JsonProperty("user") @ExcludeMissing user: JsonField = JsonMissing.of(), + ) : this(id, createdAt, object_, status, title, user, mutableMapOf()) + + /** + * Identifier of the thread. + * + * @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 (in seconds) for when the thread 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") + + /** + * Type discriminator that is always `chatkit.thread`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.thread") + * ``` + * + * 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_ + + /** + * Current status for the thread. Defaults to `active` for newly created threads. + * + * @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 status(): Status = status.getRequired("status") + + /** + * Optional human-readable title for the thread. Defaults to null when no title has been + * generated. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun title(): Optional = title.getOptional("title") + + /** + * Free-form string that identifies your end user who owns the thread. + * + * @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 user(): String = user.getRequired("user") + + /** + * 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 [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [title]. + * + * Unlike [title], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("title") @ExcludeMissing fun _title(): JsonField = title + + /** + * Returns the raw JSON value of [user]. + * + * Unlike [user], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user") @ExcludeMissing fun _user(): JsonField = user + + @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 [ChatKitThread]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .status() + * .title() + * .user() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatKitThread]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var object_: JsonValue = JsonValue.from("chatkit.thread") + private var status: JsonField? = null + private var title: JsonField? = null + private var user: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatkitThread: ChatKitThread) = apply { + id = chatkitThread.id + createdAt = chatkitThread.createdAt + object_ = chatkitThread.object_ + status = chatkitThread.status + title = chatkitThread.title + user = chatkitThread.user + additionalProperties = chatkitThread.additionalProperties.toMutableMap() + } + + /** Identifier of the thread. */ + 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 (in seconds) for when the thread 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 } + + /** + * 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("chatkit.thread") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** Current status for the thread. Defaults to `active` for newly created threads. */ + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** Alias for calling [status] with `Status.ofActive()`. */ + fun statusActive() = status(Status.ofActive()) + + /** Alias for calling [status] with `Status.ofLocked(locked)`. */ + fun status(locked: Status.Locked) = status(Status.ofLocked(locked)) + + /** + * Alias for calling [status] with the following: + * ```java + * Status.Locked.builder() + * .reason(reason) + * .build() + * ``` + */ + fun lockedStatus(reason: String?) = status(Status.Locked.builder().reason(reason).build()) + + /** Alias for calling [lockedStatus] with `reason.orElse(null)`. */ + fun lockedStatus(reason: Optional) = lockedStatus(reason.getOrNull()) + + /** Alias for calling [status] with `Status.ofClosed(closed)`. */ + fun status(closed: Status.Closed) = status(Status.ofClosed(closed)) + + /** + * Alias for calling [status] with the following: + * ```java + * Status.Closed.builder() + * .reason(reason) + * .build() + * ``` + */ + fun closedStatus(reason: String?) = status(Status.Closed.builder().reason(reason).build()) + + /** Alias for calling [closedStatus] with `reason.orElse(null)`. */ + fun closedStatus(reason: Optional) = closedStatus(reason.getOrNull()) + + /** + * Optional human-readable title for the thread. Defaults to null when no title has been + * generated. + */ + fun title(title: String?) = title(JsonField.ofNullable(title)) + + /** Alias for calling [Builder.title] with `title.orElse(null)`. */ + fun title(title: Optional) = title(title.getOrNull()) + + /** + * Sets [Builder.title] to an arbitrary JSON value. + * + * You should usually call [Builder.title] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun title(title: JsonField) = apply { this.title = title } + + /** Free-form string that identifies your end user who owns the thread. */ + fun user(user: String) = user(JsonField.of(user)) + + /** + * Sets [Builder.user] to an arbitrary JSON value. + * + * You should usually call [Builder.user] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun user(user: JsonField) = apply { this.user = user } + + 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 [ChatKitThread]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .status() + * .title() + * .user() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatKitThread = + ChatKitThread( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + object_, + checkRequired("status", status), + checkRequired("title", title), + checkRequired("user", user), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatKitThread = apply { + if (validated) { + return@apply + } + + id() + createdAt() + _object_().let { + if (it != JsonValue.from("chatkit.thread")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + status().validate() + title() + user() + 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) + + object_.let { if (it == JsonValue.from("chatkit.thread")) 1 else 0 } + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (title.asKnown().isPresent) 1 else 0) + + (if (user.asKnown().isPresent) 1 else 0) + + /** Current status for the thread. Defaults to `active` for newly created threads. */ + @JsonDeserialize(using = Status.Deserializer::class) + @JsonSerialize(using = Status.Serializer::class) + class Status + private constructor( + private val active: JsonValue? = null, + private val locked: Locked? = null, + private val closed: Closed? = null, + private val _json: JsonValue? = null, + ) { + + /** Indicates that a thread is active. */ + fun active(): Optional = Optional.ofNullable(active) + + /** Indicates that a thread is locked and cannot accept new input. */ + fun locked(): Optional = Optional.ofNullable(locked) + + /** Indicates that a thread has been closed. */ + fun closed(): Optional = Optional.ofNullable(closed) + + fun isActive(): Boolean = active != null + + fun isLocked(): Boolean = locked != null + + fun isClosed(): Boolean = closed != null + + /** Indicates that a thread is active. */ + fun asActive(): JsonValue = active.getOrThrow("active") + + /** Indicates that a thread is locked and cannot accept new input. */ + fun asLocked(): Locked = locked.getOrThrow("locked") + + /** Indicates that a thread has been closed. */ + fun asClosed(): Closed = closed.getOrThrow("closed") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + active != null -> visitor.visitActive(active) + locked != null -> visitor.visitLocked(locked) + closed != null -> visitor.visitClosed(closed) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Status = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitActive(active: JsonValue) { + active.let { + if (it != JsonValue.from(mapOf("type" to "active"))) { + throw OpenAIInvalidDataException( + "'active' is invalid, received $it" + ) + } + } + } + + override fun visitLocked(locked: Locked) { + locked.validate() + } + + override fun visitClosed(closed: Closed) { + closed.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 visitActive(active: JsonValue) = + active.let { if (it == JsonValue.from(mapOf("type" to "active"))) 1 else 0 } + + override fun visitLocked(locked: Locked) = locked.validity() + + override fun visitClosed(closed: Closed) = closed.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Status && + active == other.active && + locked == other.locked && + closed == other.closed + } + + override fun hashCode(): Int = Objects.hash(active, locked, closed) + + override fun toString(): String = + when { + active != null -> "Status{active=$active}" + locked != null -> "Status{locked=$locked}" + closed != null -> "Status{closed=$closed}" + _json != null -> "Status{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Status") + } + + companion object { + + /** Indicates that a thread is active. */ + @JvmStatic fun ofActive() = Status(active = JsonValue.from(mapOf("type" to "active"))) + + /** Indicates that a thread is locked and cannot accept new input. */ + @JvmStatic fun ofLocked(locked: Locked) = Status(locked = locked) + + /** Indicates that a thread has been closed. */ + @JvmStatic fun ofClosed(closed: Closed) = Status(closed = closed) + } + + /** An interface that defines how to map each variant of [Status] to a value of type [T]. */ + interface Visitor { + + /** Indicates that a thread is active. */ + fun visitActive(active: JsonValue): T + + /** Indicates that a thread is locked and cannot accept new input. */ + fun visitLocked(locked: Locked): T + + /** Indicates that a thread has been closed. */ + fun visitClosed(closed: Closed): T + + /** + * Maps an unknown variant of [Status] to a value of type [T]. + * + * An instance of [Status] 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 Status: $json") + } + } + + internal class Deserializer : BaseDeserializer(Status::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Status { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "active" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Status(active = it, _json = json) } + ?.takeIf { it.isValid() } ?: Status(_json = json) + } + "locked" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Status(locked = it, _json = json) + } ?: Status(_json = json) + } + "closed" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Status(closed = it, _json = json) + } ?: Status(_json = json) + } + } + + return Status(_json = json) + } + } + + internal class Serializer : BaseSerializer(Status::class) { + + override fun serialize( + value: Status, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.active != null -> generator.writeObject(value.active) + value.locked != null -> generator.writeObject(value.locked) + value.closed != null -> generator.writeObject(value.closed) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Status") + } + } + } + + /** Indicates that a thread is locked and cannot accept new input. */ + class Locked + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val reason: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("reason") + @ExcludeMissing + reason: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(reason, type, mutableMapOf()) + + /** + * Reason that the thread was locked. Defaults to null when no reason is recorded. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun reason(): Optional = reason.getOptional("reason") + + /** + * Status discriminator that is always `locked`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("locked") + * ``` + * + * 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 [reason]. + * + * Unlike [reason], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("reason") @ExcludeMissing fun _reason(): JsonField = reason + + @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 [Locked]. + * + * The following fields are required: + * ```java + * .reason() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Locked]. */ + class Builder internal constructor() { + + private var reason: JsonField? = null + private var type: JsonValue = JsonValue.from("locked") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(locked: Locked) = apply { + reason = locked.reason + type = locked.type + additionalProperties = locked.additionalProperties.toMutableMap() + } + + /** + * Reason that the thread was locked. Defaults to null when no reason is recorded. + */ + fun reason(reason: String?) = reason(JsonField.ofNullable(reason)) + + /** Alias for calling [Builder.reason] with `reason.orElse(null)`. */ + fun reason(reason: Optional) = reason(reason.getOrNull()) + + /** + * Sets [Builder.reason] to an arbitrary JSON value. + * + * You should usually call [Builder.reason] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun reason(reason: JsonField) = apply { this.reason = reason } + + /** + * 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("locked") + * ``` + * + * 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 [Locked]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .reason() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Locked = + Locked( + checkRequired("reason", reason), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Locked = apply { + if (validated) { + return@apply + } + + reason() + _type().let { + if (it != JsonValue.from("locked")) { + 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 (reason.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("locked")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Locked && + reason == other.reason && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(reason, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Locked{reason=$reason, type=$type, additionalProperties=$additionalProperties}" + } + + /** Indicates that a thread has been closed. */ + class Closed + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val reason: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("reason") + @ExcludeMissing + reason: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(reason, type, mutableMapOf()) + + /** + * Reason that the thread was closed. Defaults to null when no reason is recorded. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun reason(): Optional = reason.getOptional("reason") + + /** + * Status discriminator that is always `closed`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("closed") + * ``` + * + * 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 [reason]. + * + * Unlike [reason], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("reason") @ExcludeMissing fun _reason(): JsonField = reason + + @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 [Closed]. + * + * The following fields are required: + * ```java + * .reason() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Closed]. */ + class Builder internal constructor() { + + private var reason: JsonField? = null + private var type: JsonValue = JsonValue.from("closed") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(closed: Closed) = apply { + reason = closed.reason + type = closed.type + additionalProperties = closed.additionalProperties.toMutableMap() + } + + /** + * Reason that the thread was closed. Defaults to null when no reason is recorded. + */ + fun reason(reason: String?) = reason(JsonField.ofNullable(reason)) + + /** Alias for calling [Builder.reason] with `reason.orElse(null)`. */ + fun reason(reason: Optional) = reason(reason.getOrNull()) + + /** + * Sets [Builder.reason] to an arbitrary JSON value. + * + * You should usually call [Builder.reason] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun reason(reason: JsonField) = apply { this.reason = reason } + + /** + * 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("closed") + * ``` + * + * 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 [Closed]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .reason() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Closed = + Closed( + checkRequired("reason", reason), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Closed = apply { + if (validated) { + return@apply + } + + reason() + _type().let { + if (it != JsonValue.from("closed")) { + 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 (reason.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("closed")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Closed && + reason == other.reason && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(reason, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Closed{reason=$reason, type=$type, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatKitThread && + id == other.id && + createdAt == other.createdAt && + object_ == other.object_ && + status == other.status && + title == other.title && + user == other.user && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, object_, status, title, user, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatKitThread{id=$id, createdAt=$createdAt, object_=$object_, status=$status, title=$title, user=$user, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitThreadAssistantMessageItem.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitThreadAssistantMessageItem.kt new file mode 100644 index 00000000..c0444386 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitThreadAssistantMessageItem.kt @@ -0,0 +1,389 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 kotlin.jvm.optionals.getOrNull + +/** Assistant-authored message within a thread. */ +class ChatKitThreadAssistantMessageItem +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val content: JsonField>, + private val createdAt: JsonField, + private val object_: JsonValue, + private val threadId: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField> = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("thread_id") @ExcludeMissing threadId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(id, content, createdAt, object_, threadId, type, mutableMapOf()) + + /** + * Identifier of the thread item. + * + * @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") + + /** + * Ordered assistant response segments. + * + * @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 content(): List = content.getRequired("content") + + /** + * Unix timestamp (in seconds) for when the item 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") + + /** + * Type discriminator that is always `chatkit.thread_item`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.thread_item") + * ``` + * + * 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 parent thread. + * + * @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 threadId(): String = threadId.getRequired("thread_id") + + /** + * Type discriminator that is always `chatkit.assistant_message`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.assistant_message") + * ``` + * + * 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 [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 [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") + @ExcludeMissing + fun _content(): JsonField> = content + + /** + * 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 [threadId]. + * + * Unlike [threadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("thread_id") @ExcludeMissing fun _threadId(): JsonField = threadId + + @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 + * [ChatKitThreadAssistantMessageItem]. + * + * The following fields are required: + * ```java + * .id() + * .content() + * .createdAt() + * .threadId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatKitThreadAssistantMessageItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var content: JsonField>? = null + private var createdAt: JsonField? = null + private var object_: JsonValue = JsonValue.from("chatkit.thread_item") + private var threadId: JsonField? = null + private var type: JsonValue = JsonValue.from("chatkit.assistant_message") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatkitThreadAssistantMessageItem: ChatKitThreadAssistantMessageItem) = + apply { + id = chatkitThreadAssistantMessageItem.id + content = chatkitThreadAssistantMessageItem.content.map { it.toMutableList() } + createdAt = chatkitThreadAssistantMessageItem.createdAt + object_ = chatkitThreadAssistantMessageItem.object_ + threadId = chatkitThreadAssistantMessageItem.threadId + type = chatkitThreadAssistantMessageItem.type + additionalProperties = + chatkitThreadAssistantMessageItem.additionalProperties.toMutableMap() + } + + /** Identifier of the thread item. */ + 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 } + + /** Ordered assistant response segments. */ + fun content(content: List) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun content(content: JsonField>) = apply { + this.content = content.map { it.toMutableList() } + } + + /** + * Adds a single [ChatKitResponseOutputText] to [Builder.content]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addContent(content: ChatKitResponseOutputText) = apply { + this.content = + (this.content ?: JsonField.of(mutableListOf())).also { + checkKnown("content", it).add(content) + } + } + + /** Unix timestamp (in seconds) for when the item 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 } + + /** + * 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("chatkit.thread_item") + * ``` + * + * 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 parent thread. */ + fun threadId(threadId: String) = threadId(JsonField.of(threadId)) + + /** + * Sets [Builder.threadId] to an arbitrary JSON value. + * + * You should usually call [Builder.threadId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun threadId(threadId: JsonField) = apply { this.threadId = threadId } + + /** + * 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("chatkit.assistant_message") + * ``` + * + * 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 [ChatKitThreadAssistantMessageItem]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .content() + * .createdAt() + * .threadId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatKitThreadAssistantMessageItem = + ChatKitThreadAssistantMessageItem( + checkRequired("id", id), + checkRequired("content", content).map { it.toImmutable() }, + checkRequired("createdAt", createdAt), + object_, + checkRequired("threadId", threadId), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatKitThreadAssistantMessageItem = apply { + if (validated) { + return@apply + } + + id() + content().forEach { it.validate() } + createdAt() + _object_().let { + if (it != JsonValue.from("chatkit.thread_item")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + threadId() + _type().let { + if (it != JsonValue.from("chatkit.assistant_message")) { + 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 (id.asKnown().isPresent) 1 else 0) + + (content.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("chatkit.thread_item")) 1 else 0 } + + (if (threadId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("chatkit.assistant_message")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatKitThreadAssistantMessageItem && + id == other.id && + content == other.content && + createdAt == other.createdAt && + object_ == other.object_ && + threadId == other.threadId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, content, createdAt, object_, threadId, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatKitThreadAssistantMessageItem{id=$id, content=$content, createdAt=$createdAt, object_=$object_, threadId=$threadId, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitThreadItemList.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitThreadItemList.kt new file mode 100644 index 00000000..54ff0c87 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitThreadItemList.kt @@ -0,0 +1,2813 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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.checkRequired +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 + +/** A paginated list of thread items rendered for the ChatKit API. */ +class ChatKitThreadItemList +@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 [ChatKitThreadItemList]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatKitThreadItemList]. */ + 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(chatkitThreadItemList: ChatKitThreadItemList) = apply { + data = chatkitThreadItemList.data.map { it.toMutableList() } + firstId = chatkitThreadItemList.firstId + hasMore = chatkitThreadItemList.hasMore + lastId = chatkitThreadItemList.lastId + object_ = chatkitThreadItemList.object_ + additionalProperties = chatkitThreadItemList.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 [Data] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Data) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** Alias for calling [addData] with `Data.ofChatKitUserMessage(chatkitUserMessage)`. */ + fun addData(chatkitUserMessage: ChatKitThreadUserMessageItem) = + addData(Data.ofChatKitUserMessage(chatkitUserMessage)) + + /** + * Alias for calling [addData] with + * `Data.ofChatKitAssistantMessage(chatkitAssistantMessage)`. + */ + fun addData(chatkitAssistantMessage: ChatKitThreadAssistantMessageItem) = + addData(Data.ofChatKitAssistantMessage(chatkitAssistantMessage)) + + /** Alias for calling [addData] with `Data.ofChatKitWidget(chatkitWidget)`. */ + fun addData(chatkitWidget: ChatKitWidgetItem) = addData(Data.ofChatKitWidget(chatkitWidget)) + + /** + * Alias for calling [addData] with `Data.ofChatKitClientToolCall(chatkitClientToolCall)`. + */ + fun addData(chatkitClientToolCall: Data.ChatKitClientToolCall) = + addData(Data.ofChatKitClientToolCall(chatkitClientToolCall)) + + /** Alias for calling [addData] with `Data.ofChatKitTask(chatkitTask)`. */ + fun addData(chatkitTask: Data.ChatKitTask) = addData(Data.ofChatKitTask(chatkitTask)) + + /** Alias for calling [addData] with `Data.ofChatKitTaskGroup(chatkitTaskGroup)`. */ + fun addData(chatkitTaskGroup: Data.ChatKitTaskGroup) = + addData(Data.ofChatKitTaskGroup(chatkitTaskGroup)) + + /** 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 [ChatKitThreadItemList]. + * + * 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(): ChatKitThreadItemList = + ChatKitThreadItemList( + 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(): ChatKitThreadItemList = 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 } + + /** User-authored messages within a thread. */ + @JsonDeserialize(using = Data.Deserializer::class) + @JsonSerialize(using = Data.Serializer::class) + class Data + private constructor( + private val chatkitUserMessage: ChatKitThreadUserMessageItem? = null, + private val chatkitAssistantMessage: ChatKitThreadAssistantMessageItem? = null, + private val chatkitWidget: ChatKitWidgetItem? = null, + private val chatkitClientToolCall: ChatKitClientToolCall? = null, + private val chatkitTask: ChatKitTask? = null, + private val chatkitTaskGroup: ChatKitTaskGroup? = null, + private val _json: JsonValue? = null, + ) { + + /** User-authored messages within a thread. */ + fun chatkitUserMessage(): Optional = + Optional.ofNullable(chatkitUserMessage) + + /** Assistant-authored message within a thread. */ + fun chatkitAssistantMessage(): Optional = + Optional.ofNullable(chatkitAssistantMessage) + + /** Thread item that renders a widget payload. */ + fun chatkitWidget(): Optional = Optional.ofNullable(chatkitWidget) + + /** Record of a client side tool invocation initiated by the assistant. */ + fun chatkitClientToolCall(): Optional = + Optional.ofNullable(chatkitClientToolCall) + + /** Task emitted by the workflow to show progress and status updates. */ + fun chatkitTask(): Optional = Optional.ofNullable(chatkitTask) + + /** Collection of workflow tasks grouped together in the thread. */ + fun chatkitTaskGroup(): Optional = Optional.ofNullable(chatkitTaskGroup) + + fun isChatKitUserMessage(): Boolean = chatkitUserMessage != null + + fun isChatKitAssistantMessage(): Boolean = chatkitAssistantMessage != null + + fun isChatKitWidget(): Boolean = chatkitWidget != null + + fun isChatKitClientToolCall(): Boolean = chatkitClientToolCall != null + + fun isChatKitTask(): Boolean = chatkitTask != null + + fun isChatKitTaskGroup(): Boolean = chatkitTaskGroup != null + + /** User-authored messages within a thread. */ + fun asChatKitUserMessage(): ChatKitThreadUserMessageItem = + chatkitUserMessage.getOrThrow("chatkitUserMessage") + + /** Assistant-authored message within a thread. */ + fun asChatKitAssistantMessage(): ChatKitThreadAssistantMessageItem = + chatkitAssistantMessage.getOrThrow("chatkitAssistantMessage") + + /** Thread item that renders a widget payload. */ + fun asChatKitWidget(): ChatKitWidgetItem = chatkitWidget.getOrThrow("chatkitWidget") + + /** Record of a client side tool invocation initiated by the assistant. */ + fun asChatKitClientToolCall(): ChatKitClientToolCall = + chatkitClientToolCall.getOrThrow("chatkitClientToolCall") + + /** Task emitted by the workflow to show progress and status updates. */ + fun asChatKitTask(): ChatKitTask = chatkitTask.getOrThrow("chatkitTask") + + /** Collection of workflow tasks grouped together in the thread. */ + fun asChatKitTaskGroup(): ChatKitTaskGroup = chatkitTaskGroup.getOrThrow("chatkitTaskGroup") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + chatkitUserMessage != null -> visitor.visitChatKitUserMessage(chatkitUserMessage) + chatkitAssistantMessage != null -> + visitor.visitChatKitAssistantMessage(chatkitAssistantMessage) + chatkitWidget != null -> visitor.visitChatKitWidget(chatkitWidget) + chatkitClientToolCall != null -> + visitor.visitChatKitClientToolCall(chatkitClientToolCall) + chatkitTask != null -> visitor.visitChatKitTask(chatkitTask) + chatkitTaskGroup != null -> visitor.visitChatKitTaskGroup(chatkitTaskGroup) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Data = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitChatKitUserMessage( + chatkitUserMessage: ChatKitThreadUserMessageItem + ) { + chatkitUserMessage.validate() + } + + override fun visitChatKitAssistantMessage( + chatkitAssistantMessage: ChatKitThreadAssistantMessageItem + ) { + chatkitAssistantMessage.validate() + } + + override fun visitChatKitWidget(chatkitWidget: ChatKitWidgetItem) { + chatkitWidget.validate() + } + + override fun visitChatKitClientToolCall( + chatkitClientToolCall: ChatKitClientToolCall + ) { + chatkitClientToolCall.validate() + } + + override fun visitChatKitTask(chatkitTask: ChatKitTask) { + chatkitTask.validate() + } + + override fun visitChatKitTaskGroup(chatkitTaskGroup: ChatKitTaskGroup) { + chatkitTaskGroup.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 visitChatKitUserMessage( + chatkitUserMessage: ChatKitThreadUserMessageItem + ) = chatkitUserMessage.validity() + + override fun visitChatKitAssistantMessage( + chatkitAssistantMessage: ChatKitThreadAssistantMessageItem + ) = chatkitAssistantMessage.validity() + + override fun visitChatKitWidget(chatkitWidget: ChatKitWidgetItem) = + chatkitWidget.validity() + + override fun visitChatKitClientToolCall( + chatkitClientToolCall: ChatKitClientToolCall + ) = chatkitClientToolCall.validity() + + override fun visitChatKitTask(chatkitTask: ChatKitTask) = chatkitTask.validity() + + override fun visitChatKitTaskGroup(chatkitTaskGroup: ChatKitTaskGroup) = + chatkitTaskGroup.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Data && + chatkitUserMessage == other.chatkitUserMessage && + chatkitAssistantMessage == other.chatkitAssistantMessage && + chatkitWidget == other.chatkitWidget && + chatkitClientToolCall == other.chatkitClientToolCall && + chatkitTask == other.chatkitTask && + chatkitTaskGroup == other.chatkitTaskGroup + } + + override fun hashCode(): Int = + Objects.hash( + chatkitUserMessage, + chatkitAssistantMessage, + chatkitWidget, + chatkitClientToolCall, + chatkitTask, + chatkitTaskGroup, + ) + + override fun toString(): String = + when { + chatkitUserMessage != null -> "Data{chatkitUserMessage=$chatkitUserMessage}" + chatkitAssistantMessage != null -> + "Data{chatkitAssistantMessage=$chatkitAssistantMessage}" + chatkitWidget != null -> "Data{chatkitWidget=$chatkitWidget}" + chatkitClientToolCall != null -> + "Data{chatkitClientToolCall=$chatkitClientToolCall}" + chatkitTask != null -> "Data{chatkitTask=$chatkitTask}" + chatkitTaskGroup != null -> "Data{chatkitTaskGroup=$chatkitTaskGroup}" + _json != null -> "Data{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Data") + } + + companion object { + + /** User-authored messages within a thread. */ + @JvmStatic + fun ofChatKitUserMessage(chatkitUserMessage: ChatKitThreadUserMessageItem) = + Data(chatkitUserMessage = chatkitUserMessage) + + /** Assistant-authored message within a thread. */ + @JvmStatic + fun ofChatKitAssistantMessage( + chatkitAssistantMessage: ChatKitThreadAssistantMessageItem + ) = Data(chatkitAssistantMessage = chatkitAssistantMessage) + + /** Thread item that renders a widget payload. */ + @JvmStatic + fun ofChatKitWidget(chatkitWidget: ChatKitWidgetItem) = + Data(chatkitWidget = chatkitWidget) + + /** Record of a client side tool invocation initiated by the assistant. */ + @JvmStatic + fun ofChatKitClientToolCall(chatkitClientToolCall: ChatKitClientToolCall) = + Data(chatkitClientToolCall = chatkitClientToolCall) + + /** Task emitted by the workflow to show progress and status updates. */ + @JvmStatic fun ofChatKitTask(chatkitTask: ChatKitTask) = Data(chatkitTask = chatkitTask) + + /** Collection of workflow tasks grouped together in the thread. */ + @JvmStatic + fun ofChatKitTaskGroup(chatkitTaskGroup: ChatKitTaskGroup) = + Data(chatkitTaskGroup = chatkitTaskGroup) + } + + /** An interface that defines how to map each variant of [Data] to a value of type [T]. */ + interface Visitor { + + /** User-authored messages within a thread. */ + fun visitChatKitUserMessage(chatkitUserMessage: ChatKitThreadUserMessageItem): T + + /** Assistant-authored message within a thread. */ + fun visitChatKitAssistantMessage( + chatkitAssistantMessage: ChatKitThreadAssistantMessageItem + ): T + + /** Thread item that renders a widget payload. */ + fun visitChatKitWidget(chatkitWidget: ChatKitWidgetItem): T + + /** Record of a client side tool invocation initiated by the assistant. */ + fun visitChatKitClientToolCall(chatkitClientToolCall: ChatKitClientToolCall): T + + /** Task emitted by the workflow to show progress and status updates. */ + fun visitChatKitTask(chatkitTask: ChatKitTask): T + + /** Collection of workflow tasks grouped together in the thread. */ + fun visitChatKitTaskGroup(chatkitTaskGroup: ChatKitTaskGroup): T + + /** + * Maps an unknown variant of [Data] to a value of type [T]. + * + * An instance of [Data] 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 Data: $json") + } + } + + internal class Deserializer : BaseDeserializer(Data::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Data { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "chatkit.user_message" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Data(chatkitUserMessage = it, _json = json) } + ?: Data(_json = json) + } + "chatkit.assistant_message" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Data(chatkitAssistantMessage = it, _json = json) } + ?: Data(_json = json) + } + "chatkit.widget" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Data(chatkitWidget = it, _json = json) + } ?: Data(_json = json) + } + "chatkit.client_tool_call" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Data(chatkitClientToolCall = it, _json = json) + } ?: Data(_json = json) + } + "chatkit.task" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Data(chatkitTask = it, _json = json) + } ?: Data(_json = json) + } + "chatkit.task_group" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Data(chatkitTaskGroup = it, _json = json) + } ?: Data(_json = json) + } + } + + return Data(_json = json) + } + } + + internal class Serializer : BaseSerializer(Data::class) { + + override fun serialize( + value: Data, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.chatkitUserMessage != null -> + generator.writeObject(value.chatkitUserMessage) + value.chatkitAssistantMessage != null -> + generator.writeObject(value.chatkitAssistantMessage) + value.chatkitWidget != null -> generator.writeObject(value.chatkitWidget) + value.chatkitClientToolCall != null -> + generator.writeObject(value.chatkitClientToolCall) + value.chatkitTask != null -> generator.writeObject(value.chatkitTask) + value.chatkitTaskGroup != null -> generator.writeObject(value.chatkitTaskGroup) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Data") + } + } + } + + /** Record of a client side tool invocation initiated by the assistant. */ + class ChatKitClientToolCall + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val arguments: JsonField, + private val callId: JsonField, + private val createdAt: JsonField, + private val name: JsonField, + private val object_: JsonValue, + private val output: JsonField, + private val status: JsonField, + private val threadId: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("arguments") + @ExcludeMissing + arguments: JsonField = JsonMissing.of(), + @JsonProperty("call_id") + @ExcludeMissing + callId: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("output") + @ExcludeMissing + output: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + status: JsonField = JsonMissing.of(), + @JsonProperty("thread_id") + @ExcludeMissing + threadId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this( + id, + arguments, + callId, + createdAt, + name, + object_, + output, + status, + threadId, + type, + mutableMapOf(), + ) + + /** + * Identifier of the thread item. + * + * @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") + + /** + * JSON-encoded arguments that were sent to the tool. + * + * @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 arguments(): String = arguments.getRequired("arguments") + + /** + * Identifier for the client tool call. + * + * @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 callId(): String = callId.getRequired("call_id") + + /** + * Unix timestamp (in seconds) for when the item 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") + + /** + * Tool name that was invoked. + * + * @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") + + /** + * Type discriminator that is always `chatkit.thread_item`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.thread_item") + * ``` + * + * 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_ + + /** + * JSON-encoded output captured from the tool. Defaults to null while execution is in + * progress. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun output(): Optional = output.getOptional("output") + + /** + * Execution status for the tool call. + * + * @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 status(): Status = status.getRequired("status") + + /** + * Identifier of the parent thread. + * + * @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 threadId(): String = threadId.getRequired("thread_id") + + /** + * Type discriminator that is always `chatkit.client_tool_call`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.client_tool_call") + * ``` + * + * 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 [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 [arguments]. + * + * Unlike [arguments], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("arguments") + @ExcludeMissing + fun _arguments(): JsonField = arguments + + /** + * Returns the raw JSON value of [callId]. + * + * Unlike [callId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("call_id") @ExcludeMissing fun _callId(): JsonField = callId + + /** + * 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 [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 [output]. + * + * Unlike [output], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("output") @ExcludeMissing fun _output(): JsonField = output + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [threadId]. + * + * Unlike [threadId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("thread_id") @ExcludeMissing fun _threadId(): JsonField = threadId + + @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 + * [ChatKitClientToolCall]. + * + * The following fields are required: + * ```java + * .id() + * .arguments() + * .callId() + * .createdAt() + * .name() + * .output() + * .status() + * .threadId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatKitClientToolCall]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var arguments: JsonField? = null + private var callId: JsonField? = null + private var createdAt: JsonField? = null + private var name: JsonField? = null + private var object_: JsonValue = JsonValue.from("chatkit.thread_item") + private var output: JsonField? = null + private var status: JsonField? = null + private var threadId: JsonField? = null + private var type: JsonValue = JsonValue.from("chatkit.client_tool_call") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatkitClientToolCall: ChatKitClientToolCall) = apply { + id = chatkitClientToolCall.id + arguments = chatkitClientToolCall.arguments + callId = chatkitClientToolCall.callId + createdAt = chatkitClientToolCall.createdAt + name = chatkitClientToolCall.name + object_ = chatkitClientToolCall.object_ + output = chatkitClientToolCall.output + status = chatkitClientToolCall.status + threadId = chatkitClientToolCall.threadId + type = chatkitClientToolCall.type + additionalProperties = chatkitClientToolCall.additionalProperties.toMutableMap() + } + + /** Identifier of the thread item. */ + 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 } + + /** JSON-encoded arguments that were sent to the tool. */ + fun arguments(arguments: String) = arguments(JsonField.of(arguments)) + + /** + * Sets [Builder.arguments] to an arbitrary JSON value. + * + * You should usually call [Builder.arguments] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun arguments(arguments: JsonField) = apply { this.arguments = arguments } + + /** Identifier for the client tool call. */ + fun callId(callId: String) = callId(JsonField.of(callId)) + + /** + * Sets [Builder.callId] to an arbitrary JSON value. + * + * You should usually call [Builder.callId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun callId(callId: JsonField) = apply { this.callId = callId } + + /** Unix timestamp (in seconds) for when the item 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 } + + /** Tool name that was invoked. */ + 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("chatkit.thread_item") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** + * JSON-encoded output captured from the tool. Defaults to null while execution is + * in progress. + */ + fun output(output: String?) = output(JsonField.ofNullable(output)) + + /** Alias for calling [Builder.output] with `output.orElse(null)`. */ + fun output(output: Optional) = output(output.getOrNull()) + + /** + * Sets [Builder.output] to an arbitrary JSON value. + * + * You should usually call [Builder.output] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun output(output: JsonField) = apply { this.output = output } + + /** Execution status for the tool call. */ + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** Identifier of the parent thread. */ + fun threadId(threadId: String) = threadId(JsonField.of(threadId)) + + /** + * Sets [Builder.threadId] to an arbitrary JSON value. + * + * You should usually call [Builder.threadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun threadId(threadId: JsonField) = apply { this.threadId = threadId } + + /** + * 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("chatkit.client_tool_call") + * ``` + * + * 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 [ChatKitClientToolCall]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .arguments() + * .callId() + * .createdAt() + * .name() + * .output() + * .status() + * .threadId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatKitClientToolCall = + ChatKitClientToolCall( + checkRequired("id", id), + checkRequired("arguments", arguments), + checkRequired("callId", callId), + checkRequired("createdAt", createdAt), + checkRequired("name", name), + object_, + checkRequired("output", output), + checkRequired("status", status), + checkRequired("threadId", threadId), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatKitClientToolCall = apply { + if (validated) { + return@apply + } + + id() + arguments() + callId() + createdAt() + name() + _object_().let { + if (it != JsonValue.from("chatkit.thread_item")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + output() + status().validate() + threadId() + _type().let { + if (it != JsonValue.from("chatkit.client_tool_call")) { + 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 (id.asKnown().isPresent) 1 else 0) + + (if (arguments.asKnown().isPresent) 1 else 0) + + (if (callId.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("chatkit.thread_item")) 1 else 0 } + + (if (output.asKnown().isPresent) 1 else 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (threadId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("chatkit.client_tool_call")) 1 else 0 } + + /** Execution status for the tool call. */ + class Status @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 IN_PROGRESS = of("in_progress") + + @JvmField val COMPLETED = of("completed") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + IN_PROGRESS, + COMPLETED, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] 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 { + IN_PROGRESS, + COMPLETED, + /** + * An enum member indicating that [Status] 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) { + IN_PROGRESS -> Value.IN_PROGRESS + COMPLETED -> Value.COMPLETED + 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) { + IN_PROGRESS -> Known.IN_PROGRESS + COMPLETED -> Known.COMPLETED + else -> throw OpenAIInvalidDataException("Unknown Status: $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(): Status = 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 Status && 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 ChatKitClientToolCall && + id == other.id && + arguments == other.arguments && + callId == other.callId && + createdAt == other.createdAt && + name == other.name && + object_ == other.object_ && + output == other.output && + status == other.status && + threadId == other.threadId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + arguments, + callId, + createdAt, + name, + object_, + output, + status, + threadId, + type, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatKitClientToolCall{id=$id, arguments=$arguments, callId=$callId, createdAt=$createdAt, name=$name, object_=$object_, output=$output, status=$status, threadId=$threadId, type=$type, additionalProperties=$additionalProperties}" + } + + /** Task emitted by the workflow to show progress and status updates. */ + class ChatKitTask + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val heading: JsonField, + private val object_: JsonValue, + private val summary: JsonField, + private val taskType: JsonField, + private val threadId: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("heading") + @ExcludeMissing + heading: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("summary") + @ExcludeMissing + summary: JsonField = JsonMissing.of(), + @JsonProperty("task_type") + @ExcludeMissing + taskType: JsonField = JsonMissing.of(), + @JsonProperty("thread_id") + @ExcludeMissing + threadId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this( + id, + createdAt, + heading, + object_, + summary, + taskType, + threadId, + type, + mutableMapOf(), + ) + + /** + * Identifier of the thread item. + * + * @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 (in seconds) for when the item 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") + + /** + * Optional heading for the task. Defaults to null when not provided. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun heading(): Optional = heading.getOptional("heading") + + /** + * Type discriminator that is always `chatkit.thread_item`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.thread_item") + * ``` + * + * 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_ + + /** + * Optional summary that describes the task. Defaults to null when omitted. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun summary(): Optional = summary.getOptional("summary") + + /** + * Subtype for the task. + * + * @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 taskType(): TaskType = taskType.getRequired("task_type") + + /** + * Identifier of the parent thread. + * + * @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 threadId(): String = threadId.getRequired("thread_id") + + /** + * Type discriminator that is always `chatkit.task`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.task") + * ``` + * + * 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 [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 [heading]. + * + * Unlike [heading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("heading") @ExcludeMissing fun _heading(): JsonField = heading + + /** + * Returns the raw JSON value of [summary]. + * + * Unlike [summary], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("summary") @ExcludeMissing fun _summary(): JsonField = summary + + /** + * Returns the raw JSON value of [taskType]. + * + * Unlike [taskType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("task_type") + @ExcludeMissing + fun _taskType(): JsonField = taskType + + /** + * Returns the raw JSON value of [threadId]. + * + * Unlike [threadId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("thread_id") @ExcludeMissing fun _threadId(): JsonField = threadId + + @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 [ChatKitTask]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .heading() + * .summary() + * .taskType() + * .threadId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatKitTask]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var heading: JsonField? = null + private var object_: JsonValue = JsonValue.from("chatkit.thread_item") + private var summary: JsonField? = null + private var taskType: JsonField? = null + private var threadId: JsonField? = null + private var type: JsonValue = JsonValue.from("chatkit.task") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatkitTask: ChatKitTask) = apply { + id = chatkitTask.id + createdAt = chatkitTask.createdAt + heading = chatkitTask.heading + object_ = chatkitTask.object_ + summary = chatkitTask.summary + taskType = chatkitTask.taskType + threadId = chatkitTask.threadId + type = chatkitTask.type + additionalProperties = chatkitTask.additionalProperties.toMutableMap() + } + + /** Identifier of the thread item. */ + 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 (in seconds) for when the item 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 } + + /** Optional heading for the task. Defaults to null when not provided. */ + fun heading(heading: String?) = heading(JsonField.ofNullable(heading)) + + /** Alias for calling [Builder.heading] with `heading.orElse(null)`. */ + fun heading(heading: Optional) = heading(heading.getOrNull()) + + /** + * Sets [Builder.heading] to an arbitrary JSON value. + * + * You should usually call [Builder.heading] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun heading(heading: JsonField) = apply { this.heading = heading } + + /** + * 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("chatkit.thread_item") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** Optional summary that describes the task. Defaults to null when omitted. */ + fun summary(summary: String?) = summary(JsonField.ofNullable(summary)) + + /** Alias for calling [Builder.summary] with `summary.orElse(null)`. */ + fun summary(summary: Optional) = summary(summary.getOrNull()) + + /** + * Sets [Builder.summary] to an arbitrary JSON value. + * + * You should usually call [Builder.summary] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun summary(summary: JsonField) = apply { this.summary = summary } + + /** Subtype for the task. */ + fun taskType(taskType: TaskType) = taskType(JsonField.of(taskType)) + + /** + * Sets [Builder.taskType] to an arbitrary JSON value. + * + * You should usually call [Builder.taskType] with a well-typed [TaskType] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun taskType(taskType: JsonField) = apply { this.taskType = taskType } + + /** Identifier of the parent thread. */ + fun threadId(threadId: String) = threadId(JsonField.of(threadId)) + + /** + * Sets [Builder.threadId] to an arbitrary JSON value. + * + * You should usually call [Builder.threadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun threadId(threadId: JsonField) = apply { this.threadId = threadId } + + /** + * 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("chatkit.task") + * ``` + * + * 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 [ChatKitTask]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .heading() + * .summary() + * .taskType() + * .threadId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatKitTask = + ChatKitTask( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("heading", heading), + object_, + checkRequired("summary", summary), + checkRequired("taskType", taskType), + checkRequired("threadId", threadId), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatKitTask = apply { + if (validated) { + return@apply + } + + id() + createdAt() + heading() + _object_().let { + if (it != JsonValue.from("chatkit.thread_item")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + summary() + taskType().validate() + threadId() + _type().let { + if (it != JsonValue.from("chatkit.task")) { + 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 (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (heading.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("chatkit.thread_item")) 1 else 0 } + + (if (summary.asKnown().isPresent) 1 else 0) + + (taskType.asKnown().getOrNull()?.validity() ?: 0) + + (if (threadId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("chatkit.task")) 1 else 0 } + + /** Subtype for the task. */ + class TaskType @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 CUSTOM = of("custom") + + @JvmField val THOUGHT = of("thought") + + @JvmStatic fun of(value: String) = TaskType(JsonField.of(value)) + } + + /** An enum containing [TaskType]'s known values. */ + enum class Known { + CUSTOM, + THOUGHT, + } + + /** + * An enum containing [TaskType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [TaskType] 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 { + CUSTOM, + THOUGHT, + /** + * An enum member indicating that [TaskType] 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) { + CUSTOM -> Value.CUSTOM + THOUGHT -> Value.THOUGHT + 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) { + CUSTOM -> Known.CUSTOM + THOUGHT -> Known.THOUGHT + else -> throw OpenAIInvalidDataException("Unknown TaskType: $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(): TaskType = 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 TaskType && 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 ChatKitTask && + id == other.id && + createdAt == other.createdAt && + heading == other.heading && + object_ == other.object_ && + summary == other.summary && + taskType == other.taskType && + threadId == other.threadId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + heading, + object_, + summary, + taskType, + threadId, + type, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatKitTask{id=$id, createdAt=$createdAt, heading=$heading, object_=$object_, summary=$summary, taskType=$taskType, threadId=$threadId, type=$type, additionalProperties=$additionalProperties}" + } + + /** Collection of workflow tasks grouped together in the thread. */ + class ChatKitTaskGroup + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val object_: JsonValue, + private val tasks: JsonField>, + private val threadId: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("tasks") + @ExcludeMissing + tasks: JsonField> = JsonMissing.of(), + @JsonProperty("thread_id") + @ExcludeMissing + threadId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(id, createdAt, object_, tasks, threadId, type, mutableMapOf()) + + /** + * Identifier of the thread item. + * + * @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 (in seconds) for when the item 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") + + /** + * Type discriminator that is always `chatkit.thread_item`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.thread_item") + * ``` + * + * 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_ + + /** + * Tasks included in the group. + * + * @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 tasks(): List = tasks.getRequired("tasks") + + /** + * Identifier of the parent thread. + * + * @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 threadId(): String = threadId.getRequired("thread_id") + + /** + * Type discriminator that is always `chatkit.task_group`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.task_group") + * ``` + * + * 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 [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 [tasks]. + * + * Unlike [tasks], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tasks") @ExcludeMissing fun _tasks(): JsonField> = tasks + + /** + * Returns the raw JSON value of [threadId]. + * + * Unlike [threadId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("thread_id") @ExcludeMissing fun _threadId(): JsonField = threadId + + @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 [ChatKitTaskGroup]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .tasks() + * .threadId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatKitTaskGroup]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var object_: JsonValue = JsonValue.from("chatkit.thread_item") + private var tasks: JsonField>? = null + private var threadId: JsonField? = null + private var type: JsonValue = JsonValue.from("chatkit.task_group") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatkitTaskGroup: ChatKitTaskGroup) = apply { + id = chatkitTaskGroup.id + createdAt = chatkitTaskGroup.createdAt + object_ = chatkitTaskGroup.object_ + tasks = chatkitTaskGroup.tasks.map { it.toMutableList() } + threadId = chatkitTaskGroup.threadId + type = chatkitTaskGroup.type + additionalProperties = chatkitTaskGroup.additionalProperties.toMutableMap() + } + + /** Identifier of the thread item. */ + 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 (in seconds) for when the item 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 } + + /** + * 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("chatkit.thread_item") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** Tasks included in the group. */ + fun tasks(tasks: List) = tasks(JsonField.of(tasks)) + + /** + * Sets [Builder.tasks] to an arbitrary JSON value. + * + * You should usually call [Builder.tasks] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun tasks(tasks: JsonField>) = apply { + this.tasks = tasks.map { it.toMutableList() } + } + + /** + * Adds a single [Task] to [tasks]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTask(task: Task) = apply { + tasks = + (tasks ?: JsonField.of(mutableListOf())).also { + checkKnown("tasks", it).add(task) + } + } + + /** Identifier of the parent thread. */ + fun threadId(threadId: String) = threadId(JsonField.of(threadId)) + + /** + * Sets [Builder.threadId] to an arbitrary JSON value. + * + * You should usually call [Builder.threadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun threadId(threadId: JsonField) = apply { this.threadId = threadId } + + /** + * 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("chatkit.task_group") + * ``` + * + * 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 [ChatKitTaskGroup]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .tasks() + * .threadId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatKitTaskGroup = + ChatKitTaskGroup( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + object_, + checkRequired("tasks", tasks).map { it.toImmutable() }, + checkRequired("threadId", threadId), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatKitTaskGroup = apply { + if (validated) { + return@apply + } + + id() + createdAt() + _object_().let { + if (it != JsonValue.from("chatkit.thread_item")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + tasks().forEach { it.validate() } + threadId() + _type().let { + if (it != JsonValue.from("chatkit.task_group")) { + 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 (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("chatkit.thread_item")) 1 else 0 } + + (tasks.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (threadId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("chatkit.task_group")) 1 else 0 } + + /** Task entry that appears within a TaskGroup. */ + class Task + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val heading: JsonField, + private val summary: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("heading") + @ExcludeMissing + heading: JsonField = JsonMissing.of(), + @JsonProperty("summary") + @ExcludeMissing + summary: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(heading, summary, type, mutableMapOf()) + + /** + * Optional heading for the grouped task. Defaults to null when not provided. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun heading(): Optional = heading.getOptional("heading") + + /** + * Optional summary that describes the grouped task. Defaults to null when omitted. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun summary(): Optional = summary.getOptional("summary") + + /** + * Subtype for the grouped task. + * + * @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 type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [heading]. + * + * Unlike [heading], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("heading") @ExcludeMissing fun _heading(): JsonField = heading + + /** + * Returns the raw JSON value of [summary]. + * + * Unlike [summary], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("summary") @ExcludeMissing fun _summary(): JsonField = summary + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = 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 [Task]. + * + * The following fields are required: + * ```java + * .heading() + * .summary() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Task]. */ + class Builder internal constructor() { + + private var heading: JsonField? = null + private var summary: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(task: Task) = apply { + heading = task.heading + summary = task.summary + type = task.type + additionalProperties = task.additionalProperties.toMutableMap() + } + + /** + * Optional heading for the grouped task. Defaults to null when not provided. + */ + fun heading(heading: String?) = heading(JsonField.ofNullable(heading)) + + /** Alias for calling [Builder.heading] with `heading.orElse(null)`. */ + fun heading(heading: Optional) = heading(heading.getOrNull()) + + /** + * Sets [Builder.heading] to an arbitrary JSON value. + * + * You should usually call [Builder.heading] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun heading(heading: JsonField) = apply { this.heading = heading } + + /** + * Optional summary that describes the grouped task. Defaults to null when + * omitted. + */ + fun summary(summary: String?) = summary(JsonField.ofNullable(summary)) + + /** Alias for calling [Builder.summary] with `summary.orElse(null)`. */ + fun summary(summary: Optional) = summary(summary.getOrNull()) + + /** + * Sets [Builder.summary] to an arbitrary JSON value. + * + * You should usually call [Builder.summary] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun summary(summary: JsonField) = apply { this.summary = summary } + + /** Subtype for the grouped task. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun type(type: JsonField) = 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 [Task]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .heading() + * .summary() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Task = + Task( + checkRequired("heading", heading), + checkRequired("summary", summary), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Task = apply { + if (validated) { + return@apply + } + + heading() + summary() + type().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 = + (if (heading.asKnown().isPresent) 1 else 0) + + (if (summary.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + /** Subtype for the grouped task. */ + class Type @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 CUSTOM = of("custom") + + @JvmField val THOUGHT = of("thought") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + CUSTOM, + THOUGHT, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] 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 { + CUSTOM, + THOUGHT, + /** + * An enum member indicating that [Type] 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) { + CUSTOM -> Value.CUSTOM + THOUGHT -> Value.THOUGHT + 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) { + CUSTOM -> Known.CUSTOM + THOUGHT -> Known.THOUGHT + else -> throw OpenAIInvalidDataException("Unknown Type: $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(): Type = 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 Type && 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 Task && + heading == other.heading && + summary == other.summary && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(heading, summary, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Task{heading=$heading, summary=$summary, type=$type, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatKitTaskGroup && + id == other.id && + createdAt == other.createdAt && + object_ == other.object_ && + tasks == other.tasks && + threadId == other.threadId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, object_, tasks, threadId, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatKitTaskGroup{id=$id, createdAt=$createdAt, object_=$object_, tasks=$tasks, threadId=$threadId, type=$type, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatKitThreadItemList && + 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() = + "ChatKitThreadItemList{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitThreadUserMessageItem.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitThreadUserMessageItem.kt new file mode 100644 index 00000000..c761a8ae --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitThreadUserMessageItem.kt @@ -0,0 +1,1510 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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.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 +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** User-authored messages within a thread. */ +class ChatKitThreadUserMessageItem +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val attachments: JsonField>, + private val content: JsonField>, + private val createdAt: JsonField, + private val inferenceOptions: JsonField, + private val object_: JsonValue, + private val threadId: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("attachments") + @ExcludeMissing + attachments: JsonField> = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField> = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("inference_options") + @ExcludeMissing + inferenceOptions: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("thread_id") @ExcludeMissing threadId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this( + id, + attachments, + content, + createdAt, + inferenceOptions, + object_, + threadId, + type, + mutableMapOf(), + ) + + /** + * Identifier of the thread item. + * + * @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") + + /** + * Attachments associated with the user message. Defaults to an empty list. + * + * @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 attachments(): List = attachments.getRequired("attachments") + + /** + * Ordered content elements supplied by the user. + * + * @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 content(): List = content.getRequired("content") + + /** + * Unix timestamp (in seconds) for when the item 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") + + /** + * Inference overrides applied to the message. Defaults to null when unset. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inferenceOptions(): Optional = + inferenceOptions.getOptional("inference_options") + + /** + * Type discriminator that is always `chatkit.thread_item`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.thread_item") + * ``` + * + * 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 parent thread. + * + * @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 threadId(): String = threadId.getRequired("thread_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.user_message") + * ``` + * + * 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 [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 [attachments]. + * + * Unlike [attachments], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("attachments") + @ExcludeMissing + fun _attachments(): JsonField> = attachments + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField> = content + + /** + * 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 [inferenceOptions]. + * + * Unlike [inferenceOptions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("inference_options") + @ExcludeMissing + fun _inferenceOptions(): JsonField = inferenceOptions + + /** + * Returns the raw JSON value of [threadId]. + * + * Unlike [threadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("thread_id") @ExcludeMissing fun _threadId(): JsonField = threadId + + @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 [ChatKitThreadUserMessageItem]. + * + * The following fields are required: + * ```java + * .id() + * .attachments() + * .content() + * .createdAt() + * .inferenceOptions() + * .threadId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatKitThreadUserMessageItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var attachments: JsonField>? = null + private var content: JsonField>? = null + private var createdAt: JsonField? = null + private var inferenceOptions: JsonField? = null + private var object_: JsonValue = JsonValue.from("chatkit.thread_item") + private var threadId: JsonField? = null + private var type: JsonValue = JsonValue.from("chatkit.user_message") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatkitThreadUserMessageItem: ChatKitThreadUserMessageItem) = apply { + id = chatkitThreadUserMessageItem.id + attachments = chatkitThreadUserMessageItem.attachments.map { it.toMutableList() } + content = chatkitThreadUserMessageItem.content.map { it.toMutableList() } + createdAt = chatkitThreadUserMessageItem.createdAt + inferenceOptions = chatkitThreadUserMessageItem.inferenceOptions + object_ = chatkitThreadUserMessageItem.object_ + threadId = chatkitThreadUserMessageItem.threadId + type = chatkitThreadUserMessageItem.type + additionalProperties = chatkitThreadUserMessageItem.additionalProperties.toMutableMap() + } + + /** Identifier of the thread item. */ + 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 } + + /** Attachments associated with the user message. Defaults to an empty list. */ + fun attachments(attachments: List) = + attachments(JsonField.of(attachments)) + + /** + * Sets [Builder.attachments] to an arbitrary JSON value. + * + * You should usually call [Builder.attachments] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun attachments(attachments: JsonField>) = apply { + this.attachments = attachments.map { it.toMutableList() } + } + + /** + * Adds a single [ChatKitAttachment] to [attachments]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAttachment(attachment: ChatKitAttachment) = apply { + attachments = + (attachments ?: JsonField.of(mutableListOf())).also { + checkKnown("attachments", it).add(attachment) + } + } + + /** Ordered content elements supplied by the user. */ + fun content(content: List) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun content(content: JsonField>) = apply { + this.content = content.map { it.toMutableList() } + } + + /** + * Adds a single [Content] to [Builder.content]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addContent(content: Content) = apply { + this.content = + (this.content ?: JsonField.of(mutableListOf())).also { + checkKnown("content", it).add(content) + } + } + + /** Alias for calling [addContent] with `Content.ofInputText(inputText)`. */ + fun addContent(inputText: Content.InputText) = addContent(Content.ofInputText(inputText)) + + /** + * Alias for calling [addContent] with the following: + * ```java + * Content.InputText.builder() + * .text(text) + * .build() + * ``` + */ + fun addInputTextContent(text: String) = + addContent(Content.InputText.builder().text(text).build()) + + /** Alias for calling [addContent] with `Content.ofQuotedText(quotedText)`. */ + fun addContent(quotedText: Content.QuotedText) = + addContent(Content.ofQuotedText(quotedText)) + + /** + * Alias for calling [addContent] with the following: + * ```java + * Content.QuotedText.builder() + * .text(text) + * .build() + * ``` + */ + fun addQuotedTextContent(text: String) = + addContent(Content.QuotedText.builder().text(text).build()) + + /** Unix timestamp (in seconds) for when the item 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 } + + /** Inference overrides applied to the message. Defaults to null when unset. */ + fun inferenceOptions(inferenceOptions: InferenceOptions?) = + inferenceOptions(JsonField.ofNullable(inferenceOptions)) + + /** Alias for calling [Builder.inferenceOptions] with `inferenceOptions.orElse(null)`. */ + fun inferenceOptions(inferenceOptions: Optional) = + inferenceOptions(inferenceOptions.getOrNull()) + + /** + * Sets [Builder.inferenceOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.inferenceOptions] with a well-typed [InferenceOptions] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun inferenceOptions(inferenceOptions: JsonField) = apply { + this.inferenceOptions = inferenceOptions + } + + /** + * 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("chatkit.thread_item") + * ``` + * + * 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 parent thread. */ + fun threadId(threadId: String) = threadId(JsonField.of(threadId)) + + /** + * Sets [Builder.threadId] to an arbitrary JSON value. + * + * You should usually call [Builder.threadId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun threadId(threadId: JsonField) = apply { this.threadId = threadId } + + /** + * 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("chatkit.user_message") + * ``` + * + * 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 [ChatKitThreadUserMessageItem]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .attachments() + * .content() + * .createdAt() + * .inferenceOptions() + * .threadId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatKitThreadUserMessageItem = + ChatKitThreadUserMessageItem( + checkRequired("id", id), + checkRequired("attachments", attachments).map { it.toImmutable() }, + checkRequired("content", content).map { it.toImmutable() }, + checkRequired("createdAt", createdAt), + checkRequired("inferenceOptions", inferenceOptions), + object_, + checkRequired("threadId", threadId), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatKitThreadUserMessageItem = apply { + if (validated) { + return@apply + } + + id() + attachments().forEach { it.validate() } + content().forEach { it.validate() } + createdAt() + inferenceOptions().ifPresent { it.validate() } + _object_().let { + if (it != JsonValue.from("chatkit.thread_item")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + threadId() + _type().let { + if (it != JsonValue.from("chatkit.user_message")) { + 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 (id.asKnown().isPresent) 1 else 0) + + (attachments.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (content.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (inferenceOptions.asKnown().getOrNull()?.validity() ?: 0) + + object_.let { if (it == JsonValue.from("chatkit.thread_item")) 1 else 0 } + + (if (threadId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("chatkit.user_message")) 1 else 0 } + + /** Content blocks that comprise a user message. */ + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val inputText: InputText? = null, + private val quotedText: QuotedText? = null, + private val _json: JsonValue? = null, + ) { + + /** Text block that a user contributed to the thread. */ + fun inputText(): Optional = Optional.ofNullable(inputText) + + /** Quoted snippet that the user referenced in their message. */ + fun quotedText(): Optional = Optional.ofNullable(quotedText) + + fun isInputText(): Boolean = inputText != null + + fun isQuotedText(): Boolean = quotedText != null + + /** Text block that a user contributed to the thread. */ + fun asInputText(): InputText = inputText.getOrThrow("inputText") + + /** Quoted snippet that the user referenced in their message. */ + fun asQuotedText(): QuotedText = quotedText.getOrThrow("quotedText") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + inputText != null -> visitor.visitInputText(inputText) + quotedText != null -> visitor.visitQuotedText(quotedText) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Content = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitInputText(inputText: InputText) { + inputText.validate() + } + + override fun visitQuotedText(quotedText: QuotedText) { + quotedText.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 visitInputText(inputText: InputText) = inputText.validity() + + override fun visitQuotedText(quotedText: QuotedText) = quotedText.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + inputText == other.inputText && + quotedText == other.quotedText + } + + override fun hashCode(): Int = Objects.hash(inputText, quotedText) + + override fun toString(): String = + when { + inputText != null -> "Content{inputText=$inputText}" + quotedText != null -> "Content{quotedText=$quotedText}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + + companion object { + + /** Text block that a user contributed to the thread. */ + @JvmStatic fun ofInputText(inputText: InputText) = Content(inputText = inputText) + + /** Quoted snippet that the user referenced in their message. */ + @JvmStatic fun ofQuotedText(quotedText: QuotedText) = Content(quotedText = quotedText) + } + + /** + * An interface that defines how to map each variant of [Content] to a value of type [T]. + */ + interface Visitor { + + /** Text block that a user contributed to the thread. */ + fun visitInputText(inputText: InputText): T + + /** Quoted snippet that the user referenced in their message. */ + fun visitQuotedText(quotedText: QuotedText): T + + /** + * Maps an unknown variant of [Content] to a value of type [T]. + * + * An instance of [Content] 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 Content: $json") + } + } + + internal class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "input_text" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Content(inputText = it, _json = json) + } ?: Content(_json = json) + } + "quoted_text" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Content(quotedText = it, _json = json) + } ?: Content(_json = json) + } + } + + return Content(_json = json) + } + } + + internal class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.inputText != null -> generator.writeObject(value.inputText) + value.quotedText != null -> generator.writeObject(value.quotedText) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + + /** Text block that a user contributed to the thread. */ + class InputText + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val text: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(text, type, mutableMapOf()) + + /** + * Plain-text content supplied by the user. + * + * @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 text(): String = text.getRequired("text") + + /** + * Type discriminator that is always `input_text`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("input_text") + * ``` + * + * 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 [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + @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 [InputText]. + * + * The following fields are required: + * ```java + * .text() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputText]. */ + class Builder internal constructor() { + + private var text: JsonField? = null + private var type: JsonValue = JsonValue.from("input_text") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputText: InputText) = apply { + text = inputText.text + type = inputText.type + additionalProperties = inputText.additionalProperties.toMutableMap() + } + + /** Plain-text content supplied by the user. */ + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + /** + * 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("input_text") + * ``` + * + * 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 [InputText]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .text() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InputText = + InputText( + checkRequired("text", text), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): InputText = apply { + if (validated) { + return@apply + } + + text() + _type().let { + if (it != JsonValue.from("input_text")) { + 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 (text.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("input_text")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InputText && + text == other.text && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(text, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InputText{text=$text, type=$type, additionalProperties=$additionalProperties}" + } + + /** Quoted snippet that the user referenced in their message. */ + class QuotedText + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val text: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(text, type, mutableMapOf()) + + /** + * Quoted text content. + * + * @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 text(): String = text.getRequired("text") + + /** + * Type discriminator that is always `quoted_text`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("quoted_text") + * ``` + * + * 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 [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + @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 [QuotedText]. + * + * The following fields are required: + * ```java + * .text() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [QuotedText]. */ + class Builder internal constructor() { + + private var text: JsonField? = null + private var type: JsonValue = JsonValue.from("quoted_text") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(quotedText: QuotedText) = apply { + text = quotedText.text + type = quotedText.type + additionalProperties = quotedText.additionalProperties.toMutableMap() + } + + /** Quoted text content. */ + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + /** + * 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("quoted_text") + * ``` + * + * 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 [QuotedText]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .text() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): QuotedText = + QuotedText( + checkRequired("text", text), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): QuotedText = apply { + if (validated) { + return@apply + } + + text() + _type().let { + if (it != JsonValue.from("quoted_text")) { + 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 (text.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("quoted_text")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is QuotedText && + text == other.text && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(text, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "QuotedText{text=$text, type=$type, additionalProperties=$additionalProperties}" + } + } + + /** Inference overrides applied to the message. Defaults to null when unset. */ + class InferenceOptions + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val model: JsonField, + private val toolChoice: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of(), + @JsonProperty("tool_choice") + @ExcludeMissing + toolChoice: JsonField = JsonMissing.of(), + ) : this(model, toolChoice, mutableMapOf()) + + /** + * Model name that generated the response. Defaults to null when using the session default. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun model(): Optional = model.getOptional("model") + + /** + * Preferred tool to invoke. Defaults to null when ChatKit should auto-select. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun toolChoice(): Optional = toolChoice.getOptional("tool_choice") + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * Returns the raw JSON value of [toolChoice]. + * + * Unlike [toolChoice], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tool_choice") + @ExcludeMissing + fun _toolChoice(): JsonField = toolChoice + + @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 [InferenceOptions]. + * + * The following fields are required: + * ```java + * .model() + * .toolChoice() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InferenceOptions]. */ + class Builder internal constructor() { + + private var model: JsonField? = null + private var toolChoice: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inferenceOptions: InferenceOptions) = apply { + model = inferenceOptions.model + toolChoice = inferenceOptions.toolChoice + additionalProperties = inferenceOptions.additionalProperties.toMutableMap() + } + + /** + * Model name that generated the response. Defaults to null when using the session + * default. + */ + fun model(model: String?) = model(JsonField.ofNullable(model)) + + /** Alias for calling [Builder.model] with `model.orElse(null)`. */ + fun model(model: Optional) = model(model.getOrNull()) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** Preferred tool to invoke. Defaults to null when ChatKit should auto-select. */ + fun toolChoice(toolChoice: ToolChoice?) = toolChoice(JsonField.ofNullable(toolChoice)) + + /** Alias for calling [Builder.toolChoice] with `toolChoice.orElse(null)`. */ + fun toolChoice(toolChoice: Optional) = toolChoice(toolChoice.getOrNull()) + + /** + * Sets [Builder.toolChoice] to an arbitrary JSON value. + * + * You should usually call [Builder.toolChoice] with a well-typed [ToolChoice] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun toolChoice(toolChoice: JsonField) = apply { + this.toolChoice = toolChoice + } + + 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 [InferenceOptions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .model() + * .toolChoice() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InferenceOptions = + InferenceOptions( + checkRequired("model", model), + checkRequired("toolChoice", toolChoice), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): InferenceOptions = apply { + if (validated) { + return@apply + } + + model() + toolChoice().ifPresent { 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 = + (if (model.asKnown().isPresent) 1 else 0) + + (toolChoice.asKnown().getOrNull()?.validity() ?: 0) + + /** Preferred tool to invoke. Defaults to null when ChatKit should auto-select. */ + class ToolChoice + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val id: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of() + ) : this(id, mutableMapOf()) + + /** + * Identifier of the requested tool. + * + * @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") + + /** + * 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 + + @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 [ToolChoice]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ToolChoice]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(toolChoice: ToolChoice) = apply { + id = toolChoice.id + additionalProperties = toolChoice.additionalProperties.toMutableMap() + } + + /** Identifier of the requested tool. */ + 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 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 [ToolChoice]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ToolChoice = + ToolChoice(checkRequired("id", id), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): ToolChoice = apply { + if (validated) { + return@apply + } + + id() + 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) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ToolChoice && + id == other.id && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ToolChoice{id=$id, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InferenceOptions && + model == other.model && + toolChoice == other.toolChoice && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(model, toolChoice, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InferenceOptions{model=$model, toolChoice=$toolChoice, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatKitThreadUserMessageItem && + id == other.id && + attachments == other.attachments && + content == other.content && + createdAt == other.createdAt && + inferenceOptions == other.inferenceOptions && + object_ == other.object_ && + threadId == other.threadId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + attachments, + content, + createdAt, + inferenceOptions, + object_, + threadId, + type, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatKitThreadUserMessageItem{id=$id, attachments=$attachments, content=$content, createdAt=$createdAt, inferenceOptions=$inferenceOptions, object_=$object_, threadId=$threadId, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitWidgetItem.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitWidgetItem.kt new file mode 100644 index 00000000..4c5fff24 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatKitWidgetItem.kt @@ -0,0 +1,364 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 + +/** Thread item that renders a widget payload. */ +class ChatKitWidgetItem +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val object_: JsonValue, + private val threadId: JsonField, + private val type: JsonValue, + private val widget: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("thread_id") @ExcludeMissing threadId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("widget") @ExcludeMissing widget: JsonField = JsonMissing.of(), + ) : this(id, createdAt, object_, threadId, type, widget, mutableMapOf()) + + /** + * Identifier of the thread item. + * + * @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 (in seconds) for when the item 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") + + /** + * Type discriminator that is always `chatkit.thread_item`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.thread_item") + * ``` + * + * 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 parent thread. + * + * @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 threadId(): String = threadId.getRequired("thread_id") + + /** + * Type discriminator that is always `chatkit.widget`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.widget") + * ``` + * + * 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 + + /** + * Serialized widget payload rendered in the UI. + * + * @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 widget(): String = widget.getRequired("widget") + + /** + * 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 [threadId]. + * + * Unlike [threadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("thread_id") @ExcludeMissing fun _threadId(): JsonField = threadId + + /** + * Returns the raw JSON value of [widget]. + * + * Unlike [widget], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("widget") @ExcludeMissing fun _widget(): JsonField = widget + + @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 [ChatKitWidgetItem]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .threadId() + * .widget() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatKitWidgetItem]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var object_: JsonValue = JsonValue.from("chatkit.thread_item") + private var threadId: JsonField? = null + private var type: JsonValue = JsonValue.from("chatkit.widget") + private var widget: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatkitWidgetItem: ChatKitWidgetItem) = apply { + id = chatkitWidgetItem.id + createdAt = chatkitWidgetItem.createdAt + object_ = chatkitWidgetItem.object_ + threadId = chatkitWidgetItem.threadId + type = chatkitWidgetItem.type + widget = chatkitWidgetItem.widget + additionalProperties = chatkitWidgetItem.additionalProperties.toMutableMap() + } + + /** Identifier of the thread item. */ + 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 (in seconds) for when the item 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 } + + /** + * 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("chatkit.thread_item") + * ``` + * + * 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 parent thread. */ + fun threadId(threadId: String) = threadId(JsonField.of(threadId)) + + /** + * Sets [Builder.threadId] to an arbitrary JSON value. + * + * You should usually call [Builder.threadId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun threadId(threadId: JsonField) = apply { this.threadId = threadId } + + /** + * 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("chatkit.widget") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Serialized widget payload rendered in the UI. */ + fun widget(widget: String) = widget(JsonField.of(widget)) + + /** + * Sets [Builder.widget] to an arbitrary JSON value. + * + * You should usually call [Builder.widget] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun widget(widget: JsonField) = apply { this.widget = widget } + + 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 [ChatKitWidgetItem]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .threadId() + * .widget() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatKitWidgetItem = + ChatKitWidgetItem( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + object_, + checkRequired("threadId", threadId), + type, + checkRequired("widget", widget), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatKitWidgetItem = apply { + if (validated) { + return@apply + } + + id() + createdAt() + _object_().let { + if (it != JsonValue.from("chatkit.thread_item")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + threadId() + _type().let { + if (it != JsonValue.from("chatkit.widget")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + widget() + 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) + + object_.let { if (it == JsonValue.from("chatkit.thread_item")) 1 else 0 } + + (if (threadId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("chatkit.widget")) 1 else 0 } + + (if (widget.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatKitWidgetItem && + id == other.id && + createdAt == other.createdAt && + object_ == other.object_ && + threadId == other.threadId && + type == other.type && + widget == other.widget && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, object_, threadId, type, widget, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatKitWidgetItem{id=$id, createdAt=$createdAt, object_=$object_, threadId=$threadId, type=$type, widget=$widget, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSession.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSession.kt new file mode 100644 index 00000000..5617c325 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSession.kt @@ -0,0 +1,572 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 com.openai.models.beta.chatkit.ChatKitWorkflow +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** Represents a ChatKit session and its resolved configuration. */ +class ChatSession +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val chatkitConfiguration: JsonField, + private val clientSecret: JsonField, + private val expiresAt: JsonField, + private val maxRequestsPer1Minute: JsonField, + private val object_: JsonValue, + private val rateLimits: JsonField, + private val status: JsonField, + private val user: JsonField, + private val workflow: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("chatkit_configuration") + @ExcludeMissing + chatkitConfiguration: JsonField = JsonMissing.of(), + @JsonProperty("client_secret") + @ExcludeMissing + clientSecret: JsonField = JsonMissing.of(), + @JsonProperty("expires_at") @ExcludeMissing expiresAt: JsonField = JsonMissing.of(), + @JsonProperty("max_requests_per_1_minute") + @ExcludeMissing + maxRequestsPer1Minute: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("rate_limits") + @ExcludeMissing + rateLimits: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + status: JsonField = JsonMissing.of(), + @JsonProperty("user") @ExcludeMissing user: JsonField = JsonMissing.of(), + @JsonProperty("workflow") + @ExcludeMissing + workflow: JsonField = JsonMissing.of(), + ) : this( + id, + chatkitConfiguration, + clientSecret, + expiresAt, + maxRequestsPer1Minute, + object_, + rateLimits, + status, + user, + workflow, + mutableMapOf(), + ) + + /** + * Identifier for the ChatKit session. + * + * @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") + + /** + * Resolved ChatKit feature configuration for the session. + * + * @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 chatkitConfiguration(): ChatSessionChatKitConfiguration = + chatkitConfiguration.getRequired("chatkit_configuration") + + /** + * Ephemeral client secret that authenticates session requests. + * + * @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 clientSecret(): String = clientSecret.getRequired("client_secret") + + /** + * Unix timestamp (in seconds) for when the session expires. + * + * @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 expiresAt(): Long = expiresAt.getRequired("expires_at") + + /** + * Convenience copy of the per-minute request limit. + * + * @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 maxRequestsPer1Minute(): Long = + maxRequestsPer1Minute.getRequired("max_requests_per_1_minute") + + /** + * Type discriminator that is always `chatkit.session`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.session") + * ``` + * + * 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_ + + /** + * Resolved rate limit values. + * + * @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 rateLimits(): ChatSessionRateLimits = rateLimits.getRequired("rate_limits") + + /** + * Current lifecycle state of the session. + * + * @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 status(): ChatSessionStatus = status.getRequired("status") + + /** + * User identifier associated with the session. + * + * @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 user(): String = user.getRequired("user") + + /** + * Workflow metadata for the session. + * + * @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 workflow(): ChatKitWorkflow = workflow.getRequired("workflow") + + /** + * 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 [chatkitConfiguration]. + * + * Unlike [chatkitConfiguration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("chatkit_configuration") + @ExcludeMissing + fun _chatkitConfiguration(): JsonField = chatkitConfiguration + + /** + * Returns the raw JSON value of [clientSecret]. + * + * Unlike [clientSecret], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("client_secret") + @ExcludeMissing + fun _clientSecret(): JsonField = clientSecret + + /** + * Returns the raw JSON value of [expiresAt]. + * + * Unlike [expiresAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("expires_at") @ExcludeMissing fun _expiresAt(): JsonField = expiresAt + + /** + * Returns the raw JSON value of [maxRequestsPer1Minute]. + * + * Unlike [maxRequestsPer1Minute], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("max_requests_per_1_minute") + @ExcludeMissing + fun _maxRequestsPer1Minute(): JsonField = maxRequestsPer1Minute + + /** + * Returns the raw JSON value of [rateLimits]. + * + * Unlike [rateLimits], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rate_limits") + @ExcludeMissing + fun _rateLimits(): JsonField = rateLimits + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [user]. + * + * Unlike [user], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user") @ExcludeMissing fun _user(): JsonField = user + + /** + * Returns the raw JSON value of [workflow]. + * + * Unlike [workflow], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workflow") @ExcludeMissing fun _workflow(): JsonField = workflow + + @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 [ChatSession]. + * + * The following fields are required: + * ```java + * .id() + * .chatkitConfiguration() + * .clientSecret() + * .expiresAt() + * .maxRequestsPer1Minute() + * .rateLimits() + * .status() + * .user() + * .workflow() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatSession]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var chatkitConfiguration: JsonField? = null + private var clientSecret: JsonField? = null + private var expiresAt: JsonField? = null + private var maxRequestsPer1Minute: JsonField? = null + private var object_: JsonValue = JsonValue.from("chatkit.session") + private var rateLimits: JsonField? = null + private var status: JsonField? = null + private var user: JsonField? = null + private var workflow: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatSession: ChatSession) = apply { + id = chatSession.id + chatkitConfiguration = chatSession.chatkitConfiguration + clientSecret = chatSession.clientSecret + expiresAt = chatSession.expiresAt + maxRequestsPer1Minute = chatSession.maxRequestsPer1Minute + object_ = chatSession.object_ + rateLimits = chatSession.rateLimits + status = chatSession.status + user = chatSession.user + workflow = chatSession.workflow + additionalProperties = chatSession.additionalProperties.toMutableMap() + } + + /** Identifier for the ChatKit session. */ + 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 } + + /** Resolved ChatKit feature configuration for the session. */ + fun chatkitConfiguration(chatkitConfiguration: ChatSessionChatKitConfiguration) = + chatkitConfiguration(JsonField.of(chatkitConfiguration)) + + /** + * Sets [Builder.chatkitConfiguration] to an arbitrary JSON value. + * + * You should usually call [Builder.chatkitConfiguration] with a well-typed + * [ChatSessionChatKitConfiguration] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun chatkitConfiguration(chatkitConfiguration: JsonField) = + apply { + this.chatkitConfiguration = chatkitConfiguration + } + + /** Ephemeral client secret that authenticates session requests. */ + fun clientSecret(clientSecret: String) = clientSecret(JsonField.of(clientSecret)) + + /** + * Sets [Builder.clientSecret] to an arbitrary JSON value. + * + * You should usually call [Builder.clientSecret] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun clientSecret(clientSecret: JsonField) = apply { + this.clientSecret = clientSecret + } + + /** Unix timestamp (in seconds) for when the session expires. */ + fun expiresAt(expiresAt: Long) = expiresAt(JsonField.of(expiresAt)) + + /** + * Sets [Builder.expiresAt] to an arbitrary JSON value. + * + * You should usually call [Builder.expiresAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun expiresAt(expiresAt: JsonField) = apply { this.expiresAt = expiresAt } + + /** Convenience copy of the per-minute request limit. */ + fun maxRequestsPer1Minute(maxRequestsPer1Minute: Long) = + maxRequestsPer1Minute(JsonField.of(maxRequestsPer1Minute)) + + /** + * Sets [Builder.maxRequestsPer1Minute] to an arbitrary JSON value. + * + * You should usually call [Builder.maxRequestsPer1Minute] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxRequestsPer1Minute(maxRequestsPer1Minute: JsonField) = apply { + this.maxRequestsPer1Minute = maxRequestsPer1Minute + } + + /** + * 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("chatkit.session") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** Resolved rate limit values. */ + fun rateLimits(rateLimits: ChatSessionRateLimits) = rateLimits(JsonField.of(rateLimits)) + + /** + * Sets [Builder.rateLimits] to an arbitrary JSON value. + * + * You should usually call [Builder.rateLimits] with a well-typed [ChatSessionRateLimits] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun rateLimits(rateLimits: JsonField) = apply { + this.rateLimits = rateLimits + } + + /** Current lifecycle state of the session. */ + fun status(status: ChatSessionStatus) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [ChatSessionStatus] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** User identifier associated with the session. */ + fun user(user: String) = user(JsonField.of(user)) + + /** + * Sets [Builder.user] to an arbitrary JSON value. + * + * You should usually call [Builder.user] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun user(user: JsonField) = apply { this.user = user } + + /** Workflow metadata for the session. */ + fun workflow(workflow: ChatKitWorkflow) = workflow(JsonField.of(workflow)) + + /** + * Sets [Builder.workflow] to an arbitrary JSON value. + * + * You should usually call [Builder.workflow] with a well-typed [ChatKitWorkflow] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun workflow(workflow: JsonField) = apply { this.workflow = workflow } + + 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 [ChatSession]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .chatkitConfiguration() + * .clientSecret() + * .expiresAt() + * .maxRequestsPer1Minute() + * .rateLimits() + * .status() + * .user() + * .workflow() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatSession = + ChatSession( + checkRequired("id", id), + checkRequired("chatkitConfiguration", chatkitConfiguration), + checkRequired("clientSecret", clientSecret), + checkRequired("expiresAt", expiresAt), + checkRequired("maxRequestsPer1Minute", maxRequestsPer1Minute), + object_, + checkRequired("rateLimits", rateLimits), + checkRequired("status", status), + checkRequired("user", user), + checkRequired("workflow", workflow), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatSession = apply { + if (validated) { + return@apply + } + + id() + chatkitConfiguration().validate() + clientSecret() + expiresAt() + maxRequestsPer1Minute() + _object_().let { + if (it != JsonValue.from("chatkit.session")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + rateLimits().validate() + status().validate() + user() + workflow().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 = + (if (id.asKnown().isPresent) 1 else 0) + + (chatkitConfiguration.asKnown().getOrNull()?.validity() ?: 0) + + (if (clientSecret.asKnown().isPresent) 1 else 0) + + (if (expiresAt.asKnown().isPresent) 1 else 0) + + (if (maxRequestsPer1Minute.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("chatkit.session")) 1 else 0 } + + (rateLimits.asKnown().getOrNull()?.validity() ?: 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (user.asKnown().isPresent) 1 else 0) + + (workflow.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatSession && + id == other.id && + chatkitConfiguration == other.chatkitConfiguration && + clientSecret == other.clientSecret && + expiresAt == other.expiresAt && + maxRequestsPer1Minute == other.maxRequestsPer1Minute && + object_ == other.object_ && + rateLimits == other.rateLimits && + status == other.status && + user == other.user && + workflow == other.workflow && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + chatkitConfiguration, + clientSecret, + expiresAt, + maxRequestsPer1Minute, + object_, + rateLimits, + status, + user, + workflow, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatSession{id=$id, chatkitConfiguration=$chatkitConfiguration, clientSecret=$clientSecret, expiresAt=$expiresAt, maxRequestsPer1Minute=$maxRequestsPer1Minute, object_=$object_, rateLimits=$rateLimits, status=$status, user=$user, workflow=$workflow, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionAutomaticThreadTitling.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionAutomaticThreadTitling.kt new file mode 100644 index 00000000..f738d438 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionAutomaticThreadTitling.kt @@ -0,0 +1,177 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 + +/** Automatic thread title preferences for the session. */ +class ChatSessionAutomaticThreadTitling +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Whether automatic thread titling is enabled. + * + * @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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 + * [ChatSessionAutomaticThreadTitling]. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatSessionAutomaticThreadTitling]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatSessionAutomaticThreadTitling: ChatSessionAutomaticThreadTitling) = + apply { + enabled = chatSessionAutomaticThreadTitling.enabled + additionalProperties = + chatSessionAutomaticThreadTitling.additionalProperties.toMutableMap() + } + + /** Whether automatic thread titling is enabled. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [ChatSessionAutomaticThreadTitling]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatSessionAutomaticThreadTitling = + ChatSessionAutomaticThreadTitling( + checkRequired("enabled", enabled), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatSessionAutomaticThreadTitling = apply { + if (validated) { + return@apply + } + + enabled() + 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 (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatSessionAutomaticThreadTitling && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatSessionAutomaticThreadTitling{enabled=$enabled, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionChatKitConfiguration.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionChatKitConfiguration.kt new file mode 100644 index 00000000..c3237097 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionChatKitConfiguration.kt @@ -0,0 +1,275 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 + +/** ChatKit configuration for the session. */ +class ChatSessionChatKitConfiguration +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val automaticThreadTitling: JsonField, + private val fileUpload: JsonField, + private val history: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("automatic_thread_titling") + @ExcludeMissing + automaticThreadTitling: JsonField = JsonMissing.of(), + @JsonProperty("file_upload") + @ExcludeMissing + fileUpload: JsonField = JsonMissing.of(), + @JsonProperty("history") + @ExcludeMissing + history: JsonField = JsonMissing.of(), + ) : this(automaticThreadTitling, fileUpload, history, mutableMapOf()) + + /** + * Automatic thread titling preferences. + * + * @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 automaticThreadTitling(): ChatSessionAutomaticThreadTitling = + automaticThreadTitling.getRequired("automatic_thread_titling") + + /** + * Upload settings for the session. + * + * @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 fileUpload(): ChatSessionFileUpload = fileUpload.getRequired("file_upload") + + /** + * History retention configuration. + * + * @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 history(): ChatSessionHistory = history.getRequired("history") + + /** + * Returns the raw JSON value of [automaticThreadTitling]. + * + * Unlike [automaticThreadTitling], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("automatic_thread_titling") + @ExcludeMissing + fun _automaticThreadTitling(): JsonField = + automaticThreadTitling + + /** + * Returns the raw JSON value of [fileUpload]. + * + * Unlike [fileUpload], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_upload") + @ExcludeMissing + fun _fileUpload(): JsonField = fileUpload + + /** + * Returns the raw JSON value of [history]. + * + * Unlike [history], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("history") @ExcludeMissing fun _history(): JsonField = history + + @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 + * [ChatSessionChatKitConfiguration]. + * + * The following fields are required: + * ```java + * .automaticThreadTitling() + * .fileUpload() + * .history() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatSessionChatKitConfiguration]. */ + class Builder internal constructor() { + + private var automaticThreadTitling: JsonField? = null + private var fileUpload: JsonField? = null + private var history: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatSessionChatKitConfiguration: ChatSessionChatKitConfiguration) = + apply { + automaticThreadTitling = chatSessionChatKitConfiguration.automaticThreadTitling + fileUpload = chatSessionChatKitConfiguration.fileUpload + history = chatSessionChatKitConfiguration.history + additionalProperties = + chatSessionChatKitConfiguration.additionalProperties.toMutableMap() + } + + /** Automatic thread titling preferences. */ + fun automaticThreadTitling(automaticThreadTitling: ChatSessionAutomaticThreadTitling) = + automaticThreadTitling(JsonField.of(automaticThreadTitling)) + + /** + * Sets [Builder.automaticThreadTitling] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticThreadTitling] with a well-typed + * [ChatSessionAutomaticThreadTitling] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun automaticThreadTitling( + automaticThreadTitling: JsonField + ) = apply { this.automaticThreadTitling = automaticThreadTitling } + + /** Upload settings for the session. */ + fun fileUpload(fileUpload: ChatSessionFileUpload) = fileUpload(JsonField.of(fileUpload)) + + /** + * Sets [Builder.fileUpload] to an arbitrary JSON value. + * + * You should usually call [Builder.fileUpload] with a well-typed [ChatSessionFileUpload] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun fileUpload(fileUpload: JsonField) = apply { + this.fileUpload = fileUpload + } + + /** History retention configuration. */ + fun history(history: ChatSessionHistory) = history(JsonField.of(history)) + + /** + * Sets [Builder.history] to an arbitrary JSON value. + * + * You should usually call [Builder.history] with a well-typed [ChatSessionHistory] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun history(history: JsonField) = apply { this.history = history } + + 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 [ChatSessionChatKitConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .automaticThreadTitling() + * .fileUpload() + * .history() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatSessionChatKitConfiguration = + ChatSessionChatKitConfiguration( + checkRequired("automaticThreadTitling", automaticThreadTitling), + checkRequired("fileUpload", fileUpload), + checkRequired("history", history), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatSessionChatKitConfiguration = apply { + if (validated) { + return@apply + } + + automaticThreadTitling().validate() + fileUpload().validate() + history().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 = + (automaticThreadTitling.asKnown().getOrNull()?.validity() ?: 0) + + (fileUpload.asKnown().getOrNull()?.validity() ?: 0) + + (history.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatSessionChatKitConfiguration && + automaticThreadTitling == other.automaticThreadTitling && + fileUpload == other.fileUpload && + history == other.history && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(automaticThreadTitling, fileUpload, history, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatSessionChatKitConfiguration{automaticThreadTitling=$automaticThreadTitling, fileUpload=$fileUpload, history=$history, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionChatKitConfigurationParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionChatKitConfigurationParam.kt new file mode 100644 index 00000000..d0106f3d --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionChatKitConfigurationParam.kt @@ -0,0 +1,835 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Optional per-session configuration settings for ChatKit behavior. */ +class ChatSessionChatKitConfigurationParam +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val automaticThreadTitling: JsonField, + private val fileUpload: JsonField, + private val history: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("automatic_thread_titling") + @ExcludeMissing + automaticThreadTitling: JsonField = JsonMissing.of(), + @JsonProperty("file_upload") + @ExcludeMissing + fileUpload: JsonField = JsonMissing.of(), + @JsonProperty("history") @ExcludeMissing history: JsonField = JsonMissing.of(), + ) : this(automaticThreadTitling, fileUpload, history, mutableMapOf()) + + /** + * Configuration for automatic thread titling. When omitted, automatic thread titling is enabled + * by default. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun automaticThreadTitling(): Optional = + automaticThreadTitling.getOptional("automatic_thread_titling") + + /** + * Configuration for upload enablement and limits. When omitted, uploads are disabled by default + * (max_files 10, max_file_size 512 MB). + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fileUpload(): Optional = fileUpload.getOptional("file_upload") + + /** + * Configuration for chat history retention. When omitted, history is enabled by default with no + * limit on recent_threads (null). + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun history(): Optional = history.getOptional("history") + + /** + * Returns the raw JSON value of [automaticThreadTitling]. + * + * Unlike [automaticThreadTitling], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("automatic_thread_titling") + @ExcludeMissing + fun _automaticThreadTitling(): JsonField = automaticThreadTitling + + /** + * Returns the raw JSON value of [fileUpload]. + * + * Unlike [fileUpload], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_upload") + @ExcludeMissing + fun _fileUpload(): JsonField = fileUpload + + /** + * Returns the raw JSON value of [history]. + * + * Unlike [history], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("history") @ExcludeMissing fun _history(): JsonField = history + + @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 + * [ChatSessionChatKitConfigurationParam]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatSessionChatKitConfigurationParam]. */ + class Builder internal constructor() { + + private var automaticThreadTitling: JsonField = JsonMissing.of() + private var fileUpload: JsonField = JsonMissing.of() + private var history: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + chatSessionChatKitConfigurationParam: ChatSessionChatKitConfigurationParam + ) = apply { + automaticThreadTitling = chatSessionChatKitConfigurationParam.automaticThreadTitling + fileUpload = chatSessionChatKitConfigurationParam.fileUpload + history = chatSessionChatKitConfigurationParam.history + additionalProperties = + chatSessionChatKitConfigurationParam.additionalProperties.toMutableMap() + } + + /** + * Configuration for automatic thread titling. When omitted, automatic thread titling is + * enabled by default. + */ + fun automaticThreadTitling(automaticThreadTitling: AutomaticThreadTitling) = + automaticThreadTitling(JsonField.of(automaticThreadTitling)) + + /** + * Sets [Builder.automaticThreadTitling] to an arbitrary JSON value. + * + * You should usually call [Builder.automaticThreadTitling] with a well-typed + * [AutomaticThreadTitling] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun automaticThreadTitling(automaticThreadTitling: JsonField) = + apply { + this.automaticThreadTitling = automaticThreadTitling + } + + /** + * Configuration for upload enablement and limits. When omitted, uploads are disabled by + * default (max_files 10, max_file_size 512 MB). + */ + fun fileUpload(fileUpload: FileUpload) = fileUpload(JsonField.of(fileUpload)) + + /** + * Sets [Builder.fileUpload] to an arbitrary JSON value. + * + * You should usually call [Builder.fileUpload] with a well-typed [FileUpload] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileUpload(fileUpload: JsonField) = apply { this.fileUpload = fileUpload } + + /** + * Configuration for chat history retention. When omitted, history is enabled by default + * with no limit on recent_threads (null). + */ + fun history(history: History) = history(JsonField.of(history)) + + /** + * Sets [Builder.history] to an arbitrary JSON value. + * + * You should usually call [Builder.history] with a well-typed [History] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun history(history: JsonField) = apply { this.history = history } + + 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 [ChatSessionChatKitConfigurationParam]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ChatSessionChatKitConfigurationParam = + ChatSessionChatKitConfigurationParam( + automaticThreadTitling, + fileUpload, + history, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatSessionChatKitConfigurationParam = apply { + if (validated) { + return@apply + } + + automaticThreadTitling().ifPresent { it.validate() } + fileUpload().ifPresent { it.validate() } + history().ifPresent { 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 = + (automaticThreadTitling.asKnown().getOrNull()?.validity() ?: 0) + + (fileUpload.asKnown().getOrNull()?.validity() ?: 0) + + (history.asKnown().getOrNull()?.validity() ?: 0) + + /** + * Configuration for automatic thread titling. When omitted, automatic thread titling is enabled + * by default. + */ + class AutomaticThreadTitling + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Enable automatic thread title generation. Defaults to true. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun enabled(): Optional = enabled.getOptional("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [AutomaticThreadTitling]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AutomaticThreadTitling]. */ + class Builder internal constructor() { + + private var enabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(automaticThreadTitling: AutomaticThreadTitling) = apply { + enabled = automaticThreadTitling.enabled + additionalProperties = automaticThreadTitling.additionalProperties.toMutableMap() + } + + /** Enable automatic thread title generation. Defaults to true. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [AutomaticThreadTitling]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): AutomaticThreadTitling = + AutomaticThreadTitling(enabled, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): AutomaticThreadTitling = apply { + if (validated) { + return@apply + } + + enabled() + 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 (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AutomaticThreadTitling && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AutomaticThreadTitling{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + /** + * Configuration for upload enablement and limits. When omitted, uploads are disabled by default + * (max_files 10, max_file_size 512 MB). + */ + class FileUpload + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val maxFileSize: JsonField, + private val maxFiles: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of(), + @JsonProperty("max_file_size") + @ExcludeMissing + maxFileSize: JsonField = JsonMissing.of(), + @JsonProperty("max_files") @ExcludeMissing maxFiles: JsonField = JsonMissing.of(), + ) : this(enabled, maxFileSize, maxFiles, mutableMapOf()) + + /** + * Enable uploads for this session. Defaults to false. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun enabled(): Optional = enabled.getOptional("enabled") + + /** + * Maximum size in megabytes for each uploaded file. Defaults to 512 MB, which is the + * maximum allowable size. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun maxFileSize(): Optional = maxFileSize.getOptional("max_file_size") + + /** + * Maximum number of files that can be uploaded to the session. Defaults to 10. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun maxFiles(): Optional = maxFiles.getOptional("max_files") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + /** + * Returns the raw JSON value of [maxFileSize]. + * + * Unlike [maxFileSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("max_file_size") + @ExcludeMissing + fun _maxFileSize(): JsonField = maxFileSize + + /** + * Returns the raw JSON value of [maxFiles]. + * + * Unlike [maxFiles], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("max_files") @ExcludeMissing fun _maxFiles(): JsonField = maxFiles + + @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 [FileUpload]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [FileUpload]. */ + class Builder internal constructor() { + + private var enabled: JsonField = JsonMissing.of() + private var maxFileSize: JsonField = JsonMissing.of() + private var maxFiles: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileUpload: FileUpload) = apply { + enabled = fileUpload.enabled + maxFileSize = fileUpload.maxFileSize + maxFiles = fileUpload.maxFiles + additionalProperties = fileUpload.additionalProperties.toMutableMap() + } + + /** Enable uploads for this session. Defaults to false. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + /** + * Maximum size in megabytes for each uploaded file. Defaults to 512 MB, which is the + * maximum allowable size. + */ + fun maxFileSize(maxFileSize: Long) = maxFileSize(JsonField.of(maxFileSize)) + + /** + * Sets [Builder.maxFileSize] to an arbitrary JSON value. + * + * You should usually call [Builder.maxFileSize] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxFileSize(maxFileSize: JsonField) = apply { this.maxFileSize = maxFileSize } + + /** Maximum number of files that can be uploaded to the session. Defaults to 10. */ + fun maxFiles(maxFiles: Long) = maxFiles(JsonField.of(maxFiles)) + + /** + * Sets [Builder.maxFiles] to an arbitrary JSON value. + * + * You should usually call [Builder.maxFiles] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxFiles(maxFiles: JsonField) = apply { this.maxFiles = maxFiles } + + 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 [FileUpload]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): FileUpload = + FileUpload(enabled, maxFileSize, maxFiles, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): FileUpload = apply { + if (validated) { + return@apply + } + + enabled() + maxFileSize() + maxFiles() + 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 (enabled.asKnown().isPresent) 1 else 0) + + (if (maxFileSize.asKnown().isPresent) 1 else 0) + + (if (maxFiles.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is FileUpload && + enabled == other.enabled && + maxFileSize == other.maxFileSize && + maxFiles == other.maxFiles && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(enabled, maxFileSize, maxFiles, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileUpload{enabled=$enabled, maxFileSize=$maxFileSize, maxFiles=$maxFiles, additionalProperties=$additionalProperties}" + } + + /** + * Configuration for chat history retention. When omitted, history is enabled by default with no + * limit on recent_threads (null). + */ + class History + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val recentThreads: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of(), + @JsonProperty("recent_threads") + @ExcludeMissing + recentThreads: JsonField = JsonMissing.of(), + ) : this(enabled, recentThreads, mutableMapOf()) + + /** + * Enables chat users to access previous ChatKit threads. Defaults to true. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun enabled(): Optional = enabled.getOptional("enabled") + + /** + * Number of recent ChatKit threads users have access to. Defaults to unlimited when unset. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun recentThreads(): Optional = recentThreads.getOptional("recent_threads") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + /** + * Returns the raw JSON value of [recentThreads]. + * + * Unlike [recentThreads], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("recent_threads") + @ExcludeMissing + fun _recentThreads(): JsonField = recentThreads + + @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 [History]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [History]. */ + class Builder internal constructor() { + + private var enabled: JsonField = JsonMissing.of() + private var recentThreads: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(history: History) = apply { + enabled = history.enabled + recentThreads = history.recentThreads + additionalProperties = history.additionalProperties.toMutableMap() + } + + /** Enables chat users to access previous ChatKit threads. Defaults to true. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + /** + * Number of recent ChatKit threads users have access to. Defaults to unlimited when + * unset. + */ + fun recentThreads(recentThreads: Long) = recentThreads(JsonField.of(recentThreads)) + + /** + * Sets [Builder.recentThreads] to an arbitrary JSON value. + * + * You should usually call [Builder.recentThreads] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun recentThreads(recentThreads: JsonField) = apply { + this.recentThreads = recentThreads + } + + 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 [History]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): History = + History(enabled, recentThreads, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): History = apply { + if (validated) { + return@apply + } + + enabled() + recentThreads() + 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 (enabled.asKnown().isPresent) 1 else 0) + + (if (recentThreads.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is History && + enabled == other.enabled && + recentThreads == other.recentThreads && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(enabled, recentThreads, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "History{enabled=$enabled, recentThreads=$recentThreads, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatSessionChatKitConfigurationParam && + automaticThreadTitling == other.automaticThreadTitling && + fileUpload == other.fileUpload && + history == other.history && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(automaticThreadTitling, fileUpload, history, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatSessionChatKitConfigurationParam{automaticThreadTitling=$automaticThreadTitling, fileUpload=$fileUpload, history=$history, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionExpiresAfterParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionExpiresAfterParam.kt new file mode 100644 index 00000000..38206ebb --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionExpiresAfterParam.kt @@ -0,0 +1,215 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 + +/** Controls when the session expires relative to an anchor timestamp. */ +class ChatSessionExpiresAfterParam +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val anchor: JsonValue, + private val seconds: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("anchor") @ExcludeMissing anchor: JsonValue = JsonMissing.of(), + @JsonProperty("seconds") @ExcludeMissing seconds: JsonField = JsonMissing.of(), + ) : this(anchor, seconds, mutableMapOf()) + + /** + * Base timestamp used to calculate expiration. Currently fixed to `created_at`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("created_at") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("anchor") @ExcludeMissing fun _anchor(): JsonValue = anchor + + /** + * Number of seconds after the anchor when the session expires. + * + * @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 seconds(): Long = seconds.getRequired("seconds") + + /** + * Returns the raw JSON value of [seconds]. + * + * Unlike [seconds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("seconds") @ExcludeMissing fun _seconds(): JsonField = seconds + + @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 [ChatSessionExpiresAfterParam]. + * + * The following fields are required: + * ```java + * .seconds() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatSessionExpiresAfterParam]. */ + class Builder internal constructor() { + + private var anchor: JsonValue = JsonValue.from("created_at") + private var seconds: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatSessionExpiresAfterParam: ChatSessionExpiresAfterParam) = apply { + anchor = chatSessionExpiresAfterParam.anchor + seconds = chatSessionExpiresAfterParam.seconds + additionalProperties = chatSessionExpiresAfterParam.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("created_at") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun anchor(anchor: JsonValue) = apply { this.anchor = anchor } + + /** Number of seconds after the anchor when the session expires. */ + fun seconds(seconds: Long) = seconds(JsonField.of(seconds)) + + /** + * Sets [Builder.seconds] to an arbitrary JSON value. + * + * You should usually call [Builder.seconds] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun seconds(seconds: JsonField) = apply { this.seconds = seconds } + + 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 [ChatSessionExpiresAfterParam]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .seconds() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatSessionExpiresAfterParam = + ChatSessionExpiresAfterParam( + anchor, + checkRequired("seconds", seconds), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatSessionExpiresAfterParam = apply { + if (validated) { + return@apply + } + + _anchor().let { + if (it != JsonValue.from("created_at")) { + throw OpenAIInvalidDataException("'anchor' is invalid, received $it") + } + } + seconds() + 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 = + anchor.let { if (it == JsonValue.from("created_at")) 1 else 0 } + + (if (seconds.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatSessionExpiresAfterParam && + anchor == other.anchor && + seconds == other.seconds && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(anchor, seconds, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatSessionExpiresAfterParam{anchor=$anchor, seconds=$seconds, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionFileUpload.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionFileUpload.kt new file mode 100644 index 00000000..4b5996b5 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionFileUpload.kt @@ -0,0 +1,275 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 +import kotlin.jvm.optionals.getOrNull + +/** Upload permissions and limits applied to the session. */ +class ChatSessionFileUpload +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val enabled: JsonField, + private val maxFileSize: JsonField, + private val maxFiles: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of(), + @JsonProperty("max_file_size") + @ExcludeMissing + maxFileSize: JsonField = JsonMissing.of(), + @JsonProperty("max_files") @ExcludeMissing maxFiles: JsonField = JsonMissing.of(), + ) : this(enabled, maxFileSize, maxFiles, mutableMapOf()) + + /** + * Indicates if uploads are enabled for the session. + * + * @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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Maximum upload size in megabytes. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun maxFileSize(): Optional = maxFileSize.getOptional("max_file_size") + + /** + * Maximum number of uploads allowed during the session. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun maxFiles(): Optional = maxFiles.getOptional("max_files") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + /** + * Returns the raw JSON value of [maxFileSize]. + * + * Unlike [maxFileSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("max_file_size") @ExcludeMissing fun _maxFileSize(): JsonField = maxFileSize + + /** + * Returns the raw JSON value of [maxFiles]. + * + * Unlike [maxFiles], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("max_files") @ExcludeMissing fun _maxFiles(): JsonField = maxFiles + + @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 [ChatSessionFileUpload]. + * + * The following fields are required: + * ```java + * .enabled() + * .maxFileSize() + * .maxFiles() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatSessionFileUpload]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var maxFileSize: JsonField? = null + private var maxFiles: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatSessionFileUpload: ChatSessionFileUpload) = apply { + enabled = chatSessionFileUpload.enabled + maxFileSize = chatSessionFileUpload.maxFileSize + maxFiles = chatSessionFileUpload.maxFiles + additionalProperties = chatSessionFileUpload.additionalProperties.toMutableMap() + } + + /** Indicates if uploads are enabled for the session. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + /** Maximum upload size in megabytes. */ + fun maxFileSize(maxFileSize: Long?) = maxFileSize(JsonField.ofNullable(maxFileSize)) + + /** + * Alias for [Builder.maxFileSize]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun maxFileSize(maxFileSize: Long) = maxFileSize(maxFileSize as Long?) + + /** Alias for calling [Builder.maxFileSize] with `maxFileSize.orElse(null)`. */ + fun maxFileSize(maxFileSize: Optional) = maxFileSize(maxFileSize.getOrNull()) + + /** + * Sets [Builder.maxFileSize] to an arbitrary JSON value. + * + * You should usually call [Builder.maxFileSize] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun maxFileSize(maxFileSize: JsonField) = apply { this.maxFileSize = maxFileSize } + + /** Maximum number of uploads allowed during the session. */ + fun maxFiles(maxFiles: Long?) = maxFiles(JsonField.ofNullable(maxFiles)) + + /** + * Alias for [Builder.maxFiles]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun maxFiles(maxFiles: Long) = maxFiles(maxFiles as Long?) + + /** Alias for calling [Builder.maxFiles] with `maxFiles.orElse(null)`. */ + fun maxFiles(maxFiles: Optional) = maxFiles(maxFiles.getOrNull()) + + /** + * Sets [Builder.maxFiles] to an arbitrary JSON value. + * + * You should usually call [Builder.maxFiles] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun maxFiles(maxFiles: JsonField) = apply { this.maxFiles = maxFiles } + + 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 [ChatSessionFileUpload]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * .maxFileSize() + * .maxFiles() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatSessionFileUpload = + ChatSessionFileUpload( + checkRequired("enabled", enabled), + checkRequired("maxFileSize", maxFileSize), + checkRequired("maxFiles", maxFiles), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatSessionFileUpload = apply { + if (validated) { + return@apply + } + + enabled() + maxFileSize() + maxFiles() + 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 (enabled.asKnown().isPresent) 1 else 0) + + (if (maxFileSize.asKnown().isPresent) 1 else 0) + + (if (maxFiles.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatSessionFileUpload && + enabled == other.enabled && + maxFileSize == other.maxFileSize && + maxFiles == other.maxFiles && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(enabled, maxFileSize, maxFiles, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatSessionFileUpload{enabled=$enabled, maxFileSize=$maxFileSize, maxFiles=$maxFiles, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionHistory.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionHistory.kt new file mode 100644 index 00000000..56eae92e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionHistory.kt @@ -0,0 +1,235 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 +import kotlin.jvm.optionals.getOrNull + +/** History retention preferences returned for the session. */ +class ChatSessionHistory +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val enabled: JsonField, + private val recentThreads: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of(), + @JsonProperty("recent_threads") + @ExcludeMissing + recentThreads: JsonField = JsonMissing.of(), + ) : this(enabled, recentThreads, mutableMapOf()) + + /** + * Indicates if chat history is persisted for the session. + * + * @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 enabled(): Boolean = enabled.getRequired("enabled") + + /** + * Number of prior threads surfaced in history views. Defaults to null when all history is + * retained. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun recentThreads(): Optional = recentThreads.getOptional("recent_threads") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + /** + * Returns the raw JSON value of [recentThreads]. + * + * Unlike [recentThreads], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recent_threads") + @ExcludeMissing + fun _recentThreads(): JsonField = recentThreads + + @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 [ChatSessionHistory]. + * + * The following fields are required: + * ```java + * .enabled() + * .recentThreads() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatSessionHistory]. */ + class Builder internal constructor() { + + private var enabled: JsonField? = null + private var recentThreads: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatSessionHistory: ChatSessionHistory) = apply { + enabled = chatSessionHistory.enabled + recentThreads = chatSessionHistory.recentThreads + additionalProperties = chatSessionHistory.additionalProperties.toMutableMap() + } + + /** Indicates if chat history is persisted for the session. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + /** + * Number of prior threads surfaced in history views. Defaults to null when all history is + * retained. + */ + fun recentThreads(recentThreads: Long?) = recentThreads(JsonField.ofNullable(recentThreads)) + + /** + * Alias for [Builder.recentThreads]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun recentThreads(recentThreads: Long) = recentThreads(recentThreads as Long?) + + /** Alias for calling [Builder.recentThreads] with `recentThreads.orElse(null)`. */ + fun recentThreads(recentThreads: Optional) = recentThreads(recentThreads.getOrNull()) + + /** + * Sets [Builder.recentThreads] to an arbitrary JSON value. + * + * You should usually call [Builder.recentThreads] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun recentThreads(recentThreads: JsonField) = apply { + this.recentThreads = recentThreads + } + + 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 [ChatSessionHistory]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .enabled() + * .recentThreads() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatSessionHistory = + ChatSessionHistory( + checkRequired("enabled", enabled), + checkRequired("recentThreads", recentThreads), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatSessionHistory = apply { + if (validated) { + return@apply + } + + enabled() + recentThreads() + 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 (enabled.asKnown().isPresent) 1 else 0) + + (if (recentThreads.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatSessionHistory && + enabled == other.enabled && + recentThreads == other.recentThreads && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, recentThreads, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatSessionHistory{enabled=$enabled, recentThreads=$recentThreads, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionRateLimits.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionRateLimits.kt new file mode 100644 index 00000000..dec64882 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionRateLimits.kt @@ -0,0 +1,185 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 + +/** Active per-minute request limit for the session. */ +class ChatSessionRateLimits +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val maxRequestsPer1Minute: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("max_requests_per_1_minute") + @ExcludeMissing + maxRequestsPer1Minute: JsonField = JsonMissing.of() + ) : this(maxRequestsPer1Minute, mutableMapOf()) + + /** + * Maximum allowed requests per one-minute window. + * + * @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 maxRequestsPer1Minute(): Long = + maxRequestsPer1Minute.getRequired("max_requests_per_1_minute") + + /** + * Returns the raw JSON value of [maxRequestsPer1Minute]. + * + * Unlike [maxRequestsPer1Minute], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("max_requests_per_1_minute") + @ExcludeMissing + fun _maxRequestsPer1Minute(): JsonField = maxRequestsPer1Minute + + @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 [ChatSessionRateLimits]. + * + * The following fields are required: + * ```java + * .maxRequestsPer1Minute() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatSessionRateLimits]. */ + class Builder internal constructor() { + + private var maxRequestsPer1Minute: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatSessionRateLimits: ChatSessionRateLimits) = apply { + maxRequestsPer1Minute = chatSessionRateLimits.maxRequestsPer1Minute + additionalProperties = chatSessionRateLimits.additionalProperties.toMutableMap() + } + + /** Maximum allowed requests per one-minute window. */ + fun maxRequestsPer1Minute(maxRequestsPer1Minute: Long) = + maxRequestsPer1Minute(JsonField.of(maxRequestsPer1Minute)) + + /** + * Sets [Builder.maxRequestsPer1Minute] to an arbitrary JSON value. + * + * You should usually call [Builder.maxRequestsPer1Minute] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxRequestsPer1Minute(maxRequestsPer1Minute: JsonField) = apply { + this.maxRequestsPer1Minute = maxRequestsPer1Minute + } + + 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 [ChatSessionRateLimits]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .maxRequestsPer1Minute() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatSessionRateLimits = + ChatSessionRateLimits( + checkRequired("maxRequestsPer1Minute", maxRequestsPer1Minute), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatSessionRateLimits = apply { + if (validated) { + return@apply + } + + maxRequestsPer1Minute() + 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 (maxRequestsPer1Minute.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatSessionRateLimits && + maxRequestsPer1Minute == other.maxRequestsPer1Minute && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(maxRequestsPer1Minute, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatSessionRateLimits{maxRequestsPer1Minute=$maxRequestsPer1Minute, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionRateLimitsParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionRateLimitsParam.kt new file mode 100644 index 00000000..d399be01 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionRateLimitsParam.kt @@ -0,0 +1,170 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional + +/** Controls request rate limits for the session. */ +class ChatSessionRateLimitsParam +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val maxRequestsPer1Minute: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("max_requests_per_1_minute") + @ExcludeMissing + maxRequestsPer1Minute: JsonField = JsonMissing.of() + ) : this(maxRequestsPer1Minute, mutableMapOf()) + + /** + * Maximum number of requests allowed per minute for the session. Defaults to 10. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun maxRequestsPer1Minute(): Optional = + maxRequestsPer1Minute.getOptional("max_requests_per_1_minute") + + /** + * Returns the raw JSON value of [maxRequestsPer1Minute]. + * + * Unlike [maxRequestsPer1Minute], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("max_requests_per_1_minute") + @ExcludeMissing + fun _maxRequestsPer1Minute(): JsonField = maxRequestsPer1Minute + + @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 [ChatSessionRateLimitsParam]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatSessionRateLimitsParam]. */ + class Builder internal constructor() { + + private var maxRequestsPer1Minute: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatSessionRateLimitsParam: ChatSessionRateLimitsParam) = apply { + maxRequestsPer1Minute = chatSessionRateLimitsParam.maxRequestsPer1Minute + additionalProperties = chatSessionRateLimitsParam.additionalProperties.toMutableMap() + } + + /** Maximum number of requests allowed per minute for the session. Defaults to 10. */ + fun maxRequestsPer1Minute(maxRequestsPer1Minute: Long) = + maxRequestsPer1Minute(JsonField.of(maxRequestsPer1Minute)) + + /** + * Sets [Builder.maxRequestsPer1Minute] to an arbitrary JSON value. + * + * You should usually call [Builder.maxRequestsPer1Minute] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxRequestsPer1Minute(maxRequestsPer1Minute: JsonField) = apply { + this.maxRequestsPer1Minute = maxRequestsPer1Minute + } + + 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 [ChatSessionRateLimitsParam]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ChatSessionRateLimitsParam = + ChatSessionRateLimitsParam(maxRequestsPer1Minute, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): ChatSessionRateLimitsParam = apply { + if (validated) { + return@apply + } + + maxRequestsPer1Minute() + 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 (maxRequestsPer1Minute.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatSessionRateLimitsParam && + maxRequestsPer1Minute == other.maxRequestsPer1Minute && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(maxRequestsPer1Minute, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatSessionRateLimitsParam{maxRequestsPer1Minute=$maxRequestsPer1Minute, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionStatus.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionStatus.kt new file mode 100644 index 00000000..93375201 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionStatus.kt @@ -0,0 +1,140 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.errors.OpenAIInvalidDataException + +class ChatSessionStatus @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 ACTIVE = of("active") + + @JvmField val EXPIRED = of("expired") + + @JvmField val CANCELLED = of("cancelled") + + @JvmStatic fun of(value: String) = ChatSessionStatus(JsonField.of(value)) + } + + /** An enum containing [ChatSessionStatus]'s known values. */ + enum class Known { + ACTIVE, + EXPIRED, + CANCELLED, + } + + /** + * An enum containing [ChatSessionStatus]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ChatSessionStatus] 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 { + ACTIVE, + EXPIRED, + CANCELLED, + /** + * An enum member indicating that [ChatSessionStatus] 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) { + ACTIVE -> Value.ACTIVE + EXPIRED -> Value.EXPIRED + CANCELLED -> Value.CANCELLED + 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) { + ACTIVE -> Known.ACTIVE + EXPIRED -> Known.EXPIRED + CANCELLED -> Known.CANCELLED + else -> throw OpenAIInvalidDataException("Unknown ChatSessionStatus: $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(): ChatSessionStatus = 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 ChatSessionStatus && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionWorkflowParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionWorkflowParam.kt new file mode 100644 index 00000000..3eb2472b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ChatSessionWorkflowParam.kt @@ -0,0 +1,547 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Workflow reference and overrides applied to the chat session. */ +class ChatSessionWorkflowParam +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val stateVariables: JsonField, + private val tracing: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("state_variables") + @ExcludeMissing + stateVariables: JsonField = JsonMissing.of(), + @JsonProperty("tracing") @ExcludeMissing tracing: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(id, stateVariables, tracing, version, mutableMapOf()) + + /** + * Identifier for the workflow invoked by the session. + * + * @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") + + /** + * State variables forwarded to the workflow. Keys may be up to 64 characters, values must be + * primitive types, and the map defaults to an empty object. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun stateVariables(): Optional = stateVariables.getOptional("state_variables") + + /** + * Optional tracing overrides for the workflow invocation. When omitted, tracing is enabled by + * default. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tracing(): Optional = tracing.getOptional("tracing") + + /** + * Specific workflow version to run. Defaults to the latest deployed version. + * + * @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 [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 [stateVariables]. + * + * Unlike [stateVariables], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("state_variables") + @ExcludeMissing + fun _stateVariables(): JsonField = stateVariables + + /** + * Returns the raw JSON value of [tracing]. + * + * Unlike [tracing], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tracing") @ExcludeMissing fun _tracing(): JsonField = tracing + + /** + * 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 [ChatSessionWorkflowParam]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatSessionWorkflowParam]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var stateVariables: JsonField = JsonMissing.of() + private var tracing: JsonField = JsonMissing.of() + private var version: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatSessionWorkflowParam: ChatSessionWorkflowParam) = apply { + id = chatSessionWorkflowParam.id + stateVariables = chatSessionWorkflowParam.stateVariables + tracing = chatSessionWorkflowParam.tracing + version = chatSessionWorkflowParam.version + additionalProperties = chatSessionWorkflowParam.additionalProperties.toMutableMap() + } + + /** Identifier for the workflow invoked by the session. */ + 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 } + + /** + * State variables forwarded to the workflow. Keys may be up to 64 characters, values must + * be primitive types, and the map defaults to an empty object. + */ + fun stateVariables(stateVariables: StateVariables) = + stateVariables(JsonField.of(stateVariables)) + + /** + * Sets [Builder.stateVariables] to an arbitrary JSON value. + * + * You should usually call [Builder.stateVariables] with a well-typed [StateVariables] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun stateVariables(stateVariables: JsonField) = apply { + this.stateVariables = stateVariables + } + + /** + * Optional tracing overrides for the workflow invocation. When omitted, tracing is enabled + * by default. + */ + fun tracing(tracing: Tracing) = tracing(JsonField.of(tracing)) + + /** + * Sets [Builder.tracing] to an arbitrary JSON value. + * + * You should usually call [Builder.tracing] with a well-typed [Tracing] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun tracing(tracing: JsonField) = apply { this.tracing = tracing } + + /** Specific workflow version to run. Defaults to the latest deployed 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 [ChatSessionWorkflowParam]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatSessionWorkflowParam = + ChatSessionWorkflowParam( + checkRequired("id", id), + stateVariables, + tracing, + version, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatSessionWorkflowParam = apply { + if (validated) { + return@apply + } + + id() + stateVariables().ifPresent { it.validate() } + tracing().ifPresent { it.validate() } + 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) + + (stateVariables.asKnown().getOrNull()?.validity() ?: 0) + + (tracing.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) + + /** + * State variables forwarded to the workflow. Keys may be up to 64 characters, values must be + * primitive types, and the map defaults to an empty object. + */ + class StateVariables + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [StateVariables]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StateVariables]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(stateVariables: StateVariables) = apply { + additionalProperties = stateVariables.additionalProperties.toMutableMap() + } + + 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 [StateVariables]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): StateVariables = StateVariables(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): StateVariables = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StateVariables && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "StateVariables{additionalProperties=$additionalProperties}" + } + + /** + * Optional tracing overrides for the workflow invocation. When omitted, tracing is enabled by + * default. + */ + class Tracing + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of() + ) : this(enabled, mutableMapOf()) + + /** + * Whether tracing is enabled during the session. Defaults to true. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun enabled(): Optional = enabled.getOptional("enabled") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @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 [Tracing]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Tracing]. */ + class Builder internal constructor() { + + private var enabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(tracing: Tracing) = apply { + enabled = tracing.enabled + additionalProperties = tracing.additionalProperties.toMutableMap() + } + + /** Whether tracing is enabled during the session. Defaults to true. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + 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 [Tracing]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Tracing = Tracing(enabled, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Tracing = apply { + if (validated) { + return@apply + } + + enabled() + 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 (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tracing && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tracing{enabled=$enabled, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatSessionWorkflowParam && + id == other.id && + stateVariables == other.stateVariables && + tracing == other.tracing && + version == other.version && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, stateVariables, tracing, version, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatSessionWorkflowParam{id=$id, stateVariables=$stateVariables, tracing=$tracing, version=$version, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadDeleteParams.kt new file mode 100644 index 00000000..44976cad --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadDeleteParams.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 a ChatKit thread */ +class ThreadDeleteParams +private constructor( + private val threadId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun threadId(): Optional = Optional.ofNullable(threadId) + + /** 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(): ThreadDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ThreadDeleteParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadDeleteParams]. */ + class Builder internal constructor() { + + private var threadId: 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(threadDeleteParams: ThreadDeleteParams) = apply { + threadId = threadDeleteParams.threadId + additionalHeaders = threadDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = threadDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = threadDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun threadId(threadId: String?) = apply { this.threadId = threadId } + + /** Alias for calling [Builder.threadId] with `threadId.orElse(null)`. */ + fun threadId(threadId: Optional) = threadId(threadId.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 [ThreadDeleteParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ThreadDeleteParams = + ThreadDeleteParams( + threadId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> threadId ?: "" + 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 ThreadDeleteParams && + threadId == other.threadId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash(threadId, additionalHeaders, additionalQueryParams, additionalBodyProperties) + + override fun toString() = + "ThreadDeleteParams{threadId=$threadId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadDeleteResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadDeleteResponse.kt new file mode 100644 index 00000000..75c5e3de --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadDeleteResponse.kt @@ -0,0 +1,251 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 + +/** Confirmation payload returned after deleting a thread. */ +class ThreadDeleteResponse +@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()) + + /** + * Identifier of the deleted thread. + * + * @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") + + /** + * Indicates that the thread has been deleted. + * + * @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") + + /** + * Type discriminator that is always `chatkit.thread.deleted`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("chatkit.thread.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 [ThreadDeleteResponse]. + * + * The following fields are required: + * ```java + * .id() + * .deleted() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadDeleteResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var deleted: JsonField? = null + private var object_: JsonValue = JsonValue.from("chatkit.thread.deleted") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadDeleteResponse: ThreadDeleteResponse) = apply { + id = threadDeleteResponse.id + deleted = threadDeleteResponse.deleted + object_ = threadDeleteResponse.object_ + additionalProperties = threadDeleteResponse.additionalProperties.toMutableMap() + } + + /** Identifier of the deleted thread. */ + 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 } + + /** Indicates that the thread has been deleted. */ + 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("chatkit.thread.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 [ThreadDeleteResponse]. + * + * 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(): ThreadDeleteResponse = + ThreadDeleteResponse( + checkRequired("id", id), + checkRequired("deleted", deleted), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ThreadDeleteResponse = apply { + if (validated) { + return@apply + } + + id() + deleted() + _object_().let { + if (it != JsonValue.from("chatkit.thread.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("chatkit.thread.deleted")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ThreadDeleteResponse && + 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() = + "ThreadDeleteResponse{id=$id, deleted=$deleted, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListItemsPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListItemsPage.kt new file mode 100644 index 00000000..7d9c80e4 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListItemsPage.kt @@ -0,0 +1,139 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +import com.openai.core.AutoPager +import com.openai.core.Page +import com.openai.core.checkRequired +import com.openai.services.blocking.beta.chatkit.ThreadService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see ThreadService.listItems */ +class ThreadListItemsPage +private constructor( + private val service: ThreadService, + private val params: ThreadListItemsParams, + private val response: ChatKitThreadItemList, +) : Page { + + /** + * Delegates to [ChatKitThreadItemList], but gracefully handles missing data. + * + * @see ChatKitThreadItemList.data + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [ChatKitThreadItemList], but gracefully handles missing data. + * + * @see ChatKitThreadItemList.hasMore + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") + + /** + * Delegates to [ChatKitThreadItemList], but gracefully handles missing data. + * + * @see ChatKitThreadItemList.lastId + */ + fun lastId(): Optional = response._lastId().getOptional("last_id") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() && lastId().isPresent + + fun nextPageParams(): ThreadListItemsParams { + val nextCursor = + lastId().getOrNull() ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().after(nextCursor).build() + } + + override fun nextPage(): ThreadListItemsPage = service.listItems(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): ThreadListItemsParams = params + + /** The response that this page was parsed from. */ + fun response(): ChatKitThreadItemList = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ThreadListItemsPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadListItemsPage]. */ + class Builder internal constructor() { + + private var service: ThreadService? = null + private var params: ThreadListItemsParams? = null + private var response: ChatKitThreadItemList? = null + + @JvmSynthetic + internal fun from(threadListItemsPage: ThreadListItemsPage) = apply { + service = threadListItemsPage.service + params = threadListItemsPage.params + response = threadListItemsPage.response + } + + fun service(service: ThreadService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ThreadListItemsParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ChatKitThreadItemList) = apply { this.response = response } + + /** + * Returns an immutable instance of [ThreadListItemsPage]. + * + * 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(): ThreadListItemsPage = + ThreadListItemsPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ThreadListItemsPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = + "ThreadListItemsPage{service=$service, params=$params, response=$response}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListItemsPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListItemsPageAsync.kt new file mode 100644 index 00000000..33af8110 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListItemsPageAsync.kt @@ -0,0 +1,154 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +import com.openai.core.AutoPagerAsync +import com.openai.core.PageAsync +import com.openai.core.checkRequired +import com.openai.services.async.beta.chatkit.ThreadServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see ThreadServiceAsync.listItems */ +class ThreadListItemsPageAsync +private constructor( + private val service: ThreadServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: ThreadListItemsParams, + private val response: ChatKitThreadItemList, +) : PageAsync { + + /** + * Delegates to [ChatKitThreadItemList], but gracefully handles missing data. + * + * @see ChatKitThreadItemList.data + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [ChatKitThreadItemList], but gracefully handles missing data. + * + * @see ChatKitThreadItemList.hasMore + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") + + /** + * Delegates to [ChatKitThreadItemList], but gracefully handles missing data. + * + * @see ChatKitThreadItemList.lastId + */ + fun lastId(): Optional = response._lastId().getOptional("last_id") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() && lastId().isPresent + + fun nextPageParams(): ThreadListItemsParams { + val nextCursor = + lastId().getOrNull() ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().after(nextCursor).build() + } + + override fun nextPage(): CompletableFuture = + service.listItems(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) + + /** The parameters that were used to request this page. */ + fun params(): ThreadListItemsParams = params + + /** The response that this page was parsed from. */ + fun response(): ChatKitThreadItemList = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ThreadListItemsPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadListItemsPageAsync]. */ + class Builder internal constructor() { + + private var service: ThreadServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: ThreadListItemsParams? = null + private var response: ChatKitThreadItemList? = null + + @JvmSynthetic + internal fun from(threadListItemsPageAsync: ThreadListItemsPageAsync) = apply { + service = threadListItemsPageAsync.service + streamHandlerExecutor = threadListItemsPageAsync.streamHandlerExecutor + params = threadListItemsPageAsync.params + response = threadListItemsPageAsync.response + } + + fun service(service: ThreadServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: ThreadListItemsParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ChatKitThreadItemList) = apply { this.response = response } + + /** + * Returns an immutable instance of [ThreadListItemsPageAsync]. + * + * 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(): ThreadListItemsPageAsync = + ThreadListItemsPageAsync( + 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 ThreadListItemsPageAsync && + 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() = + "ThreadListItemsPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListItemsParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListItemsParams.kt new file mode 100644 index 00000000..96c16498 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListItemsParams.kt @@ -0,0 +1,406 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 ChatKit thread items */ +class ThreadListItemsParams +private constructor( + private val threadId: String?, + private val after: String?, + private val before: String?, + private val limit: Long?, + private val order: Order?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun threadId(): Optional = Optional.ofNullable(threadId) + + /** List items created after this thread item ID. Defaults to null for the first page. */ + fun after(): Optional = Optional.ofNullable(after) + + /** List items created before this thread item ID. Defaults to null for the newest results. */ + fun before(): Optional = Optional.ofNullable(before) + + /** Maximum number of thread items to return. Defaults to 20. */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** Sort order for results by creation time. Defaults to `desc`. */ + 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(): ThreadListItemsParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ThreadListItemsParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadListItemsParams]. */ + class Builder internal constructor() { + + private var threadId: String? = null + private var after: String? = null + private var before: 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(threadListItemsParams: ThreadListItemsParams) = apply { + threadId = threadListItemsParams.threadId + after = threadListItemsParams.after + before = threadListItemsParams.before + limit = threadListItemsParams.limit + order = threadListItemsParams.order + additionalHeaders = threadListItemsParams.additionalHeaders.toBuilder() + additionalQueryParams = threadListItemsParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String?) = apply { this.threadId = threadId } + + /** Alias for calling [Builder.threadId] with `threadId.orElse(null)`. */ + fun threadId(threadId: Optional) = threadId(threadId.getOrNull()) + + /** List items created after this thread item ID. Defaults to null for the first page. */ + fun after(after: String?) = apply { this.after = after } + + /** Alias for calling [Builder.after] with `after.orElse(null)`. */ + fun after(after: Optional) = after(after.getOrNull()) + + /** + * List items created before this thread item ID. Defaults to null for the newest results. + */ + fun before(before: String?) = apply { this.before = before } + + /** Alias for calling [Builder.before] with `before.orElse(null)`. */ + fun before(before: Optional) = before(before.getOrNull()) + + /** Maximum number of thread items to return. Defaults to 20. */ + 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 for results by creation time. Defaults to `desc`. */ + 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 [ThreadListItemsParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ThreadListItemsParams = + ThreadListItemsParams( + threadId, + after, + before, + limit, + order, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> threadId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + after?.let { put("after", it) } + before?.let { put("before", it) } + limit?.let { put("limit", it.toString()) } + order?.let { put("order", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + /** Sort order for results by creation time. Defaults to `desc`. */ + 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 ThreadListItemsParams && + threadId == other.threadId && + after == other.after && + before == other.before && + limit == other.limit && + order == other.order && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + threadId, + after, + before, + limit, + order, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "ThreadListItemsParams{threadId=$threadId, after=$after, before=$before, limit=$limit, order=$order, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListPage.kt new file mode 100644 index 00000000..4c1cb15e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListPage.kt @@ -0,0 +1,138 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +import com.openai.core.AutoPager +import com.openai.core.Page +import com.openai.core.checkRequired +import com.openai.services.blocking.beta.chatkit.ThreadService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see ThreadService.list */ +class ThreadListPage +private constructor( + private val service: ThreadService, + private val params: ThreadListParams, + private val response: ThreadListPageResponse, +) : Page { + + /** + * Delegates to [ThreadListPageResponse], but gracefully handles missing data. + * + * @see ThreadListPageResponse.data + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [ThreadListPageResponse], but gracefully handles missing data. + * + * @see ThreadListPageResponse.hasMore + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") + + /** + * Delegates to [ThreadListPageResponse], but gracefully handles missing data. + * + * @see ThreadListPageResponse.lastId + */ + fun lastId(): Optional = response._lastId().getOptional("last_id") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() && lastId().isPresent + + fun nextPageParams(): ThreadListParams { + val nextCursor = + lastId().getOrNull() ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().after(nextCursor).build() + } + + override fun nextPage(): ThreadListPage = service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): ThreadListParams = params + + /** The response that this page was parsed from. */ + fun response(): ThreadListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ThreadListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadListPage]. */ + class Builder internal constructor() { + + private var service: ThreadService? = null + private var params: ThreadListParams? = null + private var response: ThreadListPageResponse? = null + + @JvmSynthetic + internal fun from(threadListPage: ThreadListPage) = apply { + service = threadListPage.service + params = threadListPage.params + response = threadListPage.response + } + + fun service(service: ThreadService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ThreadListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ThreadListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ThreadListPage]. + * + * 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(): ThreadListPage = + ThreadListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ThreadListPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = "ThreadListPage{service=$service, params=$params, response=$response}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListPageAsync.kt new file mode 100644 index 00000000..ab9c6c86 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListPageAsync.kt @@ -0,0 +1,153 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +import com.openai.core.AutoPagerAsync +import com.openai.core.PageAsync +import com.openai.core.checkRequired +import com.openai.services.async.beta.chatkit.ThreadServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see ThreadServiceAsync.list */ +class ThreadListPageAsync +private constructor( + private val service: ThreadServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: ThreadListParams, + private val response: ThreadListPageResponse, +) : PageAsync { + + /** + * Delegates to [ThreadListPageResponse], but gracefully handles missing data. + * + * @see ThreadListPageResponse.data + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [ThreadListPageResponse], but gracefully handles missing data. + * + * @see ThreadListPageResponse.hasMore + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") + + /** + * Delegates to [ThreadListPageResponse], but gracefully handles missing data. + * + * @see ThreadListPageResponse.lastId + */ + fun lastId(): Optional = response._lastId().getOptional("last_id") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() && lastId().isPresent + + fun nextPageParams(): ThreadListParams { + val nextCursor = + lastId().getOrNull() ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().after(nextCursor).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(): ThreadListParams = params + + /** The response that this page was parsed from. */ + fun response(): ThreadListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ThreadListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadListPageAsync]. */ + class Builder internal constructor() { + + private var service: ThreadServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: ThreadListParams? = null + private var response: ThreadListPageResponse? = null + + @JvmSynthetic + internal fun from(threadListPageAsync: ThreadListPageAsync) = apply { + service = threadListPageAsync.service + streamHandlerExecutor = threadListPageAsync.streamHandlerExecutor + params = threadListPageAsync.params + response = threadListPageAsync.response + } + + fun service(service: ThreadServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: ThreadListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ThreadListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ThreadListPageAsync]. + * + * 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(): ThreadListPageAsync = + ThreadListPageAsync( + 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 ThreadListPageAsync && + 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() = + "ThreadListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListPageResponse.kt new file mode 100644 index 00000000..85ecab1d --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListPageResponse.kt @@ -0,0 +1,352 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 + +/** A paginated list of ChatKit threads. */ +class ThreadListPageResponse +@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 [ThreadListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadListPageResponse]. */ + 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(threadListPageResponse: ThreadListPageResponse) = apply { + data = threadListPageResponse.data.map { it.toMutableList() } + firstId = threadListPageResponse.firstId + hasMore = threadListPageResponse.hasMore + lastId = threadListPageResponse.lastId + object_ = threadListPageResponse.object_ + additionalProperties = threadListPageResponse.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 [ChatKitThread] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: ChatKitThread) = 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 [ThreadListPageResponse]. + * + * 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(): ThreadListPageResponse = + ThreadListPageResponse( + 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(): ThreadListPageResponse = 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 ThreadListPageResponse && + 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() = + "ThreadListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListParams.kt new file mode 100644 index 00000000..3c0d94f5 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadListParams.kt @@ -0,0 +1,397 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 ChatKit threads */ +class ThreadListParams +private constructor( + private val after: String?, + private val before: String?, + private val limit: Long?, + private val order: Order?, + private val user: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** List items created after this thread item ID. Defaults to null for the first page. */ + fun after(): Optional = Optional.ofNullable(after) + + /** List items created before this thread item ID. Defaults to null for the newest results. */ + fun before(): Optional = Optional.ofNullable(before) + + /** Maximum number of thread items to return. Defaults to 20. */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** Sort order for results by creation time. Defaults to `desc`. */ + fun order(): Optional = Optional.ofNullable(order) + + /** Filter threads that belong to this user identifier. Defaults to null to return all users. */ + fun user(): Optional = Optional.ofNullable(user) + + /** 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(): ThreadListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ThreadListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadListParams]. */ + class Builder internal constructor() { + + private var after: String? = null + private var before: String? = null + private var limit: Long? = null + private var order: Order? = null + private var user: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(threadListParams: ThreadListParams) = apply { + after = threadListParams.after + before = threadListParams.before + limit = threadListParams.limit + order = threadListParams.order + user = threadListParams.user + additionalHeaders = threadListParams.additionalHeaders.toBuilder() + additionalQueryParams = threadListParams.additionalQueryParams.toBuilder() + } + + /** List items created after this thread item ID. Defaults to null for the first page. */ + fun after(after: String?) = apply { this.after = after } + + /** Alias for calling [Builder.after] with `after.orElse(null)`. */ + fun after(after: Optional) = after(after.getOrNull()) + + /** + * List items created before this thread item ID. Defaults to null for the newest results. + */ + fun before(before: String?) = apply { this.before = before } + + /** Alias for calling [Builder.before] with `before.orElse(null)`. */ + fun before(before: Optional) = before(before.getOrNull()) + + /** Maximum number of thread items to return. Defaults to 20. */ + 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 for results by creation time. Defaults to `desc`. */ + fun order(order: Order?) = apply { this.order = order } + + /** Alias for calling [Builder.order] with `order.orElse(null)`. */ + fun order(order: Optional) = order(order.getOrNull()) + + /** + * Filter threads that belong to this user identifier. Defaults to null to return all users. + */ + fun user(user: String?) = apply { this.user = user } + + /** Alias for calling [Builder.user] with `user.orElse(null)`. */ + fun user(user: Optional) = user(user.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 [ThreadListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ThreadListParams = + ThreadListParams( + after, + before, + limit, + order, + user, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + after?.let { put("after", it) } + before?.let { put("before", it) } + limit?.let { put("limit", it.toString()) } + order?.let { put("order", it.toString()) } + user?.let { put("user", it) } + putAll(additionalQueryParams) + } + .build() + + /** Sort order for results by creation time. Defaults to `desc`. */ + 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 ThreadListParams && + after == other.after && + before == other.before && + limit == other.limit && + order == other.order && + user == other.user && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(after, before, limit, order, user, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ThreadListParams{after=$after, before=$before, limit=$limit, order=$order, user=$user, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadRetrieveParams.kt new file mode 100644 index 00000000..fe70c6cf --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/chatkit/threads/ThreadRetrieveParams.kt @@ -0,0 +1,189 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.chatkit.threads + +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 + +/** Retrieve a ChatKit thread */ +class ThreadRetrieveParams +private constructor( + private val threadId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun threadId(): Optional = Optional.ofNullable(threadId) + + /** 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(): ThreadRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ThreadRetrieveParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadRetrieveParams]. */ + class Builder internal constructor() { + + private var threadId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(threadRetrieveParams: ThreadRetrieveParams) = apply { + threadId = threadRetrieveParams.threadId + additionalHeaders = threadRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = threadRetrieveParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String?) = apply { this.threadId = threadId } + + /** Alias for calling [Builder.threadId] with `threadId.orElse(null)`. */ + fun threadId(threadId: Optional) = threadId(threadId.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 [ThreadRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ThreadRetrieveParams = + ThreadRetrieveParams(threadId, additionalHeaders.build(), additionalQueryParams.build()) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> threadId ?: "" + 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 ThreadRetrieveParams && + threadId == other.threadId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(threadId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ThreadRetrieveParams{threadId=$threadId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} 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 b90acd9e..e0612f18 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 @@ -82,7 +82,7 @@ private constructor( /** * Control how much effort the model will exert to match the style and features, especially * facial features, of input images. This parameter is only supported for `gpt-image-1`. - * Supports `high` and `low`. Defaults to `low`. + * Unsupported for `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -433,7 +433,7 @@ private constructor( /** * Control how much effort the model will exert to match the style and features, especially * facial features, of input images. This parameter is only supported for `gpt-image-1`. - * Supports `high` and `low`. Defaults to `low`. + * Unsupported for `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`. */ fun inputFidelity(inputFidelity: InputFidelity?) = apply { body.inputFidelity(inputFidelity) @@ -909,7 +909,7 @@ private constructor( /** * Control how much effort the model will exert to match the style and features, especially * facial features, of input images. This parameter is only supported for `gpt-image-1`. - * Supports `high` and `low`. Defaults to `low`. + * Unsupported for `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -1305,7 +1305,8 @@ private constructor( /** * Control how much effort the model will exert to match the style and features, * especially facial features, of input images. This parameter is only supported for - * `gpt-image-1`. Supports `high` and `low`. Defaults to `low`. + * `gpt-image-1`. Unsupported for `gpt-image-1-mini`. Supports `high` and `low`. + * Defaults to `low`. */ fun inputFidelity(inputFidelity: InputFidelity?) = inputFidelity(MultipartField.of(inputFidelity)) @@ -1991,7 +1992,7 @@ private constructor( /** * Control how much effort the model will exert to match the style and features, especially * facial features, of input images. This parameter is only supported for `gpt-image-1`. - * Supports `high` and `low`. Defaults to `low`. + * Unsupported for `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`. */ class InputFidelity @JsonCreator private constructor(private val value: JsonField) : Enum { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/images/ImageModel.kt b/openai-java-core/src/main/kotlin/com/openai/models/images/ImageModel.kt index 72e51a95..8d547ad1 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/images/ImageModel.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/images/ImageModel.kt @@ -26,6 +26,8 @@ class ImageModel @JsonCreator private constructor(private val value: JsonField Value.DALL_E_2 DALL_E_3 -> Value.DALL_E_3 GPT_IMAGE_1 -> Value.GPT_IMAGE_1 + GPT_IMAGE_1_MINI -> Value.GPT_IMAGE_1_MINI else -> Value._UNKNOWN } @@ -81,6 +86,7 @@ class ImageModel @JsonCreator private constructor(private val value: JsonField Known.DALL_E_2 DALL_E_3 -> Known.DALL_E_3 GPT_IMAGE_1 -> Known.GPT_IMAGE_1 + GPT_IMAGE_1_MINI -> Known.GPT_IMAGE_1_MINI else -> throw OpenAIInvalidDataException("Unknown ImageModel: $value") } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSession.kt b/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSession.kt index 7ca6820e..877d611e 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSession.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSession.kt @@ -1876,6 +1876,14 @@ private constructor( val GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 = of("gpt-4o-mini-realtime-preview-2024-12-17") + @JvmField val GPT_REALTIME_MINI = of("gpt-realtime-mini") + + @JvmField val GPT_REALTIME_MINI_2025_10_06 = of("gpt-realtime-mini-2025-10-06") + + @JvmField val GPT_AUDIO_MINI = of("gpt-audio-mini") + + @JvmField val GPT_AUDIO_MINI_2025_10_06 = of("gpt-audio-mini-2025-10-06") + @JvmStatic fun of(value: String) = Model(JsonField.of(value)) } @@ -1889,6 +1897,10 @@ private constructor( GPT_4O_REALTIME_PREVIEW_2025_06_03, GPT_4O_MINI_REALTIME_PREVIEW, GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17, + GPT_REALTIME_MINI, + GPT_REALTIME_MINI_2025_10_06, + GPT_AUDIO_MINI, + GPT_AUDIO_MINI_2025_10_06, } /** @@ -1909,6 +1921,10 @@ private constructor( GPT_4O_REALTIME_PREVIEW_2025_06_03, GPT_4O_MINI_REALTIME_PREVIEW, GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17, + GPT_REALTIME_MINI, + GPT_REALTIME_MINI_2025_10_06, + GPT_AUDIO_MINI, + GPT_AUDIO_MINI_2025_10_06, /** An enum member indicating that [Model] was instantiated with an unknown value. */ _UNKNOWN, } @@ -1931,6 +1947,10 @@ private constructor( GPT_4O_MINI_REALTIME_PREVIEW -> Value.GPT_4O_MINI_REALTIME_PREVIEW GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 -> Value.GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 + GPT_REALTIME_MINI -> Value.GPT_REALTIME_MINI + GPT_REALTIME_MINI_2025_10_06 -> Value.GPT_REALTIME_MINI_2025_10_06 + GPT_AUDIO_MINI -> Value.GPT_AUDIO_MINI + GPT_AUDIO_MINI_2025_10_06 -> Value.GPT_AUDIO_MINI_2025_10_06 else -> Value._UNKNOWN } @@ -1954,6 +1974,10 @@ private constructor( GPT_4O_MINI_REALTIME_PREVIEW -> Known.GPT_4O_MINI_REALTIME_PREVIEW GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 -> Known.GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 + GPT_REALTIME_MINI -> Known.GPT_REALTIME_MINI + GPT_REALTIME_MINI_2025_10_06 -> Known.GPT_REALTIME_MINI_2025_10_06 + GPT_AUDIO_MINI -> Known.GPT_AUDIO_MINI + GPT_AUDIO_MINI_2025_10_06 -> Known.GPT_AUDIO_MINI_2025_10_06 else -> throw OpenAIInvalidDataException("Unknown Model: $value") } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSessionCreateRequest.kt b/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSessionCreateRequest.kt index f97554e9..8e6b9d05 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSessionCreateRequest.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeSessionCreateRequest.kt @@ -1130,6 +1130,14 @@ private constructor( val GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 = of("gpt-4o-mini-realtime-preview-2024-12-17") + @JvmField val GPT_REALTIME_MINI = of("gpt-realtime-mini") + + @JvmField val GPT_REALTIME_MINI_2025_10_06 = of("gpt-realtime-mini-2025-10-06") + + @JvmField val GPT_AUDIO_MINI = of("gpt-audio-mini") + + @JvmField val GPT_AUDIO_MINI_2025_10_06 = of("gpt-audio-mini-2025-10-06") + @JvmStatic fun of(value: String) = Model(JsonField.of(value)) } @@ -1143,6 +1151,10 @@ private constructor( GPT_4O_REALTIME_PREVIEW_2025_06_03, GPT_4O_MINI_REALTIME_PREVIEW, GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17, + GPT_REALTIME_MINI, + GPT_REALTIME_MINI_2025_10_06, + GPT_AUDIO_MINI, + GPT_AUDIO_MINI_2025_10_06, } /** @@ -1163,6 +1175,10 @@ private constructor( GPT_4O_REALTIME_PREVIEW_2025_06_03, GPT_4O_MINI_REALTIME_PREVIEW, GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17, + GPT_REALTIME_MINI, + GPT_REALTIME_MINI_2025_10_06, + GPT_AUDIO_MINI, + GPT_AUDIO_MINI_2025_10_06, /** An enum member indicating that [Model] was instantiated with an unknown value. */ _UNKNOWN, } @@ -1185,6 +1201,10 @@ private constructor( GPT_4O_MINI_REALTIME_PREVIEW -> Value.GPT_4O_MINI_REALTIME_PREVIEW GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 -> Value.GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 + GPT_REALTIME_MINI -> Value.GPT_REALTIME_MINI + GPT_REALTIME_MINI_2025_10_06 -> Value.GPT_REALTIME_MINI_2025_10_06 + GPT_AUDIO_MINI -> Value.GPT_AUDIO_MINI + GPT_AUDIO_MINI_2025_10_06 -> Value.GPT_AUDIO_MINI_2025_10_06 else -> Value._UNKNOWN } @@ -1208,6 +1228,10 @@ private constructor( GPT_4O_MINI_REALTIME_PREVIEW -> Known.GPT_4O_MINI_REALTIME_PREVIEW GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 -> Known.GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 + GPT_REALTIME_MINI -> Known.GPT_REALTIME_MINI + GPT_REALTIME_MINI_2025_10_06 -> Known.GPT_REALTIME_MINI_2025_10_06 + GPT_AUDIO_MINI -> Known.GPT_AUDIO_MINI + GPT_AUDIO_MINI_2025_10_06 -> Known.GPT_AUDIO_MINI_2025_10_06 else -> throw OpenAIInvalidDataException("Unknown Model: $value") } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/realtime/clientsecrets/RealtimeSessionCreateResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/realtime/clientsecrets/RealtimeSessionCreateResponse.kt index 5a5554a2..ba88b10b 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/realtime/clientsecrets/RealtimeSessionCreateResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/realtime/clientsecrets/RealtimeSessionCreateResponse.kt @@ -3523,6 +3523,14 @@ private constructor( val GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 = of("gpt-4o-mini-realtime-preview-2024-12-17") + @JvmField val GPT_REALTIME_MINI = of("gpt-realtime-mini") + + @JvmField val GPT_REALTIME_MINI_2025_10_06 = of("gpt-realtime-mini-2025-10-06") + + @JvmField val GPT_AUDIO_MINI = of("gpt-audio-mini") + + @JvmField val GPT_AUDIO_MINI_2025_10_06 = of("gpt-audio-mini-2025-10-06") + @JvmStatic fun of(value: String) = Model(JsonField.of(value)) } @@ -3536,6 +3544,10 @@ private constructor( GPT_4O_REALTIME_PREVIEW_2025_06_03, GPT_4O_MINI_REALTIME_PREVIEW, GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17, + GPT_REALTIME_MINI, + GPT_REALTIME_MINI_2025_10_06, + GPT_AUDIO_MINI, + GPT_AUDIO_MINI_2025_10_06, } /** @@ -3556,6 +3568,10 @@ private constructor( GPT_4O_REALTIME_PREVIEW_2025_06_03, GPT_4O_MINI_REALTIME_PREVIEW, GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17, + GPT_REALTIME_MINI, + GPT_REALTIME_MINI_2025_10_06, + GPT_AUDIO_MINI, + GPT_AUDIO_MINI_2025_10_06, /** An enum member indicating that [Model] was instantiated with an unknown value. */ _UNKNOWN, } @@ -3578,6 +3594,10 @@ private constructor( GPT_4O_MINI_REALTIME_PREVIEW -> Value.GPT_4O_MINI_REALTIME_PREVIEW GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 -> Value.GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 + GPT_REALTIME_MINI -> Value.GPT_REALTIME_MINI + GPT_REALTIME_MINI_2025_10_06 -> Value.GPT_REALTIME_MINI_2025_10_06 + GPT_AUDIO_MINI -> Value.GPT_AUDIO_MINI + GPT_AUDIO_MINI_2025_10_06 -> Value.GPT_AUDIO_MINI_2025_10_06 else -> Value._UNKNOWN } @@ -3601,6 +3621,10 @@ private constructor( GPT_4O_MINI_REALTIME_PREVIEW -> Known.GPT_4O_MINI_REALTIME_PREVIEW GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 -> Known.GPT_4O_MINI_REALTIME_PREVIEW_2024_12_17 + GPT_REALTIME_MINI -> Known.GPT_REALTIME_MINI + GPT_REALTIME_MINI_2025_10_06 -> Known.GPT_REALTIME_MINI_2025_10_06 + GPT_AUDIO_MINI -> Known.GPT_AUDIO_MINI + GPT_AUDIO_MINI_2025_10_06 -> Known.GPT_AUDIO_MINI_2025_10_06 else -> throw OpenAIInvalidDataException("Unknown Model: $value") } 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 34153075..d0eeba9f 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 @@ -3618,7 +3618,7 @@ private constructor( /** * Control how much effort the model will exert to match the style and features, especially * facial features, of input images. This parameter is only supported for `gpt-image-1`. - * Supports `high` and `low`. Defaults to `low`. + * Unsupported for `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`. * * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -3868,7 +3868,8 @@ private constructor( /** * Control how much effort the model will exert to match the style and features, * especially facial features, of input images. This parameter is only supported for - * `gpt-image-1`. Supports `high` and `low`. Defaults to `low`. + * `gpt-image-1`. Unsupported for `gpt-image-1-mini`. Supports `high` and `low`. + * Defaults to `low`. */ fun inputFidelity(inputFidelity: InputFidelity?) = inputFidelity(JsonField.ofNullable(inputFidelity)) @@ -4248,7 +4249,7 @@ private constructor( /** * Control how much effort the model will exert to match the style and features, especially * facial features, of input images. This parameter is only supported for `gpt-image-1`. - * Supports `high` and `low`. Defaults to `low`. + * Unsupported for `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`. */ class InputFidelity @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -4590,12 +4591,15 @@ private constructor( @JvmField val GPT_IMAGE_1 = of("gpt-image-1") + @JvmField val GPT_IMAGE_1_MINI = of("gpt-image-1-mini") + @JvmStatic fun of(value: String) = Model(JsonField.of(value)) } /** An enum containing [Model]'s known values. */ enum class Known { - GPT_IMAGE_1 + GPT_IMAGE_1, + GPT_IMAGE_1_MINI, } /** @@ -4609,6 +4613,7 @@ private constructor( */ enum class Value { GPT_IMAGE_1, + GPT_IMAGE_1_MINI, /** * An enum member indicating that [Model] was instantiated with an unknown value. */ @@ -4625,6 +4630,7 @@ private constructor( fun value(): Value = when (this) { GPT_IMAGE_1 -> Value.GPT_IMAGE_1 + GPT_IMAGE_1_MINI -> Value.GPT_IMAGE_1_MINI else -> Value._UNKNOWN } @@ -4640,6 +4646,7 @@ private constructor( fun known(): Known = when (this) { GPT_IMAGE_1 -> Known.GPT_IMAGE_1 + GPT_IMAGE_1_MINI -> Known.GPT_IMAGE_1_MINI else -> throw OpenAIInvalidDataException("Unknown Model: $value") } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/videos/Video.kt b/openai-java-core/src/main/kotlin/com/openai/models/videos/Video.kt new file mode 100644 index 00000000..d351b9b2 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/videos/Video.kt @@ -0,0 +1,795 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.videos + +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.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.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Structured information describing a generated video job. */ +class Video +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val completedAt: JsonField, + private val createdAt: JsonField, + private val error: JsonField, + private val expiresAt: JsonField, + private val model: JsonField, + private val object_: JsonValue, + private val progress: JsonField, + private val remixedFromVideoId: JsonField, + private val seconds: JsonField, + private val size: JsonField, + private val status: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("completed_at") + @ExcludeMissing + completedAt: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("error") + @ExcludeMissing + error: JsonField = JsonMissing.of(), + @JsonProperty("expires_at") @ExcludeMissing expiresAt: JsonField = JsonMissing.of(), + @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("progress") @ExcludeMissing progress: JsonField = JsonMissing.of(), + @JsonProperty("remixed_from_video_id") + @ExcludeMissing + remixedFromVideoId: JsonField = JsonMissing.of(), + @JsonProperty("seconds") + @ExcludeMissing + seconds: JsonField = JsonMissing.of(), + @JsonProperty("size") @ExcludeMissing size: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + ) : this( + id, + completedAt, + createdAt, + error, + expiresAt, + model, + object_, + progress, + remixedFromVideoId, + seconds, + size, + status, + mutableMapOf(), + ) + + /** + * Unique identifier for the video job. + * + * @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 job completed, if finished. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun completedAt(): Optional = completedAt.getOptional("completed_at") + + /** + * Unix timestamp (seconds) for when the job 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") + + /** + * Error payload that explains why generation failed, if applicable. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun error(): Optional = error.getOptional("error") + + /** + * Unix timestamp (seconds) for when the downloadable assets expire, if set. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun expiresAt(): Optional = expiresAt.getOptional("expires_at") + + /** + * The video generation model that produced the job. + * + * @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 model(): VideoModel = model.getRequired("model") + + /** + * The object type, which is always `video`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("video") + * ``` + * + * 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_ + + /** + * Approximate completion percentage for the generation task. + * + * @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 progress(): Long = progress.getRequired("progress") + + /** + * Identifier of the source video if this video is a remix. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun remixedFromVideoId(): Optional = + remixedFromVideoId.getOptional("remixed_from_video_id") + + /** + * Duration of the generated clip in seconds. + * + * @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 seconds(): VideoSeconds = seconds.getRequired("seconds") + + /** + * The resolution of the generated video. + * + * @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 size(): VideoSize = size.getRequired("size") + + /** + * Current lifecycle status of the video job. + * + * @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 status(): Status = status.getRequired("status") + + /** + * 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 [completedAt]. + * + * Unlike [completedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("completed_at") @ExcludeMissing fun _completedAt(): JsonField = completedAt + + /** + * 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 [error]. + * + * Unlike [error], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error") @ExcludeMissing fun _error(): JsonField = error + + /** + * Returns the raw JSON value of [expiresAt]. + * + * Unlike [expiresAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("expires_at") @ExcludeMissing fun _expiresAt(): JsonField = expiresAt + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * Returns the raw JSON value of [progress]. + * + * Unlike [progress], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("progress") @ExcludeMissing fun _progress(): JsonField = progress + + /** + * Returns the raw JSON value of [remixedFromVideoId]. + * + * Unlike [remixedFromVideoId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("remixed_from_video_id") + @ExcludeMissing + fun _remixedFromVideoId(): JsonField = remixedFromVideoId + + /** + * Returns the raw JSON value of [seconds]. + * + * Unlike [seconds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("seconds") @ExcludeMissing fun _seconds(): JsonField = seconds + + /** + * Returns the raw JSON value of [size]. + * + * Unlike [size], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("size") @ExcludeMissing fun _size(): JsonField = size + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + @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 [Video]. + * + * The following fields are required: + * ```java + * .id() + * .completedAt() + * .createdAt() + * .error() + * .expiresAt() + * .model() + * .progress() + * .remixedFromVideoId() + * .seconds() + * .size() + * .status() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Video]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var completedAt: JsonField? = null + private var createdAt: JsonField? = null + private var error: JsonField? = null + private var expiresAt: JsonField? = null + private var model: JsonField? = null + private var object_: JsonValue = JsonValue.from("video") + private var progress: JsonField? = null + private var remixedFromVideoId: JsonField? = null + private var seconds: JsonField? = null + private var size: JsonField? = null + private var status: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(video: Video) = apply { + id = video.id + completedAt = video.completedAt + createdAt = video.createdAt + error = video.error + expiresAt = video.expiresAt + model = video.model + object_ = video.object_ + progress = video.progress + remixedFromVideoId = video.remixedFromVideoId + seconds = video.seconds + size = video.size + status = video.status + additionalProperties = video.additionalProperties.toMutableMap() + } + + /** Unique identifier for the video job. */ + 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 job completed, if finished. */ + fun completedAt(completedAt: Long?) = completedAt(JsonField.ofNullable(completedAt)) + + /** + * Alias for [Builder.completedAt]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun completedAt(completedAt: Long) = completedAt(completedAt as Long?) + + /** Alias for calling [Builder.completedAt] with `completedAt.orElse(null)`. */ + fun completedAt(completedAt: Optional) = completedAt(completedAt.getOrNull()) + + /** + * Sets [Builder.completedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.completedAt] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun completedAt(completedAt: JsonField) = apply { this.completedAt = completedAt } + + /** Unix timestamp (seconds) for when the job 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 } + + /** Error payload that explains why generation failed, if applicable. */ + fun error(error: VideoCreateError?) = error(JsonField.ofNullable(error)) + + /** Alias for calling [Builder.error] with `error.orElse(null)`. */ + fun error(error: Optional) = error(error.getOrNull()) + + /** + * Sets [Builder.error] to an arbitrary JSON value. + * + * You should usually call [Builder.error] with a well-typed [VideoCreateError] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun error(error: JsonField) = apply { this.error = error } + + /** Unix timestamp (seconds) for when the downloadable assets expire, if set. */ + fun expiresAt(expiresAt: Long?) = expiresAt(JsonField.ofNullable(expiresAt)) + + /** + * Alias for [Builder.expiresAt]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun expiresAt(expiresAt: Long) = expiresAt(expiresAt as Long?) + + /** Alias for calling [Builder.expiresAt] with `expiresAt.orElse(null)`. */ + fun expiresAt(expiresAt: Optional) = expiresAt(expiresAt.getOrNull()) + + /** + * Sets [Builder.expiresAt] to an arbitrary JSON value. + * + * You should usually call [Builder.expiresAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun expiresAt(expiresAt: JsonField) = apply { this.expiresAt = expiresAt } + + /** The video generation model that produced the job. */ + fun model(model: VideoModel) = model(JsonField.of(model)) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [VideoModel] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * 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("video") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** Approximate completion percentage for the generation task. */ + fun progress(progress: Long) = progress(JsonField.of(progress)) + + /** + * Sets [Builder.progress] to an arbitrary JSON value. + * + * You should usually call [Builder.progress] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun progress(progress: JsonField) = apply { this.progress = progress } + + /** Identifier of the source video if this video is a remix. */ + fun remixedFromVideoId(remixedFromVideoId: String?) = + remixedFromVideoId(JsonField.ofNullable(remixedFromVideoId)) + + /** + * Alias for calling [Builder.remixedFromVideoId] with `remixedFromVideoId.orElse(null)`. + */ + fun remixedFromVideoId(remixedFromVideoId: Optional) = + remixedFromVideoId(remixedFromVideoId.getOrNull()) + + /** + * Sets [Builder.remixedFromVideoId] to an arbitrary JSON value. + * + * You should usually call [Builder.remixedFromVideoId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun remixedFromVideoId(remixedFromVideoId: JsonField) = apply { + this.remixedFromVideoId = remixedFromVideoId + } + + /** Duration of the generated clip in seconds. */ + fun seconds(seconds: VideoSeconds) = seconds(JsonField.of(seconds)) + + /** + * Sets [Builder.seconds] to an arbitrary JSON value. + * + * You should usually call [Builder.seconds] with a well-typed [VideoSeconds] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun seconds(seconds: JsonField) = apply { this.seconds = seconds } + + /** The resolution of the generated video. */ + fun size(size: VideoSize) = size(JsonField.of(size)) + + /** + * Sets [Builder.size] to an arbitrary JSON value. + * + * You should usually call [Builder.size] with a well-typed [VideoSize] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun size(size: JsonField) = apply { this.size = size } + + /** Current lifecycle status of the video job. */ + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + 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 [Video]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .completedAt() + * .createdAt() + * .error() + * .expiresAt() + * .model() + * .progress() + * .remixedFromVideoId() + * .seconds() + * .size() + * .status() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Video = + Video( + checkRequired("id", id), + checkRequired("completedAt", completedAt), + checkRequired("createdAt", createdAt), + checkRequired("error", error), + checkRequired("expiresAt", expiresAt), + checkRequired("model", model), + object_, + checkRequired("progress", progress), + checkRequired("remixedFromVideoId", remixedFromVideoId), + checkRequired("seconds", seconds), + checkRequired("size", size), + checkRequired("status", status), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Video = apply { + if (validated) { + return@apply + } + + id() + completedAt() + createdAt() + error().ifPresent { it.validate() } + expiresAt() + model().validate() + _object_().let { + if (it != JsonValue.from("video")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + progress() + remixedFromVideoId() + seconds().validate() + size().validate() + status().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 = + (if (id.asKnown().isPresent) 1 else 0) + + (if (completedAt.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (error.asKnown().getOrNull()?.validity() ?: 0) + + (if (expiresAt.asKnown().isPresent) 1 else 0) + + (model.asKnown().getOrNull()?.validity() ?: 0) + + object_.let { if (it == JsonValue.from("video")) 1 else 0 } + + (if (progress.asKnown().isPresent) 1 else 0) + + (if (remixedFromVideoId.asKnown().isPresent) 1 else 0) + + (seconds.asKnown().getOrNull()?.validity() ?: 0) + + (size.asKnown().getOrNull()?.validity() ?: 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + /** Current lifecycle status of the video job. */ + class Status @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 QUEUED = of("queued") + + @JvmField val IN_PROGRESS = of("in_progress") + + @JvmField val COMPLETED = of("completed") + + @JvmField val FAILED = of("failed") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + QUEUED, + IN_PROGRESS, + COMPLETED, + FAILED, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] 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 { + QUEUED, + IN_PROGRESS, + COMPLETED, + FAILED, + /** An enum member indicating that [Status] 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) { + QUEUED -> Value.QUEUED + IN_PROGRESS -> Value.IN_PROGRESS + COMPLETED -> Value.COMPLETED + FAILED -> Value.FAILED + 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) { + QUEUED -> Known.QUEUED + IN_PROGRESS -> Known.IN_PROGRESS + COMPLETED -> Known.COMPLETED + FAILED -> Known.FAILED + else -> throw OpenAIInvalidDataException("Unknown Status: $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(): Status = 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 Status && 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 Video && + id == other.id && + completedAt == other.completedAt && + createdAt == other.createdAt && + error == other.error && + expiresAt == other.expiresAt && + model == other.model && + object_ == other.object_ && + progress == other.progress && + remixedFromVideoId == other.remixedFromVideoId && + seconds == other.seconds && + size == other.size && + status == other.status && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + completedAt, + createdAt, + error, + expiresAt, + model, + object_, + progress, + remixedFromVideoId, + seconds, + size, + status, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Video{id=$id, completedAt=$completedAt, createdAt=$createdAt, error=$error, expiresAt=$expiresAt, model=$model, object_=$object_, progress=$progress, remixedFromVideoId=$remixedFromVideoId, seconds=$seconds, size=$size, status=$status, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoCreateError.kt b/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoCreateError.kt new file mode 100644 index 00000000..6c17dcc2 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoCreateError.kt @@ -0,0 +1,204 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.videos + +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 VideoCreateError +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val code: JsonField, + private val message: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("code") @ExcludeMissing code: JsonField = JsonMissing.of(), + @JsonProperty("message") @ExcludeMissing message: JsonField = JsonMissing.of(), + ) : this(code, message, 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 code(): String = code.getRequired("code") + + /** + * @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 message(): String = message.getRequired("message") + + /** + * Returns the raw JSON value of [code]. + * + * Unlike [code], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code + + /** + * Returns the raw JSON value of [message]. + * + * Unlike [message], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("message") @ExcludeMissing fun _message(): JsonField = message + + @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 [VideoCreateError]. + * + * The following fields are required: + * ```java + * .code() + * .message() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VideoCreateError]. */ + class Builder internal constructor() { + + private var code: JsonField? = null + private var message: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(videoCreateError: VideoCreateError) = apply { + code = videoCreateError.code + message = videoCreateError.message + additionalProperties = videoCreateError.additionalProperties.toMutableMap() + } + + fun code(code: String) = code(JsonField.of(code)) + + /** + * Sets [Builder.code] to an arbitrary JSON value. + * + * You should usually call [Builder.code] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun code(code: JsonField) = apply { this.code = code } + + fun message(message: String) = message(JsonField.of(message)) + + /** + * Sets [Builder.message] to an arbitrary JSON value. + * + * You should usually call [Builder.message] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun message(message: JsonField) = apply { this.message = message } + + 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 [VideoCreateError]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .code() + * .message() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VideoCreateError = + VideoCreateError( + checkRequired("code", code), + checkRequired("message", message), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): VideoCreateError = apply { + if (validated) { + return@apply + } + + code() + message() + 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 (code.asKnown().isPresent) 1 else 0) + (if (message.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VideoCreateError && + code == other.code && + message == other.message && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(code, message, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VideoCreateError{code=$code, message=$message, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoCreateParams.kt new file mode 100644 index 00000000..418db36e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoCreateParams.kt @@ -0,0 +1,699 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.videos + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonValue +import com.openai.core.MultipartField +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 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 a video */ +class VideoCreateParams +private constructor( + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** + * Text prompt that describes the video to generate. + * + * @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 prompt(): String = body.prompt() + + /** + * Optional image reference that guides generation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputReference(): Optional = body.inputReference() + + /** + * The video generation model to use. Defaults to `sora-2`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun model(): Optional = body.model() + + /** + * Clip duration in seconds. Defaults to 4 seconds. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun seconds(): Optional = body.seconds() + + /** + * Output resolution formatted as width x height. Defaults to 720x1280. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun size(): Optional = body.size() + + /** + * Returns the raw multipart value of [prompt]. + * + * Unlike [prompt], this method doesn't throw if the multipart field has an unexpected type. + */ + fun _prompt(): MultipartField = body._prompt() + + /** + * Returns the raw multipart value of [inputReference]. + * + * Unlike [inputReference], this method doesn't throw if the multipart field has an unexpected + * type. + */ + fun _inputReference(): MultipartField = body._inputReference() + + /** + * Returns the raw multipart value of [model]. + * + * Unlike [model], this method doesn't throw if the multipart field has an unexpected type. + */ + fun _model(): MultipartField = body._model() + + /** + * Returns the raw multipart value of [seconds]. + * + * Unlike [seconds], this method doesn't throw if the multipart field has an unexpected type. + */ + fun _seconds(): MultipartField = body._seconds() + + /** + * Returns the raw multipart value of [size]. + * + * Unlike [size], this method doesn't throw if the multipart field has an unexpected type. + */ + fun _size(): MultipartField = body._size() + + 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 [VideoCreateParams]. + * + * The following fields are required: + * ```java + * .prompt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VideoCreateParams]. */ + 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(videoCreateParams: VideoCreateParams) = apply { + body = videoCreateParams.body.toBuilder() + additionalHeaders = videoCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = videoCreateParams.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: + * - [prompt] + * - [inputReference] + * - [model] + * - [seconds] + * - [size] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** Text prompt that describes the video to generate. */ + fun prompt(prompt: String) = apply { body.prompt(prompt) } + + /** + * Sets [Builder.prompt] to an arbitrary multipart value. + * + * You should usually call [Builder.prompt] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun prompt(prompt: MultipartField) = apply { body.prompt(prompt) } + + /** Optional image reference that guides generation. */ + fun inputReference(inputReference: InputStream) = apply { + body.inputReference(inputReference) + } + + /** + * Sets [Builder.inputReference] to an arbitrary multipart value. + * + * You should usually call [Builder.inputReference] with a well-typed [InputStream] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun inputReference(inputReference: MultipartField) = apply { + body.inputReference(inputReference) + } + + /** Optional image reference that guides generation. */ + fun inputReference(inputReference: ByteArray) = apply { + body.inputReference(inputReference) + } + + /** Optional image reference that guides generation. */ + fun inputReference(path: Path) = apply { body.inputReference(path) } + + /** The video generation model to use. Defaults to `sora-2`. */ + fun model(model: VideoModel) = apply { body.model(model) } + + /** + * Sets [Builder.model] to an arbitrary multipart value. + * + * You should usually call [Builder.model] with a well-typed [VideoModel] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun model(model: MultipartField) = apply { body.model(model) } + + /** Clip duration in seconds. Defaults to 4 seconds. */ + fun seconds(seconds: VideoSeconds) = apply { body.seconds(seconds) } + + /** + * Sets [Builder.seconds] to an arbitrary multipart value. + * + * You should usually call [Builder.seconds] with a well-typed [VideoSeconds] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun seconds(seconds: MultipartField) = apply { body.seconds(seconds) } + + /** Output resolution formatted as width x height. Defaults to 720x1280. */ + fun size(size: VideoSize) = apply { body.size(size) } + + /** + * Sets [Builder.size] to an arbitrary multipart value. + * + * You should usually call [Builder.size] with a well-typed [VideoSize] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun size(size: MultipartField) = apply { body.size(size) } + + 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 [VideoCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .prompt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VideoCreateParams = + VideoCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Map> = + (mapOf( + "prompt" to _prompt(), + "input_reference" to _inputReference(), + "model" to _model(), + "seconds" to _seconds(), + "size" to _size(), + ) + _additionalBodyProperties().mapValues { (_, value) -> MultipartField.of(value) }) + .toImmutable() + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Parameters for creating a new video generation job. */ + class Body + private constructor( + private val prompt: MultipartField, + private val inputReference: MultipartField, + private val model: MultipartField, + private val seconds: MultipartField, + private val size: MultipartField, + private val additionalProperties: MutableMap, + ) { + + /** + * Text prompt that describes the video to generate. + * + * @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 prompt(): String = prompt.value.getRequired("prompt") + + /** + * Optional image reference that guides generation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputReference(): Optional = + inputReference.value.getOptional("input_reference") + + /** + * The video generation model to use. Defaults to `sora-2`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun model(): Optional = model.value.getOptional("model") + + /** + * Clip duration in seconds. Defaults to 4 seconds. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun seconds(): Optional = seconds.value.getOptional("seconds") + + /** + * Output resolution formatted as width x height. Defaults to 720x1280. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun size(): Optional = size.value.getOptional("size") + + /** + * Returns the raw multipart value of [prompt]. + * + * Unlike [prompt], this method doesn't throw if the multipart field has an unexpected type. + */ + @JsonProperty("prompt") @ExcludeMissing fun _prompt(): MultipartField = prompt + + /** + * Returns the raw multipart value of [inputReference]. + * + * Unlike [inputReference], this method doesn't throw if the multipart field has an + * unexpected type. + */ + @JsonProperty("input_reference") + @ExcludeMissing + fun _inputReference(): MultipartField = inputReference + + /** + * Returns the raw multipart value of [model]. + * + * Unlike [model], this method doesn't throw if the multipart field has an unexpected type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): MultipartField = model + + /** + * Returns the raw multipart value of [seconds]. + * + * Unlike [seconds], this method doesn't throw if the multipart field has an unexpected + * type. + */ + @JsonProperty("seconds") + @ExcludeMissing + fun _seconds(): MultipartField = seconds + + /** + * Returns the raw multipart value of [size]. + * + * Unlike [size], this method doesn't throw if the multipart field has an unexpected type. + */ + @JsonProperty("size") @ExcludeMissing fun _size(): MultipartField = size + + @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 + * .prompt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var prompt: MultipartField? = null + private var inputReference: MultipartField = MultipartField.of(null) + private var model: MultipartField = MultipartField.of(null) + private var seconds: MultipartField = MultipartField.of(null) + private var size: MultipartField = MultipartField.of(null) + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + prompt = body.prompt + inputReference = body.inputReference + model = body.model + seconds = body.seconds + size = body.size + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Text prompt that describes the video to generate. */ + fun prompt(prompt: String) = prompt(MultipartField.of(prompt)) + + /** + * Sets [Builder.prompt] to an arbitrary multipart value. + * + * You should usually call [Builder.prompt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prompt(prompt: MultipartField) = apply { this.prompt = prompt } + + /** Optional image reference that guides generation. */ + fun inputReference(inputReference: InputStream) = + inputReference(MultipartField.of(inputReference)) + + /** + * Sets [Builder.inputReference] to an arbitrary multipart value. + * + * You should usually call [Builder.inputReference] with a well-typed [InputStream] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun inputReference(inputReference: MultipartField) = apply { + this.inputReference = inputReference + } + + /** Optional image reference that guides generation. */ + fun inputReference(inputReference: ByteArray) = + inputReference(inputReference.inputStream()) + + /** Optional image reference that guides generation. */ + fun inputReference(path: Path) = + inputReference( + MultipartField.builder() + .value(path.inputStream()) + .filename(path.name) + .build() + ) + + /** The video generation model to use. Defaults to `sora-2`. */ + fun model(model: VideoModel) = model(MultipartField.of(model)) + + /** + * Sets [Builder.model] to an arbitrary multipart value. + * + * You should usually call [Builder.model] with a well-typed [VideoModel] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun model(model: MultipartField) = apply { this.model = model } + + /** Clip duration in seconds. Defaults to 4 seconds. */ + fun seconds(seconds: VideoSeconds) = seconds(MultipartField.of(seconds)) + + /** + * Sets [Builder.seconds] to an arbitrary multipart value. + * + * You should usually call [Builder.seconds] with a well-typed [VideoSeconds] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun seconds(seconds: MultipartField) = apply { this.seconds = seconds } + + /** Output resolution formatted as width x height. Defaults to 720x1280. */ + fun size(size: VideoSize) = size(MultipartField.of(size)) + + /** + * Sets [Builder.size] to an arbitrary multipart value. + * + * You should usually call [Builder.size] with a well-typed [VideoSize] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun size(size: MultipartField) = apply { this.size = size } + + 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 + * .prompt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("prompt", prompt), + inputReference, + model, + seconds, + size, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + prompt() + inputReference() + model().ifPresent { it.validate() } + seconds().ifPresent { it.validate() } + size().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 && + prompt == other.prompt && + inputReference == other.inputReference && + model == other.model && + seconds == other.seconds && + size == other.size && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(prompt, inputReference, model, seconds, size, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{prompt=$prompt, inputReference=$inputReference, model=$model, seconds=$seconds, size=$size, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VideoCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "VideoCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoDeleteParams.kt new file mode 100644 index 00000000..a1c5e19b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoDeleteParams.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.videos + +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 a video */ +class VideoDeleteParams +private constructor( + private val videoId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun videoId(): Optional = Optional.ofNullable(videoId) + + /** 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(): VideoDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [VideoDeleteParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VideoDeleteParams]. */ + class Builder internal constructor() { + + private var videoId: 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(videoDeleteParams: VideoDeleteParams) = apply { + videoId = videoDeleteParams.videoId + additionalHeaders = videoDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = videoDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = videoDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun videoId(videoId: String?) = apply { this.videoId = videoId } + + /** Alias for calling [Builder.videoId] with `videoId.orElse(null)`. */ + fun videoId(videoId: Optional) = videoId(videoId.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 [VideoDeleteParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): VideoDeleteParams = + VideoDeleteParams( + videoId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> videoId ?: "" + 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 VideoDeleteParams && + videoId == other.videoId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash(videoId, additionalHeaders, additionalQueryParams, additionalBodyProperties) + + override fun toString() = + "VideoDeleteParams{videoId=$videoId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoDeleteResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoDeleteResponse.kt new file mode 100644 index 00000000..700aad62 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoDeleteResponse.kt @@ -0,0 +1,251 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.videos + +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 + +/** Confirmation payload returned after deleting a video. */ +class VideoDeleteResponse +@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()) + + /** + * Identifier of the deleted video. + * + * @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") + + /** + * Indicates that the video resource was deleted. + * + * @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") + + /** + * The object type that signals the deletion response. + * + * Expected to always return the following: + * ```java + * JsonValue.from("video.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 [VideoDeleteResponse]. + * + * The following fields are required: + * ```java + * .id() + * .deleted() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VideoDeleteResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var deleted: JsonField? = null + private var object_: JsonValue = JsonValue.from("video.deleted") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(videoDeleteResponse: VideoDeleteResponse) = apply { + id = videoDeleteResponse.id + deleted = videoDeleteResponse.deleted + object_ = videoDeleteResponse.object_ + additionalProperties = videoDeleteResponse.additionalProperties.toMutableMap() + } + + /** Identifier of the deleted video. */ + 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 } + + /** Indicates that the video resource was deleted. */ + 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("video.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 [VideoDeleteResponse]. + * + * 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(): VideoDeleteResponse = + VideoDeleteResponse( + checkRequired("id", id), + checkRequired("deleted", deleted), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): VideoDeleteResponse = apply { + if (validated) { + return@apply + } + + id() + deleted() + _object_().let { + if (it != JsonValue.from("video.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("video.deleted")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VideoDeleteResponse && + 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() = + "VideoDeleteResponse{id=$id, deleted=$deleted, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoDownloadContentParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoDownloadContentParams.kt new file mode 100644 index 00000000..9749eeb9 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoDownloadContentParams.kt @@ -0,0 +1,352 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.videos + +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 + +/** Download video content */ +class VideoDownloadContentParams +private constructor( + private val videoId: String?, + private val variant: Variant?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun videoId(): Optional = Optional.ofNullable(videoId) + + /** Which downloadable asset to return. Defaults to the MP4 video. */ + fun variant(): Optional = Optional.ofNullable(variant) + + /** 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(): VideoDownloadContentParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of [VideoDownloadContentParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VideoDownloadContentParams]. */ + class Builder internal constructor() { + + private var videoId: String? = null + private var variant: Variant? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(videoDownloadContentParams: VideoDownloadContentParams) = apply { + videoId = videoDownloadContentParams.videoId + variant = videoDownloadContentParams.variant + additionalHeaders = videoDownloadContentParams.additionalHeaders.toBuilder() + additionalQueryParams = videoDownloadContentParams.additionalQueryParams.toBuilder() + } + + fun videoId(videoId: String?) = apply { this.videoId = videoId } + + /** Alias for calling [Builder.videoId] with `videoId.orElse(null)`. */ + fun videoId(videoId: Optional) = videoId(videoId.getOrNull()) + + /** Which downloadable asset to return. Defaults to the MP4 video. */ + fun variant(variant: Variant?) = apply { this.variant = variant } + + /** Alias for calling [Builder.variant] with `variant.orElse(null)`. */ + fun variant(variant: Optional) = variant(variant.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 [VideoDownloadContentParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): VideoDownloadContentParams = + VideoDownloadContentParams( + videoId, + variant, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> videoId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + variant?.let { put("variant", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + /** Which downloadable asset to return. Defaults to the MP4 video. */ + class Variant @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 VIDEO = of("video") + + @JvmField val THUMBNAIL = of("thumbnail") + + @JvmField val SPRITESHEET = of("spritesheet") + + @JvmStatic fun of(value: String) = Variant(JsonField.of(value)) + } + + /** An enum containing [Variant]'s known values. */ + enum class Known { + VIDEO, + THUMBNAIL, + SPRITESHEET, + } + + /** + * An enum containing [Variant]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Variant] 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 { + VIDEO, + THUMBNAIL, + SPRITESHEET, + /** An enum member indicating that [Variant] 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) { + VIDEO -> Value.VIDEO + THUMBNAIL -> Value.THUMBNAIL + SPRITESHEET -> Value.SPRITESHEET + 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) { + VIDEO -> Known.VIDEO + THUMBNAIL -> Known.THUMBNAIL + SPRITESHEET -> Known.SPRITESHEET + else -> throw OpenAIInvalidDataException("Unknown Variant: $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(): Variant = 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 Variant && 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 VideoDownloadContentParams && + videoId == other.videoId && + variant == other.variant && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(videoId, variant, additionalHeaders, additionalQueryParams) + + override fun toString() = + "VideoDownloadContentParams{videoId=$videoId, variant=$variant, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoListPage.kt new file mode 100644 index 00000000..c82994ba --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/videos/VideoListPage.kt @@ -0,0 +1,137 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.videos + +import com.openai.core.AutoPager +import com.openai.core.Page +import com.openai.core.checkRequired +import com.openai.services.blocking.VideoService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see VideoService.list */ +class VideoListPage +private constructor( + private val service: VideoService, + private val params: VideoListParams, + private val response: VideoListPageResponse, +) : Page