From 3f3c1fa68b001bf721eceefe6f34ad4384662294 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 9 Jun 2026 21:01:19 +0000 Subject: [PATCH] feat: [STG-2090] Add Azure Entra model auth support --- .stats.yml | 4 +- .../api/models/sessions/ModelConfig.kt | 2551 ++++- .../api/models/sessions/SessionActParams.kt | 2716 ++++- .../models/sessions/SessionExecuteParams.kt | 8806 +++++++++++++---- .../models/sessions/SessionExtractParams.kt | 2716 ++++- .../models/sessions/SessionObserveParams.kt | 2716 ++++- .../api/models/sessions/ModelConfigTest.kt | 181 + 7 files changed, 18003 insertions(+), 1687 deletions(-) diff --git a/.stats.yml b/.stats.yml index 15099ca..90ce078 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 8 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase/stagehand-c7910965e66e73ad8b65b6cc391d431094b2a6c6577c3e9d82feaa8138e74cff.yml -openapi_spec_hash: 37748bb69c22a9ce721d9b5a5861f964 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase/stagehand-4d0d50b4f18fd74f58aca0b84d6968d1228499f2fa4e5714516f13ff6f820c9d.yml +openapi_spec_hash: f7b1a869f3e412aea4d4bd42467791bb config_hash: 1fb12ae9b478488bc1e56bfbdc210b01 diff --git a/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/ModelConfig.kt b/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/ModelConfig.kt index b6cc034..6fdf433 100644 --- a/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/ModelConfig.kt +++ b/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/ModelConfig.kt @@ -35,6 +35,8 @@ import kotlin.jvm.optionals.getOrNull class ModelConfig private constructor( private val vertexModelConfigObject: VertexModelConfigObject? = null, + private val azureEntraModelConfigObject: AzureEntraModelConfigObject? = null, + private val azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject? = null, private val genericModelConfigObject: GenericModelConfigObject? = null, private val _json: JsonValue? = null, ) { @@ -42,16 +44,32 @@ private constructor( fun vertexModelConfigObject(): Optional = Optional.ofNullable(vertexModelConfigObject) + fun azureEntraModelConfigObject(): Optional = + Optional.ofNullable(azureEntraModelConfigObject) + + fun azureApiKeyModelConfigObject(): Optional = + Optional.ofNullable(azureApiKeyModelConfigObject) + fun genericModelConfigObject(): Optional = Optional.ofNullable(genericModelConfigObject) fun isVertexModelConfigObject(): Boolean = vertexModelConfigObject != null + fun isAzureEntraModelConfigObject(): Boolean = azureEntraModelConfigObject != null + + fun isAzureApiKeyModelConfigObject(): Boolean = azureApiKeyModelConfigObject != null + fun isGenericModelConfigObject(): Boolean = genericModelConfigObject != null fun asVertexModelConfigObject(): VertexModelConfigObject = vertexModelConfigObject.getOrThrow("vertexModelConfigObject") + fun asAzureEntraModelConfigObject(): AzureEntraModelConfigObject = + azureEntraModelConfigObject.getOrThrow("azureEntraModelConfigObject") + + fun asAzureApiKeyModelConfigObject(): AzureApiKeyModelConfigObject = + azureApiKeyModelConfigObject.getOrThrow("azureApiKeyModelConfigObject") + fun asGenericModelConfigObject(): GenericModelConfigObject = genericModelConfigObject.getOrThrow("genericModelConfigObject") @@ -90,6 +108,10 @@ private constructor( when { vertexModelConfigObject != null -> visitor.visitVertexModelConfigObject(vertexModelConfigObject) + azureEntraModelConfigObject != null -> + visitor.visitAzureEntraModelConfigObject(azureEntraModelConfigObject) + azureApiKeyModelConfigObject != null -> + visitor.visitAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject) genericModelConfigObject != null -> visitor.visitGenericModelConfigObject(genericModelConfigObject) else -> visitor.unknown(_json) @@ -118,6 +140,18 @@ private constructor( vertexModelConfigObject.validate() } + override fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) { + azureEntraModelConfigObject.validate() + } + + override fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) { + azureApiKeyModelConfigObject.validate() + } + override fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ) { @@ -149,6 +183,14 @@ private constructor( vertexModelConfigObject: VertexModelConfigObject ) = vertexModelConfigObject.validity() + override fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) = azureEntraModelConfigObject.validity() + + override fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) = azureApiKeyModelConfigObject.validity() + override fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ) = genericModelConfigObject.validity() @@ -164,15 +206,27 @@ private constructor( return other is ModelConfig && vertexModelConfigObject == other.vertexModelConfigObject && + azureEntraModelConfigObject == other.azureEntraModelConfigObject && + azureApiKeyModelConfigObject == other.azureApiKeyModelConfigObject && genericModelConfigObject == other.genericModelConfigObject } - override fun hashCode(): Int = Objects.hash(vertexModelConfigObject, genericModelConfigObject) + override fun hashCode(): Int = + Objects.hash( + vertexModelConfigObject, + azureEntraModelConfigObject, + azureApiKeyModelConfigObject, + genericModelConfigObject, + ) override fun toString(): String = when { vertexModelConfigObject != null -> "ModelConfig{vertexModelConfigObject=$vertexModelConfigObject}" + azureEntraModelConfigObject != null -> + "ModelConfig{azureEntraModelConfigObject=$azureEntraModelConfigObject}" + azureApiKeyModelConfigObject != null -> + "ModelConfig{azureApiKeyModelConfigObject=$azureApiKeyModelConfigObject}" genericModelConfigObject != null -> "ModelConfig{genericModelConfigObject=$genericModelConfigObject}" _json != null -> "ModelConfig{_unknown=$_json}" @@ -185,6 +239,16 @@ private constructor( fun ofVertexModelConfigObject(vertexModelConfigObject: VertexModelConfigObject) = ModelConfig(vertexModelConfigObject = vertexModelConfigObject) + @JvmStatic + fun ofAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) = ModelConfig(azureEntraModelConfigObject = azureEntraModelConfigObject) + + @JvmStatic + fun ofAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) = ModelConfig(azureApiKeyModelConfigObject = azureApiKeyModelConfigObject) + @JvmStatic fun ofGenericModelConfigObject(genericModelConfigObject: GenericModelConfigObject) = ModelConfig(genericModelConfigObject = genericModelConfigObject) @@ -197,6 +261,14 @@ private constructor( fun visitVertexModelConfigObject(vertexModelConfigObject: VertexModelConfigObject): T + fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ): T + + fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ): T + fun visitGenericModelConfigObject(genericModelConfigObject: GenericModelConfigObject): T /** @@ -223,6 +295,12 @@ private constructor( tryDeserialize(node, jacksonTypeRef())?.let { ModelConfig(vertexModelConfigObject = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef())?.let { + ModelConfig(azureEntraModelConfigObject = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + ModelConfig(azureApiKeyModelConfigObject = it, _json = json) + }, tryDeserialize(node, jacksonTypeRef())?.let { ModelConfig(genericModelConfigObject = it, _json = json) }, @@ -252,6 +330,10 @@ private constructor( when { value.vertexModelConfigObject != null -> generator.writeObject(value.vertexModelConfigObject) + value.azureEntraModelConfigObject != null -> + generator.writeObject(value.azureEntraModelConfigObject) + value.azureApiKeyModelConfigObject != null -> + generator.writeObject(value.azureApiKeyModelConfigObject) value.genericModelConfigObject != null -> generator.writeObject(value.genericModelConfigObject) value._json != null -> generator.writeObject(value._json) @@ -2689,6 +2771,2473 @@ private constructor( "VertexModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" } + class AzureEntraModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val auth: JsonField, + private val modelName: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("auth") @ExcludeMissing auth: JsonField = JsonMissing.of(), + @JsonProperty("modelName") + @ExcludeMissing + modelName: JsonField = JsonMissing.of(), + @JsonProperty("provider") @ExcludeMissing provider: JsonValue = JsonMissing.of(), + @JsonProperty("providerOptions") + @ExcludeMissing + providerOptions: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") @ExcludeMissing baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") @ExcludeMissing headers: JsonField = JsonMissing.of(), + ) : this(auth, modelName, provider, providerOptions, baseUrl, headers, mutableMapOf()) + + /** + * Azure provider authentication configuration + * + * @throws StagehandInvalidDataException 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 auth(): Auth = auth.getRequired("auth") + + /** + * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') + * + * @throws StagehandInvalidDataException 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 modelName(): String = modelName.getRequired("modelName") + + /** + * Azure OpenAI model provider + * + * Expected to always return the following: + * ```java + * JsonValue.from("azure") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider + + /** + * Azure provider-specific model configuration + * + * @throws StagehandInvalidDataException 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 providerOptions(): ProviderOptions = providerOptions.getRequired("providerOptions") + + /** + * Base URL for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Returns the raw JSON value of [auth]. + * + * Unlike [auth], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("auth") @ExcludeMissing fun _auth(): JsonField = auth + + /** + * Returns the raw JSON value of [modelName]. + * + * Unlike [modelName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("modelName") @ExcludeMissing fun _modelName(): JsonField = modelName + + /** + * Returns the raw JSON value of [providerOptions]. + * + * Unlike [providerOptions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("providerOptions") + @ExcludeMissing + fun _providerOptions(): JsonField = providerOptions + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("headers") @ExcludeMissing fun _headers(): JsonField = headers + + @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 + * [AzureEntraModelConfigObject]. + * + * The following fields are required: + * ```java + * .auth() + * .modelName() + * .providerOptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AzureEntraModelConfigObject]. */ + class Builder internal constructor() { + + private var auth: JsonField? = null + private var modelName: JsonField? = null + private var provider: JsonValue = JsonValue.from("azure") + private var providerOptions: JsonField? = null + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(azureEntraModelConfigObject: AzureEntraModelConfigObject) = apply { + auth = azureEntraModelConfigObject.auth + modelName = azureEntraModelConfigObject.modelName + provider = azureEntraModelConfigObject.provider + providerOptions = azureEntraModelConfigObject.providerOptions + baseUrl = azureEntraModelConfigObject.baseUrl + headers = azureEntraModelConfigObject.headers + additionalProperties = + azureEntraModelConfigObject.additionalProperties.toMutableMap() + } + + /** Azure provider authentication configuration */ + fun auth(auth: Auth) = auth(JsonField.of(auth)) + + /** + * Sets [Builder.auth] to an arbitrary JSON value. + * + * You should usually call [Builder.auth] with a well-typed [Auth] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun auth(auth: JsonField) = apply { this.auth = auth } + + /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ + fun modelName(modelName: String) = modelName(JsonField.of(modelName)) + + /** + * Sets [Builder.modelName] to an arbitrary JSON value. + * + * You should usually call [Builder.modelName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelName(modelName: JsonField) = apply { this.modelName = modelName } + + /** + * 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("azure") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun provider(provider: JsonValue) = apply { this.provider = provider } + + /** Azure provider-specific model configuration */ + fun providerOptions(providerOptions: ProviderOptions) = + providerOptions(JsonField.of(providerOptions)) + + /** + * Sets [Builder.providerOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.providerOptions] with a well-typed [ProviderOptions] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun providerOptions(providerOptions: JsonField) = apply { + this.providerOptions = providerOptions + } + + /** Base URL for the model provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the model provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + 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 [AzureEntraModelConfigObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .auth() + * .modelName() + * .providerOptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AzureEntraModelConfigObject = + AzureEntraModelConfigObject( + checkRequired("auth", auth), + checkRequired("modelName", modelName), + provider, + checkRequired("providerOptions", providerOptions), + baseUrl, + headers, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AzureEntraModelConfigObject = apply { + if (validated) { + return@apply + } + + auth().validate() + modelName() + _provider().let { + if (it != JsonValue.from("azure")) { + throw StagehandInvalidDataException("'provider' is invalid, received $it") + } + } + providerOptions().validate() + baseUrl() + headers().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = + (auth.asKnown().getOrNull()?.validity() ?: 0) + + (if (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("azure")) 1 else 0 } + + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure provider authentication configuration */ + class Auth + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val token: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("token") @ExcludeMissing token: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(token, type, mutableMapOf()) + + /** + * Microsoft Entra ID bearer token for Azure OpenAI + * + * @throws StagehandInvalidDataException 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 token(): String = token.getRequired("token") + + /** + * Use a Microsoft Entra ID bearer token for authentication + * + * Expected to always return the following: + * ```java + * JsonValue.from("azureEntraId") + * ``` + * + * 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 [token]. + * + * Unlike [token], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("token") @ExcludeMissing fun _token(): JsonField = token + + @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 [Auth]. + * + * The following fields are required: + * ```java + * .token() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Auth]. */ + class Builder internal constructor() { + + private var token: JsonField? = null + private var type: JsonValue = JsonValue.from("azureEntraId") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(auth: Auth) = apply { + token = auth.token + type = auth.type + additionalProperties = auth.additionalProperties.toMutableMap() + } + + /** Microsoft Entra ID bearer token for Azure OpenAI */ + fun token(token: String) = token(JsonField.of(token)) + + /** + * Sets [Builder.token] to an arbitrary JSON value. + * + * You should usually call [Builder.token] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun token(token: JsonField) = apply { this.token = token } + + /** + * 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("azureEntraId") + * ``` + * + * 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 [Auth]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .token() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Auth = + Auth(checkRequired("token", token), type, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Auth = apply { + if (validated) { + return@apply + } + + token() + _type().let { + if (it != JsonValue.from("azureEntraId")) { + throw StagehandInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (token.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("azureEntraId")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auth && + token == other.token && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(token, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Auth{token=$token, type=$type, additionalProperties=$additionalProperties}" + } + + /** Azure provider-specific model configuration */ + class ProviderOptions + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val azure: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("azure") @ExcludeMissing azure: JsonField = JsonMissing.of() + ) : this(azure, mutableMapOf()) + + /** + * Azure OpenAI provider-specific settings + * + * @throws StagehandInvalidDataException 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 azure(): Azure = azure.getRequired("azure") + + /** + * Returns the raw JSON value of [azure]. + * + * Unlike [azure], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("azure") @ExcludeMissing fun _azure(): JsonField = azure + + @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 [ProviderOptions]. + * + * The following fields are required: + * ```java + * .azure() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProviderOptions]. */ + class Builder internal constructor() { + + private var azure: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(providerOptions: ProviderOptions) = apply { + azure = providerOptions.azure + additionalProperties = providerOptions.additionalProperties.toMutableMap() + } + + /** Azure OpenAI provider-specific settings */ + fun azure(azure: Azure) = azure(JsonField.of(azure)) + + /** + * Sets [Builder.azure] to an arbitrary JSON value. + * + * You should usually call [Builder.azure] with a well-typed [Azure] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun azure(azure: JsonField) = apply { this.azure = azure } + + 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 [ProviderOptions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .azure() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProviderOptions = + ProviderOptions( + checkRequired("azure", azure), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ProviderOptions = apply { + if (validated) { + return@apply + } + + azure().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = (azure.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure OpenAI provider-specific settings */ + class Azure + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val apiVersion: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val resourceName: JsonField, + private val useDeploymentBasedUrls: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("apiVersion") + @ExcludeMissing + apiVersion: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + @JsonProperty("resourceName") + @ExcludeMissing + resourceName: JsonField = JsonMissing.of(), + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + useDeploymentBasedUrls: JsonField = JsonMissing.of(), + ) : this( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + mutableMapOf(), + ) + + /** + * Azure OpenAI API version + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun apiVersion(): Optional = apiVersion.getOptional("apiVersion") + + /** + * Base URL for the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Azure OpenAI resource name + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun resourceName(): Optional = resourceName.getOptional("resourceName") + + /** + * Whether to use deployment-based Azure OpenAI URLs + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun useDeploymentBasedUrls(): Optional = + useDeploymentBasedUrls.getOptional("useDeploymentBasedUrls") + + /** + * Returns the raw JSON value of [apiVersion]. + * + * Unlike [apiVersion], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("apiVersion") + @ExcludeMissing + fun _apiVersion(): JsonField = apiVersion + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + /** + * Returns the raw JSON value of [resourceName]. + * + * Unlike [resourceName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("resourceName") + @ExcludeMissing + fun _resourceName(): JsonField = resourceName + + /** + * Returns the raw JSON value of [useDeploymentBasedUrls]. + * + * Unlike [useDeploymentBasedUrls], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + fun _useDeploymentBasedUrls(): JsonField = useDeploymentBasedUrls + + @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 [Azure]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Azure]. */ + class Builder internal constructor() { + + private var apiVersion: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var resourceName: JsonField = JsonMissing.of() + private var useDeploymentBasedUrls: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(azure: Azure) = apply { + apiVersion = azure.apiVersion + baseUrl = azure.baseUrl + headers = azure.headers + resourceName = azure.resourceName + useDeploymentBasedUrls = azure.useDeploymentBasedUrls + additionalProperties = azure.additionalProperties.toMutableMap() + } + + /** Azure OpenAI API version */ + fun apiVersion(apiVersion: String) = apiVersion(JsonField.of(apiVersion)) + + /** + * Sets [Builder.apiVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.apiVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiVersion(apiVersion: JsonField) = apply { + this.apiVersion = apiVersion + } + + /** Base URL for the Azure OpenAI provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the Azure OpenAI provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + /** Azure OpenAI resource name */ + fun resourceName(resourceName: String) = + resourceName(JsonField.of(resourceName)) + + /** + * Sets [Builder.resourceName] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceName] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun resourceName(resourceName: JsonField) = apply { + this.resourceName = resourceName + } + + /** Whether to use deployment-based Azure OpenAI URLs */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: Boolean) = + useDeploymentBasedUrls(JsonField.of(useDeploymentBasedUrls)) + + /** + * Sets [Builder.useDeploymentBasedUrls] to an arbitrary JSON value. + * + * You should usually call [Builder.useDeploymentBasedUrls] with a well-typed + * [Boolean] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: JsonField) = apply { + this.useDeploymentBasedUrls = useDeploymentBasedUrls + } + + 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 [Azure]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Azure = + Azure( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Azure = apply { + if (validated) { + return@apply + } + + apiVersion() + baseUrl() + headers().ifPresent { it.validate() } + resourceName() + useDeploymentBasedUrls() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (apiVersion.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceName.asKnown().isPresent) 1 else 0) + + (if (useDeploymentBasedUrls.asKnown().isPresent) 1 else 0) + + /** Custom headers sent with every request to the Azure OpenAI provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Azure && + apiVersion == other.apiVersion && + baseUrl == other.baseUrl && + headers == other.headers && + resourceName == other.resourceName && + useDeploymentBasedUrls == other.useDeploymentBasedUrls && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Azure{apiVersion=$apiVersion, baseUrl=$baseUrl, headers=$headers, resourceName=$resourceName, useDeploymentBasedUrls=$useDeploymentBasedUrls, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProviderOptions && + azure == other.azure && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(azure, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProviderOptions{azure=$azure, additionalProperties=$additionalProperties}" + } + + /** Custom headers sent with every request to the model provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AzureEntraModelConfigObject && + auth == other.auth && + modelName == other.modelName && + provider == other.provider && + providerOptions == other.providerOptions && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + auth, + modelName, + provider, + providerOptions, + baseUrl, + headers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AzureEntraModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + + class AzureApiKeyModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val modelName: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, + private val apiKey: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("modelName") + @ExcludeMissing + modelName: JsonField = JsonMissing.of(), + @JsonProperty("provider") @ExcludeMissing provider: JsonValue = JsonMissing.of(), + @JsonProperty("providerOptions") + @ExcludeMissing + providerOptions: JsonField = JsonMissing.of(), + @JsonProperty("apiKey") @ExcludeMissing apiKey: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") @ExcludeMissing baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") @ExcludeMissing headers: JsonField = JsonMissing.of(), + ) : this(modelName, provider, providerOptions, apiKey, baseUrl, headers, mutableMapOf()) + + /** + * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') + * + * @throws StagehandInvalidDataException 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 modelName(): String = modelName.getRequired("modelName") + + /** + * Azure OpenAI model provider + * + * Expected to always return the following: + * ```java + * JsonValue.from("azure") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider + + /** + * Azure provider-specific model configuration + * + * @throws StagehandInvalidDataException 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 providerOptions(): ProviderOptions = providerOptions.getRequired("providerOptions") + + /** + * API key for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun apiKey(): Optional = apiKey.getOptional("apiKey") + + /** + * Base URL for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Returns the raw JSON value of [modelName]. + * + * Unlike [modelName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("modelName") @ExcludeMissing fun _modelName(): JsonField = modelName + + /** + * Returns the raw JSON value of [providerOptions]. + * + * Unlike [providerOptions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("providerOptions") + @ExcludeMissing + fun _providerOptions(): JsonField = providerOptions + + /** + * Returns the raw JSON value of [apiKey]. + * + * Unlike [apiKey], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("apiKey") @ExcludeMissing fun _apiKey(): JsonField = apiKey + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("headers") @ExcludeMissing fun _headers(): JsonField = headers + + @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 + * [AzureApiKeyModelConfigObject]. + * + * The following fields are required: + * ```java + * .modelName() + * .providerOptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AzureApiKeyModelConfigObject]. */ + class Builder internal constructor() { + + private var modelName: JsonField? = null + private var provider: JsonValue = JsonValue.from("azure") + private var providerOptions: JsonField? = null + private var apiKey: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject) = apply { + modelName = azureApiKeyModelConfigObject.modelName + provider = azureApiKeyModelConfigObject.provider + providerOptions = azureApiKeyModelConfigObject.providerOptions + apiKey = azureApiKeyModelConfigObject.apiKey + baseUrl = azureApiKeyModelConfigObject.baseUrl + headers = azureApiKeyModelConfigObject.headers + additionalProperties = + azureApiKeyModelConfigObject.additionalProperties.toMutableMap() + } + + /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ + fun modelName(modelName: String) = modelName(JsonField.of(modelName)) + + /** + * Sets [Builder.modelName] to an arbitrary JSON value. + * + * You should usually call [Builder.modelName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun modelName(modelName: JsonField) = apply { this.modelName = modelName } + + /** + * 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("azure") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun provider(provider: JsonValue) = apply { this.provider = provider } + + /** Azure provider-specific model configuration */ + fun providerOptions(providerOptions: ProviderOptions) = + providerOptions(JsonField.of(providerOptions)) + + /** + * Sets [Builder.providerOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.providerOptions] with a well-typed [ProviderOptions] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun providerOptions(providerOptions: JsonField) = apply { + this.providerOptions = providerOptions + } + + /** API key for the model provider */ + fun apiKey(apiKey: String) = apiKey(JsonField.of(apiKey)) + + /** + * Sets [Builder.apiKey] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKey] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun apiKey(apiKey: JsonField) = apply { this.apiKey = apiKey } + + /** Base URL for the model provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the model provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + 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 [AzureApiKeyModelConfigObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .modelName() + * .providerOptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AzureApiKeyModelConfigObject = + AzureApiKeyModelConfigObject( + checkRequired("modelName", modelName), + provider, + checkRequired("providerOptions", providerOptions), + apiKey, + baseUrl, + headers, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AzureApiKeyModelConfigObject = apply { + if (validated) { + return@apply + } + + modelName() + _provider().let { + if (it != JsonValue.from("azure")) { + throw StagehandInvalidDataException("'provider' is invalid, received $it") + } + } + providerOptions().validate() + apiKey() + baseUrl() + headers().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("azure")) 1 else 0 } + + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + + (if (apiKey.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure provider-specific model configuration */ + class ProviderOptions + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val azure: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("azure") @ExcludeMissing azure: JsonField = JsonMissing.of() + ) : this(azure, mutableMapOf()) + + /** + * Azure OpenAI provider-specific settings + * + * @throws StagehandInvalidDataException 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 azure(): Azure = azure.getRequired("azure") + + /** + * Returns the raw JSON value of [azure]. + * + * Unlike [azure], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("azure") @ExcludeMissing fun _azure(): JsonField = azure + + @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 [ProviderOptions]. + * + * The following fields are required: + * ```java + * .azure() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProviderOptions]. */ + class Builder internal constructor() { + + private var azure: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(providerOptions: ProviderOptions) = apply { + azure = providerOptions.azure + additionalProperties = providerOptions.additionalProperties.toMutableMap() + } + + /** Azure OpenAI provider-specific settings */ + fun azure(azure: Azure) = azure(JsonField.of(azure)) + + /** + * Sets [Builder.azure] to an arbitrary JSON value. + * + * You should usually call [Builder.azure] with a well-typed [Azure] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun azure(azure: JsonField) = apply { this.azure = azure } + + 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 [ProviderOptions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .azure() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProviderOptions = + ProviderOptions( + checkRequired("azure", azure), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ProviderOptions = apply { + if (validated) { + return@apply + } + + azure().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = (azure.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure OpenAI provider-specific settings */ + class Azure + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val apiVersion: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val resourceName: JsonField, + private val useDeploymentBasedUrls: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("apiVersion") + @ExcludeMissing + apiVersion: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + @JsonProperty("resourceName") + @ExcludeMissing + resourceName: JsonField = JsonMissing.of(), + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + useDeploymentBasedUrls: JsonField = JsonMissing.of(), + ) : this( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + mutableMapOf(), + ) + + /** + * Azure OpenAI API version + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun apiVersion(): Optional = apiVersion.getOptional("apiVersion") + + /** + * Base URL for the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Azure OpenAI resource name + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun resourceName(): Optional = resourceName.getOptional("resourceName") + + /** + * Whether to use deployment-based Azure OpenAI URLs + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun useDeploymentBasedUrls(): Optional = + useDeploymentBasedUrls.getOptional("useDeploymentBasedUrls") + + /** + * Returns the raw JSON value of [apiVersion]. + * + * Unlike [apiVersion], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("apiVersion") + @ExcludeMissing + fun _apiVersion(): JsonField = apiVersion + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + /** + * Returns the raw JSON value of [resourceName]. + * + * Unlike [resourceName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("resourceName") + @ExcludeMissing + fun _resourceName(): JsonField = resourceName + + /** + * Returns the raw JSON value of [useDeploymentBasedUrls]. + * + * Unlike [useDeploymentBasedUrls], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + fun _useDeploymentBasedUrls(): JsonField = useDeploymentBasedUrls + + @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 [Azure]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Azure]. */ + class Builder internal constructor() { + + private var apiVersion: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var resourceName: JsonField = JsonMissing.of() + private var useDeploymentBasedUrls: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(azure: Azure) = apply { + apiVersion = azure.apiVersion + baseUrl = azure.baseUrl + headers = azure.headers + resourceName = azure.resourceName + useDeploymentBasedUrls = azure.useDeploymentBasedUrls + additionalProperties = azure.additionalProperties.toMutableMap() + } + + /** Azure OpenAI API version */ + fun apiVersion(apiVersion: String) = apiVersion(JsonField.of(apiVersion)) + + /** + * Sets [Builder.apiVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.apiVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiVersion(apiVersion: JsonField) = apply { + this.apiVersion = apiVersion + } + + /** Base URL for the Azure OpenAI provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the Azure OpenAI provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + /** Azure OpenAI resource name */ + fun resourceName(resourceName: String) = + resourceName(JsonField.of(resourceName)) + + /** + * Sets [Builder.resourceName] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceName] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun resourceName(resourceName: JsonField) = apply { + this.resourceName = resourceName + } + + /** Whether to use deployment-based Azure OpenAI URLs */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: Boolean) = + useDeploymentBasedUrls(JsonField.of(useDeploymentBasedUrls)) + + /** + * Sets [Builder.useDeploymentBasedUrls] to an arbitrary JSON value. + * + * You should usually call [Builder.useDeploymentBasedUrls] with a well-typed + * [Boolean] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: JsonField) = apply { + this.useDeploymentBasedUrls = useDeploymentBasedUrls + } + + 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 [Azure]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Azure = + Azure( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Azure = apply { + if (validated) { + return@apply + } + + apiVersion() + baseUrl() + headers().ifPresent { it.validate() } + resourceName() + useDeploymentBasedUrls() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (apiVersion.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceName.asKnown().isPresent) 1 else 0) + + (if (useDeploymentBasedUrls.asKnown().isPresent) 1 else 0) + + /** Custom headers sent with every request to the Azure OpenAI provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Azure && + apiVersion == other.apiVersion && + baseUrl == other.baseUrl && + headers == other.headers && + resourceName == other.resourceName && + useDeploymentBasedUrls == other.useDeploymentBasedUrls && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Azure{apiVersion=$apiVersion, baseUrl=$baseUrl, headers=$headers, resourceName=$resourceName, useDeploymentBasedUrls=$useDeploymentBasedUrls, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProviderOptions && + azure == other.azure && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(azure, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProviderOptions{azure=$azure, additionalProperties=$additionalProperties}" + } + + /** Custom headers sent with every request to the model provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AzureApiKeyModelConfigObject && + modelName == other.modelName && + provider == other.provider && + providerOptions == other.providerOptions && + apiKey == other.apiKey && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + modelName, + provider, + providerOptions, + apiKey, + baseUrl, + headers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AzureApiKeyModelConfigObject{modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + class GenericModelConfigObject @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( diff --git a/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionActParams.kt b/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionActParams.kt index 3085f28..27b63b0 100644 --- a/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionActParams.kt +++ b/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionActParams.kt @@ -936,6 +936,20 @@ private constructor( fun model(vertexModelConfigObject: Model.VertexModelConfigObject) = model(Model.ofVertexModelConfigObject(vertexModelConfigObject)) + /** + * Alias for calling [model] with + * `Model.ofAzureEntraModelConfigObject(azureEntraModelConfigObject)`. + */ + fun model(azureEntraModelConfigObject: Model.AzureEntraModelConfigObject) = + model(Model.ofAzureEntraModelConfigObject(azureEntraModelConfigObject)) + + /** + * Alias for calling [model] with + * `Model.ofAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject)`. + */ + fun model(azureApiKeyModelConfigObject: Model.AzureApiKeyModelConfigObject) = + model(Model.ofAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject)) + /** * Alias for calling [model] with * `Model.ofGenericModelConfigObject(genericModelConfigObject)`. @@ -1049,6 +1063,8 @@ private constructor( class Model private constructor( private val vertexModelConfigObject: VertexModelConfigObject? = null, + private val azureEntraModelConfigObject: AzureEntraModelConfigObject? = null, + private val azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject? = null, private val genericModelConfigObject: GenericModelConfigObject? = null, private val string: String? = null, private val _json: JsonValue? = null, @@ -1057,6 +1073,12 @@ private constructor( fun vertexModelConfigObject(): Optional = Optional.ofNullable(vertexModelConfigObject) + fun azureEntraModelConfigObject(): Optional = + Optional.ofNullable(azureEntraModelConfigObject) + + fun azureApiKeyModelConfigObject(): Optional = + Optional.ofNullable(azureApiKeyModelConfigObject) + fun genericModelConfigObject(): Optional = Optional.ofNullable(genericModelConfigObject) @@ -1064,6 +1086,10 @@ private constructor( fun isVertexModelConfigObject(): Boolean = vertexModelConfigObject != null + fun isAzureEntraModelConfigObject(): Boolean = azureEntraModelConfigObject != null + + fun isAzureApiKeyModelConfigObject(): Boolean = azureApiKeyModelConfigObject != null + fun isGenericModelConfigObject(): Boolean = genericModelConfigObject != null fun isString(): Boolean = string != null @@ -1071,6 +1097,12 @@ private constructor( fun asVertexModelConfigObject(): VertexModelConfigObject = vertexModelConfigObject.getOrThrow("vertexModelConfigObject") + fun asAzureEntraModelConfigObject(): AzureEntraModelConfigObject = + azureEntraModelConfigObject.getOrThrow("azureEntraModelConfigObject") + + fun asAzureApiKeyModelConfigObject(): AzureApiKeyModelConfigObject = + azureApiKeyModelConfigObject.getOrThrow("azureApiKeyModelConfigObject") + fun asGenericModelConfigObject(): GenericModelConfigObject = genericModelConfigObject.getOrThrow("genericModelConfigObject") @@ -1112,6 +1144,10 @@ private constructor( when { vertexModelConfigObject != null -> visitor.visitVertexModelConfigObject(vertexModelConfigObject) + azureEntraModelConfigObject != null -> + visitor.visitAzureEntraModelConfigObject(azureEntraModelConfigObject) + azureApiKeyModelConfigObject != null -> + visitor.visitAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject) genericModelConfigObject != null -> visitor.visitGenericModelConfigObject(genericModelConfigObject) string != null -> visitor.visitString(string) @@ -1143,6 +1179,18 @@ private constructor( vertexModelConfigObject.validate() } + override fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) { + azureEntraModelConfigObject.validate() + } + + override fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) { + azureApiKeyModelConfigObject.validate() + } + override fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ) { @@ -1177,6 +1225,14 @@ private constructor( vertexModelConfigObject: VertexModelConfigObject ) = vertexModelConfigObject.validity() + override fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) = azureEntraModelConfigObject.validity() + + override fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) = azureApiKeyModelConfigObject.validity() + override fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ) = genericModelConfigObject.validity() @@ -1194,17 +1250,29 @@ private constructor( return other is Model && vertexModelConfigObject == other.vertexModelConfigObject && + azureEntraModelConfigObject == other.azureEntraModelConfigObject && + azureApiKeyModelConfigObject == other.azureApiKeyModelConfigObject && genericModelConfigObject == other.genericModelConfigObject && string == other.string } override fun hashCode(): Int = - Objects.hash(vertexModelConfigObject, genericModelConfigObject, string) + Objects.hash( + vertexModelConfigObject, + azureEntraModelConfigObject, + azureApiKeyModelConfigObject, + genericModelConfigObject, + string, + ) override fun toString(): String = when { vertexModelConfigObject != null -> "Model{vertexModelConfigObject=$vertexModelConfigObject}" + azureEntraModelConfigObject != null -> + "Model{azureEntraModelConfigObject=$azureEntraModelConfigObject}" + azureApiKeyModelConfigObject != null -> + "Model{azureApiKeyModelConfigObject=$azureApiKeyModelConfigObject}" genericModelConfigObject != null -> "Model{genericModelConfigObject=$genericModelConfigObject}" string != null -> "Model{string=$string}" @@ -1218,6 +1286,16 @@ private constructor( fun ofVertexModelConfigObject(vertexModelConfigObject: VertexModelConfigObject) = Model(vertexModelConfigObject = vertexModelConfigObject) + @JvmStatic + fun ofAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) = Model(azureEntraModelConfigObject = azureEntraModelConfigObject) + + @JvmStatic + fun ofAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) = Model(azureApiKeyModelConfigObject = azureApiKeyModelConfigObject) + @JvmStatic fun ofGenericModelConfigObject(genericModelConfigObject: GenericModelConfigObject) = Model(genericModelConfigObject = genericModelConfigObject) @@ -1234,6 +1312,14 @@ private constructor( vertexModelConfigObject: VertexModelConfigObject ): T + fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ): T + + fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ): T + fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ): T @@ -1264,6 +1350,12 @@ private constructor( sequenceOf( tryDeserialize(node, jacksonTypeRef()) ?.let { Model(vertexModelConfigObject = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { Model(azureEntraModelConfigObject = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { + Model(azureApiKeyModelConfigObject = it, _json = json) + }, tryDeserialize(node, jacksonTypeRef()) ?.let { Model(genericModelConfigObject = it, _json = json) }, tryDeserialize(node, jacksonTypeRef())?.let { @@ -1296,6 +1388,10 @@ private constructor( when { value.vertexModelConfigObject != null -> generator.writeObject(value.vertexModelConfigObject) + value.azureEntraModelConfigObject != null -> + generator.writeObject(value.azureEntraModelConfigObject) + value.azureApiKeyModelConfigObject != null -> + generator.writeObject(value.azureApiKeyModelConfigObject) value.genericModelConfigObject != null -> generator.writeObject(value.genericModelConfigObject) value.string != null -> generator.writeObject(value.string) @@ -3838,6 +3934,2624 @@ private constructor( "VertexModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" } + class AzureEntraModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val auth: JsonField, + private val modelName: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("auth") @ExcludeMissing auth: JsonField = JsonMissing.of(), + @JsonProperty("modelName") + @ExcludeMissing + modelName: JsonField = JsonMissing.of(), + @JsonProperty("provider") + @ExcludeMissing + provider: JsonValue = JsonMissing.of(), + @JsonProperty("providerOptions") + @ExcludeMissing + providerOptions: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + ) : this( + auth, + modelName, + provider, + providerOptions, + baseUrl, + headers, + mutableMapOf(), + ) + + /** + * Azure provider authentication configuration + * + * @throws StagehandInvalidDataException 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 auth(): Auth = auth.getRequired("auth") + + /** + * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') + * + * @throws StagehandInvalidDataException 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 modelName(): String = modelName.getRequired("modelName") + + /** + * Azure OpenAI model provider + * + * Expected to always return the following: + * ```java + * JsonValue.from("azure") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider + + /** + * Azure provider-specific model configuration + * + * @throws StagehandInvalidDataException 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 providerOptions(): ProviderOptions = + providerOptions.getRequired("providerOptions") + + /** + * Base URL for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Returns the raw JSON value of [auth]. + * + * Unlike [auth], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("auth") @ExcludeMissing fun _auth(): JsonField = auth + + /** + * Returns the raw JSON value of [modelName]. + * + * Unlike [modelName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("modelName") + @ExcludeMissing + fun _modelName(): JsonField = modelName + + /** + * Returns the raw JSON value of [providerOptions]. + * + * Unlike [providerOptions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("providerOptions") + @ExcludeMissing + fun _providerOptions(): JsonField = providerOptions + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + @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 + * [AzureEntraModelConfigObject]. + * + * The following fields are required: + * ```java + * .auth() + * .modelName() + * .providerOptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AzureEntraModelConfigObject]. */ + class Builder internal constructor() { + + private var auth: JsonField? = null + private var modelName: JsonField? = null + private var provider: JsonValue = JsonValue.from("azure") + private var providerOptions: JsonField? = null + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(azureEntraModelConfigObject: AzureEntraModelConfigObject) = + apply { + auth = azureEntraModelConfigObject.auth + modelName = azureEntraModelConfigObject.modelName + provider = azureEntraModelConfigObject.provider + providerOptions = azureEntraModelConfigObject.providerOptions + baseUrl = azureEntraModelConfigObject.baseUrl + headers = azureEntraModelConfigObject.headers + additionalProperties = + azureEntraModelConfigObject.additionalProperties.toMutableMap() + } + + /** Azure provider authentication configuration */ + fun auth(auth: Auth) = auth(JsonField.of(auth)) + + /** + * Sets [Builder.auth] to an arbitrary JSON value. + * + * You should usually call [Builder.auth] with a well-typed [Auth] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun auth(auth: JsonField) = apply { this.auth = auth } + + /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ + fun modelName(modelName: String) = modelName(JsonField.of(modelName)) + + /** + * Sets [Builder.modelName] to an arbitrary JSON value. + * + * You should usually call [Builder.modelName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun modelName(modelName: JsonField) = apply { + this.modelName = modelName + } + + /** + * 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("azure") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun provider(provider: JsonValue) = apply { this.provider = provider } + + /** Azure provider-specific model configuration */ + fun providerOptions(providerOptions: ProviderOptions) = + providerOptions(JsonField.of(providerOptions)) + + /** + * Sets [Builder.providerOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.providerOptions] with a well-typed + * [ProviderOptions] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun providerOptions(providerOptions: JsonField) = apply { + this.providerOptions = providerOptions + } + + /** Base URL for the model provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the model provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + 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 [AzureEntraModelConfigObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .auth() + * .modelName() + * .providerOptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AzureEntraModelConfigObject = + AzureEntraModelConfigObject( + checkRequired("auth", auth), + checkRequired("modelName", modelName), + provider, + checkRequired("providerOptions", providerOptions), + baseUrl, + headers, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AzureEntraModelConfigObject = apply { + if (validated) { + return@apply + } + + auth().validate() + modelName() + _provider().let { + if (it != JsonValue.from("azure")) { + throw StagehandInvalidDataException( + "'provider' is invalid, received $it" + ) + } + } + providerOptions().validate() + baseUrl() + headers().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = + (auth.asKnown().getOrNull()?.validity() ?: 0) + + (if (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("azure")) 1 else 0 } + + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure provider authentication configuration */ + class Auth + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val token: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("token") + @ExcludeMissing + token: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(token, type, mutableMapOf()) + + /** + * Microsoft Entra ID bearer token for Azure OpenAI + * + * @throws StagehandInvalidDataException 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 token(): String = token.getRequired("token") + + /** + * Use a Microsoft Entra ID bearer token for authentication + * + * Expected to always return the following: + * ```java + * JsonValue.from("azureEntraId") + * ``` + * + * 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 [token]. + * + * Unlike [token], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("token") @ExcludeMissing fun _token(): JsonField = token + + @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 [Auth]. + * + * The following fields are required: + * ```java + * .token() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Auth]. */ + class Builder internal constructor() { + + private var token: JsonField? = null + private var type: JsonValue = JsonValue.from("azureEntraId") + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(auth: Auth) = apply { + token = auth.token + type = auth.type + additionalProperties = auth.additionalProperties.toMutableMap() + } + + /** Microsoft Entra ID bearer token for Azure OpenAI */ + fun token(token: String) = token(JsonField.of(token)) + + /** + * Sets [Builder.token] to an arbitrary JSON value. + * + * You should usually call [Builder.token] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun token(token: JsonField) = apply { this.token = token } + + /** + * 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("azureEntraId") + * ``` + * + * 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 [Auth]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .token() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Auth = + Auth( + checkRequired("token", token), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Auth = apply { + if (validated) { + return@apply + } + + token() + _type().let { + if (it != JsonValue.from("azureEntraId")) { + throw StagehandInvalidDataException( + "'type' is invalid, received $it" + ) + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (token.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("azureEntraId")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auth && + token == other.token && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(token, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Auth{token=$token, type=$type, additionalProperties=$additionalProperties}" + } + + /** Azure provider-specific model configuration */ + class ProviderOptions + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val azure: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("azure") + @ExcludeMissing + azure: JsonField = JsonMissing.of() + ) : this(azure, mutableMapOf()) + + /** + * Azure OpenAI provider-specific settings + * + * @throws StagehandInvalidDataException 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 azure(): Azure = azure.getRequired("azure") + + /** + * Returns the raw JSON value of [azure]. + * + * Unlike [azure], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("azure") @ExcludeMissing fun _azure(): JsonField = azure + + @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 + * [ProviderOptions]. + * + * The following fields are required: + * ```java + * .azure() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProviderOptions]. */ + class Builder internal constructor() { + + private var azure: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(providerOptions: ProviderOptions) = apply { + azure = providerOptions.azure + additionalProperties = + providerOptions.additionalProperties.toMutableMap() + } + + /** Azure OpenAI provider-specific settings */ + fun azure(azure: Azure) = azure(JsonField.of(azure)) + + /** + * Sets [Builder.azure] to an arbitrary JSON value. + * + * You should usually call [Builder.azure] with a well-typed [Azure] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun azure(azure: JsonField) = apply { this.azure = azure } + + 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 [ProviderOptions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .azure() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProviderOptions = + ProviderOptions( + checkRequired("azure", azure), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ProviderOptions = apply { + if (validated) { + return@apply + } + + azure().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = (azure.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure OpenAI provider-specific settings */ + class Azure + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val apiVersion: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val resourceName: JsonField, + private val useDeploymentBasedUrls: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("apiVersion") + @ExcludeMissing + apiVersion: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + @JsonProperty("resourceName") + @ExcludeMissing + resourceName: JsonField = JsonMissing.of(), + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + useDeploymentBasedUrls: JsonField = JsonMissing.of(), + ) : this( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + mutableMapOf(), + ) + + /** + * Azure OpenAI API version + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun apiVersion(): Optional = apiVersion.getOptional("apiVersion") + + /** + * Base URL for the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Azure OpenAI resource name + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun resourceName(): Optional = + resourceName.getOptional("resourceName") + + /** + * Whether to use deployment-based Azure OpenAI URLs + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun useDeploymentBasedUrls(): Optional = + useDeploymentBasedUrls.getOptional("useDeploymentBasedUrls") + + /** + * Returns the raw JSON value of [apiVersion]. + * + * Unlike [apiVersion], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("apiVersion") + @ExcludeMissing + fun _apiVersion(): JsonField = apiVersion + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("baseURL") + @ExcludeMissing + fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + /** + * Returns the raw JSON value of [resourceName]. + * + * Unlike [resourceName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("resourceName") + @ExcludeMissing + fun _resourceName(): JsonField = resourceName + + /** + * Returns the raw JSON value of [useDeploymentBasedUrls]. + * + * Unlike [useDeploymentBasedUrls], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + fun _useDeploymentBasedUrls(): JsonField = useDeploymentBasedUrls + + @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 [Azure]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Azure]. */ + class Builder internal constructor() { + + private var apiVersion: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var resourceName: JsonField = JsonMissing.of() + private var useDeploymentBasedUrls: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(azure: Azure) = apply { + apiVersion = azure.apiVersion + baseUrl = azure.baseUrl + headers = azure.headers + resourceName = azure.resourceName + useDeploymentBasedUrls = azure.useDeploymentBasedUrls + additionalProperties = azure.additionalProperties.toMutableMap() + } + + /** Azure OpenAI API version */ + fun apiVersion(apiVersion: String) = + apiVersion(JsonField.of(apiVersion)) + + /** + * Sets [Builder.apiVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.apiVersion] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun apiVersion(apiVersion: JsonField) = apply { + this.apiVersion = apiVersion + } + + /** Base URL for the Azure OpenAI provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { + this.baseUrl = baseUrl + } + + /** + * Custom headers sent with every request to the Azure OpenAI provider + */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun headers(headers: JsonField) = apply { + this.headers = headers + } + + /** Azure OpenAI resource name */ + fun resourceName(resourceName: String) = + resourceName(JsonField.of(resourceName)) + + /** + * Sets [Builder.resourceName] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceName] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun resourceName(resourceName: JsonField) = apply { + this.resourceName = resourceName + } + + /** Whether to use deployment-based Azure OpenAI URLs */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: Boolean) = + useDeploymentBasedUrls(JsonField.of(useDeploymentBasedUrls)) + + /** + * Sets [Builder.useDeploymentBasedUrls] to an arbitrary JSON value. + * + * You should usually call [Builder.useDeploymentBasedUrls] with a + * well-typed [Boolean] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: JsonField) = + apply { + this.useDeploymentBasedUrls = useDeploymentBasedUrls + } + + 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 [Azure]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Azure = + Azure( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Azure = apply { + if (validated) { + return@apply + } + + apiVersion() + baseUrl() + headers().ifPresent { it.validate() } + resourceName() + useDeploymentBasedUrls() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (apiVersion.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceName.asKnown().isPresent) 1 else 0) + + (if (useDeploymentBasedUrls.asKnown().isPresent) 1 else 0) + + /** Custom headers sent with every request to the Azure OpenAI provider */ + class Headers + @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 + * [Headers]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = + headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws StagehandInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Azure && + apiVersion == other.apiVersion && + baseUrl == other.baseUrl && + headers == other.headers && + resourceName == other.resourceName && + useDeploymentBasedUrls == other.useDeploymentBasedUrls && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Azure{apiVersion=$apiVersion, baseUrl=$baseUrl, headers=$headers, resourceName=$resourceName, useDeploymentBasedUrls=$useDeploymentBasedUrls, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProviderOptions && + azure == other.azure && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(azure, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProviderOptions{azure=$azure, additionalProperties=$additionalProperties}" + } + + /** Custom headers sent with every request to the model provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AzureEntraModelConfigObject && + auth == other.auth && + modelName == other.modelName && + provider == other.provider && + providerOptions == other.providerOptions && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + auth, + modelName, + provider, + providerOptions, + baseUrl, + headers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AzureEntraModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + + class AzureApiKeyModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val modelName: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, + private val apiKey: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("modelName") + @ExcludeMissing + modelName: JsonField = JsonMissing.of(), + @JsonProperty("provider") + @ExcludeMissing + provider: JsonValue = JsonMissing.of(), + @JsonProperty("providerOptions") + @ExcludeMissing + providerOptions: JsonField = JsonMissing.of(), + @JsonProperty("apiKey") + @ExcludeMissing + apiKey: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + ) : this( + modelName, + provider, + providerOptions, + apiKey, + baseUrl, + headers, + mutableMapOf(), + ) + + /** + * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') + * + * @throws StagehandInvalidDataException 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 modelName(): String = modelName.getRequired("modelName") + + /** + * Azure OpenAI model provider + * + * Expected to always return the following: + * ```java + * JsonValue.from("azure") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider + + /** + * Azure provider-specific model configuration + * + * @throws StagehandInvalidDataException 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 providerOptions(): ProviderOptions = + providerOptions.getRequired("providerOptions") + + /** + * API key for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun apiKey(): Optional = apiKey.getOptional("apiKey") + + /** + * Base URL for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Returns the raw JSON value of [modelName]. + * + * Unlike [modelName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("modelName") + @ExcludeMissing + fun _modelName(): JsonField = modelName + + /** + * Returns the raw JSON value of [providerOptions]. + * + * Unlike [providerOptions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("providerOptions") + @ExcludeMissing + fun _providerOptions(): JsonField = providerOptions + + /** + * Returns the raw JSON value of [apiKey]. + * + * Unlike [apiKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("apiKey") @ExcludeMissing fun _apiKey(): JsonField = apiKey + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + @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 + * [AzureApiKeyModelConfigObject]. + * + * The following fields are required: + * ```java + * .modelName() + * .providerOptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AzureApiKeyModelConfigObject]. */ + class Builder internal constructor() { + + private var modelName: JsonField? = null + private var provider: JsonValue = JsonValue.from("azure") + private var providerOptions: JsonField? = null + private var apiKey: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject) = + apply { + modelName = azureApiKeyModelConfigObject.modelName + provider = azureApiKeyModelConfigObject.provider + providerOptions = azureApiKeyModelConfigObject.providerOptions + apiKey = azureApiKeyModelConfigObject.apiKey + baseUrl = azureApiKeyModelConfigObject.baseUrl + headers = azureApiKeyModelConfigObject.headers + additionalProperties = + azureApiKeyModelConfigObject.additionalProperties.toMutableMap() + } + + /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ + fun modelName(modelName: String) = modelName(JsonField.of(modelName)) + + /** + * Sets [Builder.modelName] to an arbitrary JSON value. + * + * You should usually call [Builder.modelName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun modelName(modelName: JsonField) = apply { + this.modelName = modelName + } + + /** + * 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("azure") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun provider(provider: JsonValue) = apply { this.provider = provider } + + /** Azure provider-specific model configuration */ + fun providerOptions(providerOptions: ProviderOptions) = + providerOptions(JsonField.of(providerOptions)) + + /** + * Sets [Builder.providerOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.providerOptions] with a well-typed + * [ProviderOptions] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun providerOptions(providerOptions: JsonField) = apply { + this.providerOptions = providerOptions + } + + /** API key for the model provider */ + fun apiKey(apiKey: String) = apiKey(JsonField.of(apiKey)) + + /** + * Sets [Builder.apiKey] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKey(apiKey: JsonField) = apply { this.apiKey = apiKey } + + /** Base URL for the model provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the model provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + 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 [AzureApiKeyModelConfigObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .modelName() + * .providerOptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AzureApiKeyModelConfigObject = + AzureApiKeyModelConfigObject( + checkRequired("modelName", modelName), + provider, + checkRequired("providerOptions", providerOptions), + apiKey, + baseUrl, + headers, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AzureApiKeyModelConfigObject = apply { + if (validated) { + return@apply + } + + modelName() + _provider().let { + if (it != JsonValue.from("azure")) { + throw StagehandInvalidDataException( + "'provider' is invalid, received $it" + ) + } + } + providerOptions().validate() + apiKey() + baseUrl() + headers().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("azure")) 1 else 0 } + + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + + (if (apiKey.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure provider-specific model configuration */ + class ProviderOptions + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val azure: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("azure") + @ExcludeMissing + azure: JsonField = JsonMissing.of() + ) : this(azure, mutableMapOf()) + + /** + * Azure OpenAI provider-specific settings + * + * @throws StagehandInvalidDataException 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 azure(): Azure = azure.getRequired("azure") + + /** + * Returns the raw JSON value of [azure]. + * + * Unlike [azure], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("azure") @ExcludeMissing fun _azure(): JsonField = azure + + @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 + * [ProviderOptions]. + * + * The following fields are required: + * ```java + * .azure() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProviderOptions]. */ + class Builder internal constructor() { + + private var azure: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(providerOptions: ProviderOptions) = apply { + azure = providerOptions.azure + additionalProperties = + providerOptions.additionalProperties.toMutableMap() + } + + /** Azure OpenAI provider-specific settings */ + fun azure(azure: Azure) = azure(JsonField.of(azure)) + + /** + * Sets [Builder.azure] to an arbitrary JSON value. + * + * You should usually call [Builder.azure] with a well-typed [Azure] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun azure(azure: JsonField) = apply { this.azure = azure } + + 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 [ProviderOptions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .azure() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProviderOptions = + ProviderOptions( + checkRequired("azure", azure), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ProviderOptions = apply { + if (validated) { + return@apply + } + + azure().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = (azure.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure OpenAI provider-specific settings */ + class Azure + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val apiVersion: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val resourceName: JsonField, + private val useDeploymentBasedUrls: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("apiVersion") + @ExcludeMissing + apiVersion: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + @JsonProperty("resourceName") + @ExcludeMissing + resourceName: JsonField = JsonMissing.of(), + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + useDeploymentBasedUrls: JsonField = JsonMissing.of(), + ) : this( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + mutableMapOf(), + ) + + /** + * Azure OpenAI API version + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun apiVersion(): Optional = apiVersion.getOptional("apiVersion") + + /** + * Base URL for the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Azure OpenAI resource name + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun resourceName(): Optional = + resourceName.getOptional("resourceName") + + /** + * Whether to use deployment-based Azure OpenAI URLs + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun useDeploymentBasedUrls(): Optional = + useDeploymentBasedUrls.getOptional("useDeploymentBasedUrls") + + /** + * Returns the raw JSON value of [apiVersion]. + * + * Unlike [apiVersion], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("apiVersion") + @ExcludeMissing + fun _apiVersion(): JsonField = apiVersion + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("baseURL") + @ExcludeMissing + fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + /** + * Returns the raw JSON value of [resourceName]. + * + * Unlike [resourceName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("resourceName") + @ExcludeMissing + fun _resourceName(): JsonField = resourceName + + /** + * Returns the raw JSON value of [useDeploymentBasedUrls]. + * + * Unlike [useDeploymentBasedUrls], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + fun _useDeploymentBasedUrls(): JsonField = useDeploymentBasedUrls + + @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 [Azure]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Azure]. */ + class Builder internal constructor() { + + private var apiVersion: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var resourceName: JsonField = JsonMissing.of() + private var useDeploymentBasedUrls: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(azure: Azure) = apply { + apiVersion = azure.apiVersion + baseUrl = azure.baseUrl + headers = azure.headers + resourceName = azure.resourceName + useDeploymentBasedUrls = azure.useDeploymentBasedUrls + additionalProperties = azure.additionalProperties.toMutableMap() + } + + /** Azure OpenAI API version */ + fun apiVersion(apiVersion: String) = + apiVersion(JsonField.of(apiVersion)) + + /** + * Sets [Builder.apiVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.apiVersion] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun apiVersion(apiVersion: JsonField) = apply { + this.apiVersion = apiVersion + } + + /** Base URL for the Azure OpenAI provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { + this.baseUrl = baseUrl + } + + /** + * Custom headers sent with every request to the Azure OpenAI provider + */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun headers(headers: JsonField) = apply { + this.headers = headers + } + + /** Azure OpenAI resource name */ + fun resourceName(resourceName: String) = + resourceName(JsonField.of(resourceName)) + + /** + * Sets [Builder.resourceName] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceName] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun resourceName(resourceName: JsonField) = apply { + this.resourceName = resourceName + } + + /** Whether to use deployment-based Azure OpenAI URLs */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: Boolean) = + useDeploymentBasedUrls(JsonField.of(useDeploymentBasedUrls)) + + /** + * Sets [Builder.useDeploymentBasedUrls] to an arbitrary JSON value. + * + * You should usually call [Builder.useDeploymentBasedUrls] with a + * well-typed [Boolean] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: JsonField) = + apply { + this.useDeploymentBasedUrls = useDeploymentBasedUrls + } + + 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 [Azure]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Azure = + Azure( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Azure = apply { + if (validated) { + return@apply + } + + apiVersion() + baseUrl() + headers().ifPresent { it.validate() } + resourceName() + useDeploymentBasedUrls() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (apiVersion.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceName.asKnown().isPresent) 1 else 0) + + (if (useDeploymentBasedUrls.asKnown().isPresent) 1 else 0) + + /** Custom headers sent with every request to the Azure OpenAI provider */ + class Headers + @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 + * [Headers]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = + headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws StagehandInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Azure && + apiVersion == other.apiVersion && + baseUrl == other.baseUrl && + headers == other.headers && + resourceName == other.resourceName && + useDeploymentBasedUrls == other.useDeploymentBasedUrls && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Azure{apiVersion=$apiVersion, baseUrl=$baseUrl, headers=$headers, resourceName=$resourceName, useDeploymentBasedUrls=$useDeploymentBasedUrls, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProviderOptions && + azure == other.azure && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(azure, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProviderOptions{azure=$azure, additionalProperties=$additionalProperties}" + } + + /** Custom headers sent with every request to the model provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AzureApiKeyModelConfigObject && + modelName == other.modelName && + provider == other.provider && + providerOptions == other.providerOptions && + apiKey == other.apiKey && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + modelName, + provider, + providerOptions, + apiKey, + baseUrl, + headers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AzureApiKeyModelConfigObject{modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + class GenericModelConfigObject @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( diff --git a/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionExecuteParams.kt b/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionExecuteParams.kt index 3df5981..41156a6 100644 --- a/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionExecuteParams.kt +++ b/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionExecuteParams.kt @@ -887,6 +887,28 @@ private constructor( fun executionModel(vertexModelConfigObject: ExecutionModel.VertexModelConfigObject) = executionModel(ExecutionModel.ofVertexModelConfigObject(vertexModelConfigObject)) + /** + * Alias for calling [executionModel] with + * `ExecutionModel.ofAzureEntraModelConfigObject(azureEntraModelConfigObject)`. + */ + fun executionModel( + azureEntraModelConfigObject: ExecutionModel.AzureEntraModelConfigObject + ) = + executionModel( + ExecutionModel.ofAzureEntraModelConfigObject(azureEntraModelConfigObject) + ) + + /** + * Alias for calling [executionModel] with + * `ExecutionModel.ofAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject)`. + */ + fun executionModel( + azureApiKeyModelConfigObject: ExecutionModel.AzureApiKeyModelConfigObject + ) = + executionModel( + ExecutionModel.ofAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject) + ) + /** * Alias for calling [executionModel] with * `ExecutionModel.ofGenericModelConfigObject(genericModelConfigObject)`. @@ -928,6 +950,20 @@ private constructor( fun model(vertexModelConfigObject: Model.VertexModelConfigObject) = model(Model.ofVertexModelConfigObject(vertexModelConfigObject)) + /** + * Alias for calling [model] with + * `Model.ofAzureEntraModelConfigObject(azureEntraModelConfigObject)`. + */ + fun model(azureEntraModelConfigObject: Model.AzureEntraModelConfigObject) = + model(Model.ofAzureEntraModelConfigObject(azureEntraModelConfigObject)) + + /** + * Alias for calling [model] with + * `Model.ofAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject)`. + */ + fun model(azureApiKeyModelConfigObject: Model.AzureApiKeyModelConfigObject) = + model(Model.ofAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject)) + /** * Alias for calling [model] with * `Model.ofGenericModelConfigObject(genericModelConfigObject)`. @@ -1058,6 +1094,8 @@ private constructor( class ExecutionModel private constructor( private val vertexModelConfigObject: VertexModelConfigObject? = null, + private val azureEntraModelConfigObject: AzureEntraModelConfigObject? = null, + private val azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject? = null, private val genericModelConfigObject: GenericModelConfigObject? = null, private val string: String? = null, private val _json: JsonValue? = null, @@ -1066,6 +1104,12 @@ private constructor( fun vertexModelConfigObject(): Optional = Optional.ofNullable(vertexModelConfigObject) + fun azureEntraModelConfigObject(): Optional = + Optional.ofNullable(azureEntraModelConfigObject) + + fun azureApiKeyModelConfigObject(): Optional = + Optional.ofNullable(azureApiKeyModelConfigObject) + fun genericModelConfigObject(): Optional = Optional.ofNullable(genericModelConfigObject) @@ -1073,6 +1117,10 @@ private constructor( fun isVertexModelConfigObject(): Boolean = vertexModelConfigObject != null + fun isAzureEntraModelConfigObject(): Boolean = azureEntraModelConfigObject != null + + fun isAzureApiKeyModelConfigObject(): Boolean = azureApiKeyModelConfigObject != null + fun isGenericModelConfigObject(): Boolean = genericModelConfigObject != null fun isString(): Boolean = string != null @@ -1080,6 +1128,12 @@ private constructor( fun asVertexModelConfigObject(): VertexModelConfigObject = vertexModelConfigObject.getOrThrow("vertexModelConfigObject") + fun asAzureEntraModelConfigObject(): AzureEntraModelConfigObject = + azureEntraModelConfigObject.getOrThrow("azureEntraModelConfigObject") + + fun asAzureApiKeyModelConfigObject(): AzureApiKeyModelConfigObject = + azureApiKeyModelConfigObject.getOrThrow("azureApiKeyModelConfigObject") + fun asGenericModelConfigObject(): GenericModelConfigObject = genericModelConfigObject.getOrThrow("genericModelConfigObject") @@ -1121,6 +1175,10 @@ private constructor( when { vertexModelConfigObject != null -> visitor.visitVertexModelConfigObject(vertexModelConfigObject) + azureEntraModelConfigObject != null -> + visitor.visitAzureEntraModelConfigObject(azureEntraModelConfigObject) + azureApiKeyModelConfigObject != null -> + visitor.visitAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject) genericModelConfigObject != null -> visitor.visitGenericModelConfigObject(genericModelConfigObject) string != null -> visitor.visitString(string) @@ -1152,6 +1210,18 @@ private constructor( vertexModelConfigObject.validate() } + override fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) { + azureEntraModelConfigObject.validate() + } + + override fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) { + azureApiKeyModelConfigObject.validate() + } + override fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ) { @@ -1186,6 +1256,14 @@ private constructor( vertexModelConfigObject: VertexModelConfigObject ) = vertexModelConfigObject.validity() + override fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) = azureEntraModelConfigObject.validity() + + override fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) = azureApiKeyModelConfigObject.validity() + override fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ) = genericModelConfigObject.validity() @@ -1203,17 +1281,29 @@ private constructor( return other is ExecutionModel && vertexModelConfigObject == other.vertexModelConfigObject && + azureEntraModelConfigObject == other.azureEntraModelConfigObject && + azureApiKeyModelConfigObject == other.azureApiKeyModelConfigObject && genericModelConfigObject == other.genericModelConfigObject && string == other.string } override fun hashCode(): Int = - Objects.hash(vertexModelConfigObject, genericModelConfigObject, string) + Objects.hash( + vertexModelConfigObject, + azureEntraModelConfigObject, + azureApiKeyModelConfigObject, + genericModelConfigObject, + string, + ) override fun toString(): String = when { vertexModelConfigObject != null -> "ExecutionModel{vertexModelConfigObject=$vertexModelConfigObject}" + azureEntraModelConfigObject != null -> + "ExecutionModel{azureEntraModelConfigObject=$azureEntraModelConfigObject}" + azureApiKeyModelConfigObject != null -> + "ExecutionModel{azureApiKeyModelConfigObject=$azureApiKeyModelConfigObject}" genericModelConfigObject != null -> "ExecutionModel{genericModelConfigObject=$genericModelConfigObject}" string != null -> "ExecutionModel{string=$string}" @@ -1227,6 +1317,16 @@ private constructor( fun ofVertexModelConfigObject(vertexModelConfigObject: VertexModelConfigObject) = ExecutionModel(vertexModelConfigObject = vertexModelConfigObject) + @JvmStatic + fun ofAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) = ExecutionModel(azureEntraModelConfigObject = azureEntraModelConfigObject) + + @JvmStatic + fun ofAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) = ExecutionModel(azureApiKeyModelConfigObject = azureApiKeyModelConfigObject) + @JvmStatic fun ofGenericModelConfigObject(genericModelConfigObject: GenericModelConfigObject) = ExecutionModel(genericModelConfigObject = genericModelConfigObject) @@ -1244,6 +1344,14 @@ private constructor( vertexModelConfigObject: VertexModelConfigObject ): T + fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ): T + + fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ): T + fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ): T @@ -1276,6 +1384,20 @@ private constructor( ?.let { ExecutionModel(vertexModelConfigObject = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { + ExecutionModel( + azureEntraModelConfigObject = it, + _json = json, + ) + }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { + ExecutionModel( + azureApiKeyModelConfigObject = it, + _json = json, + ) + }, tryDeserialize(node, jacksonTypeRef()) ?.let { ExecutionModel(genericModelConfigObject = it, _json = json) @@ -1310,6 +1432,10 @@ private constructor( when { value.vertexModelConfigObject != null -> generator.writeObject(value.vertexModelConfigObject) + value.azureEntraModelConfigObject != null -> + generator.writeObject(value.azureEntraModelConfigObject) + value.azureApiKeyModelConfigObject != null -> + generator.writeObject(value.azureApiKeyModelConfigObject) value.genericModelConfigObject != null -> generator.writeObject(value.genericModelConfigObject) value.string != null -> generator.writeObject(value.string) @@ -3852,35 +3978,54 @@ private constructor( "VertexModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" } - class GenericModelConfigObject + class AzureEntraModelConfigObject @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( + private val auth: JsonField, private val modelName: JsonField, - private val apiKey: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, private val baseUrl: JsonField, private val headers: JsonField, - private val provider: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( + @JsonProperty("auth") @ExcludeMissing auth: JsonField = JsonMissing.of(), @JsonProperty("modelName") @ExcludeMissing modelName: JsonField = JsonMissing.of(), - @JsonProperty("apiKey") + @JsonProperty("provider") @ExcludeMissing - apiKey: JsonField = JsonMissing.of(), + provider: JsonValue = JsonMissing.of(), + @JsonProperty("providerOptions") + @ExcludeMissing + providerOptions: JsonField = JsonMissing.of(), @JsonProperty("baseURL") @ExcludeMissing baseUrl: JsonField = JsonMissing.of(), @JsonProperty("headers") @ExcludeMissing headers: JsonField = JsonMissing.of(), - @JsonProperty("provider") - @ExcludeMissing - provider: JsonField = JsonMissing.of(), - ) : this(modelName, apiKey, baseUrl, headers, provider, mutableMapOf()) + ) : this( + auth, + modelName, + provider, + providerOptions, + baseUrl, + headers, + mutableMapOf(), + ) + + /** + * Azure provider authentication configuration + * + * @throws StagehandInvalidDataException 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 auth(): Auth = auth.getRequired("auth") /** * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') @@ -3892,12 +4037,27 @@ private constructor( fun modelName(): String = modelName.getRequired("modelName") /** - * API key for the model provider + * Azure OpenAI model provider * - * @throws StagehandInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). + * Expected to always return the following: + * ```java + * JsonValue.from("azure") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). */ - fun apiKey(): Optional = apiKey.getOptional("apiKey") + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider + + /** + * Azure provider-specific model configuration + * + * @throws StagehandInvalidDataException 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 providerOptions(): ProviderOptions = + providerOptions.getRequired("providerOptions") /** * Base URL for the model provider @@ -3916,12 +4076,12 @@ private constructor( fun headers(): Optional = headers.getOptional("headers") /** - * AI provider for the model (or provide a baseURL endpoint instead) + * Returns the raw JSON value of [auth]. * - * @throws StagehandInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). + * Unlike [auth], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun provider(): Optional = provider.getOptional("provider") + @JsonProperty("auth") @ExcludeMissing fun _auth(): JsonField = auth /** * Returns the raw JSON value of [modelName]. @@ -3934,12 +4094,14 @@ private constructor( fun _modelName(): JsonField = modelName /** - * Returns the raw JSON value of [apiKey]. + * Returns the raw JSON value of [providerOptions]. * - * Unlike [apiKey], this method doesn't throw if the JSON field has an unexpected - * type. + * Unlike [providerOptions], this method doesn't throw if the JSON field has an + * unexpected type. */ - @JsonProperty("apiKey") @ExcludeMissing fun _apiKey(): JsonField = apiKey + @JsonProperty("providerOptions") + @ExcludeMissing + fun _providerOptions(): JsonField = providerOptions /** * Returns the raw JSON value of [baseUrl]. @@ -3959,16 +4121,6 @@ private constructor( @ExcludeMissing fun _headers(): JsonField = headers - /** - * Returns the raw JSON value of [provider]. - * - * Unlike [provider], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("provider") - @ExcludeMissing - fun _provider(): JsonField = provider - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -3985,36 +4137,53 @@ private constructor( /** * Returns a mutable builder for constructing an instance of - * [GenericModelConfigObject]. + * [AzureEntraModelConfigObject]. * * The following fields are required: * ```java + * .auth() * .modelName() + * .providerOptions() * ``` */ @JvmStatic fun builder() = Builder() } - /** A builder for [GenericModelConfigObject]. */ + /** A builder for [AzureEntraModelConfigObject]. */ class Builder internal constructor() { + private var auth: JsonField? = null private var modelName: JsonField? = null - private var apiKey: JsonField = JsonMissing.of() + private var provider: JsonValue = JsonValue.from("azure") + private var providerOptions: JsonField? = null private var baseUrl: JsonField = JsonMissing.of() private var headers: JsonField = JsonMissing.of() - private var provider: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(genericModelConfigObject: GenericModelConfigObject) = apply { - modelName = genericModelConfigObject.modelName - apiKey = genericModelConfigObject.apiKey - baseUrl = genericModelConfigObject.baseUrl - headers = genericModelConfigObject.headers - provider = genericModelConfigObject.provider - additionalProperties = - genericModelConfigObject.additionalProperties.toMutableMap() - } + internal fun from(azureEntraModelConfigObject: AzureEntraModelConfigObject) = + apply { + auth = azureEntraModelConfigObject.auth + modelName = azureEntraModelConfigObject.modelName + provider = azureEntraModelConfigObject.provider + providerOptions = azureEntraModelConfigObject.providerOptions + baseUrl = azureEntraModelConfigObject.baseUrl + headers = azureEntraModelConfigObject.headers + additionalProperties = + azureEntraModelConfigObject.additionalProperties.toMutableMap() + } + + /** Azure provider authentication configuration */ + fun auth(auth: Auth) = auth(JsonField.of(auth)) + + /** + * Sets [Builder.auth] to an arbitrary JSON value. + * + * You should usually call [Builder.auth] with a well-typed [Auth] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun auth(auth: JsonField) = apply { this.auth = auth } /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ fun modelName(modelName: String) = modelName(JsonField.of(modelName)) @@ -4030,17 +4199,34 @@ private constructor( this.modelName = modelName } - /** API key for the model provider */ - fun apiKey(apiKey: String) = apiKey(JsonField.of(apiKey)) + /** + * 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("azure") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun provider(provider: JsonValue) = apply { this.provider = provider } + + /** Azure provider-specific model configuration */ + fun providerOptions(providerOptions: ProviderOptions) = + providerOptions(JsonField.of(providerOptions)) /** - * Sets [Builder.apiKey] to an arbitrary JSON value. + * Sets [Builder.providerOptions] to an arbitrary JSON value. * - * You should usually call [Builder.apiKey] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. + * You should usually call [Builder.providerOptions] with a well-typed + * [ProviderOptions] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. */ - fun apiKey(apiKey: JsonField) = apply { this.apiKey = apiKey } + fun providerOptions(providerOptions: JsonField) = apply { + this.providerOptions = providerOptions + } /** Base URL for the model provider */ fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) @@ -4066,18 +4252,6 @@ private constructor( */ fun headers(headers: JsonField) = apply { this.headers = headers } - /** AI provider for the model (or provide a baseURL endpoint instead) */ - fun provider(provider: Provider) = provider(JsonField.of(provider)) - - /** - * Sets [Builder.provider] to an arbitrary JSON value. - * - * You should usually call [Builder.provider] with a well-typed [Provider] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun provider(provider: JsonField) = apply { this.provider = provider } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -4101,24 +4275,27 @@ private constructor( } /** - * Returns an immutable instance of [GenericModelConfigObject]. + * Returns an immutable instance of [AzureEntraModelConfigObject]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java + * .auth() * .modelName() + * .providerOptions() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): GenericModelConfigObject = - GenericModelConfigObject( + fun build(): AzureEntraModelConfigObject = + AzureEntraModelConfigObject( + checkRequired("auth", auth), checkRequired("modelName", modelName), - apiKey, + provider, + checkRequired("providerOptions", providerOptions), baseUrl, headers, - provider, additionalProperties.toMutableMap(), ) } @@ -4135,16 +4312,23 @@ private constructor( * @throws StagehandInvalidDataException if any value type in this object doesn't * match its expected type. */ - fun validate(): GenericModelConfigObject = apply { + fun validate(): AzureEntraModelConfigObject = apply { if (validated) { return@apply } + auth().validate() modelName() - apiKey() + _provider().let { + if (it != JsonValue.from("azure")) { + throw StagehandInvalidDataException( + "'provider' is invalid, received $it" + ) + } + } + providerOptions().validate() baseUrl() headers().ifPresent { it.validate() } - provider().ifPresent { it.validate() } validated = true } @@ -4164,43 +4348,126 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (modelName.asKnown().isPresent) 1 else 0) + - (if (apiKey.asKnown().isPresent) 1 else 0) + + (auth.asKnown().getOrNull()?.validity() ?: 0) + + (if (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("azure")) 1 else 0 } + + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + (if (baseUrl.asKnown().isPresent) 1 else 0) + - (headers.asKnown().getOrNull()?.validity() ?: 0) + - (provider.asKnown().getOrNull()?.validity() ?: 0) + (headers.asKnown().getOrNull()?.validity() ?: 0) - /** Custom headers sent with every request to the model provider */ - class Headers - @JsonCreator + /** Azure provider authentication configuration */ + class Auth + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val token: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, ) { - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun toBuilder() = Builder().from(this) + @JsonCreator + private constructor( + @JsonProperty("token") + @ExcludeMissing + token: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(token, type, mutableMapOf()) - companion object { + /** + * Microsoft Entra ID bearer token for Azure OpenAI + * + * @throws StagehandInvalidDataException 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 token(): String = token.getRequired("token") - /** Returns a mutable builder for constructing an instance of [Headers]. */ + /** + * Use a Microsoft Entra ID bearer token for authentication + * + * Expected to always return the following: + * ```java + * JsonValue.from("azureEntraId") + * ``` + * + * 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 [token]. + * + * Unlike [token], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("token") @ExcludeMissing fun _token(): JsonField = token + + @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 [Auth]. + * + * The following fields are required: + * ```java + * .token() + * ``` + */ @JvmStatic fun builder() = Builder() } - /** A builder for [Headers]. */ + /** A builder for [Auth]. */ class Builder internal constructor() { + private var token: JsonField? = null + private var type: JsonValue = JsonValue.from("azureEntraId") private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(headers: Headers) = apply { - additionalProperties = headers.additionalProperties.toMutableMap() + internal fun from(auth: Auth) = apply { + token = auth.token + type = auth.type + additionalProperties = auth.additionalProperties.toMutableMap() } + /** Microsoft Entra ID bearer token for Azure OpenAI */ + fun token(token: String) = token(JsonField.of(token)) + + /** + * Sets [Builder.token] to an arbitrary JSON value. + * + * You should usually call [Builder.token] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun token(token: JsonField) = apply { this.token = token } + + /** + * 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("azureEntraId") + * ``` + * + * 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() @@ -4224,11 +4491,23 @@ private constructor( } /** - * Returns an immutable instance of [Headers]. + * Returns an immutable instance of [Auth]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .token() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Headers = Headers(additionalProperties.toImmutable()) + fun build(): Auth = + Auth( + checkRequired("token", token), + type, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -4243,11 +4522,19 @@ private constructor( * @throws StagehandInvalidDataException if any value type in this object * doesn't match its expected type. */ - fun validate(): Headers = apply { + fun validate(): Auth = apply { if (validated) { return@apply } + token() + _type().let { + if (it != JsonValue.from("azureEntraId")) { + throw StagehandInvalidDataException( + "'type' is invalid, received $it" + ) + } + } validated = true } @@ -4267,157 +4554,173 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - additionalProperties.count { (_, value) -> - !value.isNull() && !value.isMissing() - } + (if (token.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("azureEntraId")) 1 else 0 } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is Headers && + return other is Auth && + token == other.token && + type == other.type && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + private val hashCode: Int by lazy { + Objects.hash(token, type, additionalProperties) + } override fun hashCode(): Int = hashCode - override fun toString() = "Headers{additionalProperties=$additionalProperties}" + override fun toString() = + "Auth{token=$token, type=$type, additionalProperties=$additionalProperties}" } - /** AI provider for the model (or provide a baseURL endpoint instead) */ - class Provider - @JsonCreator - private constructor(private val value: JsonField) : Enum { + /** Azure provider-specific model configuration */ + class ProviderOptions + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val azure: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("azure") + @ExcludeMissing + azure: JsonField = JsonMissing.of() + ) : this(azure, mutableMapOf()) /** - * Returns this class instance's raw value. + * Azure OpenAI provider-specific settings * - * 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. + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded with + * an unexpected value). */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value + fun azure(): Azure = azure.getRequired("azure") + + /** + * Returns the raw JSON value of [azure]. + * + * Unlike [azure], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("azure") @ExcludeMissing fun _azure(): JsonField = azure + + @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 { - @JvmField val OPENAI = of("openai") + /** + * Returns a mutable builder for constructing an instance of + * [ProviderOptions]. + * + * The following fields are required: + * ```java + * .azure() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - @JvmField val ANTHROPIC = of("anthropic") + /** A builder for [ProviderOptions]. */ + class Builder internal constructor() { - @JvmField val GOOGLE = of("google") + private var azure: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() - @JvmField val MICROSOFT = of("microsoft") + @JvmSynthetic + internal fun from(providerOptions: ProviderOptions) = apply { + azure = providerOptions.azure + additionalProperties = + providerOptions.additionalProperties.toMutableMap() + } - @JvmField val BEDROCK = of("bedrock") + /** Azure OpenAI provider-specific settings */ + fun azure(azure: Azure) = azure(JsonField.of(azure)) - @JvmStatic fun of(value: String) = Provider(JsonField.of(value)) - } + /** + * Sets [Builder.azure] to an arbitrary JSON value. + * + * You should usually call [Builder.azure] with a well-typed [Azure] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun azure(azure: JsonField) = apply { this.azure = azure } - /** An enum containing [Provider]'s known values. */ - enum class Known { - OPENAI, - ANTHROPIC, - GOOGLE, - MICROSOFT, - BEDROCK, - } + 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) + } - /** - * An enum containing [Provider]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Provider] 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 { - OPENAI, - ANTHROPIC, - GOOGLE, - MICROSOFT, - BEDROCK, /** - * An enum member indicating that [Provider] was instantiated with an - * unknown value. + * Returns an immutable instance of [ProviderOptions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .azure() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - _UNKNOWN, + fun build(): ProviderOptions = + ProviderOptions( + checkRequired("azure", azure), + additionalProperties.toMutableMap(), + ) } - /** - * 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) { - OPENAI -> Value.OPENAI - ANTHROPIC -> Value.ANTHROPIC - GOOGLE -> Value.GOOGLE - MICROSOFT -> Value.MICROSOFT - BEDROCK -> Value.BEDROCK - else -> Value._UNKNOWN - } + private var validated: Boolean = false /** - * Returns an enum member corresponding to this class instance's value. + * Validates that the types of all values in this object match their expected + * types recursively. * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. + * This method is _not_ forwards compatible with new types from the API for + * existing fields. * - * @throws StagehandInvalidDataException if this class instance's value is a not - * a known member. + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. */ - fun known(): Known = - when (this) { - OPENAI -> Known.OPENAI - ANTHROPIC -> Known.ANTHROPIC - GOOGLE -> Known.GOOGLE - MICROSOFT -> Known.MICROSOFT - BEDROCK -> Known.BEDROCK - else -> throw StagehandInvalidDataException("Unknown Provider: $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 StagehandInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - StagehandInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - /** - * Validates that the types of all values in this object match their expected - * types recursively. - * - * This method is _not_ forwards compatible with new types from the API for - * existing fields. - * - * @throws StagehandInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Provider = apply { + fun validate(): ProviderOptions = apply { if (validated) { return@apply } - known() + azure().validate() validated = true } @@ -4436,475 +4739,680 @@ private constructor( * Used for best match union deserialization. */ @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + internal fun validity(): Int = (azure.asKnown().getOrNull()?.validity() ?: 0) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** Azure OpenAI provider-specific settings */ + class Azure + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val apiVersion: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val resourceName: JsonField, + private val useDeploymentBasedUrls: JsonField, + private val additionalProperties: MutableMap, + ) { - return other is Provider && value == other.value - } + @JsonCreator + private constructor( + @JsonProperty("apiVersion") + @ExcludeMissing + apiVersion: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + @JsonProperty("resourceName") + @ExcludeMissing + resourceName: JsonField = JsonMissing.of(), + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + useDeploymentBasedUrls: JsonField = JsonMissing.of(), + ) : this( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + mutableMapOf(), + ) - override fun hashCode() = value.hashCode() + /** + * Azure OpenAI API version + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun apiVersion(): Optional = apiVersion.getOptional("apiVersion") - override fun toString() = value.toString() - } + /** + * Base URL for the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Custom headers sent with every request to the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") - return other is GenericModelConfigObject && - modelName == other.modelName && - apiKey == other.apiKey && - baseUrl == other.baseUrl && - headers == other.headers && - provider == other.provider && - additionalProperties == other.additionalProperties - } + /** + * Azure OpenAI resource name + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun resourceName(): Optional = + resourceName.getOptional("resourceName") - private val hashCode: Int by lazy { - Objects.hash( - modelName, - apiKey, - baseUrl, - headers, - provider, - additionalProperties, - ) - } + /** + * Whether to use deployment-based Azure OpenAI URLs + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun useDeploymentBasedUrls(): Optional = + useDeploymentBasedUrls.getOptional("useDeploymentBasedUrls") - override fun hashCode(): Int = hashCode + /** + * Returns the raw JSON value of [apiVersion]. + * + * Unlike [apiVersion], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("apiVersion") + @ExcludeMissing + fun _apiVersion(): JsonField = apiVersion - override fun toString() = - "GenericModelConfigObject{modelName=$modelName, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, provider=$provider, additionalProperties=$additionalProperties}" - } - } + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("baseURL") + @ExcludeMissing + fun _baseUrl(): JsonField = baseUrl - /** Tool mode for the agent (dom, hybrid, cua). If set, overrides cua. */ - class Mode @JsonCreator private constructor(private val value: JsonField) : Enum { + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers - /** - * 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 + /** + * Returns the raw JSON value of [resourceName]. + * + * Unlike [resourceName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("resourceName") + @ExcludeMissing + fun _resourceName(): JsonField = resourceName - companion object { + /** + * Returns the raw JSON value of [useDeploymentBasedUrls]. + * + * Unlike [useDeploymentBasedUrls], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + fun _useDeploymentBasedUrls(): JsonField = useDeploymentBasedUrls - @JvmField val DOM = of("dom") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - @JvmField val HYBRID = of("hybrid") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - @JvmField val CUA = of("cua") + fun toBuilder() = Builder().from(this) - @JvmStatic fun of(value: String) = Mode(JsonField.of(value)) - } + companion object { - /** An enum containing [Mode]'s known values. */ - enum class Known { - DOM, - HYBRID, - CUA, - } + /** + * Returns a mutable builder for constructing an instance of [Azure]. + */ + @JvmStatic fun builder() = Builder() + } - /** - * An enum containing [Mode]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Mode] 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 { - DOM, - HYBRID, - CUA, - /** An enum member indicating that [Mode] was instantiated with an unknown value. */ - _UNKNOWN, - } + /** A builder for [Azure]. */ + class Builder internal constructor() { - /** - * 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) { - DOM -> Value.DOM - HYBRID -> Value.HYBRID - CUA -> Value.CUA - else -> Value._UNKNOWN - } + private var apiVersion: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var resourceName: JsonField = JsonMissing.of() + private var useDeploymentBasedUrls: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() - /** - * 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 StagehandInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - DOM -> Known.DOM - HYBRID -> Known.HYBRID - CUA -> Known.CUA - else -> throw StagehandInvalidDataException("Unknown Mode: $value") - } + @JvmSynthetic + internal fun from(azure: Azure) = apply { + apiVersion = azure.apiVersion + baseUrl = azure.baseUrl + headers = azure.headers + resourceName = azure.resourceName + useDeploymentBasedUrls = azure.useDeploymentBasedUrls + additionalProperties = azure.additionalProperties.toMutableMap() + } - /** - * 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 StagehandInvalidDataException if this class instance's value does not have - * the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - StagehandInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false + /** Azure OpenAI API version */ + fun apiVersion(apiVersion: String) = + apiVersion(JsonField.of(apiVersion)) - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws StagehandInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): Mode = apply { - if (validated) { - return@apply - } + /** + * Sets [Builder.apiVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.apiVersion] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun apiVersion(apiVersion: JsonField) = apply { + this.apiVersion = apiVersion + } - known() - validated = true - } + /** Base URL for the Azure OpenAI provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) - fun isValid(): Boolean = - try { - validate() - true - } catch (e: StagehandInvalidDataException) { - false - } + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { + this.baseUrl = baseUrl + } - /** - * 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 + /** + * Custom headers sent with every request to the Azure OpenAI provider + */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun headers(headers: JsonField) = apply { + this.headers = headers + } - return other is Mode && value == other.value - } + /** Azure OpenAI resource name */ + fun resourceName(resourceName: String) = + resourceName(JsonField.of(resourceName)) - override fun hashCode() = value.hashCode() + /** + * Sets [Builder.resourceName] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceName] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun resourceName(resourceName: JsonField) = apply { + this.resourceName = resourceName + } - override fun toString() = value.toString() - } + /** Whether to use deployment-based Azure OpenAI URLs */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: Boolean) = + useDeploymentBasedUrls(JsonField.of(useDeploymentBasedUrls)) - /** Model configuration object or model name string (e.g., 'openai/gpt-5-nano') */ - @JsonDeserialize(using = Model.Deserializer::class) - @JsonSerialize(using = Model.Serializer::class) - class Model - private constructor( - private val vertexModelConfigObject: VertexModelConfigObject? = null, - private val genericModelConfigObject: GenericModelConfigObject? = null, - private val string: String? = null, - private val _json: JsonValue? = null, - ) { + /** + * Sets [Builder.useDeploymentBasedUrls] to an arbitrary JSON value. + * + * You should usually call [Builder.useDeploymentBasedUrls] with a + * well-typed [Boolean] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: JsonField) = + apply { + this.useDeploymentBasedUrls = useDeploymentBasedUrls + } - fun vertexModelConfigObject(): Optional = - Optional.ofNullable(vertexModelConfigObject) + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun genericModelConfigObject(): Optional = - Optional.ofNullable(genericModelConfigObject) + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - fun string(): Optional = Optional.ofNullable(string) + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - fun isVertexModelConfigObject(): Boolean = vertexModelConfigObject != null + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun isGenericModelConfigObject(): Boolean = genericModelConfigObject != null + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun isString(): Boolean = string != null + /** + * Returns an immutable instance of [Azure]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Azure = + Azure( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties.toMutableMap(), + ) + } - fun asVertexModelConfigObject(): VertexModelConfigObject = - vertexModelConfigObject.getOrThrow("vertexModelConfigObject") + private var validated: Boolean = false - fun asGenericModelConfigObject(): GenericModelConfigObject = - genericModelConfigObject.getOrThrow("genericModelConfigObject") + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Azure = apply { + if (validated) { + return@apply + } - fun asString(): String = string.getOrThrow("string") + apiVersion() + baseUrl() + headers().ifPresent { it.validate() } + resourceName() + useDeploymentBasedUrls() + validated = true + } - fun _json(): Optional = Optional.ofNullable(_json) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + false + } - /** - * Maps this instance's current variant to a value of type [T] using the given - * [visitor]. - * - * Note that this method is _not_ forwards compatible with new variants from the API, - * unless [visitor] overrides [Visitor.unknown]. To handle variants not known to this - * version of the SDK gracefully, consider overriding [Visitor.unknown]: - * ```java - * import com.browserbase.api.core.JsonValue; - * import java.util.Optional; - * - * Optional result = model.accept(new Model.Visitor>() { - * @Override - * public Optional visitVertexModelConfigObject(VertexModelConfigObject vertexModelConfigObject) { - * return Optional.of(vertexModelConfigObject.toString()); - * } - * - * // ... - * - * @Override - * public Optional unknown(JsonValue json) { - * // Or inspect the `json`. - * return Optional.empty(); - * } - * }); - * ``` - * - * @throws StagehandInvalidDataException if [Visitor.unknown] is not overridden in - * [visitor] and the current variant is unknown. - */ - fun accept(visitor: Visitor): T = - when { - vertexModelConfigObject != null -> - visitor.visitVertexModelConfigObject(vertexModelConfigObject) - genericModelConfigObject != null -> - visitor.visitGenericModelConfigObject(genericModelConfigObject) - string != null -> visitor.visitString(string) - else -> visitor.unknown(_json) - } + /** + * 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 (apiVersion.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceName.asKnown().isPresent) 1 else 0) + + (if (useDeploymentBasedUrls.asKnown().isPresent) 1 else 0) - private var validated: Boolean = false + /** Custom headers sent with every request to the Azure OpenAI provider */ + class Headers + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - /** - * Validates that the types of all values in this object match their expected types - * recursively. - * - * This method is _not_ forwards compatible with new types from the API for existing - * fields. - * - * @throws StagehandInvalidDataException if any value type in this object doesn't match - * its expected type. - */ - fun validate(): Model = apply { - if (validated) { - return@apply - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties - accept( - object : Visitor { - override fun visitVertexModelConfigObject( - vertexModelConfigObject: VertexModelConfigObject - ) { - vertexModelConfigObject.validate() - } + fun toBuilder() = Builder().from(this) - override fun visitGenericModelConfigObject( - genericModelConfigObject: GenericModelConfigObject - ) { - genericModelConfigObject.validate() - } + companion object { - override fun visitString(string: String) {} - } - ) - validated = true - } + /** + * Returns a mutable builder for constructing an instance of + * [Headers]. + */ + @JvmStatic fun builder() = Builder() + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: StagehandInvalidDataException) { - false - } + /** A builder for [Headers]. */ + class Builder internal constructor() { - /** - * 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 visitVertexModelConfigObject( - vertexModelConfigObject: VertexModelConfigObject - ) = vertexModelConfigObject.validity() + private var additionalProperties: MutableMap = + mutableMapOf() - override fun visitGenericModelConfigObject( - genericModelConfigObject: GenericModelConfigObject - ) = genericModelConfigObject.validity() + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = + headers.additionalProperties.toMutableMap() + } - override fun visitString(string: String) = 1 + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - override fun unknown(json: JsonValue?) = 0 - } - ) + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } - return other is Model && - vertexModelConfigObject == other.vertexModelConfigObject && - genericModelConfigObject == other.genericModelConfigObject && - string == other.string - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - override fun hashCode(): Int = - Objects.hash(vertexModelConfigObject, genericModelConfigObject, string) + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - override fun toString(): String = - when { - vertexModelConfigObject != null -> - "Model{vertexModelConfigObject=$vertexModelConfigObject}" - genericModelConfigObject != null -> - "Model{genericModelConfigObject=$genericModelConfigObject}" - string != null -> "Model{string=$string}" - _json != null -> "Model{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Model") - } + /** + * Returns an immutable instance of [Headers]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } - companion object { + private var validated: Boolean = false - @JvmStatic - fun ofVertexModelConfigObject(vertexModelConfigObject: VertexModelConfigObject) = - Model(vertexModelConfigObject = vertexModelConfigObject) + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws StagehandInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } - @JvmStatic - fun ofGenericModelConfigObject(genericModelConfigObject: GenericModelConfigObject) = - Model(genericModelConfigObject = genericModelConfigObject) + validated = true + } - @JvmStatic fun ofString(string: String) = Model(string = string) - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + false + } - /** - * An interface that defines how to map each variant of [Model] to a value of type [T]. - */ - interface Visitor { + /** + * 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() + } - fun visitVertexModelConfigObject( - vertexModelConfigObject: VertexModelConfigObject - ): T + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun visitGenericModelConfigObject( - genericModelConfigObject: GenericModelConfigObject - ): T + return other is Headers && + additionalProperties == other.additionalProperties + } - fun visitString(string: String): T + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /** - * Maps an unknown variant of [Model] to a value of type [T]. - * - * An instance of [Model] 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 StagehandInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw StagehandInvalidDataException("Unknown Model: $json") - } - } + override fun hashCode(): Int = hashCode - internal class Deserializer : BaseDeserializer(Model::class) { + override fun toString() = + "Headers{additionalProperties=$additionalProperties}" + } - override fun ObjectCodec.deserialize(node: JsonNode): Model { - val json = JsonValue.fromJsonNode(node) + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef()) - ?.let { Model(vertexModelConfigObject = it, _json = json) }, - tryDeserialize(node, jacksonTypeRef()) - ?.let { Model(genericModelConfigObject = it, _json = json) }, - tryDeserialize(node, jacksonTypeRef())?.let { - Model(string = it, _json = json) - }, + return other is Azure && + apiVersion == other.apiVersion && + baseUrl == other.baseUrl && + headers == other.headers && + resourceName == other.resourceName && + useDeploymentBasedUrls == other.useDeploymentBasedUrls && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties, ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely incompatible - // with all the possible variants (e.g. deserializing from boolean). - 0 -> Model(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, then use the - // first completely valid match, or simply the first match if none are - // completely valid. - else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Azure{apiVersion=$apiVersion, baseUrl=$baseUrl, headers=$headers, resourceName=$resourceName, useDeploymentBasedUrls=$useDeploymentBasedUrls, additionalProperties=$additionalProperties}" } - } - } - internal class Serializer : BaseSerializer(Model::class) { + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - override fun serialize( - value: Model, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.vertexModelConfigObject != null -> - generator.writeObject(value.vertexModelConfigObject) - value.genericModelConfigObject != null -> - generator.writeObject(value.genericModelConfigObject) - value.string != null -> generator.writeObject(value.string) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Model") + return other is ProviderOptions && + azure == other.azure && + additionalProperties == other.additionalProperties } - } - } - class VertexModelConfigObject - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val auth: JsonField, - private val modelName: JsonField, - private val provider: JsonValue, - private val providerOptions: JsonField, - private val apiKey: JsonField, - private val baseUrl: JsonField, - private val headers: JsonField, - private val additionalProperties: MutableMap, - ) { + private val hashCode: Int by lazy { Objects.hash(azure, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProviderOptions{azure=$azure, additionalProperties=$additionalProperties}" + } + + /** Custom headers sent with every request to the model provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AzureEntraModelConfigObject && + auth == other.auth && + modelName == other.modelName && + provider == other.provider && + providerOptions == other.providerOptions && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + auth, + modelName, + provider, + providerOptions, + baseUrl, + headers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AzureEntraModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + + class AzureApiKeyModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val modelName: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, + private val apiKey: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { @JsonCreator private constructor( - @JsonProperty("auth") @ExcludeMissing auth: JsonField = JsonMissing.of(), @JsonProperty("modelName") @ExcludeMissing modelName: JsonField = JsonMissing.of(), @@ -4924,7 +5432,6 @@ private constructor( @ExcludeMissing headers: JsonField = JsonMissing.of(), ) : this( - auth, modelName, provider, providerOptions, @@ -4934,15 +5441,6 @@ private constructor( mutableMapOf(), ) - /** - * Vertex provider authentication configuration - * - * @throws StagehandInvalidDataException 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 auth(): Auth = auth.getRequired("auth") - /** * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') * @@ -4953,11 +5451,11 @@ private constructor( fun modelName(): String = modelName.getRequired("modelName") /** - * Vertex AI model provider + * Azure OpenAI model provider * * Expected to always return the following: * ```java - * JsonValue.from("vertex") + * JsonValue.from("azure") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server @@ -4966,7 +5464,7 @@ private constructor( @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider /** - * Vertex provider-specific model configuration + * Azure provider-specific model configuration * * @throws StagehandInvalidDataException if the JSON field has an unexpected type or * is unexpectedly missing or null (e.g. if the server responded with an @@ -4999,14 +5497,6 @@ private constructor( */ fun headers(): Optional = headers.getOptional("headers") - /** - * Returns the raw JSON value of [auth]. - * - * Unlike [auth], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("auth") @ExcludeMissing fun _auth(): JsonField = auth - /** * Returns the raw JSON value of [modelName]. * @@ -5069,11 +5559,10 @@ private constructor( /** * Returns a mutable builder for constructing an instance of - * [VertexModelConfigObject]. + * [AzureApiKeyModelConfigObject]. * * The following fields are required: * ```java - * .auth() * .modelName() * .providerOptions() * ``` @@ -5081,12 +5570,11 @@ private constructor( @JvmStatic fun builder() = Builder() } - /** A builder for [VertexModelConfigObject]. */ + /** A builder for [AzureApiKeyModelConfigObject]. */ class Builder internal constructor() { - private var auth: JsonField? = null private var modelName: JsonField? = null - private var provider: JsonValue = JsonValue.from("vertex") + private var provider: JsonValue = JsonValue.from("azure") private var providerOptions: JsonField? = null private var apiKey: JsonField = JsonMissing.of() private var baseUrl: JsonField = JsonMissing.of() @@ -5094,29 +5582,17 @@ private constructor( private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(vertexModelConfigObject: VertexModelConfigObject) = apply { - auth = vertexModelConfigObject.auth - modelName = vertexModelConfigObject.modelName - provider = vertexModelConfigObject.provider - providerOptions = vertexModelConfigObject.providerOptions - apiKey = vertexModelConfigObject.apiKey - baseUrl = vertexModelConfigObject.baseUrl - headers = vertexModelConfigObject.headers - additionalProperties = - vertexModelConfigObject.additionalProperties.toMutableMap() - } - - /** Vertex provider authentication configuration */ - fun auth(auth: Auth) = auth(JsonField.of(auth)) - - /** - * Sets [Builder.auth] to an arbitrary JSON value. - * - * You should usually call [Builder.auth] with a well-typed [Auth] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun auth(auth: JsonField) = apply { this.auth = auth } + internal fun from(azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject) = + apply { + modelName = azureApiKeyModelConfigObject.modelName + provider = azureApiKeyModelConfigObject.provider + providerOptions = azureApiKeyModelConfigObject.providerOptions + apiKey = azureApiKeyModelConfigObject.apiKey + baseUrl = azureApiKeyModelConfigObject.baseUrl + headers = azureApiKeyModelConfigObject.headers + additionalProperties = + azureApiKeyModelConfigObject.additionalProperties.toMutableMap() + } /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ fun modelName(modelName: String) = modelName(JsonField.of(modelName)) @@ -5138,7 +5614,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to * the following: * ```java - * JsonValue.from("vertex") + * JsonValue.from("azure") * ``` * * This method is primarily for setting the field to an undocumented or not yet @@ -5146,7 +5622,7 @@ private constructor( */ fun provider(provider: JsonValue) = apply { this.provider = provider } - /** Vertex provider-specific model configuration */ + /** Azure provider-specific model configuration */ fun providerOptions(providerOptions: ProviderOptions) = providerOptions(JsonField.of(providerOptions)) @@ -5220,22 +5696,20 @@ private constructor( } /** - * Returns an immutable instance of [VertexModelConfigObject]. + * Returns an immutable instance of [AzureApiKeyModelConfigObject]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java - * .auth() * .modelName() * .providerOptions() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): VertexModelConfigObject = - VertexModelConfigObject( - checkRequired("auth", auth), + fun build(): AzureApiKeyModelConfigObject = + AzureApiKeyModelConfigObject( checkRequired("modelName", modelName), provider, checkRequired("providerOptions", providerOptions), @@ -5258,15 +5732,14 @@ private constructor( * @throws StagehandInvalidDataException if any value type in this object doesn't * match its expected type. */ - fun validate(): VertexModelConfigObject = apply { + fun validate(): AzureApiKeyModelConfigObject = apply { if (validated) { return@apply } - auth().validate() modelName() _provider().let { - if (it != JsonValue.from("vertex")) { + if (it != JsonValue.from("azure")) { throw StagehandInvalidDataException( "'provider' is invalid, received $it" ) @@ -5295,130 +5768,44 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (auth.asKnown().getOrNull()?.validity() ?: 0) + - (if (modelName.asKnown().isPresent) 1 else 0) + - provider.let { if (it == JsonValue.from("vertex")) 1 else 0 } + + (if (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("azure")) 1 else 0 } + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + (if (apiKey.asKnown().isPresent) 1 else 0) + (if (baseUrl.asKnown().isPresent) 1 else 0) + (headers.asKnown().getOrNull()?.validity() ?: 0) - /** Vertex provider authentication configuration */ - class Auth + /** Azure provider-specific model configuration */ + class ProviderOptions @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val credentials: JsonField, - private val type: JsonValue, - private val projectId: JsonField, - private val scopes: JsonField, - private val universeDomain: JsonField, + private val azure: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("credentials") - @ExcludeMissing - credentials: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - @JsonProperty("projectId") - @ExcludeMissing - projectId: JsonField = JsonMissing.of(), - @JsonProperty("scopes") - @ExcludeMissing - scopes: JsonField = JsonMissing.of(), - @JsonProperty("universeDomain") + @JsonProperty("azure") @ExcludeMissing - universeDomain: JsonField = JsonMissing.of(), - ) : this(credentials, type, projectId, scopes, universeDomain, mutableMapOf()) + azure: JsonField = JsonMissing.of() + ) : this(azure, mutableMapOf()) /** - * Google Cloud service account credentials + * Azure OpenAI provider-specific settings * * @throws StagehandInvalidDataException 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 credentials(): Credentials = credentials.getRequired("credentials") + fun azure(): Azure = azure.getRequired("azure") /** - * Use inline Google Cloud service account credentials for provider - * authentication + * Returns the raw JSON value of [azure]. * - * Expected to always return the following: - * ```java - * JsonValue.from("googleServiceAccount") - * ``` - * - * However, this method can be useful for debugging and logging (e.g. if the - * server responded with an unexpected value). + * Unlike [azure], this method doesn't throw if the JSON field has an unexpected + * type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type - - /** - * Google Cloud project ID used by google-auth-library - * - * @throws StagehandInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun projectId(): Optional = projectId.getOptional("projectId") - - /** - * Google auth scopes for the desired API request - * - * @throws StagehandInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun scopes(): Optional = scopes.getOptional("scopes") - - /** - * Google Cloud universe domain - * - * @throws StagehandInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun universeDomain(): Optional = - universeDomain.getOptional("universeDomain") - - /** - * Returns the raw JSON value of [credentials]. - * - * Unlike [credentials], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("credentials") - @ExcludeMissing - fun _credentials(): JsonField = credentials - - /** - * Returns the raw JSON value of [projectId]. - * - * Unlike [projectId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("projectId") - @ExcludeMissing - fun _projectId(): JsonField = projectId - - /** - * Returns the raw JSON value of [scopes]. - * - * Unlike [scopes], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("scopes") - @ExcludeMissing - fun _scopes(): JsonField = scopes - - /** - * Returns the raw JSON value of [universeDomain]. - * - * Unlike [universeDomain], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("universeDomain") - @ExcludeMissing - fun _universeDomain(): JsonField = universeDomain + @JsonProperty("azure") @ExcludeMissing fun _azure(): JsonField = azure @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -5435,113 +5822,42 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [Auth]. + * Returns a mutable builder for constructing an instance of + * [ProviderOptions]. * * The following fields are required: * ```java - * .credentials() + * .azure() * ``` */ @JvmStatic fun builder() = Builder() } - /** A builder for [Auth]. */ + /** A builder for [ProviderOptions]. */ class Builder internal constructor() { - private var credentials: JsonField? = null - private var type: JsonValue = JsonValue.from("googleServiceAccount") - private var projectId: JsonField = JsonMissing.of() - private var scopes: JsonField = JsonMissing.of() - private var universeDomain: JsonField = JsonMissing.of() + private var azure: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(auth: Auth) = apply { - credentials = auth.credentials - type = auth.type - projectId = auth.projectId - scopes = auth.scopes - universeDomain = auth.universeDomain - additionalProperties = auth.additionalProperties.toMutableMap() - } - - /** Google Cloud service account credentials */ - fun credentials(credentials: Credentials) = - credentials(JsonField.of(credentials)) - - /** - * Sets [Builder.credentials] to an arbitrary JSON value. - * - * You should usually call [Builder.credentials] with a well-typed - * [Credentials] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun credentials(credentials: JsonField) = apply { - this.credentials = credentials - } - - /** - * 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("googleServiceAccount") - * ``` - * - * This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun type(type: JsonValue) = apply { this.type = type } - - /** Google Cloud project ID used by google-auth-library */ - fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun projectId(projectId: JsonField) = apply { - this.projectId = projectId + internal fun from(providerOptions: ProviderOptions) = apply { + azure = providerOptions.azure + additionalProperties = + providerOptions.additionalProperties.toMutableMap() } - /** Google auth scopes for the desired API request */ - fun scopes(scopes: Scopes) = scopes(JsonField.of(scopes)) + /** Azure OpenAI provider-specific settings */ + fun azure(azure: Azure) = azure(JsonField.of(azure)) /** - * Sets [Builder.scopes] to an arbitrary JSON value. + * Sets [Builder.azure] to an arbitrary JSON value. * - * You should usually call [Builder.scopes] with a well-typed [Scopes] value + * You should usually call [Builder.azure] with a well-typed [Azure] value * instead. This method is primarily for setting the field to an * undocumented or not yet supported value. */ - fun scopes(scopes: JsonField) = apply { this.scopes = scopes } - - /** Alias for calling [scopes] with `Scopes.ofString(string)`. */ - fun scopes(string: String) = scopes(Scopes.ofString(string)) - - /** Alias for calling [scopes] with `Scopes.ofStrings(strings)`. */ - fun scopesOfStrings(strings: List) = - scopes(Scopes.ofStrings(strings)) - - /** Google Cloud universe domain */ - fun universeDomain(universeDomain: String) = - universeDomain(JsonField.of(universeDomain)) - - /** - * Sets [Builder.universeDomain] to an arbitrary JSON value. - * - * You should usually call [Builder.universeDomain] with a well-typed - * [String] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun universeDomain(universeDomain: JsonField) = apply { - this.universeDomain = universeDomain - } + fun azure(azure: JsonField) = apply { this.azure = azure } fun additionalProperties(additionalProperties: Map) = apply { @@ -5566,24 +5882,20 @@ private constructor( } /** - * Returns an immutable instance of [Auth]. + * Returns an immutable instance of [ProviderOptions]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java - * .credentials() + * .azure() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): Auth = - Auth( - checkRequired("credentials", credentials), - type, - projectId, - scopes, - universeDomain, + fun build(): ProviderOptions = + ProviderOptions( + checkRequired("azure", azure), additionalProperties.toMutableMap(), ) } @@ -5600,22 +5912,12 @@ private constructor( * @throws StagehandInvalidDataException if any value type in this object * doesn't match its expected type. */ - fun validate(): Auth = apply { + fun validate(): ProviderOptions = apply { if (validated) { return@apply } - credentials().validate() - _type().let { - if (it != JsonValue.from("googleServiceAccount")) { - throw StagehandInvalidDataException( - "'type' is invalid, received $it" - ) - } - } - projectId() - scopes().ifPresent { it.validate() } - universeDomain() + azure().validate() validated = true } @@ -5634,262 +5936,137 @@ private constructor( * Used for best match union deserialization. */ @JvmSynthetic - internal fun validity(): Int = - (credentials.asKnown().getOrNull()?.validity() ?: 0) + - type.let { - if (it == JsonValue.from("googleServiceAccount")) 1 else 0 - } + - (if (projectId.asKnown().isPresent) 1 else 0) + - (scopes.asKnown().getOrNull()?.validity() ?: 0) + - (if (universeDomain.asKnown().isPresent) 1 else 0) + internal fun validity(): Int = (azure.asKnown().getOrNull()?.validity() ?: 0) - /** Google Cloud service account credentials */ - class Credentials + /** Azure OpenAI provider-specific settings */ + class Azure @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val clientEmail: JsonField, - private val privateKey: JsonField, - private val authProviderX509CertUrl: JsonField, - private val authUri: JsonField, - private val clientId: JsonField, - private val clientX509CertUrl: JsonField, - private val privateKeyId: JsonField, - private val projectId: JsonField, - private val tokenUri: JsonField, - private val type: JsonField, - private val universeDomain: JsonField, + private val apiVersion: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val resourceName: JsonField, + private val useDeploymentBasedUrls: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("client_email") - @ExcludeMissing - clientEmail: JsonField = JsonMissing.of(), - @JsonProperty("private_key") + @JsonProperty("apiVersion") @ExcludeMissing - privateKey: JsonField = JsonMissing.of(), - @JsonProperty("auth_provider_x509_cert_url") - @ExcludeMissing - authProviderX509CertUrl: JsonField = JsonMissing.of(), - @JsonProperty("auth_uri") - @ExcludeMissing - authUri: JsonField = JsonMissing.of(), - @JsonProperty("client_id") - @ExcludeMissing - clientId: JsonField = JsonMissing.of(), - @JsonProperty("client_x509_cert_url") - @ExcludeMissing - clientX509CertUrl: JsonField = JsonMissing.of(), - @JsonProperty("private_key_id") - @ExcludeMissing - privateKeyId: JsonField = JsonMissing.of(), - @JsonProperty("project_id") + apiVersion: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") @ExcludeMissing - projectId: JsonField = JsonMissing.of(), - @JsonProperty("token_uri") + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") @ExcludeMissing - tokenUri: JsonField = JsonMissing.of(), - @JsonProperty("type") + headers: JsonField = JsonMissing.of(), + @JsonProperty("resourceName") @ExcludeMissing - type: JsonField = JsonMissing.of(), - @JsonProperty("universe_domain") + resourceName: JsonField = JsonMissing.of(), + @JsonProperty("useDeploymentBasedUrls") @ExcludeMissing - universeDomain: JsonField = JsonMissing.of(), + useDeploymentBasedUrls: JsonField = JsonMissing.of(), ) : this( - clientEmail, - privateKey, - authProviderX509CertUrl, - authUri, - clientId, - clientX509CertUrl, - privateKeyId, - projectId, - tokenUri, - type, - universeDomain, + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, mutableMapOf(), ) /** + * Azure OpenAI API version + * * @throws StagehandInvalidDataException if the JSON field has an unexpected - * type or is unexpectedly missing or null (e.g. if the server responded - * with an unexpected value). + * type (e.g. if the server responded with an unexpected value). */ - fun clientEmail(): String = clientEmail.getRequired("client_email") - - /** - * @throws StagehandInvalidDataException 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 privateKey(): String = privateKey.getRequired("private_key") - - /** - * @throws StagehandInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun authProviderX509CertUrl(): Optional = - authProviderX509CertUrl.getOptional("auth_provider_x509_cert_url") - - /** - * @throws StagehandInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun authUri(): Optional = authUri.getOptional("auth_uri") - - /** - * @throws StagehandInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun clientId(): Optional = clientId.getOptional("client_id") - - /** - * @throws StagehandInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun clientX509CertUrl(): Optional = - clientX509CertUrl.getOptional("client_x509_cert_url") + fun apiVersion(): Optional = apiVersion.getOptional("apiVersion") /** + * Base URL for the Azure OpenAI provider + * * @throws StagehandInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun privateKeyId(): Optional = - privateKeyId.getOptional("private_key_id") - - /** - * @throws StagehandInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun projectId(): Optional = projectId.getOptional("project_id") + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") /** + * Custom headers sent with every request to the Azure OpenAI provider + * * @throws StagehandInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun tokenUri(): Optional = tokenUri.getOptional("token_uri") + fun headers(): Optional = headers.getOptional("headers") /** + * Azure OpenAI resource name + * * @throws StagehandInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun type(): Optional = type.getOptional("type") + fun resourceName(): Optional = + resourceName.getOptional("resourceName") /** + * Whether to use deployment-based Azure OpenAI URLs + * * @throws StagehandInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun universeDomain(): Optional = - universeDomain.getOptional("universe_domain") - - /** - * Returns the raw JSON value of [clientEmail]. - * - * Unlike [clientEmail], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("client_email") - @ExcludeMissing - fun _clientEmail(): JsonField = clientEmail - - /** - * Returns the raw JSON value of [privateKey]. - * - * Unlike [privateKey], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("private_key") - @ExcludeMissing - fun _privateKey(): JsonField = privateKey - - /** - * Returns the raw JSON value of [authProviderX509CertUrl]. - * - * Unlike [authProviderX509CertUrl], this method doesn't throw if the JSON - * field has an unexpected type. - */ - @JsonProperty("auth_provider_x509_cert_url") - @ExcludeMissing - fun _authProviderX509CertUrl(): JsonField = authProviderX509CertUrl - - /** - * Returns the raw JSON value of [authUri]. - * - * Unlike [authUri], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("auth_uri") - @ExcludeMissing - fun _authUri(): JsonField = authUri + fun useDeploymentBasedUrls(): Optional = + useDeploymentBasedUrls.getOptional("useDeploymentBasedUrls") /** - * Returns the raw JSON value of [clientId]. + * Returns the raw JSON value of [apiVersion]. * - * Unlike [clientId], this method doesn't throw if the JSON field has an + * Unlike [apiVersion], this method doesn't throw if the JSON field has an * unexpected type. */ - @JsonProperty("client_id") - @ExcludeMissing - fun _clientId(): JsonField = clientId - - /** - * Returns the raw JSON value of [clientX509CertUrl]. - * - * Unlike [clientX509CertUrl], this method doesn't throw if the JSON field - * has an unexpected type. - */ - @JsonProperty("client_x509_cert_url") + @JsonProperty("apiVersion") @ExcludeMissing - fun _clientX509CertUrl(): JsonField = clientX509CertUrl + fun _apiVersion(): JsonField = apiVersion /** - * Returns the raw JSON value of [privateKeyId]. + * Returns the raw JSON value of [baseUrl]. * - * Unlike [privateKeyId], this method doesn't throw if the JSON field has an + * Unlike [baseUrl], this method doesn't throw if the JSON field has an * unexpected type. */ - @JsonProperty("private_key_id") + @JsonProperty("baseURL") @ExcludeMissing - fun _privateKeyId(): JsonField = privateKeyId + fun _baseUrl(): JsonField = baseUrl /** - * Returns the raw JSON value of [projectId]. + * Returns the raw JSON value of [headers]. * - * Unlike [projectId], this method doesn't throw if the JSON field has an + * Unlike [headers], this method doesn't throw if the JSON field has an * unexpected type. */ - @JsonProperty("project_id") + @JsonProperty("headers") @ExcludeMissing - fun _projectId(): JsonField = projectId + fun _headers(): JsonField = headers /** - * Returns the raw JSON value of [tokenUri]. + * Returns the raw JSON value of [resourceName]. * - * Unlike [tokenUri], this method doesn't throw if the JSON field has an + * Unlike [resourceName], this method doesn't throw if the JSON field has an * unexpected type. */ - @JsonProperty("token_uri") + @JsonProperty("resourceName") @ExcludeMissing - fun _tokenUri(): JsonField = tokenUri - - /** - * 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 + fun _resourceName(): JsonField = resourceName /** - * Returns the raw JSON value of [universeDomain]. + * Returns the raw JSON value of [useDeploymentBasedUrls]. * - * Unlike [universeDomain], this method doesn't throw if the JSON field has - * an unexpected type. + * Unlike [useDeploymentBasedUrls], this method doesn't throw if the JSON + * field has an unexpected type. */ - @JsonProperty("universe_domain") + @JsonProperty("useDeploymentBasedUrls") @ExcludeMissing - fun _universeDomain(): JsonField = universeDomain + fun _useDeploymentBasedUrls(): JsonField = useDeploymentBasedUrls @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -5906,205 +6083,114 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of - * [Credentials]. - * - * The following fields are required: - * ```java - * .clientEmail() - * .privateKey() - * ``` + * Returns a mutable builder for constructing an instance of [Azure]. */ @JvmStatic fun builder() = Builder() } - /** A builder for [Credentials]. */ + /** A builder for [Azure]. */ class Builder internal constructor() { - private var clientEmail: JsonField? = null - private var privateKey: JsonField? = null - private var authProviderX509CertUrl: JsonField = + private var apiVersion: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var resourceName: JsonField = JsonMissing.of() + private var useDeploymentBasedUrls: JsonField = JsonMissing.of() - private var authUri: JsonField = JsonMissing.of() - private var clientId: JsonField = JsonMissing.of() - private var clientX509CertUrl: JsonField = JsonMissing.of() - private var privateKeyId: JsonField = JsonMissing.of() - private var projectId: JsonField = JsonMissing.of() - private var tokenUri: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() - private var universeDomain: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(credentials: Credentials) = apply { - clientEmail = credentials.clientEmail - privateKey = credentials.privateKey - authProviderX509CertUrl = credentials.authProviderX509CertUrl - authUri = credentials.authUri - clientId = credentials.clientId - clientX509CertUrl = credentials.clientX509CertUrl - privateKeyId = credentials.privateKeyId - projectId = credentials.projectId - tokenUri = credentials.tokenUri - type = credentials.type - universeDomain = credentials.universeDomain - additionalProperties = - credentials.additionalProperties.toMutableMap() - } - - fun clientEmail(clientEmail: String) = - clientEmail(JsonField.of(clientEmail)) - - /** - * Sets [Builder.clientEmail] to an arbitrary JSON value. - * - * You should usually call [Builder.clientEmail] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun clientEmail(clientEmail: JsonField) = apply { - this.clientEmail = clientEmail + internal fun from(azure: Azure) = apply { + apiVersion = azure.apiVersion + baseUrl = azure.baseUrl + headers = azure.headers + resourceName = azure.resourceName + useDeploymentBasedUrls = azure.useDeploymentBasedUrls + additionalProperties = azure.additionalProperties.toMutableMap() } - fun privateKey(privateKey: String) = - privateKey(JsonField.of(privateKey)) + /** Azure OpenAI API version */ + fun apiVersion(apiVersion: String) = + apiVersion(JsonField.of(apiVersion)) /** - * Sets [Builder.privateKey] to an arbitrary JSON value. + * Sets [Builder.apiVersion] to an arbitrary JSON value. * - * You should usually call [Builder.privateKey] with a well-typed + * You should usually call [Builder.apiVersion] with a well-typed * [String] value instead. This method is primarily for setting the * field to an undocumented or not yet supported value. */ - fun privateKey(privateKey: JsonField) = apply { - this.privateKey = privateKey + fun apiVersion(apiVersion: JsonField) = apply { + this.apiVersion = apiVersion } - fun authProviderX509CertUrl(authProviderX509CertUrl: String) = - authProviderX509CertUrl(JsonField.of(authProviderX509CertUrl)) - - /** - * Sets [Builder.authProviderX509CertUrl] to an arbitrary JSON value. - * - * You should usually call [Builder.authProviderX509CertUrl] with a - * well-typed [String] value instead. This method is primarily for - * setting the field to an undocumented or not yet supported value. - */ - fun authProviderX509CertUrl( - authProviderX509CertUrl: JsonField - ) = apply { this.authProviderX509CertUrl = authProviderX509CertUrl } - - fun authUri(authUri: String) = authUri(JsonField.of(authUri)) + /** Base URL for the Azure OpenAI provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) /** - * Sets [Builder.authUri] to an arbitrary JSON value. + * Sets [Builder.baseUrl] to an arbitrary JSON value. * - * You should usually call [Builder.authUri] with a well-typed [String] + * You should usually call [Builder.baseUrl] with a well-typed [String] * value instead. This method is primarily for setting the field to an * undocumented or not yet supported value. */ - fun authUri(authUri: JsonField) = apply { - this.authUri = authUri + fun baseUrl(baseUrl: JsonField) = apply { + this.baseUrl = baseUrl } - fun clientId(clientId: String) = clientId(JsonField.of(clientId)) + /** + * Custom headers sent with every request to the Azure OpenAI provider + */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) /** - * Sets [Builder.clientId] to an arbitrary JSON value. + * Sets [Builder.headers] to an arbitrary JSON value. * - * You should usually call [Builder.clientId] with a well-typed [String] + * You should usually call [Builder.headers] with a well-typed [Headers] * value instead. This method is primarily for setting the field to an * undocumented or not yet supported value. */ - fun clientId(clientId: JsonField) = apply { - this.clientId = clientId + fun headers(headers: JsonField) = apply { + this.headers = headers } - fun clientX509CertUrl(clientX509CertUrl: String) = - clientX509CertUrl(JsonField.of(clientX509CertUrl)) + /** Azure OpenAI resource name */ + fun resourceName(resourceName: String) = + resourceName(JsonField.of(resourceName)) /** - * Sets [Builder.clientX509CertUrl] to an arbitrary JSON value. + * Sets [Builder.resourceName] to an arbitrary JSON value. * - * You should usually call [Builder.clientX509CertUrl] with a well-typed + * You should usually call [Builder.resourceName] with a well-typed * [String] value instead. This method is primarily for setting the * field to an undocumented or not yet supported value. */ - fun clientX509CertUrl(clientX509CertUrl: JsonField) = apply { - this.clientX509CertUrl = clientX509CertUrl + fun resourceName(resourceName: JsonField) = apply { + this.resourceName = resourceName } - fun privateKeyId(privateKeyId: String) = - privateKeyId(JsonField.of(privateKeyId)) + /** Whether to use deployment-based Azure OpenAI URLs */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: Boolean) = + useDeploymentBasedUrls(JsonField.of(useDeploymentBasedUrls)) /** - * Sets [Builder.privateKeyId] to an arbitrary JSON value. + * Sets [Builder.useDeploymentBasedUrls] to an arbitrary JSON value. * - * You should usually call [Builder.privateKeyId] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. + * You should usually call [Builder.useDeploymentBasedUrls] with a + * well-typed [Boolean] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. */ - fun privateKeyId(privateKeyId: JsonField) = apply { - this.privateKeyId = privateKeyId - } + fun useDeploymentBasedUrls(useDeploymentBasedUrls: JsonField) = + apply { + this.useDeploymentBasedUrls = useDeploymentBasedUrls + } - fun projectId(projectId: String) = projectId(JsonField.of(projectId)) - - /** - * Sets [Builder.projectId] to an arbitrary JSON value. - * - * You should usually call [Builder.projectId] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun projectId(projectId: JsonField) = apply { - this.projectId = projectId - } - - fun tokenUri(tokenUri: String) = tokenUri(JsonField.of(tokenUri)) - - /** - * Sets [Builder.tokenUri] to an arbitrary JSON value. - * - * You should usually call [Builder.tokenUri] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun tokenUri(tokenUri: JsonField) = apply { - this.tokenUri = tokenUri - } - - 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 universeDomain(universeDomain: String) = - universeDomain(JsonField.of(universeDomain)) - - /** - * Sets [Builder.universeDomain] to an arbitrary JSON value. - * - * You should usually call [Builder.universeDomain] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun universeDomain(universeDomain: JsonField) = apply { - this.universeDomain = universeDomain - } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } fun putAdditionalProperty(key: String, value: JsonValue) = apply { additionalProperties.put(key, value) @@ -6123,32 +6209,18 @@ private constructor( } /** - * Returns an immutable instance of [Credentials]. + * Returns an immutable instance of [Azure]. * * Further updates to this [Builder] will not mutate the returned * instance. - * - * The following fields are required: - * ```java - * .clientEmail() - * .privateKey() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ - fun build(): Credentials = - Credentials( - checkRequired("clientEmail", clientEmail), - checkRequired("privateKey", privateKey), - authProviderX509CertUrl, - authUri, - clientId, - clientX509CertUrl, - privateKeyId, - projectId, - tokenUri, - type, - universeDomain, + fun build(): Azure = + Azure( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, additionalProperties.toMutableMap(), ) } @@ -6165,22 +6237,16 @@ private constructor( * @throws StagehandInvalidDataException if any value type in this object * doesn't match its expected type. */ - fun validate(): Credentials = apply { + fun validate(): Azure = apply { if (validated) { return@apply } - clientEmail() - privateKey() - authProviderX509CertUrl() - authUri() - clientId() - clientX509CertUrl() - privateKeyId() - projectId() - tokenUri() - type().ifPresent { it.validate() } - universeDomain() + apiVersion() + baseUrl() + headers().ifPresent { it.validate() } + resourceName() + useDeploymentBasedUrls() validated = true } @@ -6200,109 +6266,80 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (clientEmail.asKnown().isPresent) 1 else 0) + - (if (privateKey.asKnown().isPresent) 1 else 0) + - (if (authProviderX509CertUrl.asKnown().isPresent) 1 else 0) + - (if (authUri.asKnown().isPresent) 1 else 0) + - (if (clientId.asKnown().isPresent) 1 else 0) + - (if (clientX509CertUrl.asKnown().isPresent) 1 else 0) + - (if (privateKeyId.asKnown().isPresent) 1 else 0) + - (if (projectId.asKnown().isPresent) 1 else 0) + - (if (tokenUri.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (if (universeDomain.asKnown().isPresent) 1 else 0) + (if (apiVersion.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceName.asKnown().isPresent) 1 else 0) + + (if (useDeploymentBasedUrls.asKnown().isPresent) 1 else 0) - class Type + /** Custom headers sent with every request to the Azure OpenAI provider */ + class Headers @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. - */ + private constructor( @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { + private val additionalProperties: Map + ) { - @JvmField val SERVICE_ACCOUNT = of("service_account") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + additionalProperties - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } + fun toBuilder() = Builder().from(this) - /** An enum containing [Type]'s known values. */ - enum class Known { - SERVICE_ACCOUNT - } + companion object { - /** - * 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 { - SERVICE_ACCOUNT, /** - * An enum member indicating that [Type] was instantiated with an - * unknown value. + * Returns a mutable builder for constructing an instance of + * [Headers]. */ - _UNKNOWN, + @JvmStatic fun builder() = Builder() } - /** - * 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) { - SERVICE_ACCOUNT -> Value.SERVICE_ACCOUNT - else -> Value._UNKNOWN + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = + headers.additionalProperties.toMutableMap() } - /** - * 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 StagehandInvalidDataException if this class instance's value - * is a not a known member. - */ - fun known(): Known = - when (this) { - SERVICE_ACCOUNT -> Known.SERVICE_ACCOUNT - else -> - throw StagehandInvalidDataException("Unknown Type: $value") + fun additionalProperties( + additionalProperties: Map + ) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - /** - * 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 StagehandInvalidDataException if this class instance's value - * does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - StagehandInvalidDataException("Value is not a String") + 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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + private var validated: Boolean = false /** @@ -6315,12 +6352,11 @@ private constructor( * @throws StagehandInvalidDataException if any value type in this * object doesn't match its expected type. */ - fun validate(): Type = apply { + fun validate(): Headers = apply { if (validated) { return@apply } - known() validated = true } @@ -6339,19 +6375,26 @@ private constructor( * Used for best match union deserialization. */ @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + 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 Type && value == other.value + return other is Headers && + additionalProperties == other.additionalProperties } - override fun hashCode() = value.hashCode() + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - override fun toString() = value.toString() + override fun hashCode(): Int = hashCode + + override fun toString() = + "Headers{additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -6359,34 +6402,22 @@ private constructor( return true } - return other is Credentials && - clientEmail == other.clientEmail && - privateKey == other.privateKey && - authProviderX509CertUrl == other.authProviderX509CertUrl && - authUri == other.authUri && - clientId == other.clientId && - clientX509CertUrl == other.clientX509CertUrl && - privateKeyId == other.privateKeyId && - projectId == other.projectId && - tokenUri == other.tokenUri && - type == other.type && - universeDomain == other.universeDomain && + return other is Azure && + apiVersion == other.apiVersion && + baseUrl == other.baseUrl && + headers == other.headers && + resourceName == other.resourceName && + useDeploymentBasedUrls == other.useDeploymentBasedUrls && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { Objects.hash( - clientEmail, - privateKey, - authProviderX509CertUrl, - authUri, - clientId, - clientX509CertUrl, - privateKeyId, - projectId, - tokenUri, - type, - universeDomain, + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, additionalProperties, ) } @@ -6394,291 +6425,5657 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Credentials{clientEmail=$clientEmail, privateKey=$privateKey, authProviderX509CertUrl=$authProviderX509CertUrl, authUri=$authUri, clientId=$clientId, clientX509CertUrl=$clientX509CertUrl, privateKeyId=$privateKeyId, projectId=$projectId, tokenUri=$tokenUri, type=$type, universeDomain=$universeDomain, additionalProperties=$additionalProperties}" + "Azure{apiVersion=$apiVersion, baseUrl=$baseUrl, headers=$headers, resourceName=$resourceName, useDeploymentBasedUrls=$useDeploymentBasedUrls, additionalProperties=$additionalProperties}" } - /** Google auth scopes for the desired API request */ - @JsonDeserialize(using = Scopes.Deserializer::class) - @JsonSerialize(using = Scopes.Serializer::class) - class Scopes - private constructor( - private val string: String? = null, - private val strings: List? = null, - private val _json: JsonValue? = null, - ) { + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun string(): Optional = Optional.ofNullable(string) + return other is ProviderOptions && + azure == other.azure && + additionalProperties == other.additionalProperties + } - fun strings(): Optional> = Optional.ofNullable(strings) + private val hashCode: Int by lazy { Objects.hash(azure, additionalProperties) } - fun isString(): Boolean = string != null + override fun hashCode(): Int = hashCode - fun isStrings(): Boolean = strings != null + override fun toString() = + "ProviderOptions{azure=$azure, additionalProperties=$additionalProperties}" + } - fun asString(): String = string.getOrThrow("string") + /** Custom headers sent with every request to the model provider */ + class Headers + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { - fun asStrings(): List = strings.getOrThrow("strings") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties - fun _json(): Optional = Optional.ofNullable(_json) + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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) + } /** - * Maps this instance's current variant to a value of type [T] using the - * given [visitor]. - * - * Note that this method is _not_ forwards compatible with new variants from - * the API, unless [visitor] overrides [Visitor.unknown]. To handle variants - * not known to this version of the SDK gracefully, consider overriding - * [Visitor.unknown]: - * ```java - * import com.browserbase.api.core.JsonValue; - * import java.util.Optional; - * - * Optional result = scopes.accept(new Scopes.Visitor>() { - * @Override - * public Optional visitString(String string) { - * return Optional.of(string.toString()); - * } - * - * // ... - * - * @Override - * public Optional unknown(JsonValue json) { - * // Or inspect the `json`. - * return Optional.empty(); - * } - * }); - * ``` + * Returns an immutable instance of [Headers]. * - * @throws StagehandInvalidDataException if [Visitor.unknown] is not - * overridden in [visitor] and the current variant is unknown. + * Further updates to this [Builder] will not mutate the returned instance. */ - fun accept(visitor: Visitor): T = - when { - string != null -> visitor.visitString(string) - strings != null -> visitor.visitStrings(strings) - else -> visitor.unknown(_json) - } + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AzureApiKeyModelConfigObject && + modelName == other.modelName && + provider == other.provider && + providerOptions == other.providerOptions && + apiKey == other.apiKey && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + modelName, + provider, + providerOptions, + apiKey, + baseUrl, + headers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AzureApiKeyModelConfigObject{modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + + class GenericModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val modelName: JsonField, + private val apiKey: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val provider: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("modelName") + @ExcludeMissing + modelName: JsonField = JsonMissing.of(), + @JsonProperty("apiKey") + @ExcludeMissing + apiKey: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + @JsonProperty("provider") + @ExcludeMissing + provider: JsonField = JsonMissing.of(), + ) : this(modelName, apiKey, baseUrl, headers, provider, mutableMapOf()) + + /** + * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') + * + * @throws StagehandInvalidDataException 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 modelName(): String = modelName.getRequired("modelName") + + /** + * API key for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun apiKey(): Optional = apiKey.getOptional("apiKey") + + /** + * Base URL for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * AI provider for the model (or provide a baseURL endpoint instead) + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun provider(): Optional = provider.getOptional("provider") + + /** + * Returns the raw JSON value of [modelName]. + * + * Unlike [modelName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("modelName") + @ExcludeMissing + fun _modelName(): JsonField = modelName + + /** + * Returns the raw JSON value of [apiKey]. + * + * Unlike [apiKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("apiKey") @ExcludeMissing fun _apiKey(): JsonField = apiKey + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + /** + * Returns the raw JSON value of [provider]. + * + * Unlike [provider], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("provider") + @ExcludeMissing + fun _provider(): JsonField = provider + + @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 + * [GenericModelConfigObject]. + * + * The following fields are required: + * ```java + * .modelName() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [GenericModelConfigObject]. */ + class Builder internal constructor() { + + private var modelName: JsonField? = null + private var apiKey: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var provider: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(genericModelConfigObject: GenericModelConfigObject) = apply { + modelName = genericModelConfigObject.modelName + apiKey = genericModelConfigObject.apiKey + baseUrl = genericModelConfigObject.baseUrl + headers = genericModelConfigObject.headers + provider = genericModelConfigObject.provider + additionalProperties = + genericModelConfigObject.additionalProperties.toMutableMap() + } + + /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ + fun modelName(modelName: String) = modelName(JsonField.of(modelName)) + + /** + * Sets [Builder.modelName] to an arbitrary JSON value. + * + * You should usually call [Builder.modelName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun modelName(modelName: JsonField) = apply { + this.modelName = modelName + } + + /** API key for the model provider */ + fun apiKey(apiKey: String) = apiKey(JsonField.of(apiKey)) + + /** + * Sets [Builder.apiKey] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKey(apiKey: JsonField) = apply { this.apiKey = apiKey } + + /** Base URL for the model provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the model provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + /** AI provider for the model (or provide a baseURL endpoint instead) */ + fun provider(provider: Provider) = provider(JsonField.of(provider)) + + /** + * Sets [Builder.provider] to an arbitrary JSON value. + * + * You should usually call [Builder.provider] with a well-typed [Provider] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun provider(provider: JsonField) = apply { this.provider = provider } + + 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 [GenericModelConfigObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .modelName() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): GenericModelConfigObject = + GenericModelConfigObject( + checkRequired("modelName", modelName), + apiKey, + baseUrl, + headers, + provider, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): GenericModelConfigObject = apply { + if (validated) { + return@apply + } + + modelName() + apiKey() + baseUrl() + headers().ifPresent { it.validate() } + provider().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (modelName.asKnown().isPresent) 1 else 0) + + (if (apiKey.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (provider.asKnown().getOrNull()?.validity() ?: 0) + + /** Custom headers sent with every request to the model provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + /** AI provider for the model (or provide a baseURL endpoint instead) */ + class Provider + @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 OPENAI = of("openai") + + @JvmField val ANTHROPIC = of("anthropic") + + @JvmField val GOOGLE = of("google") + + @JvmField val MICROSOFT = of("microsoft") + + @JvmField val BEDROCK = of("bedrock") + + @JvmStatic fun of(value: String) = Provider(JsonField.of(value)) + } + + /** An enum containing [Provider]'s known values. */ + enum class Known { + OPENAI, + ANTHROPIC, + GOOGLE, + MICROSOFT, + BEDROCK, + } + + /** + * An enum containing [Provider]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Provider] 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 { + OPENAI, + ANTHROPIC, + GOOGLE, + MICROSOFT, + BEDROCK, + /** + * An enum member indicating that [Provider] 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) { + OPENAI -> Value.OPENAI + ANTHROPIC -> Value.ANTHROPIC + GOOGLE -> Value.GOOGLE + MICROSOFT -> Value.MICROSOFT + BEDROCK -> Value.BEDROCK + 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 StagehandInvalidDataException if this class instance's value is a not + * a known member. + */ + fun known(): Known = + when (this) { + OPENAI -> Known.OPENAI + ANTHROPIC -> Known.ANTHROPIC + GOOGLE -> Known.GOOGLE + MICROSOFT -> Known.MICROSOFT + BEDROCK -> Known.BEDROCK + else -> throw StagehandInvalidDataException("Unknown Provider: $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 StagehandInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + StagehandInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Provider = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Provider && 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 GenericModelConfigObject && + modelName == other.modelName && + apiKey == other.apiKey && + baseUrl == other.baseUrl && + headers == other.headers && + provider == other.provider && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + modelName, + apiKey, + baseUrl, + headers, + provider, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "GenericModelConfigObject{modelName=$modelName, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, provider=$provider, additionalProperties=$additionalProperties}" + } + } + + /** Tool mode for the agent (dom, hybrid, cua). If set, overrides cua. */ + class Mode @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 DOM = of("dom") + + @JvmField val HYBRID = of("hybrid") + + @JvmField val CUA = of("cua") + + @JvmStatic fun of(value: String) = Mode(JsonField.of(value)) + } + + /** An enum containing [Mode]'s known values. */ + enum class Known { + DOM, + HYBRID, + CUA, + } + + /** + * An enum containing [Mode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Mode] 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 { + DOM, + HYBRID, + CUA, + /** An enum member indicating that [Mode] 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) { + DOM -> Value.DOM + HYBRID -> Value.HYBRID + CUA -> Value.CUA + 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 StagehandInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + DOM -> Known.DOM + HYBRID -> Known.HYBRID + CUA -> Known.CUA + else -> throw StagehandInvalidDataException("Unknown Mode: $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 StagehandInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + StagehandInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Mode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Mode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Model configuration object or model name string (e.g., 'openai/gpt-5-nano') */ + @JsonDeserialize(using = Model.Deserializer::class) + @JsonSerialize(using = Model.Serializer::class) + class Model + private constructor( + private val vertexModelConfigObject: VertexModelConfigObject? = null, + private val azureEntraModelConfigObject: AzureEntraModelConfigObject? = null, + private val azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject? = null, + private val genericModelConfigObject: GenericModelConfigObject? = null, + private val string: String? = null, + private val _json: JsonValue? = null, + ) { + + fun vertexModelConfigObject(): Optional = + Optional.ofNullable(vertexModelConfigObject) + + fun azureEntraModelConfigObject(): Optional = + Optional.ofNullable(azureEntraModelConfigObject) + + fun azureApiKeyModelConfigObject(): Optional = + Optional.ofNullable(azureApiKeyModelConfigObject) + + fun genericModelConfigObject(): Optional = + Optional.ofNullable(genericModelConfigObject) + + fun string(): Optional = Optional.ofNullable(string) + + fun isVertexModelConfigObject(): Boolean = vertexModelConfigObject != null + + fun isAzureEntraModelConfigObject(): Boolean = azureEntraModelConfigObject != null + + fun isAzureApiKeyModelConfigObject(): Boolean = azureApiKeyModelConfigObject != null + + fun isGenericModelConfigObject(): Boolean = genericModelConfigObject != null + + fun isString(): Boolean = string != null + + fun asVertexModelConfigObject(): VertexModelConfigObject = + vertexModelConfigObject.getOrThrow("vertexModelConfigObject") + + fun asAzureEntraModelConfigObject(): AzureEntraModelConfigObject = + azureEntraModelConfigObject.getOrThrow("azureEntraModelConfigObject") + + fun asAzureApiKeyModelConfigObject(): AzureApiKeyModelConfigObject = + azureApiKeyModelConfigObject.getOrThrow("azureApiKeyModelConfigObject") + + fun asGenericModelConfigObject(): GenericModelConfigObject = + genericModelConfigObject.getOrThrow("genericModelConfigObject") + + fun asString(): String = string.getOrThrow("string") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given + * [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, + * unless [visitor] overrides [Visitor.unknown]. To handle variants not known to this + * version of the SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.browserbase.api.core.JsonValue; + * import java.util.Optional; + * + * Optional result = model.accept(new Model.Visitor>() { + * @Override + * public Optional visitVertexModelConfigObject(VertexModelConfigObject vertexModelConfigObject) { + * return Optional.of(vertexModelConfigObject.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws StagehandInvalidDataException if [Visitor.unknown] is not overridden in + * [visitor] and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + vertexModelConfigObject != null -> + visitor.visitVertexModelConfigObject(vertexModelConfigObject) + azureEntraModelConfigObject != null -> + visitor.visitAzureEntraModelConfigObject(azureEntraModelConfigObject) + azureApiKeyModelConfigObject != null -> + visitor.visitAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject) + genericModelConfigObject != null -> + visitor.visitGenericModelConfigObject(genericModelConfigObject) + string != null -> visitor.visitString(string) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Model = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitVertexModelConfigObject( + vertexModelConfigObject: VertexModelConfigObject + ) { + vertexModelConfigObject.validate() + } + + override fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) { + azureEntraModelConfigObject.validate() + } + + override fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) { + azureApiKeyModelConfigObject.validate() + } + + override fun visitGenericModelConfigObject( + genericModelConfigObject: GenericModelConfigObject + ) { + genericModelConfigObject.validate() + } + + override fun visitString(string: String) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 visitVertexModelConfigObject( + vertexModelConfigObject: VertexModelConfigObject + ) = vertexModelConfigObject.validity() + + override fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) = azureEntraModelConfigObject.validity() + + override fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) = azureApiKeyModelConfigObject.validity() + + override fun visitGenericModelConfigObject( + genericModelConfigObject: GenericModelConfigObject + ) = genericModelConfigObject.validity() + + override fun visitString(string: String) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Model && + vertexModelConfigObject == other.vertexModelConfigObject && + azureEntraModelConfigObject == other.azureEntraModelConfigObject && + azureApiKeyModelConfigObject == other.azureApiKeyModelConfigObject && + genericModelConfigObject == other.genericModelConfigObject && + string == other.string + } + + override fun hashCode(): Int = + Objects.hash( + vertexModelConfigObject, + azureEntraModelConfigObject, + azureApiKeyModelConfigObject, + genericModelConfigObject, + string, + ) + + override fun toString(): String = + when { + vertexModelConfigObject != null -> + "Model{vertexModelConfigObject=$vertexModelConfigObject}" + azureEntraModelConfigObject != null -> + "Model{azureEntraModelConfigObject=$azureEntraModelConfigObject}" + azureApiKeyModelConfigObject != null -> + "Model{azureApiKeyModelConfigObject=$azureApiKeyModelConfigObject}" + genericModelConfigObject != null -> + "Model{genericModelConfigObject=$genericModelConfigObject}" + string != null -> "Model{string=$string}" + _json != null -> "Model{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Model") + } + + companion object { + + @JvmStatic + fun ofVertexModelConfigObject(vertexModelConfigObject: VertexModelConfigObject) = + Model(vertexModelConfigObject = vertexModelConfigObject) + + @JvmStatic + fun ofAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) = Model(azureEntraModelConfigObject = azureEntraModelConfigObject) + + @JvmStatic + fun ofAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) = Model(azureApiKeyModelConfigObject = azureApiKeyModelConfigObject) + + @JvmStatic + fun ofGenericModelConfigObject(genericModelConfigObject: GenericModelConfigObject) = + Model(genericModelConfigObject = genericModelConfigObject) + + @JvmStatic fun ofString(string: String) = Model(string = string) + } + + /** + * An interface that defines how to map each variant of [Model] to a value of type [T]. + */ + interface Visitor { + + fun visitVertexModelConfigObject( + vertexModelConfigObject: VertexModelConfigObject + ): T + + fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ): T + + fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ): T + + fun visitGenericModelConfigObject( + genericModelConfigObject: GenericModelConfigObject + ): T + + fun visitString(string: String): T + + /** + * Maps an unknown variant of [Model] to a value of type [T]. + * + * An instance of [Model] 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 StagehandInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw StagehandInvalidDataException("Unknown Model: $json") + } + } + + internal class Deserializer : BaseDeserializer(Model::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Model { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef()) + ?.let { Model(vertexModelConfigObject = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { Model(azureEntraModelConfigObject = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { + Model(azureApiKeyModelConfigObject = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { Model(genericModelConfigObject = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef())?.let { + Model(string = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible + // with all the possible variants (e.g. deserializing from boolean). + 0 -> Model(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the + // first completely valid match, or simply the first match if none are + // completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Model::class) { + + override fun serialize( + value: Model, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.vertexModelConfigObject != null -> + generator.writeObject(value.vertexModelConfigObject) + value.azureEntraModelConfigObject != null -> + generator.writeObject(value.azureEntraModelConfigObject) + value.azureApiKeyModelConfigObject != null -> + generator.writeObject(value.azureApiKeyModelConfigObject) + value.genericModelConfigObject != null -> + generator.writeObject(value.genericModelConfigObject) + value.string != null -> generator.writeObject(value.string) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Model") + } + } + } + + class VertexModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val auth: JsonField, + private val modelName: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, + private val apiKey: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("auth") @ExcludeMissing auth: JsonField = JsonMissing.of(), + @JsonProperty("modelName") + @ExcludeMissing + modelName: JsonField = JsonMissing.of(), + @JsonProperty("provider") + @ExcludeMissing + provider: JsonValue = JsonMissing.of(), + @JsonProperty("providerOptions") + @ExcludeMissing + providerOptions: JsonField = JsonMissing.of(), + @JsonProperty("apiKey") + @ExcludeMissing + apiKey: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + ) : this( + auth, + modelName, + provider, + providerOptions, + apiKey, + baseUrl, + headers, + mutableMapOf(), + ) + + /** + * Vertex provider authentication configuration + * + * @throws StagehandInvalidDataException 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 auth(): Auth = auth.getRequired("auth") + + /** + * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') + * + * @throws StagehandInvalidDataException 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 modelName(): String = modelName.getRequired("modelName") + + /** + * Vertex AI model provider + * + * Expected to always return the following: + * ```java + * JsonValue.from("vertex") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider + + /** + * Vertex provider-specific model configuration + * + * @throws StagehandInvalidDataException 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 providerOptions(): ProviderOptions = + providerOptions.getRequired("providerOptions") + + /** + * API key for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun apiKey(): Optional = apiKey.getOptional("apiKey") + + /** + * Base URL for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Returns the raw JSON value of [auth]. + * + * Unlike [auth], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("auth") @ExcludeMissing fun _auth(): JsonField = auth + + /** + * Returns the raw JSON value of [modelName]. + * + * Unlike [modelName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("modelName") + @ExcludeMissing + fun _modelName(): JsonField = modelName + + /** + * Returns the raw JSON value of [providerOptions]. + * + * Unlike [providerOptions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("providerOptions") + @ExcludeMissing + fun _providerOptions(): JsonField = providerOptions + + /** + * Returns the raw JSON value of [apiKey]. + * + * Unlike [apiKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("apiKey") @ExcludeMissing fun _apiKey(): JsonField = apiKey + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + @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 + * [VertexModelConfigObject]. + * + * The following fields are required: + * ```java + * .auth() + * .modelName() + * .providerOptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VertexModelConfigObject]. */ + class Builder internal constructor() { + + private var auth: JsonField? = null + private var modelName: JsonField? = null + private var provider: JsonValue = JsonValue.from("vertex") + private var providerOptions: JsonField? = null + private var apiKey: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(vertexModelConfigObject: VertexModelConfigObject) = apply { + auth = vertexModelConfigObject.auth + modelName = vertexModelConfigObject.modelName + provider = vertexModelConfigObject.provider + providerOptions = vertexModelConfigObject.providerOptions + apiKey = vertexModelConfigObject.apiKey + baseUrl = vertexModelConfigObject.baseUrl + headers = vertexModelConfigObject.headers + additionalProperties = + vertexModelConfigObject.additionalProperties.toMutableMap() + } + + /** Vertex provider authentication configuration */ + fun auth(auth: Auth) = auth(JsonField.of(auth)) + + /** + * Sets [Builder.auth] to an arbitrary JSON value. + * + * You should usually call [Builder.auth] with a well-typed [Auth] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun auth(auth: JsonField) = apply { this.auth = auth } + + /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ + fun modelName(modelName: String) = modelName(JsonField.of(modelName)) + + /** + * Sets [Builder.modelName] to an arbitrary JSON value. + * + * You should usually call [Builder.modelName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun modelName(modelName: JsonField) = apply { + this.modelName = modelName + } + + /** + * 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("vertex") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun provider(provider: JsonValue) = apply { this.provider = provider } + + /** Vertex provider-specific model configuration */ + fun providerOptions(providerOptions: ProviderOptions) = + providerOptions(JsonField.of(providerOptions)) + + /** + * Sets [Builder.providerOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.providerOptions] with a well-typed + * [ProviderOptions] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun providerOptions(providerOptions: JsonField) = apply { + this.providerOptions = providerOptions + } + + /** API key for the model provider */ + fun apiKey(apiKey: String) = apiKey(JsonField.of(apiKey)) + + /** + * Sets [Builder.apiKey] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKey(apiKey: JsonField) = apply { this.apiKey = apiKey } + + /** Base URL for the model provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the model provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + 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 [VertexModelConfigObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .auth() + * .modelName() + * .providerOptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VertexModelConfigObject = + VertexModelConfigObject( + checkRequired("auth", auth), + checkRequired("modelName", modelName), + provider, + checkRequired("providerOptions", providerOptions), + apiKey, + baseUrl, + headers, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): VertexModelConfigObject = apply { + if (validated) { + return@apply + } + + auth().validate() + modelName() + _provider().let { + if (it != JsonValue.from("vertex")) { + throw StagehandInvalidDataException( + "'provider' is invalid, received $it" + ) + } + } + providerOptions().validate() + apiKey() + baseUrl() + headers().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = + (auth.asKnown().getOrNull()?.validity() ?: 0) + + (if (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("vertex")) 1 else 0 } + + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + + (if (apiKey.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + /** Vertex provider authentication configuration */ + class Auth + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val credentials: JsonField, + private val type: JsonValue, + private val projectId: JsonField, + private val scopes: JsonField, + private val universeDomain: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("credentials") + @ExcludeMissing + credentials: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("projectId") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("scopes") + @ExcludeMissing + scopes: JsonField = JsonMissing.of(), + @JsonProperty("universeDomain") + @ExcludeMissing + universeDomain: JsonField = JsonMissing.of(), + ) : this(credentials, type, projectId, scopes, universeDomain, mutableMapOf()) + + /** + * Google Cloud service account credentials + * + * @throws StagehandInvalidDataException 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 credentials(): Credentials = credentials.getRequired("credentials") + + /** + * Use inline Google Cloud service account credentials for provider + * authentication + * + * Expected to always return the following: + * ```java + * JsonValue.from("googleServiceAccount") + * ``` + * + * 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 + + /** + * Google Cloud project ID used by google-auth-library + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("projectId") + + /** + * Google auth scopes for the desired API request + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun scopes(): Optional = scopes.getOptional("scopes") + + /** + * Google Cloud universe domain + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun universeDomain(): Optional = + universeDomain.getOptional("universeDomain") + + /** + * Returns the raw JSON value of [credentials]. + * + * Unlike [credentials], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("credentials") + @ExcludeMissing + fun _credentials(): JsonField = credentials + + /** + * Returns the raw JSON value of [projectId]. + * + * Unlike [projectId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("projectId") + @ExcludeMissing + fun _projectId(): JsonField = projectId + + /** + * Returns the raw JSON value of [scopes]. + * + * Unlike [scopes], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("scopes") + @ExcludeMissing + fun _scopes(): JsonField = scopes + + /** + * Returns the raw JSON value of [universeDomain]. + * + * Unlike [universeDomain], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("universeDomain") + @ExcludeMissing + fun _universeDomain(): JsonField = universeDomain + + @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 [Auth]. + * + * The following fields are required: + * ```java + * .credentials() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Auth]. */ + class Builder internal constructor() { + + private var credentials: JsonField? = null + private var type: JsonValue = JsonValue.from("googleServiceAccount") + private var projectId: JsonField = JsonMissing.of() + private var scopes: JsonField = JsonMissing.of() + private var universeDomain: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(auth: Auth) = apply { + credentials = auth.credentials + type = auth.type + projectId = auth.projectId + scopes = auth.scopes + universeDomain = auth.universeDomain + additionalProperties = auth.additionalProperties.toMutableMap() + } + + /** Google Cloud service account credentials */ + fun credentials(credentials: Credentials) = + credentials(JsonField.of(credentials)) + + /** + * Sets [Builder.credentials] to an arbitrary JSON value. + * + * You should usually call [Builder.credentials] with a well-typed + * [Credentials] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun credentials(credentials: JsonField) = apply { + this.credentials = credentials + } + + /** + * 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("googleServiceAccount") + * ``` + * + * This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Google Cloud project ID used by google-auth-library */ + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) + + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun projectId(projectId: JsonField) = apply { + this.projectId = projectId + } + + /** Google auth scopes for the desired API request */ + fun scopes(scopes: Scopes) = scopes(JsonField.of(scopes)) + + /** + * Sets [Builder.scopes] to an arbitrary JSON value. + * + * You should usually call [Builder.scopes] with a well-typed [Scopes] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun scopes(scopes: JsonField) = apply { this.scopes = scopes } + + /** Alias for calling [scopes] with `Scopes.ofString(string)`. */ + fun scopes(string: String) = scopes(Scopes.ofString(string)) + + /** Alias for calling [scopes] with `Scopes.ofStrings(strings)`. */ + fun scopesOfStrings(strings: List) = + scopes(Scopes.ofStrings(strings)) + + /** Google Cloud universe domain */ + fun universeDomain(universeDomain: String) = + universeDomain(JsonField.of(universeDomain)) + + /** + * Sets [Builder.universeDomain] to an arbitrary JSON value. + * + * You should usually call [Builder.universeDomain] with a well-typed + * [String] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun universeDomain(universeDomain: JsonField) = apply { + this.universeDomain = universeDomain + } + + 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 [Auth]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .credentials() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Auth = + Auth( + checkRequired("credentials", credentials), + type, + projectId, + scopes, + universeDomain, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Auth = apply { + if (validated) { + return@apply + } + + credentials().validate() + _type().let { + if (it != JsonValue.from("googleServiceAccount")) { + throw StagehandInvalidDataException( + "'type' is invalid, received $it" + ) + } + } + projectId() + scopes().ifPresent { it.validate() } + universeDomain() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = + (credentials.asKnown().getOrNull()?.validity() ?: 0) + + type.let { + if (it == JsonValue.from("googleServiceAccount")) 1 else 0 + } + + (if (projectId.asKnown().isPresent) 1 else 0) + + (scopes.asKnown().getOrNull()?.validity() ?: 0) + + (if (universeDomain.asKnown().isPresent) 1 else 0) + + /** Google Cloud service account credentials */ + class Credentials + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val clientEmail: JsonField, + private val privateKey: JsonField, + private val authProviderX509CertUrl: JsonField, + private val authUri: JsonField, + private val clientId: JsonField, + private val clientX509CertUrl: JsonField, + private val privateKeyId: JsonField, + private val projectId: JsonField, + private val tokenUri: JsonField, + private val type: JsonField, + private val universeDomain: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("client_email") + @ExcludeMissing + clientEmail: JsonField = JsonMissing.of(), + @JsonProperty("private_key") + @ExcludeMissing + privateKey: JsonField = JsonMissing.of(), + @JsonProperty("auth_provider_x509_cert_url") + @ExcludeMissing + authProviderX509CertUrl: JsonField = JsonMissing.of(), + @JsonProperty("auth_uri") + @ExcludeMissing + authUri: JsonField = JsonMissing.of(), + @JsonProperty("client_id") + @ExcludeMissing + clientId: JsonField = JsonMissing.of(), + @JsonProperty("client_x509_cert_url") + @ExcludeMissing + clientX509CertUrl: JsonField = JsonMissing.of(), + @JsonProperty("private_key_id") + @ExcludeMissing + privateKeyId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") + @ExcludeMissing + projectId: JsonField = JsonMissing.of(), + @JsonProperty("token_uri") + @ExcludeMissing + tokenUri: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + @JsonProperty("universe_domain") + @ExcludeMissing + universeDomain: JsonField = JsonMissing.of(), + ) : this( + clientEmail, + privateKey, + authProviderX509CertUrl, + authUri, + clientId, + clientX509CertUrl, + privateKeyId, + projectId, + tokenUri, + type, + universeDomain, + mutableMapOf(), + ) + + /** + * @throws StagehandInvalidDataException 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 clientEmail(): String = clientEmail.getRequired("client_email") + + /** + * @throws StagehandInvalidDataException 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 privateKey(): String = privateKey.getRequired("private_key") + + /** + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun authProviderX509CertUrl(): Optional = + authProviderX509CertUrl.getOptional("auth_provider_x509_cert_url") + + /** + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun authUri(): Optional = authUri.getOptional("auth_uri") + + /** + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun clientId(): Optional = clientId.getOptional("client_id") + + /** + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun clientX509CertUrl(): Optional = + clientX509CertUrl.getOptional("client_x509_cert_url") + + /** + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun privateKeyId(): Optional = + privateKeyId.getOptional("private_key_id") + + /** + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun projectId(): Optional = projectId.getOptional("project_id") + + /** + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun tokenUri(): Optional = tokenUri.getOptional("token_uri") + + /** + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun universeDomain(): Optional = + universeDomain.getOptional("universe_domain") + + /** + * Returns the raw JSON value of [clientEmail]. + * + * Unlike [clientEmail], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("client_email") + @ExcludeMissing + fun _clientEmail(): JsonField = clientEmail + + /** + * Returns the raw JSON value of [privateKey]. + * + * Unlike [privateKey], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("private_key") + @ExcludeMissing + fun _privateKey(): JsonField = privateKey + + /** + * Returns the raw JSON value of [authProviderX509CertUrl]. + * + * Unlike [authProviderX509CertUrl], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("auth_provider_x509_cert_url") + @ExcludeMissing + fun _authProviderX509CertUrl(): JsonField = authProviderX509CertUrl + + /** + * Returns the raw JSON value of [authUri]. + * + * Unlike [authUri], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("auth_uri") + @ExcludeMissing + fun _authUri(): JsonField = authUri + + /** + * Returns the raw JSON value of [clientId]. + * + * Unlike [clientId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("client_id") + @ExcludeMissing + fun _clientId(): JsonField = clientId + + /** + * Returns the raw JSON value of [clientX509CertUrl]. + * + * Unlike [clientX509CertUrl], this method doesn't throw if the JSON field + * has an unexpected type. + */ + @JsonProperty("client_x509_cert_url") + @ExcludeMissing + fun _clientX509CertUrl(): JsonField = clientX509CertUrl + + /** + * Returns the raw JSON value of [privateKeyId]. + * + * Unlike [privateKeyId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("private_key_id") + @ExcludeMissing + fun _privateKeyId(): JsonField = privateKeyId + + /** + * Returns the raw JSON value of [projectId]. + * + * Unlike [projectId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("project_id") + @ExcludeMissing + fun _projectId(): JsonField = projectId + + /** + * Returns the raw JSON value of [tokenUri]. + * + * Unlike [tokenUri], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("token_uri") + @ExcludeMissing + fun _tokenUri(): JsonField = tokenUri + + /** + * 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 + + /** + * Returns the raw JSON value of [universeDomain]. + * + * Unlike [universeDomain], this method doesn't throw if the JSON field has + * an unexpected type. + */ + @JsonProperty("universe_domain") + @ExcludeMissing + fun _universeDomain(): JsonField = universeDomain + + @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 + * [Credentials]. + * + * The following fields are required: + * ```java + * .clientEmail() + * .privateKey() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Credentials]. */ + class Builder internal constructor() { + + private var clientEmail: JsonField? = null + private var privateKey: JsonField? = null + private var authProviderX509CertUrl: JsonField = + JsonMissing.of() + private var authUri: JsonField = JsonMissing.of() + private var clientId: JsonField = JsonMissing.of() + private var clientX509CertUrl: JsonField = JsonMissing.of() + private var privateKeyId: JsonField = JsonMissing.of() + private var projectId: JsonField = JsonMissing.of() + private var tokenUri: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var universeDomain: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(credentials: Credentials) = apply { + clientEmail = credentials.clientEmail + privateKey = credentials.privateKey + authProviderX509CertUrl = credentials.authProviderX509CertUrl + authUri = credentials.authUri + clientId = credentials.clientId + clientX509CertUrl = credentials.clientX509CertUrl + privateKeyId = credentials.privateKeyId + projectId = credentials.projectId + tokenUri = credentials.tokenUri + type = credentials.type + universeDomain = credentials.universeDomain + additionalProperties = + credentials.additionalProperties.toMutableMap() + } + + fun clientEmail(clientEmail: String) = + clientEmail(JsonField.of(clientEmail)) + + /** + * Sets [Builder.clientEmail] to an arbitrary JSON value. + * + * You should usually call [Builder.clientEmail] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun clientEmail(clientEmail: JsonField) = apply { + this.clientEmail = clientEmail + } + + fun privateKey(privateKey: String) = + privateKey(JsonField.of(privateKey)) + + /** + * Sets [Builder.privateKey] to an arbitrary JSON value. + * + * You should usually call [Builder.privateKey] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun privateKey(privateKey: JsonField) = apply { + this.privateKey = privateKey + } + + fun authProviderX509CertUrl(authProviderX509CertUrl: String) = + authProviderX509CertUrl(JsonField.of(authProviderX509CertUrl)) + + /** + * Sets [Builder.authProviderX509CertUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.authProviderX509CertUrl] with a + * well-typed [String] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun authProviderX509CertUrl( + authProviderX509CertUrl: JsonField + ) = apply { this.authProviderX509CertUrl = authProviderX509CertUrl } + + fun authUri(authUri: String) = authUri(JsonField.of(authUri)) + + /** + * Sets [Builder.authUri] to an arbitrary JSON value. + * + * You should usually call [Builder.authUri] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun authUri(authUri: JsonField) = apply { + this.authUri = authUri + } + + fun clientId(clientId: String) = clientId(JsonField.of(clientId)) + + /** + * Sets [Builder.clientId] to an arbitrary JSON value. + * + * You should usually call [Builder.clientId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun clientId(clientId: JsonField) = apply { + this.clientId = clientId + } + + fun clientX509CertUrl(clientX509CertUrl: String) = + clientX509CertUrl(JsonField.of(clientX509CertUrl)) + + /** + * Sets [Builder.clientX509CertUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.clientX509CertUrl] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun clientX509CertUrl(clientX509CertUrl: JsonField) = apply { + this.clientX509CertUrl = clientX509CertUrl + } + + fun privateKeyId(privateKeyId: String) = + privateKeyId(JsonField.of(privateKeyId)) + + /** + * Sets [Builder.privateKeyId] to an arbitrary JSON value. + * + * You should usually call [Builder.privateKeyId] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun privateKeyId(privateKeyId: JsonField) = apply { + this.privateKeyId = privateKeyId + } + + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) + + /** + * Sets [Builder.projectId] to an arbitrary JSON value. + * + * You should usually call [Builder.projectId] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun projectId(projectId: JsonField) = apply { + this.projectId = projectId + } + + fun tokenUri(tokenUri: String) = tokenUri(JsonField.of(tokenUri)) + + /** + * Sets [Builder.tokenUri] to an arbitrary JSON value. + * + * You should usually call [Builder.tokenUri] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun tokenUri(tokenUri: JsonField) = apply { + this.tokenUri = tokenUri + } + + 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 universeDomain(universeDomain: String) = + universeDomain(JsonField.of(universeDomain)) + + /** + * Sets [Builder.universeDomain] to an arbitrary JSON value. + * + * You should usually call [Builder.universeDomain] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun universeDomain(universeDomain: JsonField) = apply { + this.universeDomain = universeDomain + } + + 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 [Credentials]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .clientEmail() + * .privateKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Credentials = + Credentials( + checkRequired("clientEmail", clientEmail), + checkRequired("privateKey", privateKey), + authProviderX509CertUrl, + authUri, + clientId, + clientX509CertUrl, + privateKeyId, + projectId, + tokenUri, + type, + universeDomain, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Credentials = apply { + if (validated) { + return@apply + } + + clientEmail() + privateKey() + authProviderX509CertUrl() + authUri() + clientId() + clientX509CertUrl() + privateKeyId() + projectId() + tokenUri() + type().ifPresent { it.validate() } + universeDomain() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (clientEmail.asKnown().isPresent) 1 else 0) + + (if (privateKey.asKnown().isPresent) 1 else 0) + + (if (authProviderX509CertUrl.asKnown().isPresent) 1 else 0) + + (if (authUri.asKnown().isPresent) 1 else 0) + + (if (clientId.asKnown().isPresent) 1 else 0) + + (if (clientX509CertUrl.asKnown().isPresent) 1 else 0) + + (if (privateKeyId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (tokenUri.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (universeDomain.asKnown().isPresent) 1 else 0) + + 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 SERVICE_ACCOUNT = of("service_account") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SERVICE_ACCOUNT + } + + /** + * 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 { + SERVICE_ACCOUNT, + /** + * 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) { + SERVICE_ACCOUNT -> Value.SERVICE_ACCOUNT + 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 StagehandInvalidDataException if this class instance's value + * is a not a known member. + */ + fun known(): Known = + when (this) { + SERVICE_ACCOUNT -> Known.SERVICE_ACCOUNT + else -> + throw StagehandInvalidDataException("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 StagehandInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + StagehandInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws StagehandInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Credentials && + clientEmail == other.clientEmail && + privateKey == other.privateKey && + authProviderX509CertUrl == other.authProviderX509CertUrl && + authUri == other.authUri && + clientId == other.clientId && + clientX509CertUrl == other.clientX509CertUrl && + privateKeyId == other.privateKeyId && + projectId == other.projectId && + tokenUri == other.tokenUri && + type == other.type && + universeDomain == other.universeDomain && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + clientEmail, + privateKey, + authProviderX509CertUrl, + authUri, + clientId, + clientX509CertUrl, + privateKeyId, + projectId, + tokenUri, + type, + universeDomain, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Credentials{clientEmail=$clientEmail, privateKey=$privateKey, authProviderX509CertUrl=$authProviderX509CertUrl, authUri=$authUri, clientId=$clientId, clientX509CertUrl=$clientX509CertUrl, privateKeyId=$privateKeyId, projectId=$projectId, tokenUri=$tokenUri, type=$type, universeDomain=$universeDomain, additionalProperties=$additionalProperties}" + } + + /** Google auth scopes for the desired API request */ + @JsonDeserialize(using = Scopes.Deserializer::class) + @JsonSerialize(using = Scopes.Serializer::class) + class Scopes + private constructor( + private val string: String? = null, + private val strings: List? = null, + private val _json: JsonValue? = null, + ) { + + fun string(): Optional = Optional.ofNullable(string) + + fun strings(): Optional> = Optional.ofNullable(strings) + + fun isString(): Boolean = string != null + + fun isStrings(): Boolean = strings != null + + fun asString(): String = string.getOrThrow("string") + + fun asStrings(): List = strings.getOrThrow("strings") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the + * given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from + * the API, unless [visitor] overrides [Visitor.unknown]. To handle variants + * not known to this version of the SDK gracefully, consider overriding + * [Visitor.unknown]: + * ```java + * import com.browserbase.api.core.JsonValue; + * import java.util.Optional; + * + * Optional result = scopes.accept(new Scopes.Visitor>() { + * @Override + * public Optional visitString(String string) { + * return Optional.of(string.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws StagehandInvalidDataException if [Visitor.unknown] is not + * overridden in [visitor] and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + string != null -> visitor.visitString(string) + strings != null -> visitor.visitStrings(strings) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Scopes = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitString(string: String) {} + + override fun visitStrings(strings: List) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 visitString(string: String) = 1 + + override fun visitStrings(strings: List) = strings.size + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Scopes && + string == other.string && + strings == other.strings + } + + override fun hashCode(): Int = Objects.hash(string, strings) + + override fun toString(): String = + when { + string != null -> "Scopes{string=$string}" + strings != null -> "Scopes{strings=$strings}" + _json != null -> "Scopes{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Scopes") + } + + companion object { + + @JvmStatic fun ofString(string: String) = Scopes(string = string) + + @JvmStatic + fun ofStrings(strings: List) = + Scopes(strings = strings.toImmutable()) + } + + /** + * An interface that defines how to map each variant of [Scopes] to a value + * of type [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + fun visitStrings(strings: List): T + + /** + * Maps an unknown variant of [Scopes] to a value of type [T]. + * + * An instance of [Scopes] 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 StagehandInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw StagehandInvalidDataException("Unknown Scopes: $json") + } + } + + internal class Deserializer : BaseDeserializer(Scopes::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Scopes { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Scopes(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef>()) + ?.let { Scopes(strings = it, _json = json) }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. + // deserializing from boolean). + 0 -> Scopes(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, + // then use the first completely valid match, or simply the + // first match if none are completely valid. + else -> + bestMatches.firstOrNull { it.isValid() } + ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Scopes::class) { + + override fun serialize( + value: Scopes, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.strings != null -> generator.writeObject(value.strings) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Scopes") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auth && + credentials == other.credentials && + type == other.type && + projectId == other.projectId && + scopes == other.scopes && + universeDomain == other.universeDomain && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + credentials, + type, + projectId, + scopes, + universeDomain, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Auth{credentials=$credentials, type=$type, projectId=$projectId, scopes=$scopes, universeDomain=$universeDomain, additionalProperties=$additionalProperties}" + } + + /** Vertex provider-specific model configuration */ + class ProviderOptions + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val vertex: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("vertex") + @ExcludeMissing + vertex: JsonField = JsonMissing.of() + ) : this(vertex, mutableMapOf()) + + /** + * Vertex AI provider-specific settings + * + * @throws StagehandInvalidDataException 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 vertex(): Vertex = vertex.getRequired("vertex") + + /** + * Returns the raw JSON value of [vertex]. + * + * Unlike [vertex], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vertex") + @ExcludeMissing + fun _vertex(): JsonField = vertex + + @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 + * [ProviderOptions]. + * + * The following fields are required: + * ```java + * .vertex() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProviderOptions]. */ + class Builder internal constructor() { + + private var vertex: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(providerOptions: ProviderOptions) = apply { + vertex = providerOptions.vertex + additionalProperties = + providerOptions.additionalProperties.toMutableMap() + } + + /** Vertex AI provider-specific settings */ + fun vertex(vertex: Vertex) = vertex(JsonField.of(vertex)) + + /** + * Sets [Builder.vertex] to an arbitrary JSON value. + * + * You should usually call [Builder.vertex] with a well-typed [Vertex] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun vertex(vertex: JsonField) = apply { this.vertex = vertex } + + 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 [ProviderOptions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .vertex() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProviderOptions = + ProviderOptions( + checkRequired("vertex", vertex), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ProviderOptions = apply { + if (validated) { + return@apply + } + + vertex().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = (vertex.asKnown().getOrNull()?.validity() ?: 0) + + /** Vertex AI provider-specific settings */ + class Vertex + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val location: JsonField, + private val project: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("location") + @ExcludeMissing + location: JsonField = JsonMissing.of(), + @JsonProperty("project") + @ExcludeMissing + project: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + ) : this(location, project, baseUrl, headers, mutableMapOf()) + + /** + * Google Cloud location for Vertex AI models + * + * @throws StagehandInvalidDataException 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 location(): String = location.getRequired("location") + + /** + * Google Cloud project ID for Vertex AI models + * + * @throws StagehandInvalidDataException 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 project(): String = project.getRequired("project") + + /** + * Base URL for the Vertex AI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the Vertex AI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Returns the raw JSON value of [location]. + * + * Unlike [location], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("location") + @ExcludeMissing + fun _location(): JsonField = location + + /** + * Returns the raw JSON value of [project]. + * + * Unlike [project], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("project") + @ExcludeMissing + fun _project(): JsonField = project + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("baseURL") + @ExcludeMissing + fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + @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 [Vertex]. + * + * The following fields are required: + * ```java + * .location() + * .project() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Vertex]. */ + class Builder internal constructor() { + + private var location: JsonField? = null + private var project: JsonField? = null + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(vertex: Vertex) = apply { + location = vertex.location + project = vertex.project + baseUrl = vertex.baseUrl + headers = vertex.headers + additionalProperties = vertex.additionalProperties.toMutableMap() + } + + /** Google Cloud location for Vertex AI models */ + fun location(location: String) = location(JsonField.of(location)) + + /** + * Sets [Builder.location] to an arbitrary JSON value. + * + * You should usually call [Builder.location] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun location(location: JsonField) = apply { + this.location = location + } + + /** Google Cloud project ID for Vertex AI models */ + fun project(project: String) = project(JsonField.of(project)) + + /** + * Sets [Builder.project] to an arbitrary JSON value. + * + * You should usually call [Builder.project] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun project(project: JsonField) = apply { + this.project = project + } + + /** Base URL for the Vertex AI provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { + this.baseUrl = baseUrl + } + + /** Custom headers sent with every request to the Vertex AI provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun headers(headers: JsonField) = apply { + this.headers = headers + } + + 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 [Vertex]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .location() + * .project() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Vertex = + Vertex( + checkRequired("location", location), + checkRequired("project", project), + baseUrl, + headers, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Vertex = apply { + if (validated) { + return@apply + } + + location() + project() + baseUrl() + headers().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (location.asKnown().isPresent) 1 else 0) + + (if (project.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + /** Custom headers sent with every request to the Vertex AI provider */ + class Headers + @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 + * [Headers]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = + headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws StagehandInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Vertex && + location == other.location && + project == other.project && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(location, project, baseUrl, headers, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Vertex{location=$location, project=$project, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProviderOptions && + vertex == other.vertex && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(vertex, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProviderOptions{vertex=$vertex, additionalProperties=$additionalProperties}" + } + + /** Custom headers sent with every request to the model provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VertexModelConfigObject && + auth == other.auth && + modelName == other.modelName && + provider == other.provider && + providerOptions == other.providerOptions && + apiKey == other.apiKey && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + auth, + modelName, + provider, + providerOptions, + apiKey, + baseUrl, + headers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VertexModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + + class AzureEntraModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val auth: JsonField, + private val modelName: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("auth") @ExcludeMissing auth: JsonField = JsonMissing.of(), + @JsonProperty("modelName") + @ExcludeMissing + modelName: JsonField = JsonMissing.of(), + @JsonProperty("provider") + @ExcludeMissing + provider: JsonValue = JsonMissing.of(), + @JsonProperty("providerOptions") + @ExcludeMissing + providerOptions: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + ) : this( + auth, + modelName, + provider, + providerOptions, + baseUrl, + headers, + mutableMapOf(), + ) + + /** + * Azure provider authentication configuration + * + * @throws StagehandInvalidDataException 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 auth(): Auth = auth.getRequired("auth") + + /** + * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') + * + * @throws StagehandInvalidDataException 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 modelName(): String = modelName.getRequired("modelName") + + /** + * Azure OpenAI model provider + * + * Expected to always return the following: + * ```java + * JsonValue.from("azure") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider + + /** + * Azure provider-specific model configuration + * + * @throws StagehandInvalidDataException 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 providerOptions(): ProviderOptions = + providerOptions.getRequired("providerOptions") + + /** + * Base URL for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Returns the raw JSON value of [auth]. + * + * Unlike [auth], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("auth") @ExcludeMissing fun _auth(): JsonField = auth + + /** + * Returns the raw JSON value of [modelName]. + * + * Unlike [modelName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("modelName") + @ExcludeMissing + fun _modelName(): JsonField = modelName + + /** + * Returns the raw JSON value of [providerOptions]. + * + * Unlike [providerOptions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("providerOptions") + @ExcludeMissing + fun _providerOptions(): JsonField = providerOptions + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + @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 + * [AzureEntraModelConfigObject]. + * + * The following fields are required: + * ```java + * .auth() + * .modelName() + * .providerOptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AzureEntraModelConfigObject]. */ + class Builder internal constructor() { + + private var auth: JsonField? = null + private var modelName: JsonField? = null + private var provider: JsonValue = JsonValue.from("azure") + private var providerOptions: JsonField? = null + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(azureEntraModelConfigObject: AzureEntraModelConfigObject) = + apply { + auth = azureEntraModelConfigObject.auth + modelName = azureEntraModelConfigObject.modelName + provider = azureEntraModelConfigObject.provider + providerOptions = azureEntraModelConfigObject.providerOptions + baseUrl = azureEntraModelConfigObject.baseUrl + headers = azureEntraModelConfigObject.headers + additionalProperties = + azureEntraModelConfigObject.additionalProperties.toMutableMap() + } + + /** Azure provider authentication configuration */ + fun auth(auth: Auth) = auth(JsonField.of(auth)) + + /** + * Sets [Builder.auth] to an arbitrary JSON value. + * + * You should usually call [Builder.auth] with a well-typed [Auth] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun auth(auth: JsonField) = apply { this.auth = auth } + + /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ + fun modelName(modelName: String) = modelName(JsonField.of(modelName)) + + /** + * Sets [Builder.modelName] to an arbitrary JSON value. + * + * You should usually call [Builder.modelName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun modelName(modelName: JsonField) = apply { + this.modelName = modelName + } + + /** + * 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("azure") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun provider(provider: JsonValue) = apply { this.provider = provider } + + /** Azure provider-specific model configuration */ + fun providerOptions(providerOptions: ProviderOptions) = + providerOptions(JsonField.of(providerOptions)) + + /** + * Sets [Builder.providerOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.providerOptions] with a well-typed + * [ProviderOptions] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun providerOptions(providerOptions: JsonField) = apply { + this.providerOptions = providerOptions + } + + /** Base URL for the model provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the model provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + 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 [AzureEntraModelConfigObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .auth() + * .modelName() + * .providerOptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AzureEntraModelConfigObject = + AzureEntraModelConfigObject( + checkRequired("auth", auth), + checkRequired("modelName", modelName), + provider, + checkRequired("providerOptions", providerOptions), + baseUrl, + headers, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AzureEntraModelConfigObject = apply { + if (validated) { + return@apply + } + + auth().validate() + modelName() + _provider().let { + if (it != JsonValue.from("azure")) { + throw StagehandInvalidDataException( + "'provider' is invalid, received $it" + ) + } + } + providerOptions().validate() + baseUrl() + headers().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = + (auth.asKnown().getOrNull()?.validity() ?: 0) + + (if (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("azure")) 1 else 0 } + + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure provider authentication configuration */ + class Auth + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val token: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("token") + @ExcludeMissing + token: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(token, type, mutableMapOf()) + + /** + * Microsoft Entra ID bearer token for Azure OpenAI + * + * @throws StagehandInvalidDataException 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 token(): String = token.getRequired("token") + + /** + * Use a Microsoft Entra ID bearer token for authentication + * + * Expected to always return the following: + * ```java + * JsonValue.from("azureEntraId") + * ``` + * + * 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 [token]. + * + * Unlike [token], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("token") @ExcludeMissing fun _token(): JsonField = token + + @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 [Auth]. + * + * The following fields are required: + * ```java + * .token() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Auth]. */ + class Builder internal constructor() { + + private var token: JsonField? = null + private var type: JsonValue = JsonValue.from("azureEntraId") + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(auth: Auth) = apply { + token = auth.token + type = auth.type + additionalProperties = auth.additionalProperties.toMutableMap() + } + + /** Microsoft Entra ID bearer token for Azure OpenAI */ + fun token(token: String) = token(JsonField.of(token)) + + /** + * Sets [Builder.token] to an arbitrary JSON value. + * + * You should usually call [Builder.token] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun token(token: JsonField) = apply { this.token = token } + + /** + * 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("azureEntraId") + * ``` + * + * 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 [Auth]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .token() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Auth = + Auth( + checkRequired("token", token), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Auth = apply { + if (validated) { + return@apply + } + + token() + _type().let { + if (it != JsonValue.from("azureEntraId")) { + throw StagehandInvalidDataException( + "'type' is invalid, received $it" + ) + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (token.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("azureEntraId")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auth && + token == other.token && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(token, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Auth{token=$token, type=$type, additionalProperties=$additionalProperties}" + } + + /** Azure provider-specific model configuration */ + class ProviderOptions + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val azure: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("azure") + @ExcludeMissing + azure: JsonField = JsonMissing.of() + ) : this(azure, mutableMapOf()) + + /** + * Azure OpenAI provider-specific settings + * + * @throws StagehandInvalidDataException 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 azure(): Azure = azure.getRequired("azure") + + /** + * Returns the raw JSON value of [azure]. + * + * Unlike [azure], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("azure") @ExcludeMissing fun _azure(): JsonField = azure + + @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 + * [ProviderOptions]. + * + * The following fields are required: + * ```java + * .azure() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProviderOptions]. */ + class Builder internal constructor() { + + private var azure: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(providerOptions: ProviderOptions) = apply { + azure = providerOptions.azure + additionalProperties = + providerOptions.additionalProperties.toMutableMap() + } + + /** Azure OpenAI provider-specific settings */ + fun azure(azure: Azure) = azure(JsonField.of(azure)) + + /** + * Sets [Builder.azure] to an arbitrary JSON value. + * + * You should usually call [Builder.azure] with a well-typed [Azure] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun azure(azure: JsonField) = apply { this.azure = azure } + + 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 [ProviderOptions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .azure() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProviderOptions = + ProviderOptions( + checkRequired("azure", azure), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ProviderOptions = apply { + if (validated) { + return@apply + } + + azure().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = (azure.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure OpenAI provider-specific settings */ + class Azure + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val apiVersion: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val resourceName: JsonField, + private val useDeploymentBasedUrls: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("apiVersion") + @ExcludeMissing + apiVersion: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + @JsonProperty("resourceName") + @ExcludeMissing + resourceName: JsonField = JsonMissing.of(), + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + useDeploymentBasedUrls: JsonField = JsonMissing.of(), + ) : this( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + mutableMapOf(), + ) + + /** + * Azure OpenAI API version + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun apiVersion(): Optional = apiVersion.getOptional("apiVersion") + + /** + * Base URL for the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Azure OpenAI resource name + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun resourceName(): Optional = + resourceName.getOptional("resourceName") + + /** + * Whether to use deployment-based Azure OpenAI URLs + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun useDeploymentBasedUrls(): Optional = + useDeploymentBasedUrls.getOptional("useDeploymentBasedUrls") + + /** + * Returns the raw JSON value of [apiVersion]. + * + * Unlike [apiVersion], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("apiVersion") + @ExcludeMissing + fun _apiVersion(): JsonField = apiVersion + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("baseURL") + @ExcludeMissing + fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + /** + * Returns the raw JSON value of [resourceName]. + * + * Unlike [resourceName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("resourceName") + @ExcludeMissing + fun _resourceName(): JsonField = resourceName + + /** + * Returns the raw JSON value of [useDeploymentBasedUrls]. + * + * Unlike [useDeploymentBasedUrls], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + fun _useDeploymentBasedUrls(): JsonField = useDeploymentBasedUrls + + @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 [Azure]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Azure]. */ + class Builder internal constructor() { + + private var apiVersion: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var resourceName: JsonField = JsonMissing.of() + private var useDeploymentBasedUrls: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(azure: Azure) = apply { + apiVersion = azure.apiVersion + baseUrl = azure.baseUrl + headers = azure.headers + resourceName = azure.resourceName + useDeploymentBasedUrls = azure.useDeploymentBasedUrls + additionalProperties = azure.additionalProperties.toMutableMap() + } + + /** Azure OpenAI API version */ + fun apiVersion(apiVersion: String) = + apiVersion(JsonField.of(apiVersion)) + + /** + * Sets [Builder.apiVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.apiVersion] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun apiVersion(apiVersion: JsonField) = apply { + this.apiVersion = apiVersion + } + + /** Base URL for the Azure OpenAI provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { + this.baseUrl = baseUrl + } + + /** + * Custom headers sent with every request to the Azure OpenAI provider + */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun headers(headers: JsonField) = apply { + this.headers = headers + } + + /** Azure OpenAI resource name */ + fun resourceName(resourceName: String) = + resourceName(JsonField.of(resourceName)) + + /** + * Sets [Builder.resourceName] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceName] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun resourceName(resourceName: JsonField) = apply { + this.resourceName = resourceName + } + + /** Whether to use deployment-based Azure OpenAI URLs */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: Boolean) = + useDeploymentBasedUrls(JsonField.of(useDeploymentBasedUrls)) + + /** + * Sets [Builder.useDeploymentBasedUrls] to an arbitrary JSON value. + * + * You should usually call [Builder.useDeploymentBasedUrls] with a + * well-typed [Boolean] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: JsonField) = + apply { + this.useDeploymentBasedUrls = useDeploymentBasedUrls + } + + 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 [Azure]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Azure = + Azure( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Azure = apply { + if (validated) { + return@apply + } + + apiVersion() + baseUrl() + headers().ifPresent { it.validate() } + resourceName() + useDeploymentBasedUrls() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (apiVersion.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceName.asKnown().isPresent) 1 else 0) + + (if (useDeploymentBasedUrls.asKnown().isPresent) 1 else 0) + + /** Custom headers sent with every request to the Azure OpenAI provider */ + class Headers + @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 + * [Headers]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = + headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws StagehandInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Azure && + apiVersion == other.apiVersion && + baseUrl == other.baseUrl && + headers == other.headers && + resourceName == other.resourceName && + useDeploymentBasedUrls == other.useDeploymentBasedUrls && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Azure{apiVersion=$apiVersion, baseUrl=$baseUrl, headers=$headers, resourceName=$resourceName, useDeploymentBasedUrls=$useDeploymentBasedUrls, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProviderOptions && + azure == other.azure && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(azure, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProviderOptions{azure=$azure, additionalProperties=$additionalProperties}" + } + + /** Custom headers sent with every request to the model provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AzureEntraModelConfigObject && + auth == other.auth && + modelName == other.modelName && + provider == other.provider && + providerOptions == other.providerOptions && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + auth, + modelName, + provider, + providerOptions, + baseUrl, + headers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AzureEntraModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + + class AzureApiKeyModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val modelName: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, + private val apiKey: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("modelName") + @ExcludeMissing + modelName: JsonField = JsonMissing.of(), + @JsonProperty("provider") + @ExcludeMissing + provider: JsonValue = JsonMissing.of(), + @JsonProperty("providerOptions") + @ExcludeMissing + providerOptions: JsonField = JsonMissing.of(), + @JsonProperty("apiKey") + @ExcludeMissing + apiKey: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + ) : this( + modelName, + provider, + providerOptions, + apiKey, + baseUrl, + headers, + mutableMapOf(), + ) + + /** + * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') + * + * @throws StagehandInvalidDataException 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 modelName(): String = modelName.getRequired("modelName") + + /** + * Azure OpenAI model provider + * + * Expected to always return the following: + * ```java + * JsonValue.from("azure") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider + + /** + * Azure provider-specific model configuration + * + * @throws StagehandInvalidDataException 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 providerOptions(): ProviderOptions = + providerOptions.getRequired("providerOptions") + + /** + * API key for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun apiKey(): Optional = apiKey.getOptional("apiKey") + + /** + * Base URL for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Returns the raw JSON value of [modelName]. + * + * Unlike [modelName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("modelName") + @ExcludeMissing + fun _modelName(): JsonField = modelName + + /** + * Returns the raw JSON value of [providerOptions]. + * + * Unlike [providerOptions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("providerOptions") + @ExcludeMissing + fun _providerOptions(): JsonField = providerOptions + + /** + * Returns the raw JSON value of [apiKey]. + * + * Unlike [apiKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("apiKey") @ExcludeMissing fun _apiKey(): JsonField = apiKey + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers - private var validated: Boolean = false + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - /** - * Validates that the types of all values in this object match their - * expected types recursively. - * - * This method is _not_ forwards compatible with new types from the API for - * existing fields. - * - * @throws StagehandInvalidDataException if any value type in this object - * doesn't match its expected type. - */ - fun validate(): Scopes = apply { - if (validated) { - return@apply - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - accept( - object : Visitor { - override fun visitString(string: String) {} + fun toBuilder() = Builder().from(this) - override fun visitStrings(strings: List) {} - } - ) - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: StagehandInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of + * [AzureApiKeyModelConfigObject]. + * + * The following fields are required: + * ```java + * .modelName() + * .providerOptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * 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 visitString(string: String) = 1 + /** A builder for [AzureApiKeyModelConfigObject]. */ + class Builder internal constructor() { - override fun visitStrings(strings: List) = strings.size + private var modelName: JsonField? = null + private var provider: JsonValue = JsonValue.from("azure") + private var providerOptions: JsonField? = null + private var apiKey: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - override fun unknown(json: JsonValue?) = 0 - } - ) + @JvmSynthetic + internal fun from(azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject) = + apply { + modelName = azureApiKeyModelConfigObject.modelName + provider = azureApiKeyModelConfigObject.provider + providerOptions = azureApiKeyModelConfigObject.providerOptions + apiKey = azureApiKeyModelConfigObject.apiKey + baseUrl = azureApiKeyModelConfigObject.baseUrl + headers = azureApiKeyModelConfigObject.headers + additionalProperties = + azureApiKeyModelConfigObject.additionalProperties.toMutableMap() + } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ + fun modelName(modelName: String) = modelName(JsonField.of(modelName)) - return other is Scopes && - string == other.string && - strings == other.strings - } + /** + * Sets [Builder.modelName] to an arbitrary JSON value. + * + * You should usually call [Builder.modelName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun modelName(modelName: JsonField) = apply { + this.modelName = modelName + } - override fun hashCode(): Int = Objects.hash(string, strings) + /** + * 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("azure") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun provider(provider: JsonValue) = apply { this.provider = provider } - override fun toString(): String = - when { - string != null -> "Scopes{string=$string}" - strings != null -> "Scopes{strings=$strings}" - _json != null -> "Scopes{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Scopes") - } + /** Azure provider-specific model configuration */ + fun providerOptions(providerOptions: ProviderOptions) = + providerOptions(JsonField.of(providerOptions)) - companion object { + /** + * Sets [Builder.providerOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.providerOptions] with a well-typed + * [ProviderOptions] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun providerOptions(providerOptions: JsonField) = apply { + this.providerOptions = providerOptions + } - @JvmStatic fun ofString(string: String) = Scopes(string = string) + /** API key for the model provider */ + fun apiKey(apiKey: String) = apiKey(JsonField.of(apiKey)) - @JvmStatic - fun ofStrings(strings: List) = - Scopes(strings = strings.toImmutable()) - } + /** + * Sets [Builder.apiKey] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKey(apiKey: JsonField) = apply { this.apiKey = apiKey } - /** - * An interface that defines how to map each variant of [Scopes] to a value - * of type [T]. - */ - interface Visitor { + /** Base URL for the model provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) - fun visitString(string: String): T + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } - fun visitStrings(strings: List): T + /** Custom headers sent with every request to the model provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) - /** - * Maps an unknown variant of [Scopes] to a value of type [T]. - * - * An instance of [Scopes] 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 StagehandInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw StagehandInvalidDataException("Unknown Scopes: $json") - } - } + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } - internal class Deserializer : BaseDeserializer(Scopes::class) { + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - override fun ObjectCodec.deserialize(node: JsonNode): Scopes { - val json = JsonValue.fromJsonNode(node) + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Scopes(string = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Scopes(strings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from boolean). - 0 -> Scopes(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - internal class Serializer : BaseSerializer(Scopes::class) { + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - override fun serialize( - value: Scopes, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.string != null -> generator.writeObject(value.string) - value.strings != null -> generator.writeObject(value.strings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Scopes") - } - } - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns an immutable instance of [AzureApiKeyModelConfigObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .modelName() + * .providerOptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AzureApiKeyModelConfigObject = + AzureApiKeyModelConfigObject( + checkRequired("modelName", modelName), + provider, + checkRequired("providerOptions", providerOptions), + apiKey, + baseUrl, + headers, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false - return other is Auth && - credentials == other.credentials && - type == other.type && - projectId == other.projectId && - scopes == other.scopes && - universeDomain == other.universeDomain && - additionalProperties == other.additionalProperties + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AzureApiKeyModelConfigObject = apply { + if (validated) { + return@apply } - private val hashCode: Int by lazy { - Objects.hash( - credentials, - type, - projectId, - scopes, - universeDomain, - additionalProperties, - ) + modelName() + _provider().let { + if (it != JsonValue.from("azure")) { + throw StagehandInvalidDataException( + "'provider' is invalid, received $it" + ) + } } + providerOptions().validate() + apiKey() + baseUrl() + headers().ifPresent { it.validate() } + validated = true + } - override fun hashCode(): Int = hashCode + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + false + } - override fun toString() = - "Auth{credentials=$credentials, type=$type, projectId=$projectId, scopes=$scopes, universeDomain=$universeDomain, additionalProperties=$additionalProperties}" - } + /** + * 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 (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("azure")) 1 else 0 } + + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + + (if (apiKey.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) - /** Vertex provider-specific model configuration */ + /** Azure provider-specific model configuration */ class ProviderOptions @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val vertex: JsonField, + private val azure: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("vertex") + @JsonProperty("azure") @ExcludeMissing - vertex: JsonField = JsonMissing.of() - ) : this(vertex, mutableMapOf()) + azure: JsonField = JsonMissing.of() + ) : this(azure, mutableMapOf()) /** - * Vertex AI provider-specific settings + * Azure OpenAI provider-specific settings * * @throws StagehandInvalidDataException 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 vertex(): Vertex = vertex.getRequired("vertex") + fun azure(): Azure = azure.getRequired("azure") /** - * Returns the raw JSON value of [vertex]. + * Returns the raw JSON value of [azure]. * - * Unlike [vertex], this method doesn't throw if the JSON field has an - * unexpected type. + * Unlike [azure], this method doesn't throw if the JSON field has an unexpected + * type. */ - @JsonProperty("vertex") - @ExcludeMissing - fun _vertex(): JsonField = vertex + @JsonProperty("azure") @ExcludeMissing fun _azure(): JsonField = azure @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -6700,7 +12097,7 @@ private constructor( * * The following fields are required: * ```java - * .vertex() + * .azure() * ``` */ @JvmStatic fun builder() = Builder() @@ -6709,28 +12106,28 @@ private constructor( /** A builder for [ProviderOptions]. */ class Builder internal constructor() { - private var vertex: JsonField? = null + private var azure: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(providerOptions: ProviderOptions) = apply { - vertex = providerOptions.vertex + azure = providerOptions.azure additionalProperties = providerOptions.additionalProperties.toMutableMap() } - /** Vertex AI provider-specific settings */ - fun vertex(vertex: Vertex) = vertex(JsonField.of(vertex)) + /** Azure OpenAI provider-specific settings */ + fun azure(azure: Azure) = azure(JsonField.of(azure)) /** - * Sets [Builder.vertex] to an arbitrary JSON value. + * Sets [Builder.azure] to an arbitrary JSON value. * - * You should usually call [Builder.vertex] with a well-typed [Vertex] value + * You should usually call [Builder.azure] with a well-typed [Azure] value * instead. This method is primarily for setting the field to an * undocumented or not yet supported value. */ - fun vertex(vertex: JsonField) = apply { this.vertex = vertex } + fun azure(azure: JsonField) = apply { this.azure = azure } fun additionalProperties(additionalProperties: Map) = apply { @@ -6761,14 +12158,14 @@ private constructor( * * The following fields are required: * ```java - * .vertex() + * .azure() * ``` * * @throws IllegalStateException if any required field is unset. */ fun build(): ProviderOptions = ProviderOptions( - checkRequired("vertex", vertex), + checkRequired("azure", azure), additionalProperties.toMutableMap(), ) } @@ -6790,7 +12187,7 @@ private constructor( return@apply } - vertex().validate() + azure().validate() validated = true } @@ -6809,88 +12206,97 @@ private constructor( * Used for best match union deserialization. */ @JvmSynthetic - internal fun validity(): Int = (vertex.asKnown().getOrNull()?.validity() ?: 0) + internal fun validity(): Int = (azure.asKnown().getOrNull()?.validity() ?: 0) - /** Vertex AI provider-specific settings */ - class Vertex + /** Azure OpenAI provider-specific settings */ + class Azure @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val location: JsonField, - private val project: JsonField, + private val apiVersion: JsonField, private val baseUrl: JsonField, private val headers: JsonField, + private val resourceName: JsonField, + private val useDeploymentBasedUrls: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("location") + @JsonProperty("apiVersion") @ExcludeMissing - location: JsonField = JsonMissing.of(), - @JsonProperty("project") - @ExcludeMissing - project: JsonField = JsonMissing.of(), + apiVersion: JsonField = JsonMissing.of(), @JsonProperty("baseURL") @ExcludeMissing baseUrl: JsonField = JsonMissing.of(), @JsonProperty("headers") @ExcludeMissing headers: JsonField = JsonMissing.of(), - ) : this(location, project, baseUrl, headers, mutableMapOf()) + @JsonProperty("resourceName") + @ExcludeMissing + resourceName: JsonField = JsonMissing.of(), + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + useDeploymentBasedUrls: JsonField = JsonMissing.of(), + ) : this( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + mutableMapOf(), + ) /** - * Google Cloud location for Vertex AI models + * Azure OpenAI API version * * @throws StagehandInvalidDataException if the JSON field has an unexpected - * type or is unexpectedly missing or null (e.g. if the server responded - * with an unexpected value). + * type (e.g. if the server responded with an unexpected value). */ - fun location(): String = location.getRequired("location") + fun apiVersion(): Optional = apiVersion.getOptional("apiVersion") /** - * Google Cloud project ID for Vertex AI models + * Base URL for the Azure OpenAI provider * * @throws StagehandInvalidDataException if the JSON field has an unexpected - * type or is unexpectedly missing or null (e.g. if the server responded - * with an unexpected value). + * type (e.g. if the server responded with an unexpected value). */ - fun project(): String = project.getRequired("project") + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") /** - * Base URL for the Vertex AI provider + * Custom headers sent with every request to the Azure OpenAI provider * * @throws StagehandInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + fun headers(): Optional = headers.getOptional("headers") /** - * Custom headers sent with every request to the Vertex AI provider + * Azure OpenAI resource name * * @throws StagehandInvalidDataException if the JSON field has an unexpected * type (e.g. if the server responded with an unexpected value). */ - fun headers(): Optional = headers.getOptional("headers") + fun resourceName(): Optional = + resourceName.getOptional("resourceName") /** - * Returns the raw JSON value of [location]. + * Whether to use deployment-based Azure OpenAI URLs * - * Unlike [location], this method doesn't throw if the JSON field has an - * unexpected type. + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). */ - @JsonProperty("location") - @ExcludeMissing - fun _location(): JsonField = location + fun useDeploymentBasedUrls(): Optional = + useDeploymentBasedUrls.getOptional("useDeploymentBasedUrls") /** - * Returns the raw JSON value of [project]. + * Returns the raw JSON value of [apiVersion]. * - * Unlike [project], this method doesn't throw if the JSON field has an + * Unlike [apiVersion], this method doesn't throw if the JSON field has an * unexpected type. */ - @JsonProperty("project") + @JsonProperty("apiVersion") @ExcludeMissing - fun _project(): JsonField = project + fun _apiVersion(): JsonField = apiVersion /** * Returns the raw JSON value of [baseUrl]. @@ -6912,6 +12318,26 @@ private constructor( @ExcludeMissing fun _headers(): JsonField = headers + /** + * Returns the raw JSON value of [resourceName]. + * + * Unlike [resourceName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("resourceName") + @ExcludeMissing + fun _resourceName(): JsonField = resourceName + + /** + * Returns the raw JSON value of [useDeploymentBasedUrls]. + * + * Unlike [useDeploymentBasedUrls], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + fun _useDeploymentBasedUrls(): JsonField = useDeploymentBasedUrls + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -6927,65 +12353,49 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of [Vertex]. - * - * The following fields are required: - * ```java - * .location() - * .project() - * ``` + * Returns a mutable builder for constructing an instance of [Azure]. */ @JvmStatic fun builder() = Builder() } - /** A builder for [Vertex]. */ + /** A builder for [Azure]. */ class Builder internal constructor() { - private var location: JsonField? = null - private var project: JsonField? = null + private var apiVersion: JsonField = JsonMissing.of() private var baseUrl: JsonField = JsonMissing.of() private var headers: JsonField = JsonMissing.of() + private var resourceName: JsonField = JsonMissing.of() + private var useDeploymentBasedUrls: JsonField = + JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(vertex: Vertex) = apply { - location = vertex.location - project = vertex.project - baseUrl = vertex.baseUrl - headers = vertex.headers - additionalProperties = vertex.additionalProperties.toMutableMap() - } - - /** Google Cloud location for Vertex AI models */ - fun location(location: String) = location(JsonField.of(location)) - - /** - * Sets [Builder.location] to an arbitrary JSON value. - * - * You should usually call [Builder.location] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun location(location: JsonField) = apply { - this.location = location + internal fun from(azure: Azure) = apply { + apiVersion = azure.apiVersion + baseUrl = azure.baseUrl + headers = azure.headers + resourceName = azure.resourceName + useDeploymentBasedUrls = azure.useDeploymentBasedUrls + additionalProperties = azure.additionalProperties.toMutableMap() } - /** Google Cloud project ID for Vertex AI models */ - fun project(project: String) = project(JsonField.of(project)) + /** Azure OpenAI API version */ + fun apiVersion(apiVersion: String) = + apiVersion(JsonField.of(apiVersion)) /** - * Sets [Builder.project] to an arbitrary JSON value. + * Sets [Builder.apiVersion] to an arbitrary JSON value. * - * You should usually call [Builder.project] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. + * You should usually call [Builder.apiVersion] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. */ - fun project(project: JsonField) = apply { - this.project = project + fun apiVersion(apiVersion: JsonField) = apply { + this.apiVersion = apiVersion } - /** Base URL for the Vertex AI provider */ + /** Base URL for the Azure OpenAI provider */ fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) /** @@ -6999,7 +12409,9 @@ private constructor( this.baseUrl = baseUrl } - /** Custom headers sent with every request to the Vertex AI provider */ + /** + * Custom headers sent with every request to the Azure OpenAI provider + */ fun headers(headers: Headers) = headers(JsonField.of(headers)) /** @@ -7013,6 +12425,37 @@ private constructor( this.headers = headers } + /** Azure OpenAI resource name */ + fun resourceName(resourceName: String) = + resourceName(JsonField.of(resourceName)) + + /** + * Sets [Builder.resourceName] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceName] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun resourceName(resourceName: JsonField) = apply { + this.resourceName = resourceName + } + + /** Whether to use deployment-based Azure OpenAI URLs */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: Boolean) = + useDeploymentBasedUrls(JsonField.of(useDeploymentBasedUrls)) + + /** + * Sets [Builder.useDeploymentBasedUrls] to an arbitrary JSON value. + * + * You should usually call [Builder.useDeploymentBasedUrls] with a + * well-typed [Boolean] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: JsonField) = + apply { + this.useDeploymentBasedUrls = useDeploymentBasedUrls + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -7036,25 +12479,18 @@ private constructor( } /** - * Returns an immutable instance of [Vertex]. + * Returns an immutable instance of [Azure]. * * Further updates to this [Builder] will not mutate the returned * instance. - * - * The following fields are required: - * ```java - * .location() - * .project() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ - fun build(): Vertex = - Vertex( - checkRequired("location", location), - checkRequired("project", project), + fun build(): Azure = + Azure( + apiVersion, baseUrl, headers, + resourceName, + useDeploymentBasedUrls, additionalProperties.toMutableMap(), ) } @@ -7071,15 +12507,16 @@ private constructor( * @throws StagehandInvalidDataException if any value type in this object * doesn't match its expected type. */ - fun validate(): Vertex = apply { + fun validate(): Azure = apply { if (validated) { return@apply } - location() - project() + apiVersion() baseUrl() headers().ifPresent { it.validate() } + resourceName() + useDeploymentBasedUrls() validated = true } @@ -7099,12 +12536,13 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (location.asKnown().isPresent) 1 else 0) + - (if (project.asKnown().isPresent) 1 else 0) + + (if (apiVersion.asKnown().isPresent) 1 else 0) + (if (baseUrl.asKnown().isPresent) 1 else 0) + - (headers.asKnown().getOrNull()?.validity() ?: 0) + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceName.asKnown().isPresent) 1 else 0) + + (if (useDeploymentBasedUrls.asKnown().isPresent) 1 else 0) - /** Custom headers sent with every request to the Vertex AI provider */ + /** Custom headers sent with every request to the Azure OpenAI provider */ class Headers @JsonCreator private constructor( @@ -7234,22 +12672,30 @@ private constructor( return true } - return other is Vertex && - location == other.location && - project == other.project && + return other is Azure && + apiVersion == other.apiVersion && baseUrl == other.baseUrl && headers == other.headers && + resourceName == other.resourceName && + useDeploymentBasedUrls == other.useDeploymentBasedUrls && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(location, project, baseUrl, headers, additionalProperties) + Objects.hash( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "Vertex{location=$location, project=$project, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + "Azure{apiVersion=$apiVersion, baseUrl=$baseUrl, headers=$headers, resourceName=$resourceName, useDeploymentBasedUrls=$useDeploymentBasedUrls, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -7258,16 +12704,16 @@ private constructor( } return other is ProviderOptions && - vertex == other.vertex && + azure == other.azure && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(vertex, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(azure, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "ProviderOptions{vertex=$vertex, additionalProperties=$additionalProperties}" + "ProviderOptions{azure=$azure, additionalProperties=$additionalProperties}" } /** Custom headers sent with every request to the model provider */ @@ -7392,8 +12838,7 @@ private constructor( return true } - return other is VertexModelConfigObject && - auth == other.auth && + return other is AzureApiKeyModelConfigObject && modelName == other.modelName && provider == other.provider && providerOptions == other.providerOptions && @@ -7405,7 +12850,6 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( - auth, modelName, provider, providerOptions, @@ -7419,7 +12863,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "VertexModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + "AzureApiKeyModelConfigObject{modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" } class GenericModelConfigObject diff --git a/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionExtractParams.kt b/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionExtractParams.kt index 2dea515..5778de5 100644 --- a/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionExtractParams.kt +++ b/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionExtractParams.kt @@ -823,6 +823,20 @@ private constructor( fun model(vertexModelConfigObject: Model.VertexModelConfigObject) = model(Model.ofVertexModelConfigObject(vertexModelConfigObject)) + /** + * Alias for calling [model] with + * `Model.ofAzureEntraModelConfigObject(azureEntraModelConfigObject)`. + */ + fun model(azureEntraModelConfigObject: Model.AzureEntraModelConfigObject) = + model(Model.ofAzureEntraModelConfigObject(azureEntraModelConfigObject)) + + /** + * Alias for calling [model] with + * `Model.ofAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject)`. + */ + fun model(azureApiKeyModelConfigObject: Model.AzureApiKeyModelConfigObject) = + model(Model.ofAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject)) + /** * Alias for calling [model] with * `Model.ofGenericModelConfigObject(genericModelConfigObject)`. @@ -959,6 +973,8 @@ private constructor( class Model private constructor( private val vertexModelConfigObject: VertexModelConfigObject? = null, + private val azureEntraModelConfigObject: AzureEntraModelConfigObject? = null, + private val azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject? = null, private val genericModelConfigObject: GenericModelConfigObject? = null, private val string: String? = null, private val _json: JsonValue? = null, @@ -967,6 +983,12 @@ private constructor( fun vertexModelConfigObject(): Optional = Optional.ofNullable(vertexModelConfigObject) + fun azureEntraModelConfigObject(): Optional = + Optional.ofNullable(azureEntraModelConfigObject) + + fun azureApiKeyModelConfigObject(): Optional = + Optional.ofNullable(azureApiKeyModelConfigObject) + fun genericModelConfigObject(): Optional = Optional.ofNullable(genericModelConfigObject) @@ -974,6 +996,10 @@ private constructor( fun isVertexModelConfigObject(): Boolean = vertexModelConfigObject != null + fun isAzureEntraModelConfigObject(): Boolean = azureEntraModelConfigObject != null + + fun isAzureApiKeyModelConfigObject(): Boolean = azureApiKeyModelConfigObject != null + fun isGenericModelConfigObject(): Boolean = genericModelConfigObject != null fun isString(): Boolean = string != null @@ -981,6 +1007,12 @@ private constructor( fun asVertexModelConfigObject(): VertexModelConfigObject = vertexModelConfigObject.getOrThrow("vertexModelConfigObject") + fun asAzureEntraModelConfigObject(): AzureEntraModelConfigObject = + azureEntraModelConfigObject.getOrThrow("azureEntraModelConfigObject") + + fun asAzureApiKeyModelConfigObject(): AzureApiKeyModelConfigObject = + azureApiKeyModelConfigObject.getOrThrow("azureApiKeyModelConfigObject") + fun asGenericModelConfigObject(): GenericModelConfigObject = genericModelConfigObject.getOrThrow("genericModelConfigObject") @@ -1022,6 +1054,10 @@ private constructor( when { vertexModelConfigObject != null -> visitor.visitVertexModelConfigObject(vertexModelConfigObject) + azureEntraModelConfigObject != null -> + visitor.visitAzureEntraModelConfigObject(azureEntraModelConfigObject) + azureApiKeyModelConfigObject != null -> + visitor.visitAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject) genericModelConfigObject != null -> visitor.visitGenericModelConfigObject(genericModelConfigObject) string != null -> visitor.visitString(string) @@ -1053,6 +1089,18 @@ private constructor( vertexModelConfigObject.validate() } + override fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) { + azureEntraModelConfigObject.validate() + } + + override fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) { + azureApiKeyModelConfigObject.validate() + } + override fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ) { @@ -1087,6 +1135,14 @@ private constructor( vertexModelConfigObject: VertexModelConfigObject ) = vertexModelConfigObject.validity() + override fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) = azureEntraModelConfigObject.validity() + + override fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) = azureApiKeyModelConfigObject.validity() + override fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ) = genericModelConfigObject.validity() @@ -1104,17 +1160,29 @@ private constructor( return other is Model && vertexModelConfigObject == other.vertexModelConfigObject && + azureEntraModelConfigObject == other.azureEntraModelConfigObject && + azureApiKeyModelConfigObject == other.azureApiKeyModelConfigObject && genericModelConfigObject == other.genericModelConfigObject && string == other.string } override fun hashCode(): Int = - Objects.hash(vertexModelConfigObject, genericModelConfigObject, string) + Objects.hash( + vertexModelConfigObject, + azureEntraModelConfigObject, + azureApiKeyModelConfigObject, + genericModelConfigObject, + string, + ) override fun toString(): String = when { vertexModelConfigObject != null -> "Model{vertexModelConfigObject=$vertexModelConfigObject}" + azureEntraModelConfigObject != null -> + "Model{azureEntraModelConfigObject=$azureEntraModelConfigObject}" + azureApiKeyModelConfigObject != null -> + "Model{azureApiKeyModelConfigObject=$azureApiKeyModelConfigObject}" genericModelConfigObject != null -> "Model{genericModelConfigObject=$genericModelConfigObject}" string != null -> "Model{string=$string}" @@ -1128,6 +1196,16 @@ private constructor( fun ofVertexModelConfigObject(vertexModelConfigObject: VertexModelConfigObject) = Model(vertexModelConfigObject = vertexModelConfigObject) + @JvmStatic + fun ofAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) = Model(azureEntraModelConfigObject = azureEntraModelConfigObject) + + @JvmStatic + fun ofAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) = Model(azureApiKeyModelConfigObject = azureApiKeyModelConfigObject) + @JvmStatic fun ofGenericModelConfigObject(genericModelConfigObject: GenericModelConfigObject) = Model(genericModelConfigObject = genericModelConfigObject) @@ -1144,6 +1222,14 @@ private constructor( vertexModelConfigObject: VertexModelConfigObject ): T + fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ): T + + fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ): T + fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ): T @@ -1174,6 +1260,12 @@ private constructor( sequenceOf( tryDeserialize(node, jacksonTypeRef()) ?.let { Model(vertexModelConfigObject = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { Model(azureEntraModelConfigObject = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { + Model(azureApiKeyModelConfigObject = it, _json = json) + }, tryDeserialize(node, jacksonTypeRef()) ?.let { Model(genericModelConfigObject = it, _json = json) }, tryDeserialize(node, jacksonTypeRef())?.let { @@ -1206,6 +1298,10 @@ private constructor( when { value.vertexModelConfigObject != null -> generator.writeObject(value.vertexModelConfigObject) + value.azureEntraModelConfigObject != null -> + generator.writeObject(value.azureEntraModelConfigObject) + value.azureApiKeyModelConfigObject != null -> + generator.writeObject(value.azureApiKeyModelConfigObject) value.genericModelConfigObject != null -> generator.writeObject(value.genericModelConfigObject) value.string != null -> generator.writeObject(value.string) @@ -3748,6 +3844,2624 @@ private constructor( "VertexModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" } + class AzureEntraModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val auth: JsonField, + private val modelName: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("auth") @ExcludeMissing auth: JsonField = JsonMissing.of(), + @JsonProperty("modelName") + @ExcludeMissing + modelName: JsonField = JsonMissing.of(), + @JsonProperty("provider") + @ExcludeMissing + provider: JsonValue = JsonMissing.of(), + @JsonProperty("providerOptions") + @ExcludeMissing + providerOptions: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + ) : this( + auth, + modelName, + provider, + providerOptions, + baseUrl, + headers, + mutableMapOf(), + ) + + /** + * Azure provider authentication configuration + * + * @throws StagehandInvalidDataException 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 auth(): Auth = auth.getRequired("auth") + + /** + * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') + * + * @throws StagehandInvalidDataException 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 modelName(): String = modelName.getRequired("modelName") + + /** + * Azure OpenAI model provider + * + * Expected to always return the following: + * ```java + * JsonValue.from("azure") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider + + /** + * Azure provider-specific model configuration + * + * @throws StagehandInvalidDataException 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 providerOptions(): ProviderOptions = + providerOptions.getRequired("providerOptions") + + /** + * Base URL for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Returns the raw JSON value of [auth]. + * + * Unlike [auth], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("auth") @ExcludeMissing fun _auth(): JsonField = auth + + /** + * Returns the raw JSON value of [modelName]. + * + * Unlike [modelName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("modelName") + @ExcludeMissing + fun _modelName(): JsonField = modelName + + /** + * Returns the raw JSON value of [providerOptions]. + * + * Unlike [providerOptions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("providerOptions") + @ExcludeMissing + fun _providerOptions(): JsonField = providerOptions + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + @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 + * [AzureEntraModelConfigObject]. + * + * The following fields are required: + * ```java + * .auth() + * .modelName() + * .providerOptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AzureEntraModelConfigObject]. */ + class Builder internal constructor() { + + private var auth: JsonField? = null + private var modelName: JsonField? = null + private var provider: JsonValue = JsonValue.from("azure") + private var providerOptions: JsonField? = null + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(azureEntraModelConfigObject: AzureEntraModelConfigObject) = + apply { + auth = azureEntraModelConfigObject.auth + modelName = azureEntraModelConfigObject.modelName + provider = azureEntraModelConfigObject.provider + providerOptions = azureEntraModelConfigObject.providerOptions + baseUrl = azureEntraModelConfigObject.baseUrl + headers = azureEntraModelConfigObject.headers + additionalProperties = + azureEntraModelConfigObject.additionalProperties.toMutableMap() + } + + /** Azure provider authentication configuration */ + fun auth(auth: Auth) = auth(JsonField.of(auth)) + + /** + * Sets [Builder.auth] to an arbitrary JSON value. + * + * You should usually call [Builder.auth] with a well-typed [Auth] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun auth(auth: JsonField) = apply { this.auth = auth } + + /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ + fun modelName(modelName: String) = modelName(JsonField.of(modelName)) + + /** + * Sets [Builder.modelName] to an arbitrary JSON value. + * + * You should usually call [Builder.modelName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun modelName(modelName: JsonField) = apply { + this.modelName = modelName + } + + /** + * 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("azure") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun provider(provider: JsonValue) = apply { this.provider = provider } + + /** Azure provider-specific model configuration */ + fun providerOptions(providerOptions: ProviderOptions) = + providerOptions(JsonField.of(providerOptions)) + + /** + * Sets [Builder.providerOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.providerOptions] with a well-typed + * [ProviderOptions] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun providerOptions(providerOptions: JsonField) = apply { + this.providerOptions = providerOptions + } + + /** Base URL for the model provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the model provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + 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 [AzureEntraModelConfigObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .auth() + * .modelName() + * .providerOptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AzureEntraModelConfigObject = + AzureEntraModelConfigObject( + checkRequired("auth", auth), + checkRequired("modelName", modelName), + provider, + checkRequired("providerOptions", providerOptions), + baseUrl, + headers, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AzureEntraModelConfigObject = apply { + if (validated) { + return@apply + } + + auth().validate() + modelName() + _provider().let { + if (it != JsonValue.from("azure")) { + throw StagehandInvalidDataException( + "'provider' is invalid, received $it" + ) + } + } + providerOptions().validate() + baseUrl() + headers().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = + (auth.asKnown().getOrNull()?.validity() ?: 0) + + (if (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("azure")) 1 else 0 } + + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure provider authentication configuration */ + class Auth + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val token: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("token") + @ExcludeMissing + token: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(token, type, mutableMapOf()) + + /** + * Microsoft Entra ID bearer token for Azure OpenAI + * + * @throws StagehandInvalidDataException 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 token(): String = token.getRequired("token") + + /** + * Use a Microsoft Entra ID bearer token for authentication + * + * Expected to always return the following: + * ```java + * JsonValue.from("azureEntraId") + * ``` + * + * 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 [token]. + * + * Unlike [token], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("token") @ExcludeMissing fun _token(): JsonField = token + + @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 [Auth]. + * + * The following fields are required: + * ```java + * .token() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Auth]. */ + class Builder internal constructor() { + + private var token: JsonField? = null + private var type: JsonValue = JsonValue.from("azureEntraId") + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(auth: Auth) = apply { + token = auth.token + type = auth.type + additionalProperties = auth.additionalProperties.toMutableMap() + } + + /** Microsoft Entra ID bearer token for Azure OpenAI */ + fun token(token: String) = token(JsonField.of(token)) + + /** + * Sets [Builder.token] to an arbitrary JSON value. + * + * You should usually call [Builder.token] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun token(token: JsonField) = apply { this.token = token } + + /** + * 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("azureEntraId") + * ``` + * + * 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 [Auth]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .token() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Auth = + Auth( + checkRequired("token", token), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Auth = apply { + if (validated) { + return@apply + } + + token() + _type().let { + if (it != JsonValue.from("azureEntraId")) { + throw StagehandInvalidDataException( + "'type' is invalid, received $it" + ) + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (token.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("azureEntraId")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auth && + token == other.token && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(token, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Auth{token=$token, type=$type, additionalProperties=$additionalProperties}" + } + + /** Azure provider-specific model configuration */ + class ProviderOptions + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val azure: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("azure") + @ExcludeMissing + azure: JsonField = JsonMissing.of() + ) : this(azure, mutableMapOf()) + + /** + * Azure OpenAI provider-specific settings + * + * @throws StagehandInvalidDataException 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 azure(): Azure = azure.getRequired("azure") + + /** + * Returns the raw JSON value of [azure]. + * + * Unlike [azure], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("azure") @ExcludeMissing fun _azure(): JsonField = azure + + @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 + * [ProviderOptions]. + * + * The following fields are required: + * ```java + * .azure() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProviderOptions]. */ + class Builder internal constructor() { + + private var azure: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(providerOptions: ProviderOptions) = apply { + azure = providerOptions.azure + additionalProperties = + providerOptions.additionalProperties.toMutableMap() + } + + /** Azure OpenAI provider-specific settings */ + fun azure(azure: Azure) = azure(JsonField.of(azure)) + + /** + * Sets [Builder.azure] to an arbitrary JSON value. + * + * You should usually call [Builder.azure] with a well-typed [Azure] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun azure(azure: JsonField) = apply { this.azure = azure } + + 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 [ProviderOptions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .azure() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProviderOptions = + ProviderOptions( + checkRequired("azure", azure), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ProviderOptions = apply { + if (validated) { + return@apply + } + + azure().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = (azure.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure OpenAI provider-specific settings */ + class Azure + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val apiVersion: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val resourceName: JsonField, + private val useDeploymentBasedUrls: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("apiVersion") + @ExcludeMissing + apiVersion: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + @JsonProperty("resourceName") + @ExcludeMissing + resourceName: JsonField = JsonMissing.of(), + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + useDeploymentBasedUrls: JsonField = JsonMissing.of(), + ) : this( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + mutableMapOf(), + ) + + /** + * Azure OpenAI API version + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun apiVersion(): Optional = apiVersion.getOptional("apiVersion") + + /** + * Base URL for the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Azure OpenAI resource name + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun resourceName(): Optional = + resourceName.getOptional("resourceName") + + /** + * Whether to use deployment-based Azure OpenAI URLs + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun useDeploymentBasedUrls(): Optional = + useDeploymentBasedUrls.getOptional("useDeploymentBasedUrls") + + /** + * Returns the raw JSON value of [apiVersion]. + * + * Unlike [apiVersion], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("apiVersion") + @ExcludeMissing + fun _apiVersion(): JsonField = apiVersion + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("baseURL") + @ExcludeMissing + fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + /** + * Returns the raw JSON value of [resourceName]. + * + * Unlike [resourceName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("resourceName") + @ExcludeMissing + fun _resourceName(): JsonField = resourceName + + /** + * Returns the raw JSON value of [useDeploymentBasedUrls]. + * + * Unlike [useDeploymentBasedUrls], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + fun _useDeploymentBasedUrls(): JsonField = useDeploymentBasedUrls + + @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 [Azure]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Azure]. */ + class Builder internal constructor() { + + private var apiVersion: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var resourceName: JsonField = JsonMissing.of() + private var useDeploymentBasedUrls: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(azure: Azure) = apply { + apiVersion = azure.apiVersion + baseUrl = azure.baseUrl + headers = azure.headers + resourceName = azure.resourceName + useDeploymentBasedUrls = azure.useDeploymentBasedUrls + additionalProperties = azure.additionalProperties.toMutableMap() + } + + /** Azure OpenAI API version */ + fun apiVersion(apiVersion: String) = + apiVersion(JsonField.of(apiVersion)) + + /** + * Sets [Builder.apiVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.apiVersion] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun apiVersion(apiVersion: JsonField) = apply { + this.apiVersion = apiVersion + } + + /** Base URL for the Azure OpenAI provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { + this.baseUrl = baseUrl + } + + /** + * Custom headers sent with every request to the Azure OpenAI provider + */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun headers(headers: JsonField) = apply { + this.headers = headers + } + + /** Azure OpenAI resource name */ + fun resourceName(resourceName: String) = + resourceName(JsonField.of(resourceName)) + + /** + * Sets [Builder.resourceName] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceName] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun resourceName(resourceName: JsonField) = apply { + this.resourceName = resourceName + } + + /** Whether to use deployment-based Azure OpenAI URLs */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: Boolean) = + useDeploymentBasedUrls(JsonField.of(useDeploymentBasedUrls)) + + /** + * Sets [Builder.useDeploymentBasedUrls] to an arbitrary JSON value. + * + * You should usually call [Builder.useDeploymentBasedUrls] with a + * well-typed [Boolean] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: JsonField) = + apply { + this.useDeploymentBasedUrls = useDeploymentBasedUrls + } + + 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 [Azure]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Azure = + Azure( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Azure = apply { + if (validated) { + return@apply + } + + apiVersion() + baseUrl() + headers().ifPresent { it.validate() } + resourceName() + useDeploymentBasedUrls() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (apiVersion.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceName.asKnown().isPresent) 1 else 0) + + (if (useDeploymentBasedUrls.asKnown().isPresent) 1 else 0) + + /** Custom headers sent with every request to the Azure OpenAI provider */ + class Headers + @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 + * [Headers]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = + headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws StagehandInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Azure && + apiVersion == other.apiVersion && + baseUrl == other.baseUrl && + headers == other.headers && + resourceName == other.resourceName && + useDeploymentBasedUrls == other.useDeploymentBasedUrls && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Azure{apiVersion=$apiVersion, baseUrl=$baseUrl, headers=$headers, resourceName=$resourceName, useDeploymentBasedUrls=$useDeploymentBasedUrls, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProviderOptions && + azure == other.azure && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(azure, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProviderOptions{azure=$azure, additionalProperties=$additionalProperties}" + } + + /** Custom headers sent with every request to the model provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AzureEntraModelConfigObject && + auth == other.auth && + modelName == other.modelName && + provider == other.provider && + providerOptions == other.providerOptions && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + auth, + modelName, + provider, + providerOptions, + baseUrl, + headers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AzureEntraModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + + class AzureApiKeyModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val modelName: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, + private val apiKey: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("modelName") + @ExcludeMissing + modelName: JsonField = JsonMissing.of(), + @JsonProperty("provider") + @ExcludeMissing + provider: JsonValue = JsonMissing.of(), + @JsonProperty("providerOptions") + @ExcludeMissing + providerOptions: JsonField = JsonMissing.of(), + @JsonProperty("apiKey") + @ExcludeMissing + apiKey: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + ) : this( + modelName, + provider, + providerOptions, + apiKey, + baseUrl, + headers, + mutableMapOf(), + ) + + /** + * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') + * + * @throws StagehandInvalidDataException 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 modelName(): String = modelName.getRequired("modelName") + + /** + * Azure OpenAI model provider + * + * Expected to always return the following: + * ```java + * JsonValue.from("azure") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider + + /** + * Azure provider-specific model configuration + * + * @throws StagehandInvalidDataException 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 providerOptions(): ProviderOptions = + providerOptions.getRequired("providerOptions") + + /** + * API key for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun apiKey(): Optional = apiKey.getOptional("apiKey") + + /** + * Base URL for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Returns the raw JSON value of [modelName]. + * + * Unlike [modelName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("modelName") + @ExcludeMissing + fun _modelName(): JsonField = modelName + + /** + * Returns the raw JSON value of [providerOptions]. + * + * Unlike [providerOptions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("providerOptions") + @ExcludeMissing + fun _providerOptions(): JsonField = providerOptions + + /** + * Returns the raw JSON value of [apiKey]. + * + * Unlike [apiKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("apiKey") @ExcludeMissing fun _apiKey(): JsonField = apiKey + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + @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 + * [AzureApiKeyModelConfigObject]. + * + * The following fields are required: + * ```java + * .modelName() + * .providerOptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AzureApiKeyModelConfigObject]. */ + class Builder internal constructor() { + + private var modelName: JsonField? = null + private var provider: JsonValue = JsonValue.from("azure") + private var providerOptions: JsonField? = null + private var apiKey: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject) = + apply { + modelName = azureApiKeyModelConfigObject.modelName + provider = azureApiKeyModelConfigObject.provider + providerOptions = azureApiKeyModelConfigObject.providerOptions + apiKey = azureApiKeyModelConfigObject.apiKey + baseUrl = azureApiKeyModelConfigObject.baseUrl + headers = azureApiKeyModelConfigObject.headers + additionalProperties = + azureApiKeyModelConfigObject.additionalProperties.toMutableMap() + } + + /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ + fun modelName(modelName: String) = modelName(JsonField.of(modelName)) + + /** + * Sets [Builder.modelName] to an arbitrary JSON value. + * + * You should usually call [Builder.modelName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun modelName(modelName: JsonField) = apply { + this.modelName = modelName + } + + /** + * 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("azure") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun provider(provider: JsonValue) = apply { this.provider = provider } + + /** Azure provider-specific model configuration */ + fun providerOptions(providerOptions: ProviderOptions) = + providerOptions(JsonField.of(providerOptions)) + + /** + * Sets [Builder.providerOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.providerOptions] with a well-typed + * [ProviderOptions] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun providerOptions(providerOptions: JsonField) = apply { + this.providerOptions = providerOptions + } + + /** API key for the model provider */ + fun apiKey(apiKey: String) = apiKey(JsonField.of(apiKey)) + + /** + * Sets [Builder.apiKey] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKey(apiKey: JsonField) = apply { this.apiKey = apiKey } + + /** Base URL for the model provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the model provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + 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 [AzureApiKeyModelConfigObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .modelName() + * .providerOptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AzureApiKeyModelConfigObject = + AzureApiKeyModelConfigObject( + checkRequired("modelName", modelName), + provider, + checkRequired("providerOptions", providerOptions), + apiKey, + baseUrl, + headers, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AzureApiKeyModelConfigObject = apply { + if (validated) { + return@apply + } + + modelName() + _provider().let { + if (it != JsonValue.from("azure")) { + throw StagehandInvalidDataException( + "'provider' is invalid, received $it" + ) + } + } + providerOptions().validate() + apiKey() + baseUrl() + headers().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("azure")) 1 else 0 } + + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + + (if (apiKey.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure provider-specific model configuration */ + class ProviderOptions + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val azure: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("azure") + @ExcludeMissing + azure: JsonField = JsonMissing.of() + ) : this(azure, mutableMapOf()) + + /** + * Azure OpenAI provider-specific settings + * + * @throws StagehandInvalidDataException 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 azure(): Azure = azure.getRequired("azure") + + /** + * Returns the raw JSON value of [azure]. + * + * Unlike [azure], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("azure") @ExcludeMissing fun _azure(): JsonField = azure + + @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 + * [ProviderOptions]. + * + * The following fields are required: + * ```java + * .azure() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProviderOptions]. */ + class Builder internal constructor() { + + private var azure: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(providerOptions: ProviderOptions) = apply { + azure = providerOptions.azure + additionalProperties = + providerOptions.additionalProperties.toMutableMap() + } + + /** Azure OpenAI provider-specific settings */ + fun azure(azure: Azure) = azure(JsonField.of(azure)) + + /** + * Sets [Builder.azure] to an arbitrary JSON value. + * + * You should usually call [Builder.azure] with a well-typed [Azure] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun azure(azure: JsonField) = apply { this.azure = azure } + + 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 [ProviderOptions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .azure() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProviderOptions = + ProviderOptions( + checkRequired("azure", azure), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ProviderOptions = apply { + if (validated) { + return@apply + } + + azure().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = (azure.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure OpenAI provider-specific settings */ + class Azure + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val apiVersion: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val resourceName: JsonField, + private val useDeploymentBasedUrls: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("apiVersion") + @ExcludeMissing + apiVersion: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + @JsonProperty("resourceName") + @ExcludeMissing + resourceName: JsonField = JsonMissing.of(), + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + useDeploymentBasedUrls: JsonField = JsonMissing.of(), + ) : this( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + mutableMapOf(), + ) + + /** + * Azure OpenAI API version + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun apiVersion(): Optional = apiVersion.getOptional("apiVersion") + + /** + * Base URL for the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Azure OpenAI resource name + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun resourceName(): Optional = + resourceName.getOptional("resourceName") + + /** + * Whether to use deployment-based Azure OpenAI URLs + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun useDeploymentBasedUrls(): Optional = + useDeploymentBasedUrls.getOptional("useDeploymentBasedUrls") + + /** + * Returns the raw JSON value of [apiVersion]. + * + * Unlike [apiVersion], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("apiVersion") + @ExcludeMissing + fun _apiVersion(): JsonField = apiVersion + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("baseURL") + @ExcludeMissing + fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + /** + * Returns the raw JSON value of [resourceName]. + * + * Unlike [resourceName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("resourceName") + @ExcludeMissing + fun _resourceName(): JsonField = resourceName + + /** + * Returns the raw JSON value of [useDeploymentBasedUrls]. + * + * Unlike [useDeploymentBasedUrls], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + fun _useDeploymentBasedUrls(): JsonField = useDeploymentBasedUrls + + @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 [Azure]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Azure]. */ + class Builder internal constructor() { + + private var apiVersion: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var resourceName: JsonField = JsonMissing.of() + private var useDeploymentBasedUrls: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(azure: Azure) = apply { + apiVersion = azure.apiVersion + baseUrl = azure.baseUrl + headers = azure.headers + resourceName = azure.resourceName + useDeploymentBasedUrls = azure.useDeploymentBasedUrls + additionalProperties = azure.additionalProperties.toMutableMap() + } + + /** Azure OpenAI API version */ + fun apiVersion(apiVersion: String) = + apiVersion(JsonField.of(apiVersion)) + + /** + * Sets [Builder.apiVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.apiVersion] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun apiVersion(apiVersion: JsonField) = apply { + this.apiVersion = apiVersion + } + + /** Base URL for the Azure OpenAI provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { + this.baseUrl = baseUrl + } + + /** + * Custom headers sent with every request to the Azure OpenAI provider + */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun headers(headers: JsonField) = apply { + this.headers = headers + } + + /** Azure OpenAI resource name */ + fun resourceName(resourceName: String) = + resourceName(JsonField.of(resourceName)) + + /** + * Sets [Builder.resourceName] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceName] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun resourceName(resourceName: JsonField) = apply { + this.resourceName = resourceName + } + + /** Whether to use deployment-based Azure OpenAI URLs */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: Boolean) = + useDeploymentBasedUrls(JsonField.of(useDeploymentBasedUrls)) + + /** + * Sets [Builder.useDeploymentBasedUrls] to an arbitrary JSON value. + * + * You should usually call [Builder.useDeploymentBasedUrls] with a + * well-typed [Boolean] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: JsonField) = + apply { + this.useDeploymentBasedUrls = useDeploymentBasedUrls + } + + 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 [Azure]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Azure = + Azure( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Azure = apply { + if (validated) { + return@apply + } + + apiVersion() + baseUrl() + headers().ifPresent { it.validate() } + resourceName() + useDeploymentBasedUrls() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (apiVersion.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceName.asKnown().isPresent) 1 else 0) + + (if (useDeploymentBasedUrls.asKnown().isPresent) 1 else 0) + + /** Custom headers sent with every request to the Azure OpenAI provider */ + class Headers + @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 + * [Headers]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = + headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws StagehandInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Azure && + apiVersion == other.apiVersion && + baseUrl == other.baseUrl && + headers == other.headers && + resourceName == other.resourceName && + useDeploymentBasedUrls == other.useDeploymentBasedUrls && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Azure{apiVersion=$apiVersion, baseUrl=$baseUrl, headers=$headers, resourceName=$resourceName, useDeploymentBasedUrls=$useDeploymentBasedUrls, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProviderOptions && + azure == other.azure && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(azure, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProviderOptions{azure=$azure, additionalProperties=$additionalProperties}" + } + + /** Custom headers sent with every request to the model provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AzureApiKeyModelConfigObject && + modelName == other.modelName && + provider == other.provider && + providerOptions == other.providerOptions && + apiKey == other.apiKey && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + modelName, + provider, + providerOptions, + apiKey, + baseUrl, + headers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AzureApiKeyModelConfigObject{modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + class GenericModelConfigObject @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( diff --git a/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionObserveParams.kt b/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionObserveParams.kt index 87e37b2..8c95c20 100644 --- a/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionObserveParams.kt +++ b/stagehand-java-core/src/main/kotlin/com/browserbase/api/models/sessions/SessionObserveParams.kt @@ -765,6 +765,20 @@ private constructor( fun model(vertexModelConfigObject: Model.VertexModelConfigObject) = model(Model.ofVertexModelConfigObject(vertexModelConfigObject)) + /** + * Alias for calling [model] with + * `Model.ofAzureEntraModelConfigObject(azureEntraModelConfigObject)`. + */ + fun model(azureEntraModelConfigObject: Model.AzureEntraModelConfigObject) = + model(Model.ofAzureEntraModelConfigObject(azureEntraModelConfigObject)) + + /** + * Alias for calling [model] with + * `Model.ofAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject)`. + */ + fun model(azureApiKeyModelConfigObject: Model.AzureApiKeyModelConfigObject) = + model(Model.ofAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject)) + /** * Alias for calling [model] with * `Model.ofGenericModelConfigObject(genericModelConfigObject)`. @@ -902,6 +916,8 @@ private constructor( class Model private constructor( private val vertexModelConfigObject: VertexModelConfigObject? = null, + private val azureEntraModelConfigObject: AzureEntraModelConfigObject? = null, + private val azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject? = null, private val genericModelConfigObject: GenericModelConfigObject? = null, private val string: String? = null, private val _json: JsonValue? = null, @@ -910,6 +926,12 @@ private constructor( fun vertexModelConfigObject(): Optional = Optional.ofNullable(vertexModelConfigObject) + fun azureEntraModelConfigObject(): Optional = + Optional.ofNullable(azureEntraModelConfigObject) + + fun azureApiKeyModelConfigObject(): Optional = + Optional.ofNullable(azureApiKeyModelConfigObject) + fun genericModelConfigObject(): Optional = Optional.ofNullable(genericModelConfigObject) @@ -917,6 +939,10 @@ private constructor( fun isVertexModelConfigObject(): Boolean = vertexModelConfigObject != null + fun isAzureEntraModelConfigObject(): Boolean = azureEntraModelConfigObject != null + + fun isAzureApiKeyModelConfigObject(): Boolean = azureApiKeyModelConfigObject != null + fun isGenericModelConfigObject(): Boolean = genericModelConfigObject != null fun isString(): Boolean = string != null @@ -924,6 +950,12 @@ private constructor( fun asVertexModelConfigObject(): VertexModelConfigObject = vertexModelConfigObject.getOrThrow("vertexModelConfigObject") + fun asAzureEntraModelConfigObject(): AzureEntraModelConfigObject = + azureEntraModelConfigObject.getOrThrow("azureEntraModelConfigObject") + + fun asAzureApiKeyModelConfigObject(): AzureApiKeyModelConfigObject = + azureApiKeyModelConfigObject.getOrThrow("azureApiKeyModelConfigObject") + fun asGenericModelConfigObject(): GenericModelConfigObject = genericModelConfigObject.getOrThrow("genericModelConfigObject") @@ -965,6 +997,10 @@ private constructor( when { vertexModelConfigObject != null -> visitor.visitVertexModelConfigObject(vertexModelConfigObject) + azureEntraModelConfigObject != null -> + visitor.visitAzureEntraModelConfigObject(azureEntraModelConfigObject) + azureApiKeyModelConfigObject != null -> + visitor.visitAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject) genericModelConfigObject != null -> visitor.visitGenericModelConfigObject(genericModelConfigObject) string != null -> visitor.visitString(string) @@ -996,6 +1032,18 @@ private constructor( vertexModelConfigObject.validate() } + override fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) { + azureEntraModelConfigObject.validate() + } + + override fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) { + azureApiKeyModelConfigObject.validate() + } + override fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ) { @@ -1030,6 +1078,14 @@ private constructor( vertexModelConfigObject: VertexModelConfigObject ) = vertexModelConfigObject.validity() + override fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) = azureEntraModelConfigObject.validity() + + override fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) = azureApiKeyModelConfigObject.validity() + override fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ) = genericModelConfigObject.validity() @@ -1047,17 +1103,29 @@ private constructor( return other is Model && vertexModelConfigObject == other.vertexModelConfigObject && + azureEntraModelConfigObject == other.azureEntraModelConfigObject && + azureApiKeyModelConfigObject == other.azureApiKeyModelConfigObject && genericModelConfigObject == other.genericModelConfigObject && string == other.string } override fun hashCode(): Int = - Objects.hash(vertexModelConfigObject, genericModelConfigObject, string) + Objects.hash( + vertexModelConfigObject, + azureEntraModelConfigObject, + azureApiKeyModelConfigObject, + genericModelConfigObject, + string, + ) override fun toString(): String = when { vertexModelConfigObject != null -> "Model{vertexModelConfigObject=$vertexModelConfigObject}" + azureEntraModelConfigObject != null -> + "Model{azureEntraModelConfigObject=$azureEntraModelConfigObject}" + azureApiKeyModelConfigObject != null -> + "Model{azureApiKeyModelConfigObject=$azureApiKeyModelConfigObject}" genericModelConfigObject != null -> "Model{genericModelConfigObject=$genericModelConfigObject}" string != null -> "Model{string=$string}" @@ -1071,6 +1139,16 @@ private constructor( fun ofVertexModelConfigObject(vertexModelConfigObject: VertexModelConfigObject) = Model(vertexModelConfigObject = vertexModelConfigObject) + @JvmStatic + fun ofAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ) = Model(azureEntraModelConfigObject = azureEntraModelConfigObject) + + @JvmStatic + fun ofAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ) = Model(azureApiKeyModelConfigObject = azureApiKeyModelConfigObject) + @JvmStatic fun ofGenericModelConfigObject(genericModelConfigObject: GenericModelConfigObject) = Model(genericModelConfigObject = genericModelConfigObject) @@ -1087,6 +1165,14 @@ private constructor( vertexModelConfigObject: VertexModelConfigObject ): T + fun visitAzureEntraModelConfigObject( + azureEntraModelConfigObject: AzureEntraModelConfigObject + ): T + + fun visitAzureApiKeyModelConfigObject( + azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject + ): T + fun visitGenericModelConfigObject( genericModelConfigObject: GenericModelConfigObject ): T @@ -1117,6 +1203,12 @@ private constructor( sequenceOf( tryDeserialize(node, jacksonTypeRef()) ?.let { Model(vertexModelConfigObject = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { Model(azureEntraModelConfigObject = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { + Model(azureApiKeyModelConfigObject = it, _json = json) + }, tryDeserialize(node, jacksonTypeRef()) ?.let { Model(genericModelConfigObject = it, _json = json) }, tryDeserialize(node, jacksonTypeRef())?.let { @@ -1149,6 +1241,10 @@ private constructor( when { value.vertexModelConfigObject != null -> generator.writeObject(value.vertexModelConfigObject) + value.azureEntraModelConfigObject != null -> + generator.writeObject(value.azureEntraModelConfigObject) + value.azureApiKeyModelConfigObject != null -> + generator.writeObject(value.azureApiKeyModelConfigObject) value.genericModelConfigObject != null -> generator.writeObject(value.genericModelConfigObject) value.string != null -> generator.writeObject(value.string) @@ -3691,6 +3787,2624 @@ private constructor( "VertexModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" } + class AzureEntraModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val auth: JsonField, + private val modelName: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("auth") @ExcludeMissing auth: JsonField = JsonMissing.of(), + @JsonProperty("modelName") + @ExcludeMissing + modelName: JsonField = JsonMissing.of(), + @JsonProperty("provider") + @ExcludeMissing + provider: JsonValue = JsonMissing.of(), + @JsonProperty("providerOptions") + @ExcludeMissing + providerOptions: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + ) : this( + auth, + modelName, + provider, + providerOptions, + baseUrl, + headers, + mutableMapOf(), + ) + + /** + * Azure provider authentication configuration + * + * @throws StagehandInvalidDataException 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 auth(): Auth = auth.getRequired("auth") + + /** + * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') + * + * @throws StagehandInvalidDataException 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 modelName(): String = modelName.getRequired("modelName") + + /** + * Azure OpenAI model provider + * + * Expected to always return the following: + * ```java + * JsonValue.from("azure") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider + + /** + * Azure provider-specific model configuration + * + * @throws StagehandInvalidDataException 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 providerOptions(): ProviderOptions = + providerOptions.getRequired("providerOptions") + + /** + * Base URL for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Returns the raw JSON value of [auth]. + * + * Unlike [auth], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("auth") @ExcludeMissing fun _auth(): JsonField = auth + + /** + * Returns the raw JSON value of [modelName]. + * + * Unlike [modelName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("modelName") + @ExcludeMissing + fun _modelName(): JsonField = modelName + + /** + * Returns the raw JSON value of [providerOptions]. + * + * Unlike [providerOptions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("providerOptions") + @ExcludeMissing + fun _providerOptions(): JsonField = providerOptions + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + @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 + * [AzureEntraModelConfigObject]. + * + * The following fields are required: + * ```java + * .auth() + * .modelName() + * .providerOptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AzureEntraModelConfigObject]. */ + class Builder internal constructor() { + + private var auth: JsonField? = null + private var modelName: JsonField? = null + private var provider: JsonValue = JsonValue.from("azure") + private var providerOptions: JsonField? = null + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(azureEntraModelConfigObject: AzureEntraModelConfigObject) = + apply { + auth = azureEntraModelConfigObject.auth + modelName = azureEntraModelConfigObject.modelName + provider = azureEntraModelConfigObject.provider + providerOptions = azureEntraModelConfigObject.providerOptions + baseUrl = azureEntraModelConfigObject.baseUrl + headers = azureEntraModelConfigObject.headers + additionalProperties = + azureEntraModelConfigObject.additionalProperties.toMutableMap() + } + + /** Azure provider authentication configuration */ + fun auth(auth: Auth) = auth(JsonField.of(auth)) + + /** + * Sets [Builder.auth] to an arbitrary JSON value. + * + * You should usually call [Builder.auth] with a well-typed [Auth] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun auth(auth: JsonField) = apply { this.auth = auth } + + /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ + fun modelName(modelName: String) = modelName(JsonField.of(modelName)) + + /** + * Sets [Builder.modelName] to an arbitrary JSON value. + * + * You should usually call [Builder.modelName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun modelName(modelName: JsonField) = apply { + this.modelName = modelName + } + + /** + * 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("azure") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun provider(provider: JsonValue) = apply { this.provider = provider } + + /** Azure provider-specific model configuration */ + fun providerOptions(providerOptions: ProviderOptions) = + providerOptions(JsonField.of(providerOptions)) + + /** + * Sets [Builder.providerOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.providerOptions] with a well-typed + * [ProviderOptions] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun providerOptions(providerOptions: JsonField) = apply { + this.providerOptions = providerOptions + } + + /** Base URL for the model provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the model provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + 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 [AzureEntraModelConfigObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .auth() + * .modelName() + * .providerOptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AzureEntraModelConfigObject = + AzureEntraModelConfigObject( + checkRequired("auth", auth), + checkRequired("modelName", modelName), + provider, + checkRequired("providerOptions", providerOptions), + baseUrl, + headers, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AzureEntraModelConfigObject = apply { + if (validated) { + return@apply + } + + auth().validate() + modelName() + _provider().let { + if (it != JsonValue.from("azure")) { + throw StagehandInvalidDataException( + "'provider' is invalid, received $it" + ) + } + } + providerOptions().validate() + baseUrl() + headers().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = + (auth.asKnown().getOrNull()?.validity() ?: 0) + + (if (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("azure")) 1 else 0 } + + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure provider authentication configuration */ + class Auth + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val token: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("token") + @ExcludeMissing + token: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(token, type, mutableMapOf()) + + /** + * Microsoft Entra ID bearer token for Azure OpenAI + * + * @throws StagehandInvalidDataException 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 token(): String = token.getRequired("token") + + /** + * Use a Microsoft Entra ID bearer token for authentication + * + * Expected to always return the following: + * ```java + * JsonValue.from("azureEntraId") + * ``` + * + * 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 [token]. + * + * Unlike [token], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("token") @ExcludeMissing fun _token(): JsonField = token + + @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 [Auth]. + * + * The following fields are required: + * ```java + * .token() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Auth]. */ + class Builder internal constructor() { + + private var token: JsonField? = null + private var type: JsonValue = JsonValue.from("azureEntraId") + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(auth: Auth) = apply { + token = auth.token + type = auth.type + additionalProperties = auth.additionalProperties.toMutableMap() + } + + /** Microsoft Entra ID bearer token for Azure OpenAI */ + fun token(token: String) = token(JsonField.of(token)) + + /** + * Sets [Builder.token] to an arbitrary JSON value. + * + * You should usually call [Builder.token] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun token(token: JsonField) = apply { this.token = token } + + /** + * 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("azureEntraId") + * ``` + * + * 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 [Auth]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .token() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Auth = + Auth( + checkRequired("token", token), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Auth = apply { + if (validated) { + return@apply + } + + token() + _type().let { + if (it != JsonValue.from("azureEntraId")) { + throw StagehandInvalidDataException( + "'type' is invalid, received $it" + ) + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (token.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("azureEntraId")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Auth && + token == other.token && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(token, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Auth{token=$token, type=$type, additionalProperties=$additionalProperties}" + } + + /** Azure provider-specific model configuration */ + class ProviderOptions + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val azure: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("azure") + @ExcludeMissing + azure: JsonField = JsonMissing.of() + ) : this(azure, mutableMapOf()) + + /** + * Azure OpenAI provider-specific settings + * + * @throws StagehandInvalidDataException 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 azure(): Azure = azure.getRequired("azure") + + /** + * Returns the raw JSON value of [azure]. + * + * Unlike [azure], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("azure") @ExcludeMissing fun _azure(): JsonField = azure + + @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 + * [ProviderOptions]. + * + * The following fields are required: + * ```java + * .azure() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProviderOptions]. */ + class Builder internal constructor() { + + private var azure: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(providerOptions: ProviderOptions) = apply { + azure = providerOptions.azure + additionalProperties = + providerOptions.additionalProperties.toMutableMap() + } + + /** Azure OpenAI provider-specific settings */ + fun azure(azure: Azure) = azure(JsonField.of(azure)) + + /** + * Sets [Builder.azure] to an arbitrary JSON value. + * + * You should usually call [Builder.azure] with a well-typed [Azure] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun azure(azure: JsonField) = apply { this.azure = azure } + + 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 [ProviderOptions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .azure() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProviderOptions = + ProviderOptions( + checkRequired("azure", azure), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ProviderOptions = apply { + if (validated) { + return@apply + } + + azure().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = (azure.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure OpenAI provider-specific settings */ + class Azure + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val apiVersion: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val resourceName: JsonField, + private val useDeploymentBasedUrls: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("apiVersion") + @ExcludeMissing + apiVersion: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + @JsonProperty("resourceName") + @ExcludeMissing + resourceName: JsonField = JsonMissing.of(), + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + useDeploymentBasedUrls: JsonField = JsonMissing.of(), + ) : this( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + mutableMapOf(), + ) + + /** + * Azure OpenAI API version + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun apiVersion(): Optional = apiVersion.getOptional("apiVersion") + + /** + * Base URL for the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Azure OpenAI resource name + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun resourceName(): Optional = + resourceName.getOptional("resourceName") + + /** + * Whether to use deployment-based Azure OpenAI URLs + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun useDeploymentBasedUrls(): Optional = + useDeploymentBasedUrls.getOptional("useDeploymentBasedUrls") + + /** + * Returns the raw JSON value of [apiVersion]. + * + * Unlike [apiVersion], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("apiVersion") + @ExcludeMissing + fun _apiVersion(): JsonField = apiVersion + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("baseURL") + @ExcludeMissing + fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + /** + * Returns the raw JSON value of [resourceName]. + * + * Unlike [resourceName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("resourceName") + @ExcludeMissing + fun _resourceName(): JsonField = resourceName + + /** + * Returns the raw JSON value of [useDeploymentBasedUrls]. + * + * Unlike [useDeploymentBasedUrls], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + fun _useDeploymentBasedUrls(): JsonField = useDeploymentBasedUrls + + @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 [Azure]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Azure]. */ + class Builder internal constructor() { + + private var apiVersion: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var resourceName: JsonField = JsonMissing.of() + private var useDeploymentBasedUrls: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(azure: Azure) = apply { + apiVersion = azure.apiVersion + baseUrl = azure.baseUrl + headers = azure.headers + resourceName = azure.resourceName + useDeploymentBasedUrls = azure.useDeploymentBasedUrls + additionalProperties = azure.additionalProperties.toMutableMap() + } + + /** Azure OpenAI API version */ + fun apiVersion(apiVersion: String) = + apiVersion(JsonField.of(apiVersion)) + + /** + * Sets [Builder.apiVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.apiVersion] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun apiVersion(apiVersion: JsonField) = apply { + this.apiVersion = apiVersion + } + + /** Base URL for the Azure OpenAI provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { + this.baseUrl = baseUrl + } + + /** + * Custom headers sent with every request to the Azure OpenAI provider + */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun headers(headers: JsonField) = apply { + this.headers = headers + } + + /** Azure OpenAI resource name */ + fun resourceName(resourceName: String) = + resourceName(JsonField.of(resourceName)) + + /** + * Sets [Builder.resourceName] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceName] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun resourceName(resourceName: JsonField) = apply { + this.resourceName = resourceName + } + + /** Whether to use deployment-based Azure OpenAI URLs */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: Boolean) = + useDeploymentBasedUrls(JsonField.of(useDeploymentBasedUrls)) + + /** + * Sets [Builder.useDeploymentBasedUrls] to an arbitrary JSON value. + * + * You should usually call [Builder.useDeploymentBasedUrls] with a + * well-typed [Boolean] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: JsonField) = + apply { + this.useDeploymentBasedUrls = useDeploymentBasedUrls + } + + 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 [Azure]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Azure = + Azure( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Azure = apply { + if (validated) { + return@apply + } + + apiVersion() + baseUrl() + headers().ifPresent { it.validate() } + resourceName() + useDeploymentBasedUrls() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (apiVersion.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceName.asKnown().isPresent) 1 else 0) + + (if (useDeploymentBasedUrls.asKnown().isPresent) 1 else 0) + + /** Custom headers sent with every request to the Azure OpenAI provider */ + class Headers + @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 + * [Headers]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = + headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws StagehandInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Azure && + apiVersion == other.apiVersion && + baseUrl == other.baseUrl && + headers == other.headers && + resourceName == other.resourceName && + useDeploymentBasedUrls == other.useDeploymentBasedUrls && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Azure{apiVersion=$apiVersion, baseUrl=$baseUrl, headers=$headers, resourceName=$resourceName, useDeploymentBasedUrls=$useDeploymentBasedUrls, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProviderOptions && + azure == other.azure && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(azure, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProviderOptions{azure=$azure, additionalProperties=$additionalProperties}" + } + + /** Custom headers sent with every request to the model provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AzureEntraModelConfigObject && + auth == other.auth && + modelName == other.modelName && + provider == other.provider && + providerOptions == other.providerOptions && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + auth, + modelName, + provider, + providerOptions, + baseUrl, + headers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AzureEntraModelConfigObject{auth=$auth, modelName=$modelName, provider=$provider, providerOptions=$providerOptions, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + + class AzureApiKeyModelConfigObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val modelName: JsonField, + private val provider: JsonValue, + private val providerOptions: JsonField, + private val apiKey: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("modelName") + @ExcludeMissing + modelName: JsonField = JsonMissing.of(), + @JsonProperty("provider") + @ExcludeMissing + provider: JsonValue = JsonMissing.of(), + @JsonProperty("providerOptions") + @ExcludeMissing + providerOptions: JsonField = JsonMissing.of(), + @JsonProperty("apiKey") + @ExcludeMissing + apiKey: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + ) : this( + modelName, + provider, + providerOptions, + apiKey, + baseUrl, + headers, + mutableMapOf(), + ) + + /** + * Model name string with provider prefix (e.g., 'openai/gpt-5-nano') + * + * @throws StagehandInvalidDataException 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 modelName(): String = modelName.getRequired("modelName") + + /** + * Azure OpenAI model provider + * + * Expected to always return the following: + * ```java + * JsonValue.from("azure") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("provider") @ExcludeMissing fun _provider(): JsonValue = provider + + /** + * Azure provider-specific model configuration + * + * @throws StagehandInvalidDataException 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 providerOptions(): ProviderOptions = + providerOptions.getRequired("providerOptions") + + /** + * API key for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun apiKey(): Optional = apiKey.getOptional("apiKey") + + /** + * Base URL for the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the model provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Returns the raw JSON value of [modelName]. + * + * Unlike [modelName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("modelName") + @ExcludeMissing + fun _modelName(): JsonField = modelName + + /** + * Returns the raw JSON value of [providerOptions]. + * + * Unlike [providerOptions], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("providerOptions") + @ExcludeMissing + fun _providerOptions(): JsonField = providerOptions + + /** + * Returns the raw JSON value of [apiKey]. + * + * Unlike [apiKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("apiKey") @ExcludeMissing fun _apiKey(): JsonField = apiKey + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("baseURL") @ExcludeMissing fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + @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 + * [AzureApiKeyModelConfigObject]. + * + * The following fields are required: + * ```java + * .modelName() + * .providerOptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AzureApiKeyModelConfigObject]. */ + class Builder internal constructor() { + + private var modelName: JsonField? = null + private var provider: JsonValue = JsonValue.from("azure") + private var providerOptions: JsonField? = null + private var apiKey: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(azureApiKeyModelConfigObject: AzureApiKeyModelConfigObject) = + apply { + modelName = azureApiKeyModelConfigObject.modelName + provider = azureApiKeyModelConfigObject.provider + providerOptions = azureApiKeyModelConfigObject.providerOptions + apiKey = azureApiKeyModelConfigObject.apiKey + baseUrl = azureApiKeyModelConfigObject.baseUrl + headers = azureApiKeyModelConfigObject.headers + additionalProperties = + azureApiKeyModelConfigObject.additionalProperties.toMutableMap() + } + + /** Model name string with provider prefix (e.g., 'openai/gpt-5-nano') */ + fun modelName(modelName: String) = modelName(JsonField.of(modelName)) + + /** + * Sets [Builder.modelName] to an arbitrary JSON value. + * + * You should usually call [Builder.modelName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun modelName(modelName: JsonField) = apply { + this.modelName = modelName + } + + /** + * 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("azure") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun provider(provider: JsonValue) = apply { this.provider = provider } + + /** Azure provider-specific model configuration */ + fun providerOptions(providerOptions: ProviderOptions) = + providerOptions(JsonField.of(providerOptions)) + + /** + * Sets [Builder.providerOptions] to an arbitrary JSON value. + * + * You should usually call [Builder.providerOptions] with a well-typed + * [ProviderOptions] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun providerOptions(providerOptions: JsonField) = apply { + this.providerOptions = providerOptions + } + + /** API key for the model provider */ + fun apiKey(apiKey: String) = apiKey(JsonField.of(apiKey)) + + /** + * Sets [Builder.apiKey] to an arbitrary JSON value. + * + * You should usually call [Builder.apiKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun apiKey(apiKey: JsonField) = apply { this.apiKey = apiKey } + + /** Base URL for the model provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { this.baseUrl = baseUrl } + + /** Custom headers sent with every request to the model provider */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun headers(headers: JsonField) = apply { this.headers = headers } + + 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 [AzureApiKeyModelConfigObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .modelName() + * .providerOptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AzureApiKeyModelConfigObject = + AzureApiKeyModelConfigObject( + checkRequired("modelName", modelName), + provider, + checkRequired("providerOptions", providerOptions), + apiKey, + baseUrl, + headers, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StagehandInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AzureApiKeyModelConfigObject = apply { + if (validated) { + return@apply + } + + modelName() + _provider().let { + if (it != JsonValue.from("azure")) { + throw StagehandInvalidDataException( + "'provider' is invalid, received $it" + ) + } + } + providerOptions().validate() + apiKey() + baseUrl() + headers().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (modelName.asKnown().isPresent) 1 else 0) + + provider.let { if (it == JsonValue.from("azure")) 1 else 0 } + + (providerOptions.asKnown().getOrNull()?.validity() ?: 0) + + (if (apiKey.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure provider-specific model configuration */ + class ProviderOptions + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val azure: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("azure") + @ExcludeMissing + azure: JsonField = JsonMissing.of() + ) : this(azure, mutableMapOf()) + + /** + * Azure OpenAI provider-specific settings + * + * @throws StagehandInvalidDataException 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 azure(): Azure = azure.getRequired("azure") + + /** + * Returns the raw JSON value of [azure]. + * + * Unlike [azure], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("azure") @ExcludeMissing fun _azure(): JsonField = azure + + @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 + * [ProviderOptions]. + * + * The following fields are required: + * ```java + * .azure() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ProviderOptions]. */ + class Builder internal constructor() { + + private var azure: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(providerOptions: ProviderOptions) = apply { + azure = providerOptions.azure + additionalProperties = + providerOptions.additionalProperties.toMutableMap() + } + + /** Azure OpenAI provider-specific settings */ + fun azure(azure: Azure) = azure(JsonField.of(azure)) + + /** + * Sets [Builder.azure] to an arbitrary JSON value. + * + * You should usually call [Builder.azure] with a well-typed [Azure] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun azure(azure: JsonField) = apply { this.azure = azure } + + 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 [ProviderOptions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .azure() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ProviderOptions = + ProviderOptions( + checkRequired("azure", azure), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): ProviderOptions = apply { + if (validated) { + return@apply + } + + azure().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 = (azure.asKnown().getOrNull()?.validity() ?: 0) + + /** Azure OpenAI provider-specific settings */ + class Azure + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val apiVersion: JsonField, + private val baseUrl: JsonField, + private val headers: JsonField, + private val resourceName: JsonField, + private val useDeploymentBasedUrls: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("apiVersion") + @ExcludeMissing + apiVersion: JsonField = JsonMissing.of(), + @JsonProperty("baseURL") + @ExcludeMissing + baseUrl: JsonField = JsonMissing.of(), + @JsonProperty("headers") + @ExcludeMissing + headers: JsonField = JsonMissing.of(), + @JsonProperty("resourceName") + @ExcludeMissing + resourceName: JsonField = JsonMissing.of(), + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + useDeploymentBasedUrls: JsonField = JsonMissing.of(), + ) : this( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + mutableMapOf(), + ) + + /** + * Azure OpenAI API version + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun apiVersion(): Optional = apiVersion.getOptional("apiVersion") + + /** + * Base URL for the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun baseUrl(): Optional = baseUrl.getOptional("baseURL") + + /** + * Custom headers sent with every request to the Azure OpenAI provider + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun headers(): Optional = headers.getOptional("headers") + + /** + * Azure OpenAI resource name + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun resourceName(): Optional = + resourceName.getOptional("resourceName") + + /** + * Whether to use deployment-based Azure OpenAI URLs + * + * @throws StagehandInvalidDataException if the JSON field has an unexpected + * type (e.g. if the server responded with an unexpected value). + */ + fun useDeploymentBasedUrls(): Optional = + useDeploymentBasedUrls.getOptional("useDeploymentBasedUrls") + + /** + * Returns the raw JSON value of [apiVersion]. + * + * Unlike [apiVersion], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("apiVersion") + @ExcludeMissing + fun _apiVersion(): JsonField = apiVersion + + /** + * Returns the raw JSON value of [baseUrl]. + * + * Unlike [baseUrl], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("baseURL") + @ExcludeMissing + fun _baseUrl(): JsonField = baseUrl + + /** + * Returns the raw JSON value of [headers]. + * + * Unlike [headers], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("headers") + @ExcludeMissing + fun _headers(): JsonField = headers + + /** + * Returns the raw JSON value of [resourceName]. + * + * Unlike [resourceName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("resourceName") + @ExcludeMissing + fun _resourceName(): JsonField = resourceName + + /** + * Returns the raw JSON value of [useDeploymentBasedUrls]. + * + * Unlike [useDeploymentBasedUrls], this method doesn't throw if the JSON + * field has an unexpected type. + */ + @JsonProperty("useDeploymentBasedUrls") + @ExcludeMissing + fun _useDeploymentBasedUrls(): JsonField = useDeploymentBasedUrls + + @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 [Azure]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Azure]. */ + class Builder internal constructor() { + + private var apiVersion: JsonField = JsonMissing.of() + private var baseUrl: JsonField = JsonMissing.of() + private var headers: JsonField = JsonMissing.of() + private var resourceName: JsonField = JsonMissing.of() + private var useDeploymentBasedUrls: JsonField = + JsonMissing.of() + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(azure: Azure) = apply { + apiVersion = azure.apiVersion + baseUrl = azure.baseUrl + headers = azure.headers + resourceName = azure.resourceName + useDeploymentBasedUrls = azure.useDeploymentBasedUrls + additionalProperties = azure.additionalProperties.toMutableMap() + } + + /** Azure OpenAI API version */ + fun apiVersion(apiVersion: String) = + apiVersion(JsonField.of(apiVersion)) + + /** + * Sets [Builder.apiVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.apiVersion] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun apiVersion(apiVersion: JsonField) = apply { + this.apiVersion = apiVersion + } + + /** Base URL for the Azure OpenAI provider */ + fun baseUrl(baseUrl: String) = baseUrl(JsonField.of(baseUrl)) + + /** + * Sets [Builder.baseUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.baseUrl] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun baseUrl(baseUrl: JsonField) = apply { + this.baseUrl = baseUrl + } + + /** + * Custom headers sent with every request to the Azure OpenAI provider + */ + fun headers(headers: Headers) = headers(JsonField.of(headers)) + + /** + * Sets [Builder.headers] to an arbitrary JSON value. + * + * You should usually call [Builder.headers] with a well-typed [Headers] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun headers(headers: JsonField) = apply { + this.headers = headers + } + + /** Azure OpenAI resource name */ + fun resourceName(resourceName: String) = + resourceName(JsonField.of(resourceName)) + + /** + * Sets [Builder.resourceName] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceName] with a well-typed + * [String] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun resourceName(resourceName: JsonField) = apply { + this.resourceName = resourceName + } + + /** Whether to use deployment-based Azure OpenAI URLs */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: Boolean) = + useDeploymentBasedUrls(JsonField.of(useDeploymentBasedUrls)) + + /** + * Sets [Builder.useDeploymentBasedUrls] to an arbitrary JSON value. + * + * You should usually call [Builder.useDeploymentBasedUrls] with a + * well-typed [Boolean] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun useDeploymentBasedUrls(useDeploymentBasedUrls: JsonField) = + apply { + this.useDeploymentBasedUrls = useDeploymentBasedUrls + } + + 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 [Azure]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Azure = + Azure( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Azure = apply { + if (validated) { + return@apply + } + + apiVersion() + baseUrl() + headers().ifPresent { it.validate() } + resourceName() + useDeploymentBasedUrls() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 (apiVersion.asKnown().isPresent) 1 else 0) + + (if (baseUrl.asKnown().isPresent) 1 else 0) + + (headers.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceName.asKnown().isPresent) 1 else 0) + + (if (useDeploymentBasedUrls.asKnown().isPresent) 1 else 0) + + /** Custom headers sent with every request to the Azure OpenAI provider */ + class Headers + @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 + * [Headers]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = + headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their + * expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API + * for existing fields. + * + * @throws StagehandInvalidDataException if any value type in this + * object doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Azure && + apiVersion == other.apiVersion && + baseUrl == other.baseUrl && + headers == other.headers && + resourceName == other.resourceName && + useDeploymentBasedUrls == other.useDeploymentBasedUrls && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + apiVersion, + baseUrl, + headers, + resourceName, + useDeploymentBasedUrls, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Azure{apiVersion=$apiVersion, baseUrl=$baseUrl, headers=$headers, resourceName=$resourceName, useDeploymentBasedUrls=$useDeploymentBasedUrls, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ProviderOptions && + azure == other.azure && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(azure, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ProviderOptions{azure=$azure, additionalProperties=$additionalProperties}" + } + + /** Custom headers sent with every request to the model provider */ + class Headers + @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 [Headers]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Headers]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(headers: Headers) = apply { + additionalProperties = headers.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 [Headers]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Headers = Headers(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected + * types recursively. + * + * This method is _not_ forwards compatible with new types from the API for + * existing fields. + * + * @throws StagehandInvalidDataException if any value type in this object + * doesn't match its expected type. + */ + fun validate(): Headers = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StagehandInvalidDataException) { + 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 Headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Headers{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AzureApiKeyModelConfigObject && + modelName == other.modelName && + provider == other.provider && + providerOptions == other.providerOptions && + apiKey == other.apiKey && + baseUrl == other.baseUrl && + headers == other.headers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + modelName, + provider, + providerOptions, + apiKey, + baseUrl, + headers, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AzureApiKeyModelConfigObject{modelName=$modelName, provider=$provider, providerOptions=$providerOptions, apiKey=$apiKey, baseUrl=$baseUrl, headers=$headers, additionalProperties=$additionalProperties}" + } + class GenericModelConfigObject @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( diff --git a/stagehand-java-core/src/test/kotlin/com/browserbase/api/models/sessions/ModelConfigTest.kt b/stagehand-java-core/src/test/kotlin/com/browserbase/api/models/sessions/ModelConfigTest.kt index aa99343..f370509 100644 --- a/stagehand-java-core/src/test/kotlin/com/browserbase/api/models/sessions/ModelConfigTest.kt +++ b/stagehand-java-core/src/test/kotlin/com/browserbase/api/models/sessions/ModelConfigTest.kt @@ -74,6 +74,8 @@ internal class ModelConfigTest { val modelConfig = ModelConfig.ofVertexModelConfigObject(vertexModelConfigObject) assertThat(modelConfig.vertexModelConfigObject()).contains(vertexModelConfigObject) + assertThat(modelConfig.azureEntraModelConfigObject()).isEmpty + assertThat(modelConfig.azureApiKeyModelConfigObject()).isEmpty assertThat(modelConfig.genericModelConfigObject()).isEmpty } @@ -146,6 +148,183 @@ internal class ModelConfigTest { assertThat(roundtrippedModelConfig).isEqualTo(modelConfig) } + @Test + fun ofAzureEntraModelConfigObject() { + val azureEntraModelConfigObject = + ModelConfig.AzureEntraModelConfigObject.builder() + .auth(ModelConfig.AzureEntraModelConfigObject.Auth.builder().token("x").build()) + .modelName("openai/gpt-5.4-mini") + .providerOptions( + ModelConfig.AzureEntraModelConfigObject.ProviderOptions.builder() + .azure( + ModelConfig.AzureEntraModelConfigObject.ProviderOptions.Azure.builder() + .apiVersion("2024-10-01-preview") + .baseUrl("https://example.com") + .headers( + ModelConfig.AzureEntraModelConfigObject.ProviderOptions.Azure + .Headers + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceName("my-azure-openai-resource") + .useDeploymentBasedUrls(true) + .build() + ) + .build() + ) + .baseUrl("https://api.openai.com/v1") + .headers( + ModelConfig.AzureEntraModelConfigObject.Headers.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .build() + + val modelConfig = ModelConfig.ofAzureEntraModelConfigObject(azureEntraModelConfigObject) + + assertThat(modelConfig.vertexModelConfigObject()).isEmpty + assertThat(modelConfig.azureEntraModelConfigObject()).contains(azureEntraModelConfigObject) + assertThat(modelConfig.azureApiKeyModelConfigObject()).isEmpty + assertThat(modelConfig.genericModelConfigObject()).isEmpty + } + + @Test + fun ofAzureEntraModelConfigObjectRoundtrip() { + val jsonMapper = jsonMapper() + val modelConfig = + ModelConfig.ofAzureEntraModelConfigObject( + ModelConfig.AzureEntraModelConfigObject.builder() + .auth(ModelConfig.AzureEntraModelConfigObject.Auth.builder().token("x").build()) + .modelName("openai/gpt-5.4-mini") + .providerOptions( + ModelConfig.AzureEntraModelConfigObject.ProviderOptions.builder() + .azure( + ModelConfig.AzureEntraModelConfigObject.ProviderOptions.Azure + .builder() + .apiVersion("2024-10-01-preview") + .baseUrl("https://example.com") + .headers( + ModelConfig.AzureEntraModelConfigObject.ProviderOptions + .Azure + .Headers + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceName("my-azure-openai-resource") + .useDeploymentBasedUrls(true) + .build() + ) + .build() + ) + .baseUrl("https://api.openai.com/v1") + .headers( + ModelConfig.AzureEntraModelConfigObject.Headers.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .build() + ) + + val roundtrippedModelConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(modelConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedModelConfig).isEqualTo(modelConfig) + } + + @Test + fun ofAzureApiKeyModelConfigObject() { + val azureApiKeyModelConfigObject = + ModelConfig.AzureApiKeyModelConfigObject.builder() + .modelName("openai/gpt-5.4-mini") + .providerOptions( + ModelConfig.AzureApiKeyModelConfigObject.ProviderOptions.builder() + .azure( + ModelConfig.AzureApiKeyModelConfigObject.ProviderOptions.Azure.builder() + .apiVersion("2024-10-01-preview") + .baseUrl("https://example.com") + .headers( + ModelConfig.AzureApiKeyModelConfigObject.ProviderOptions.Azure + .Headers + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceName("my-azure-openai-resource") + .useDeploymentBasedUrls(true) + .build() + ) + .build() + ) + .apiKey("sk-some-openai-api-key") + .baseUrl("https://api.openai.com/v1") + .headers( + ModelConfig.AzureApiKeyModelConfigObject.Headers.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .build() + + val modelConfig = ModelConfig.ofAzureApiKeyModelConfigObject(azureApiKeyModelConfigObject) + + assertThat(modelConfig.vertexModelConfigObject()).isEmpty + assertThat(modelConfig.azureEntraModelConfigObject()).isEmpty + assertThat(modelConfig.azureApiKeyModelConfigObject()) + .contains(azureApiKeyModelConfigObject) + assertThat(modelConfig.genericModelConfigObject()).isEmpty + } + + @Test + fun ofAzureApiKeyModelConfigObjectRoundtrip() { + val jsonMapper = jsonMapper() + val modelConfig = + ModelConfig.ofAzureApiKeyModelConfigObject( + ModelConfig.AzureApiKeyModelConfigObject.builder() + .modelName("openai/gpt-5.4-mini") + .providerOptions( + ModelConfig.AzureApiKeyModelConfigObject.ProviderOptions.builder() + .azure( + ModelConfig.AzureApiKeyModelConfigObject.ProviderOptions.Azure + .builder() + .apiVersion("2024-10-01-preview") + .baseUrl("https://example.com") + .headers( + ModelConfig.AzureApiKeyModelConfigObject.ProviderOptions + .Azure + .Headers + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceName("my-azure-openai-resource") + .useDeploymentBasedUrls(true) + .build() + ) + .build() + ) + .apiKey("sk-some-openai-api-key") + .baseUrl("https://api.openai.com/v1") + .headers( + ModelConfig.AzureApiKeyModelConfigObject.Headers.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .build() + ) + + val roundtrippedModelConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(modelConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedModelConfig).isEqualTo(modelConfig) + } + @Test fun ofGenericModelConfigObject() { val genericModelConfigObject = @@ -164,6 +343,8 @@ internal class ModelConfigTest { val modelConfig = ModelConfig.ofGenericModelConfigObject(genericModelConfigObject) assertThat(modelConfig.vertexModelConfigObject()).isEmpty + assertThat(modelConfig.azureEntraModelConfigObject()).isEmpty + assertThat(modelConfig.azureApiKeyModelConfigObject()).isEmpty assertThat(modelConfig.genericModelConfigObject()).contains(genericModelConfigObject) }