diff --git a/.stats.yml b/.stats.yml index 93f240e..77de729 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 144 +configured_endpoints: 150 diff --git a/README.md b/README.md index 7c54030..53f6701 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Maven Central](https://img.shields.io/maven-central/v/ai.llamaindex.llamacloud/llama-cloud)](https://central.sonatype.com/artifact/ai.llamaindex.llamacloud/llama-cloud/1.8.0) -[![javadoc](https://javadoc.io/badge2/ai.llamaindex.llamacloud/llama-cloud/1.8.0/javadoc.svg)](https://javadoc.io/doc/ai.llamaindex.llamacloud/llama-cloud/1.7.0) +[![javadoc](https://javadoc.io/badge2/ai.llamaindex.llamacloud/llama-cloud/1.8.0/javadoc.svg)](https://javadoc.io/doc/ai.llamaindex.llamacloud/llama-cloud/1.8.0) @@ -271,13 +271,13 @@ To access this data, prefix any HTTP method call on a client or service with `wi ```java import ai.llamaindex.llamacloud.core.http.Headers; import ai.llamaindex.llamacloud.core.http.HttpResponseFor; -import ai.llamaindex.llamacloud.models.beta.indexes.IndexListPage; -import ai.llamaindex.llamacloud.models.beta.indexes.IndexListParams; +import ai.llamaindex.llamacloud.models.indexes.IndexListPage; +import ai.llamaindex.llamacloud.models.indexes.IndexListParams; IndexListParams params = IndexListParams.builder() .projectId("my-project-id") .build(); -HttpResponseFor page = client.beta().indexes().withRawResponse().list(params); +HttpResponseFor page = client.indexes().withRawResponse().list(params); int statusCode = page.statusCode(); Headers headers = page.headers(); @@ -286,7 +286,7 @@ Headers headers = page.headers(); You can still deserialize the response into an instance of a Java class if needed: ```java -import ai.llamaindex.llamacloud.models.beta.indexes.IndexListPage; +import ai.llamaindex.llamacloud.models.indexes.IndexListPage; IndexListPage parsedPage = page.parse(); ``` @@ -497,9 +497,9 @@ Requests time out after 1 minute by default. To set a custom timeout, configure the method call using the `timeout` method: ```java -import ai.llamaindex.llamacloud.models.beta.indexes.IndexListPage; +import ai.llamaindex.llamacloud.models.indexes.IndexListPage; -IndexListPage page = client.beta().indexes().list(RequestOptions.builder().timeout(Duration.ofSeconds(30)).build()); +IndexListPage page = client.indexes().list(RequestOptions.builder().timeout(Duration.ofSeconds(30)).build()); ``` Or configure the default for all method calls at the client level: diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClient.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClient.kt index 1a592df..5b931f1 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClient.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClient.kt @@ -3,8 +3,10 @@ package ai.llamaindex.llamacloud.client import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.services.blocking.AlphaService import ai.llamaindex.llamacloud.services.blocking.BatchService import ai.llamaindex.llamacloud.services.blocking.BetaService +import ai.llamaindex.llamacloud.services.blocking.ChatService import ai.llamaindex.llamacloud.services.blocking.ClassifierService import ai.llamaindex.llamacloud.services.blocking.ClassifyService import ai.llamaindex.llamacloud.services.blocking.ConfigurationService @@ -13,9 +15,11 @@ import ai.llamaindex.llamacloud.services.blocking.DataSourceService import ai.llamaindex.llamacloud.services.blocking.ExtractService import ai.llamaindex.llamacloud.services.blocking.ExtractionAgentService import ai.llamaindex.llamacloud.services.blocking.FileService +import ai.llamaindex.llamacloud.services.blocking.IndexService import ai.llamaindex.llamacloud.services.blocking.ParsingService import ai.llamaindex.llamacloud.services.blocking.PipelineService import ai.llamaindex.llamacloud.services.blocking.ProjectService +import ai.llamaindex.llamacloud.services.blocking.RetrievalService import ai.llamaindex.llamacloud.services.blocking.RetrieverService import ai.llamaindex.llamacloud.services.blocking.SplitService import ai.llamaindex.llamacloud.services.blocking.V2ProjectService @@ -90,8 +94,16 @@ interface LlamaCloudClient { fun retrievers(): RetrieverService + fun indexes(): IndexService + + fun retrieval(): RetrievalService + + fun chat(): ChatService + fun beta(): BetaService + fun alpha(): AlphaService + /** * Closes this client, relinquishing any underlying resources. * @@ -147,6 +159,14 @@ interface LlamaCloudClient { fun retrievers(): RetrieverService.WithRawResponse + fun indexes(): IndexService.WithRawResponse + + fun retrieval(): RetrievalService.WithRawResponse + + fun chat(): ChatService.WithRawResponse + fun beta(): BetaService.WithRawResponse + + fun alpha(): AlphaService.WithRawResponse } } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClientAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClientAsync.kt index 8c3dea6..3116c1b 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClientAsync.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClientAsync.kt @@ -3,8 +3,10 @@ package ai.llamaindex.llamacloud.client import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.services.async.AlphaServiceAsync import ai.llamaindex.llamacloud.services.async.BatchServiceAsync import ai.llamaindex.llamacloud.services.async.BetaServiceAsync +import ai.llamaindex.llamacloud.services.async.ChatServiceAsync import ai.llamaindex.llamacloud.services.async.ClassifierServiceAsync import ai.llamaindex.llamacloud.services.async.ClassifyServiceAsync import ai.llamaindex.llamacloud.services.async.ConfigurationServiceAsync @@ -13,9 +15,11 @@ import ai.llamaindex.llamacloud.services.async.DataSourceServiceAsync import ai.llamaindex.llamacloud.services.async.ExtractServiceAsync import ai.llamaindex.llamacloud.services.async.ExtractionAgentServiceAsync import ai.llamaindex.llamacloud.services.async.FileServiceAsync +import ai.llamaindex.llamacloud.services.async.IndexServiceAsync import ai.llamaindex.llamacloud.services.async.ParsingServiceAsync import ai.llamaindex.llamacloud.services.async.PipelineServiceAsync import ai.llamaindex.llamacloud.services.async.ProjectServiceAsync +import ai.llamaindex.llamacloud.services.async.RetrievalServiceAsync import ai.llamaindex.llamacloud.services.async.RetrieverServiceAsync import ai.llamaindex.llamacloud.services.async.SplitServiceAsync import ai.llamaindex.llamacloud.services.async.V2ProjectServiceAsync @@ -90,8 +94,16 @@ interface LlamaCloudClientAsync { fun retrievers(): RetrieverServiceAsync + fun indexes(): IndexServiceAsync + + fun retrieval(): RetrievalServiceAsync + + fun chat(): ChatServiceAsync + fun beta(): BetaServiceAsync + fun alpha(): AlphaServiceAsync + /** * Closes this client, relinquishing any underlying resources. * @@ -151,6 +163,14 @@ interface LlamaCloudClientAsync { fun retrievers(): RetrieverServiceAsync.WithRawResponse + fun indexes(): IndexServiceAsync.WithRawResponse + + fun retrieval(): RetrievalServiceAsync.WithRawResponse + + fun chat(): ChatServiceAsync.WithRawResponse + fun beta(): BetaServiceAsync.WithRawResponse + + fun alpha(): AlphaServiceAsync.WithRawResponse } } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClientAsyncImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClientAsyncImpl.kt index aa24ea6..f5986da 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClientAsyncImpl.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClientAsyncImpl.kt @@ -4,10 +4,14 @@ package ai.llamaindex.llamacloud.client import ai.llamaindex.llamacloud.core.ClientOptions import ai.llamaindex.llamacloud.core.getPackageVersion +import ai.llamaindex.llamacloud.services.async.AlphaServiceAsync +import ai.llamaindex.llamacloud.services.async.AlphaServiceAsyncImpl import ai.llamaindex.llamacloud.services.async.BatchServiceAsync import ai.llamaindex.llamacloud.services.async.BatchServiceAsyncImpl import ai.llamaindex.llamacloud.services.async.BetaServiceAsync import ai.llamaindex.llamacloud.services.async.BetaServiceAsyncImpl +import ai.llamaindex.llamacloud.services.async.ChatServiceAsync +import ai.llamaindex.llamacloud.services.async.ChatServiceAsyncImpl import ai.llamaindex.llamacloud.services.async.ClassifierServiceAsync import ai.llamaindex.llamacloud.services.async.ClassifierServiceAsyncImpl import ai.llamaindex.llamacloud.services.async.ClassifyServiceAsync @@ -24,12 +28,16 @@ import ai.llamaindex.llamacloud.services.async.ExtractionAgentServiceAsync import ai.llamaindex.llamacloud.services.async.ExtractionAgentServiceAsyncImpl import ai.llamaindex.llamacloud.services.async.FileServiceAsync import ai.llamaindex.llamacloud.services.async.FileServiceAsyncImpl +import ai.llamaindex.llamacloud.services.async.IndexServiceAsync +import ai.llamaindex.llamacloud.services.async.IndexServiceAsyncImpl import ai.llamaindex.llamacloud.services.async.ParsingServiceAsync import ai.llamaindex.llamacloud.services.async.ParsingServiceAsyncImpl import ai.llamaindex.llamacloud.services.async.PipelineServiceAsync import ai.llamaindex.llamacloud.services.async.PipelineServiceAsyncImpl import ai.llamaindex.llamacloud.services.async.ProjectServiceAsync import ai.llamaindex.llamacloud.services.async.ProjectServiceAsyncImpl +import ai.llamaindex.llamacloud.services.async.RetrievalServiceAsync +import ai.llamaindex.llamacloud.services.async.RetrievalServiceAsyncImpl import ai.llamaindex.llamacloud.services.async.RetrieverServiceAsync import ai.llamaindex.llamacloud.services.async.RetrieverServiceAsyncImpl import ai.llamaindex.llamacloud.services.async.SplitServiceAsync @@ -119,8 +127,22 @@ class LlamaCloudClientAsyncImpl(private val clientOptions: ClientOptions) : Llam RetrieverServiceAsyncImpl(clientOptionsWithUserAgent) } + private val indexes: IndexServiceAsync by lazy { + IndexServiceAsyncImpl(clientOptionsWithUserAgent) + } + + private val retrieval: RetrievalServiceAsync by lazy { + RetrievalServiceAsyncImpl(clientOptionsWithUserAgent) + } + + private val chat: ChatServiceAsync by lazy { ChatServiceAsyncImpl(clientOptionsWithUserAgent) } + private val beta: BetaServiceAsync by lazy { BetaServiceAsyncImpl(clientOptionsWithUserAgent) } + private val alpha: AlphaServiceAsync by lazy { + AlphaServiceAsyncImpl(clientOptionsWithUserAgent) + } + override fun sync(): LlamaCloudClient = sync override fun withRawResponse(): LlamaCloudClientAsync.WithRawResponse = withRawResponse @@ -160,8 +182,16 @@ class LlamaCloudClientAsyncImpl(private val clientOptions: ClientOptions) : Llam override fun retrievers(): RetrieverServiceAsync = retrievers + override fun indexes(): IndexServiceAsync = indexes + + override fun retrieval(): RetrievalServiceAsync = retrieval + + override fun chat(): ChatServiceAsync = chat + override fun beta(): BetaServiceAsync = beta + override fun alpha(): AlphaServiceAsync = alpha + override fun close() = clientOptions.close() class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : @@ -231,10 +261,26 @@ class LlamaCloudClientAsyncImpl(private val clientOptions: ClientOptions) : Llam RetrieverServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val indexes: IndexServiceAsync.WithRawResponse by lazy { + IndexServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + private val retrieval: RetrievalServiceAsync.WithRawResponse by lazy { + RetrievalServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + private val chat: ChatServiceAsync.WithRawResponse by lazy { + ChatServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + private val beta: BetaServiceAsync.WithRawResponse by lazy { BetaServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val alpha: AlphaServiceAsync.WithRawResponse by lazy { + AlphaServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): LlamaCloudClientAsync.WithRawResponse = @@ -275,6 +321,14 @@ class LlamaCloudClientAsyncImpl(private val clientOptions: ClientOptions) : Llam override fun retrievers(): RetrieverServiceAsync.WithRawResponse = retrievers + override fun indexes(): IndexServiceAsync.WithRawResponse = indexes + + override fun retrieval(): RetrievalServiceAsync.WithRawResponse = retrieval + + override fun chat(): ChatServiceAsync.WithRawResponse = chat + override fun beta(): BetaServiceAsync.WithRawResponse = beta + + override fun alpha(): AlphaServiceAsync.WithRawResponse = alpha } } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClientImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClientImpl.kt index b9e8526..d7152ec 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClientImpl.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/client/LlamaCloudClientImpl.kt @@ -4,10 +4,14 @@ package ai.llamaindex.llamacloud.client import ai.llamaindex.llamacloud.core.ClientOptions import ai.llamaindex.llamacloud.core.getPackageVersion +import ai.llamaindex.llamacloud.services.blocking.AlphaService +import ai.llamaindex.llamacloud.services.blocking.AlphaServiceImpl import ai.llamaindex.llamacloud.services.blocking.BatchService import ai.llamaindex.llamacloud.services.blocking.BatchServiceImpl import ai.llamaindex.llamacloud.services.blocking.BetaService import ai.llamaindex.llamacloud.services.blocking.BetaServiceImpl +import ai.llamaindex.llamacloud.services.blocking.ChatService +import ai.llamaindex.llamacloud.services.blocking.ChatServiceImpl import ai.llamaindex.llamacloud.services.blocking.ClassifierService import ai.llamaindex.llamacloud.services.blocking.ClassifierServiceImpl import ai.llamaindex.llamacloud.services.blocking.ClassifyService @@ -24,12 +28,16 @@ import ai.llamaindex.llamacloud.services.blocking.ExtractionAgentService import ai.llamaindex.llamacloud.services.blocking.ExtractionAgentServiceImpl import ai.llamaindex.llamacloud.services.blocking.FileService import ai.llamaindex.llamacloud.services.blocking.FileServiceImpl +import ai.llamaindex.llamacloud.services.blocking.IndexService +import ai.llamaindex.llamacloud.services.blocking.IndexServiceImpl import ai.llamaindex.llamacloud.services.blocking.ParsingService import ai.llamaindex.llamacloud.services.blocking.ParsingServiceImpl import ai.llamaindex.llamacloud.services.blocking.PipelineService import ai.llamaindex.llamacloud.services.blocking.PipelineServiceImpl import ai.llamaindex.llamacloud.services.blocking.ProjectService import ai.llamaindex.llamacloud.services.blocking.ProjectServiceImpl +import ai.llamaindex.llamacloud.services.blocking.RetrievalService +import ai.llamaindex.llamacloud.services.blocking.RetrievalServiceImpl import ai.llamaindex.llamacloud.services.blocking.RetrieverService import ai.llamaindex.llamacloud.services.blocking.RetrieverServiceImpl import ai.llamaindex.llamacloud.services.blocking.SplitService @@ -109,8 +117,18 @@ class LlamaCloudClientImpl(private val clientOptions: ClientOptions) : LlamaClou RetrieverServiceImpl(clientOptionsWithUserAgent) } + private val indexes: IndexService by lazy { IndexServiceImpl(clientOptionsWithUserAgent) } + + private val retrieval: RetrievalService by lazy { + RetrievalServiceImpl(clientOptionsWithUserAgent) + } + + private val chat: ChatService by lazy { ChatServiceImpl(clientOptionsWithUserAgent) } + private val beta: BetaService by lazy { BetaServiceImpl(clientOptionsWithUserAgent) } + private val alpha: AlphaService by lazy { AlphaServiceImpl(clientOptionsWithUserAgent) } + override fun async(): LlamaCloudClientAsync = async override fun withRawResponse(): LlamaCloudClient.WithRawResponse = withRawResponse @@ -150,8 +168,16 @@ class LlamaCloudClientImpl(private val clientOptions: ClientOptions) : LlamaClou override fun retrievers(): RetrieverService = retrievers + override fun indexes(): IndexService = indexes + + override fun retrieval(): RetrievalService = retrieval + + override fun chat(): ChatService = chat + override fun beta(): BetaService = beta + override fun alpha(): AlphaService = alpha + override fun close() = clientOptions.close() class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : @@ -221,10 +247,26 @@ class LlamaCloudClientImpl(private val clientOptions: ClientOptions) : LlamaClou RetrieverServiceImpl.WithRawResponseImpl(clientOptions) } + private val indexes: IndexService.WithRawResponse by lazy { + IndexServiceImpl.WithRawResponseImpl(clientOptions) + } + + private val retrieval: RetrievalService.WithRawResponse by lazy { + RetrievalServiceImpl.WithRawResponseImpl(clientOptions) + } + + private val chat: ChatService.WithRawResponse by lazy { + ChatServiceImpl.WithRawResponseImpl(clientOptions) + } + private val beta: BetaService.WithRawResponse by lazy { BetaServiceImpl.WithRawResponseImpl(clientOptions) } + private val alpha: AlphaService.WithRawResponse by lazy { + AlphaServiceImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): LlamaCloudClient.WithRawResponse = @@ -264,6 +306,14 @@ class LlamaCloudClientImpl(private val clientOptions: ClientOptions) : LlamaClou override fun retrievers(): RetrieverService.WithRawResponse = retrievers + override fun indexes(): IndexService.WithRawResponse = indexes + + override fun retrieval(): RetrievalService.WithRawResponse = retrieval + + override fun chat(): ChatService.WithRawResponse = chat + override fun beta(): BetaService.WithRawResponse = beta + + override fun alpha(): AlphaService.WithRawResponse = alpha } } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCancelParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCancelParams.kt new file mode 100644 index 0000000..fd6b78e --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCancelParams.kt @@ -0,0 +1,273 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Cancel a running Verify job. + * + * Stops processing and marks the job as CANCELLED. Returns the updated job. Jobs already in a + * terminal state (COMPLETED, FAILED, CANCELLED) cannot be cancelled. + */ +class VerifyCancelParams +private constructor( + private val jobId: String?, + private val organizationId: String?, + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun jobId(): Optional = Optional.ofNullable(jobId) + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): VerifyCancelParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [VerifyCancelParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyCancelParams]. */ + class Builder internal constructor() { + + private var jobId: String? = null + private var organizationId: String? = null + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(verifyCancelParams: VerifyCancelParams) = apply { + jobId = verifyCancelParams.jobId + organizationId = verifyCancelParams.organizationId + projectId = verifyCancelParams.projectId + additionalHeaders = verifyCancelParams.additionalHeaders.toBuilder() + additionalQueryParams = verifyCancelParams.additionalQueryParams.toBuilder() + additionalBodyProperties = verifyCancelParams.additionalBodyProperties.toMutableMap() + } + + fun jobId(jobId: String?) = apply { this.jobId = jobId } + + /** Alias for calling [Builder.jobId] with `jobId.orElse(null)`. */ + fun jobId(jobId: Optional) = jobId(jobId.getOrNull()) + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [VerifyCancelParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): VerifyCancelParams = + VerifyCancelParams( + jobId, + organizationId, + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> jobId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyCancelParams && + jobId == other.jobId && + organizationId == other.organizationId && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + jobId, + organizationId, + projectId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "VerifyCancelParams{jobId=$jobId, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCancelResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCancelResponse.kt new file mode 100644 index 0000000..7c9d91f --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCancelResponse.kt @@ -0,0 +1,4698 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Response for a Verify job. */ +class VerifyCancelResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val configuration: JsonField, + private val documentInputType: JsonField, + private val fileInput: JsonField, + private val projectId: JsonField, + private val status: JsonField, + private val userId: JsonField, + private val createdAt: JsonField, + private val errorMessage: JsonField, + private val result: JsonField, + private val transactionId: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("configuration") + @ExcludeMissing + configuration: JsonField = JsonMissing.of(), + @JsonProperty("document_input_type") + @ExcludeMissing + documentInputType: JsonField = JsonMissing.of(), + @JsonProperty("file_input") @ExcludeMissing fileInput: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("error_message") + @ExcludeMissing + errorMessage: JsonField = JsonMissing.of(), + @JsonProperty("result") @ExcludeMissing result: JsonField = JsonMissing.of(), + @JsonProperty("transaction_id") + @ExcludeMissing + transactionId: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + ) : this( + id, + configuration, + documentInputType, + fileInput, + projectId, + status, + userId, + createdAt, + errorMessage, + result, + transactionId, + updatedAt, + mutableMapOf(), + ) + + /** + * Unique identifier + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * Verify configuration used for this job + * + * @throws LlamaCloudInvalidDataException 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 configuration(): Configuration = configuration.getRequired("configuration") + + /** + * Type of the document input (FILE) + * + * @throws LlamaCloudInvalidDataException 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 documentInputType(): DocumentInputType = + documentInputType.getRequired("document_input_type") + + /** + * ID of the input file + * + * @throws LlamaCloudInvalidDataException 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 fileInput(): String = fileInput.getRequired("file_input") + + /** + * Project this job belongs to + * + * @throws LlamaCloudInvalidDataException 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 projectId(): String = projectId.getRequired("project_id") + + /** + * Current job status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun status(): Status = status.getRequired("status") + + /** + * User who created this job + * + * @throws LlamaCloudInvalidDataException 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 userId(): String = userId.getRequired("user_id") + + /** + * Creation datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * Error message if job failed + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun errorMessage(): Optional = errorMessage.getOptional("error_message") + + /** + * Result of a Verify (doctored-document) analysis. + * + * Raw per-signal detail (evidence list, per-family sub-scores, raw regions, forensic heatmaps) + * is available separately via the job's details endpoint. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun result(): Optional = result.getOptional("result") + + /** + * Idempotency key + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun transactionId(): Optional = transactionId.getOptional("transaction_id") + + /** + * Update datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [configuration]. + * + * Unlike [configuration], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("configuration") + @ExcludeMissing + fun _configuration(): JsonField = configuration + + /** + * Returns the raw JSON value of [documentInputType]. + * + * Unlike [documentInputType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("document_input_type") + @ExcludeMissing + fun _documentInputType(): JsonField = documentInputType + + /** + * Returns the raw JSON value of [fileInput]. + * + * Unlike [fileInput], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_input") @ExcludeMissing fun _fileInput(): JsonField = fileInput + + /** + * 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 [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [errorMessage]. + * + * Unlike [errorMessage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error_message") + @ExcludeMissing + fun _errorMessage(): JsonField = errorMessage + + /** + * Returns the raw JSON value of [result]. + * + * Unlike [result], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("result") @ExcludeMissing fun _result(): JsonField = result + + /** + * Returns the raw JSON value of [transactionId]. + * + * Unlike [transactionId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("transaction_id") + @ExcludeMissing + fun _transactionId(): JsonField = transactionId + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") + @ExcludeMissing + fun _updatedAt(): JsonField = updatedAt + + @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 [VerifyCancelResponse]. + * + * The following fields are required: + * ```java + * .id() + * .configuration() + * .documentInputType() + * .fileInput() + * .projectId() + * .status() + * .userId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyCancelResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var configuration: JsonField? = null + private var documentInputType: JsonField? = null + private var fileInput: JsonField? = null + private var projectId: JsonField? = null + private var status: JsonField? = null + private var userId: JsonField? = null + private var createdAt: JsonField = JsonMissing.of() + private var errorMessage: JsonField = JsonMissing.of() + private var result: JsonField = JsonMissing.of() + private var transactionId: JsonField = JsonMissing.of() + private var updatedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(verifyCancelResponse: VerifyCancelResponse) = apply { + id = verifyCancelResponse.id + configuration = verifyCancelResponse.configuration + documentInputType = verifyCancelResponse.documentInputType + fileInput = verifyCancelResponse.fileInput + projectId = verifyCancelResponse.projectId + status = verifyCancelResponse.status + userId = verifyCancelResponse.userId + createdAt = verifyCancelResponse.createdAt + errorMessage = verifyCancelResponse.errorMessage + result = verifyCancelResponse.result + transactionId = verifyCancelResponse.transactionId + updatedAt = verifyCancelResponse.updatedAt + additionalProperties = verifyCancelResponse.additionalProperties.toMutableMap() + } + + /** Unique identifier */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Verify configuration used for this job */ + fun configuration(configuration: Configuration) = configuration(JsonField.of(configuration)) + + /** + * Sets [Builder.configuration] to an arbitrary JSON value. + * + * You should usually call [Builder.configuration] with a well-typed [Configuration] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun configuration(configuration: JsonField) = apply { + this.configuration = configuration + } + + /** Type of the document input (FILE) */ + fun documentInputType(documentInputType: DocumentInputType) = + documentInputType(JsonField.of(documentInputType)) + + /** + * Sets [Builder.documentInputType] to an arbitrary JSON value. + * + * You should usually call [Builder.documentInputType] with a well-typed [DocumentInputType] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun documentInputType(documentInputType: JsonField) = apply { + this.documentInputType = documentInputType + } + + /** ID of the input file */ + fun fileInput(fileInput: String) = fileInput(JsonField.of(fileInput)) + + /** + * Sets [Builder.fileInput] to an arbitrary JSON value. + * + * You should usually call [Builder.fileInput] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun fileInput(fileInput: JsonField) = apply { this.fileInput = fileInput } + + /** Project this job belongs to */ + 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 } + + /** Current job status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED */ + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** User who created this job */ + fun userId(userId: String) = userId(JsonField.of(userId)) + + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } + + /** Creation datetime */ + fun createdAt(createdAt: OffsetDateTime?) = createdAt(JsonField.ofNullable(createdAt)) + + /** Alias for calling [Builder.createdAt] with `createdAt.orElse(null)`. */ + fun createdAt(createdAt: Optional) = createdAt(createdAt.getOrNull()) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Error message if job failed */ + fun errorMessage(errorMessage: String?) = errorMessage(JsonField.ofNullable(errorMessage)) + + /** Alias for calling [Builder.errorMessage] with `errorMessage.orElse(null)`. */ + fun errorMessage(errorMessage: Optional) = errorMessage(errorMessage.getOrNull()) + + /** + * Sets [Builder.errorMessage] to an arbitrary JSON value. + * + * You should usually call [Builder.errorMessage] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun errorMessage(errorMessage: JsonField) = apply { + this.errorMessage = errorMessage + } + + /** + * Result of a Verify (doctored-document) analysis. + * + * Raw per-signal detail (evidence list, per-family sub-scores, raw regions, forensic + * heatmaps) is available separately via the job's details endpoint. + */ + fun result(result: Result?) = result(JsonField.ofNullable(result)) + + /** Alias for calling [Builder.result] with `result.orElse(null)`. */ + fun result(result: Optional) = result(result.getOrNull()) + + /** + * Sets [Builder.result] to an arbitrary JSON value. + * + * You should usually call [Builder.result] with a well-typed [Result] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun result(result: JsonField) = apply { this.result = result } + + /** Idempotency key */ + fun transactionId(transactionId: String?) = + transactionId(JsonField.ofNullable(transactionId)) + + /** Alias for calling [Builder.transactionId] with `transactionId.orElse(null)`. */ + fun transactionId(transactionId: Optional) = + transactionId(transactionId.getOrNull()) + + /** + * Sets [Builder.transactionId] to an arbitrary JSON value. + * + * You should usually call [Builder.transactionId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun transactionId(transactionId: JsonField) = apply { + this.transactionId = transactionId + } + + /** Update datetime */ + fun updatedAt(updatedAt: OffsetDateTime?) = updatedAt(JsonField.ofNullable(updatedAt)) + + /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ + fun updatedAt(updatedAt: Optional) = updatedAt(updatedAt.getOrNull()) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + 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 [VerifyCancelResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .configuration() + * .documentInputType() + * .fileInput() + * .projectId() + * .status() + * .userId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VerifyCancelResponse = + VerifyCancelResponse( + checkRequired("id", id), + checkRequired("configuration", configuration), + checkRequired("documentInputType", documentInputType), + checkRequired("fileInput", fileInput), + checkRequired("projectId", projectId), + checkRequired("status", status), + checkRequired("userId", userId), + createdAt, + errorMessage, + result, + transactionId, + updatedAt, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): VerifyCancelResponse = apply { + if (validated) { + return@apply + } + + id() + configuration().validate() + documentInputType().validate() + fileInput() + projectId() + status().validate() + userId() + createdAt() + errorMessage() + result().ifPresent { it.validate() } + transactionId() + updatedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (configuration.asKnown().getOrNull()?.validity() ?: 0) + + (documentInputType.asKnown().getOrNull()?.validity() ?: 0) + + (if (fileInput.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (errorMessage.asKnown().isPresent) 1 else 0) + + (result.asKnown().getOrNull()?.validity() ?: 0) + + (if (transactionId.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + /** Verify configuration used for this job */ + class Configuration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val targetPages: JsonField, + private val tier: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("target_pages") + @ExcludeMissing + targetPages: JsonField = JsonMissing.of(), + @JsonProperty("tier") @ExcludeMissing tier: JsonField = JsonMissing.of(), + ) : this(targetPages, tier, mutableMapOf()) + + /** + * Comma-separated page numbers or ranges to analyze (1-based). Omit to analyze all pages. + * Ignored for non-PDF inputs. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun targetPages(): Optional = targetPages.getOptional("target_pages") + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, content + * integrity, container structure, pixel statistics); 'agentic' (default) runs the full + * pipeline including the learned detectors and the semantic review pass. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tier(): Optional = tier.getOptional("tier") + + /** + * Returns the raw JSON value of [targetPages]. + * + * Unlike [targetPages], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("target_pages") + @ExcludeMissing + fun _targetPages(): JsonField = targetPages + + /** + * Returns the raw JSON value of [tier]. + * + * Unlike [tier], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tier") @ExcludeMissing fun _tier(): JsonField = tier + + @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 [Configuration]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Configuration]. */ + class Builder internal constructor() { + + private var targetPages: JsonField = JsonMissing.of() + private var tier: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(configuration: Configuration) = apply { + targetPages = configuration.targetPages + tier = configuration.tier + additionalProperties = configuration.additionalProperties.toMutableMap() + } + + /** + * Comma-separated page numbers or ranges to analyze (1-based). Omit to analyze all + * pages. Ignored for non-PDF inputs. + */ + fun targetPages(targetPages: String?) = targetPages(JsonField.ofNullable(targetPages)) + + /** Alias for calling [Builder.targetPages] with `targetPages.orElse(null)`. */ + fun targetPages(targetPages: Optional) = targetPages(targetPages.getOrNull()) + + /** + * Sets [Builder.targetPages] to an arbitrary JSON value. + * + * You should usually call [Builder.targetPages] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun targetPages(targetPages: JsonField) = apply { + this.targetPages = targetPages + } + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, + * content integrity, container structure, pixel statistics); 'agentic' (default) runs + * the full pipeline including the learned detectors and the semantic review pass. + */ + fun tier(tier: Tier) = tier(JsonField.of(tier)) + + /** + * Sets [Builder.tier] to an arbitrary JSON value. + * + * You should usually call [Builder.tier] with a well-typed [Tier] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tier(tier: JsonField) = apply { this.tier = tier } + + 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 [Configuration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Configuration = + Configuration(targetPages, tier, 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Configuration = apply { + if (validated) { + return@apply + } + + targetPages() + tier().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (targetPages.asKnown().isPresent) 1 else 0) + + (tier.asKnown().getOrNull()?.validity() ?: 0) + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, content + * integrity, container structure, pixel statistics); 'agentic' (default) runs the full + * pipeline including the learned detectors and the semantic review pass. + */ + class Tier @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 AGENTIC = of("agentic") + + @JvmField val FAST = of("fast") + + @JvmStatic fun of(value: String) = Tier(JsonField.of(value)) + } + + /** An enum containing [Tier]'s known values. */ + enum class Known { + AGENTIC, + FAST, + } + + /** + * An enum containing [Tier]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Tier] 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 { + AGENTIC, + FAST, + /** An enum member indicating that [Tier] 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) { + AGENTIC -> Value.AGENTIC + FAST -> Value.FAST + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + AGENTIC -> Known.AGENTIC + FAST -> Known.FAST + else -> throw LlamaCloudInvalidDataException("Unknown Tier: $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 LlamaCloudInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Tier && 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 Configuration && + targetPages == other.targetPages && + tier == other.tier && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(targetPages, tier, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Configuration{targetPages=$targetPages, tier=$tier, additionalProperties=$additionalProperties}" + } + + /** Type of the document input (FILE) */ + class DocumentInputType @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 FILE_ID = of("file_id") + + @JvmField val PARSE_JOB_ID = of("parse_job_id") + + @JvmField val URL = of("url") + + @JvmStatic fun of(value: String) = DocumentInputType(JsonField.of(value)) + } + + /** An enum containing [DocumentInputType]'s known values. */ + enum class Known { + FILE_ID, + PARSE_JOB_ID, + URL, + } + + /** + * An enum containing [DocumentInputType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [DocumentInputType] 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 { + FILE_ID, + PARSE_JOB_ID, + URL, + /** + * An enum member indicating that [DocumentInputType] 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) { + FILE_ID -> Value.FILE_ID + PARSE_JOB_ID -> Value.PARSE_JOB_ID + URL -> Value.URL + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + FILE_ID -> Known.FILE_ID + PARSE_JOB_ID -> Known.PARSE_JOB_ID + URL -> Known.URL + else -> throw LlamaCloudInvalidDataException("Unknown DocumentInputType: $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 LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): DocumentInputType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 DocumentInputType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Current job status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED */ + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val CANCELLED = of("CANCELLED") + + @JvmField val COMPLETED = of("COMPLETED") + + @JvmField val FAILED = of("FAILED") + + @JvmField val PENDING = of("PENDING") + + @JvmField val RUNNING = of("RUNNING") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + CANCELLED, + COMPLETED, + FAILED, + PENDING, + RUNNING, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + CANCELLED, + COMPLETED, + FAILED, + PENDING, + RUNNING, + /** An enum member indicating that [Status] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + CANCELLED -> Value.CANCELLED + COMPLETED -> Value.COMPLETED + FAILED -> Value.FAILED + PENDING -> Value.PENDING + RUNNING -> Value.RUNNING + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + CANCELLED -> Known.CANCELLED + COMPLETED -> Known.COMPLETED + FAILED -> Known.FAILED + PENDING -> Known.PENDING + RUNNING -> Known.RUNNING + else -> throw LlamaCloudInvalidDataException("Unknown Status: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Status = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Status && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * Result of a Verify (doctored-document) analysis. + * + * Raw per-signal detail (evidence list, per-family sub-scores, raw regions, forensic heatmaps) + * is available separately via the job's details endpoint. + */ + class Result + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val detectorVersion: JsonField, + private val overallScore: JsonField, + private val verdict: JsonField, + private val compositeScores: JsonField, + private val confidence: JsonField, + private val error: JsonField, + private val pageCount: JsonField, + private val pageDimensions: JsonField>, + private val reasoning: JsonField, + private val suspectRegions: JsonField>, + private val syntheticScore: JsonField, + private val tamperingScore: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("detector_version") + @ExcludeMissing + detectorVersion: JsonField = JsonMissing.of(), + @JsonProperty("overall_score") + @ExcludeMissing + overallScore: JsonField = JsonMissing.of(), + @JsonProperty("verdict") @ExcludeMissing verdict: JsonField = JsonMissing.of(), + @JsonProperty("composite_scores") + @ExcludeMissing + compositeScores: JsonField = JsonMissing.of(), + @JsonProperty("confidence") + @ExcludeMissing + confidence: JsonField = JsonMissing.of(), + @JsonProperty("error") @ExcludeMissing error: JsonField = JsonMissing.of(), + @JsonProperty("page_count") + @ExcludeMissing + pageCount: JsonField = JsonMissing.of(), + @JsonProperty("page_dimensions") + @ExcludeMissing + pageDimensions: JsonField> = JsonMissing.of(), + @JsonProperty("reasoning") + @ExcludeMissing + reasoning: JsonField = JsonMissing.of(), + @JsonProperty("suspect_regions") + @ExcludeMissing + suspectRegions: JsonField> = JsonMissing.of(), + @JsonProperty("synthetic_score") + @ExcludeMissing + syntheticScore: JsonField = JsonMissing.of(), + @JsonProperty("tampering_score") + @ExcludeMissing + tamperingScore: JsonField = JsonMissing.of(), + ) : this( + detectorVersion, + overallScore, + verdict, + compositeScores, + confidence, + error, + pageCount, + pageDimensions, + reasoning, + suspectRegions, + syntheticScore, + tamperingScore, + mutableMapOf(), + ) + + /** + * Version of the detector that produced the result + * + * @throws LlamaCloudInvalidDataException 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 detectorVersion(): String = detectorVersion.getRequired("detector_version") + + /** + * Overall doctoring likelihood (0 to 1) + * + * @throws LlamaCloudInvalidDataException 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 overallScore(): Double = overallScore.getRequired("overall_score") + + /** + * Overall verdict for the document + * + * @throws LlamaCloudInvalidDataException 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 verdict(): Verdict = verdict.getRequired("verdict") + + /** + * Composite scores, each answering one question about the document + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun compositeScores(): Optional = + compositeScores.getOptional("composite_scores") + + /** + * Confidence in the verdict (0 to 1): how firmly the detected signals support the verdict + * bucket, independent of the doctoring likelihood itself + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun confidence(): Optional = confidence.getOptional("confidence") + + /** + * Error detail when the analysis could not complete + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun error(): Optional = error.getOptional("error") + + /** + * Number of analysed pages (1 for images/docx) + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun pageCount(): Optional = pageCount.getOptional("page_count") + + /** + * Rendered pixel size per page, so region bboxes can be scaled onto the page + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun pageDimensions(): Optional> = + pageDimensions.getOptional("page_dimensions") + + /** + * Explanation of the verdict + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun reasoning(): Optional = reasoning.getOptional("reasoning") + + /** + * Regions that led to the suspected fraud, ranked most-suspect first, each with an + * explanation of what makes it suspect + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun suspectRegions(): Optional> = + suspectRegions.getOptional("suspect_regions") + + /** + * Likelihood (0 to 1) that the document is wholly generated or fabricated rather than a + * capture of a real document. Null for jobs completed before this score was introduced + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun syntheticScore(): Optional = syntheticScore.getOptional("synthetic_score") + + /** + * Likelihood (0 to 1) that a real captured document was locally edited — a genuine capture + * with regions altered after the fact. Null for jobs completed before this score was + * introduced + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tamperingScore(): Optional = tamperingScore.getOptional("tampering_score") + + /** + * Returns the raw JSON value of [detectorVersion]. + * + * Unlike [detectorVersion], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("detector_version") + @ExcludeMissing + fun _detectorVersion(): JsonField = detectorVersion + + /** + * Returns the raw JSON value of [overallScore]. + * + * Unlike [overallScore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("overall_score") + @ExcludeMissing + fun _overallScore(): JsonField = overallScore + + /** + * Returns the raw JSON value of [verdict]. + * + * Unlike [verdict], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("verdict") @ExcludeMissing fun _verdict(): JsonField = verdict + + /** + * Returns the raw JSON value of [compositeScores]. + * + * Unlike [compositeScores], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("composite_scores") + @ExcludeMissing + fun _compositeScores(): JsonField = compositeScores + + /** + * Returns the raw JSON value of [confidence]. + * + * Unlike [confidence], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("confidence") + @ExcludeMissing + fun _confidence(): JsonField = confidence + + /** + * Returns the raw JSON value of [error]. + * + * Unlike [error], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error") @ExcludeMissing fun _error(): JsonField = error + + /** + * Returns the raw JSON value of [pageCount]. + * + * Unlike [pageCount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page_count") @ExcludeMissing fun _pageCount(): JsonField = pageCount + + /** + * Returns the raw JSON value of [pageDimensions]. + * + * Unlike [pageDimensions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("page_dimensions") + @ExcludeMissing + fun _pageDimensions(): JsonField> = pageDimensions + + /** + * Returns the raw JSON value of [reasoning]. + * + * Unlike [reasoning], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("reasoning") @ExcludeMissing fun _reasoning(): JsonField = reasoning + + /** + * Returns the raw JSON value of [suspectRegions]. + * + * Unlike [suspectRegions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("suspect_regions") + @ExcludeMissing + fun _suspectRegions(): JsonField> = suspectRegions + + /** + * Returns the raw JSON value of [syntheticScore]. + * + * Unlike [syntheticScore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("synthetic_score") + @ExcludeMissing + fun _syntheticScore(): JsonField = syntheticScore + + /** + * Returns the raw JSON value of [tamperingScore]. + * + * Unlike [tamperingScore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tampering_score") + @ExcludeMissing + fun _tamperingScore(): JsonField = tamperingScore + + @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 [Result]. + * + * The following fields are required: + * ```java + * .detectorVersion() + * .overallScore() + * .verdict() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Result]. */ + class Builder internal constructor() { + + private var detectorVersion: JsonField? = null + private var overallScore: JsonField? = null + private var verdict: JsonField? = null + private var compositeScores: JsonField = JsonMissing.of() + private var confidence: JsonField = JsonMissing.of() + private var error: JsonField = JsonMissing.of() + private var pageCount: JsonField = JsonMissing.of() + private var pageDimensions: JsonField>? = null + private var reasoning: JsonField = JsonMissing.of() + private var suspectRegions: JsonField>? = null + private var syntheticScore: JsonField = JsonMissing.of() + private var tamperingScore: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(result: Result) = apply { + detectorVersion = result.detectorVersion + overallScore = result.overallScore + verdict = result.verdict + compositeScores = result.compositeScores + confidence = result.confidence + error = result.error + pageCount = result.pageCount + pageDimensions = result.pageDimensions.map { it.toMutableList() } + reasoning = result.reasoning + suspectRegions = result.suspectRegions.map { it.toMutableList() } + syntheticScore = result.syntheticScore + tamperingScore = result.tamperingScore + additionalProperties = result.additionalProperties.toMutableMap() + } + + /** Version of the detector that produced the result */ + fun detectorVersion(detectorVersion: String) = + detectorVersion(JsonField.of(detectorVersion)) + + /** + * Sets [Builder.detectorVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.detectorVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun detectorVersion(detectorVersion: JsonField) = apply { + this.detectorVersion = detectorVersion + } + + /** Overall doctoring likelihood (0 to 1) */ + fun overallScore(overallScore: Double) = overallScore(JsonField.of(overallScore)) + + /** + * Sets [Builder.overallScore] to an arbitrary JSON value. + * + * You should usually call [Builder.overallScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun overallScore(overallScore: JsonField) = apply { + this.overallScore = overallScore + } + + /** Overall verdict for the document */ + fun verdict(verdict: Verdict) = verdict(JsonField.of(verdict)) + + /** + * Sets [Builder.verdict] to an arbitrary JSON value. + * + * You should usually call [Builder.verdict] with a well-typed [Verdict] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun verdict(verdict: JsonField) = apply { this.verdict = verdict } + + /** Composite scores, each answering one question about the document */ + fun compositeScores(compositeScores: CompositeScores) = + compositeScores(JsonField.of(compositeScores)) + + /** + * Sets [Builder.compositeScores] to an arbitrary JSON value. + * + * You should usually call [Builder.compositeScores] with a well-typed [CompositeScores] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun compositeScores(compositeScores: JsonField) = apply { + this.compositeScores = compositeScores + } + + /** + * Confidence in the verdict (0 to 1): how firmly the detected signals support the + * verdict bucket, independent of the doctoring likelihood itself + */ + fun confidence(confidence: Double) = confidence(JsonField.of(confidence)) + + /** + * Sets [Builder.confidence] to an arbitrary JSON value. + * + * You should usually call [Builder.confidence] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun confidence(confidence: JsonField) = apply { this.confidence = confidence } + + /** Error detail when the analysis could not complete */ + fun error(error: String?) = error(JsonField.ofNullable(error)) + + /** Alias for calling [Builder.error] with `error.orElse(null)`. */ + fun error(error: Optional) = error(error.getOrNull()) + + /** + * Sets [Builder.error] to an arbitrary JSON value. + * + * You should usually call [Builder.error] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun error(error: JsonField) = apply { this.error = error } + + /** Number of analysed pages (1 for images/docx) */ + fun pageCount(pageCount: Long) = pageCount(JsonField.of(pageCount)) + + /** + * Sets [Builder.pageCount] to an arbitrary JSON value. + * + * You should usually call [Builder.pageCount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pageCount(pageCount: JsonField) = apply { this.pageCount = pageCount } + + /** Rendered pixel size per page, so region bboxes can be scaled onto the page */ + fun pageDimensions(pageDimensions: List) = + pageDimensions(JsonField.of(pageDimensions)) + + /** + * Sets [Builder.pageDimensions] to an arbitrary JSON value. + * + * You should usually call [Builder.pageDimensions] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun pageDimensions(pageDimensions: JsonField>) = apply { + this.pageDimensions = pageDimensions.map { it.toMutableList() } + } + + /** + * Adds a single [PageDimension] to [pageDimensions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPageDimension(pageDimension: PageDimension) = apply { + pageDimensions = + (pageDimensions ?: JsonField.of(mutableListOf())).also { + checkKnown("pageDimensions", it).add(pageDimension) + } + } + + /** Explanation of the verdict */ + fun reasoning(reasoning: String) = reasoning(JsonField.of(reasoning)) + + /** + * Sets [Builder.reasoning] to an arbitrary JSON value. + * + * You should usually call [Builder.reasoning] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun reasoning(reasoning: JsonField) = apply { this.reasoning = reasoning } + + /** + * Regions that led to the suspected fraud, ranked most-suspect first, each with an + * explanation of what makes it suspect + */ + fun suspectRegions(suspectRegions: List) = + suspectRegions(JsonField.of(suspectRegions)) + + /** + * Sets [Builder.suspectRegions] to an arbitrary JSON value. + * + * You should usually call [Builder.suspectRegions] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun suspectRegions(suspectRegions: JsonField>) = apply { + this.suspectRegions = suspectRegions.map { it.toMutableList() } + } + + /** + * Adds a single [SuspectRegion] to [suspectRegions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSuspectRegion(suspectRegion: SuspectRegion) = apply { + suspectRegions = + (suspectRegions ?: JsonField.of(mutableListOf())).also { + checkKnown("suspectRegions", it).add(suspectRegion) + } + } + + /** + * Likelihood (0 to 1) that the document is wholly generated or fabricated rather than a + * capture of a real document. Null for jobs completed before this score was introduced + */ + fun syntheticScore(syntheticScore: Double?) = + syntheticScore(JsonField.ofNullable(syntheticScore)) + + /** + * Alias for [Builder.syntheticScore]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun syntheticScore(syntheticScore: Double) = syntheticScore(syntheticScore as Double?) + + /** Alias for calling [Builder.syntheticScore] with `syntheticScore.orElse(null)`. */ + fun syntheticScore(syntheticScore: Optional) = + syntheticScore(syntheticScore.getOrNull()) + + /** + * Sets [Builder.syntheticScore] to an arbitrary JSON value. + * + * You should usually call [Builder.syntheticScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun syntheticScore(syntheticScore: JsonField) = apply { + this.syntheticScore = syntheticScore + } + + /** + * Likelihood (0 to 1) that a real captured document was locally edited — a genuine + * capture with regions altered after the fact. Null for jobs completed before this + * score was introduced + */ + fun tamperingScore(tamperingScore: Double?) = + tamperingScore(JsonField.ofNullable(tamperingScore)) + + /** + * Alias for [Builder.tamperingScore]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun tamperingScore(tamperingScore: Double) = tamperingScore(tamperingScore as Double?) + + /** Alias for calling [Builder.tamperingScore] with `tamperingScore.orElse(null)`. */ + fun tamperingScore(tamperingScore: Optional) = + tamperingScore(tamperingScore.getOrNull()) + + /** + * Sets [Builder.tamperingScore] to an arbitrary JSON value. + * + * You should usually call [Builder.tamperingScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tamperingScore(tamperingScore: JsonField) = apply { + this.tamperingScore = tamperingScore + } + + 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 [Result]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .detectorVersion() + * .overallScore() + * .verdict() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Result = + Result( + checkRequired("detectorVersion", detectorVersion), + checkRequired("overallScore", overallScore), + checkRequired("verdict", verdict), + compositeScores, + confidence, + error, + pageCount, + (pageDimensions ?: JsonMissing.of()).map { it.toImmutable() }, + reasoning, + (suspectRegions ?: JsonMissing.of()).map { it.toImmutable() }, + syntheticScore, + tamperingScore, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Result = apply { + if (validated) { + return@apply + } + + detectorVersion() + overallScore() + verdict().validate() + compositeScores().ifPresent { it.validate() } + confidence() + error() + pageCount() + pageDimensions().ifPresent { it.forEach { it.validate() } } + reasoning() + suspectRegions().ifPresent { it.forEach { it.validate() } } + syntheticScore() + tamperingScore() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (detectorVersion.asKnown().isPresent) 1 else 0) + + (if (overallScore.asKnown().isPresent) 1 else 0) + + (verdict.asKnown().getOrNull()?.validity() ?: 0) + + (compositeScores.asKnown().getOrNull()?.validity() ?: 0) + + (if (confidence.asKnown().isPresent) 1 else 0) + + (if (error.asKnown().isPresent) 1 else 0) + + (if (pageCount.asKnown().isPresent) 1 else 0) + + (pageDimensions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (reasoning.asKnown().isPresent) 1 else 0) + + (suspectRegions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (syntheticScore.asKnown().isPresent) 1 else 0) + + (if (tamperingScore.asKnown().isPresent) 1 else 0) + + /** Overall verdict for the document */ + class Verdict @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 AUTHENTIC = of("AUTHENTIC") + + @JvmField val DOCTORED = of("DOCTORED") + + @JvmField val LIKELY_DOCTORED = of("LIKELY_DOCTORED") + + @JvmField val NO_STRONG_SIGNAL = of("NO_STRONG_SIGNAL") + + @JvmField val SUSPICIOUS = of("SUSPICIOUS") + + @JvmStatic fun of(value: String) = Verdict(JsonField.of(value)) + } + + /** An enum containing [Verdict]'s known values. */ + enum class Known { + AUTHENTIC, + DOCTORED, + LIKELY_DOCTORED, + NO_STRONG_SIGNAL, + SUSPICIOUS, + } + + /** + * An enum containing [Verdict]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Verdict] 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 { + AUTHENTIC, + DOCTORED, + LIKELY_DOCTORED, + NO_STRONG_SIGNAL, + SUSPICIOUS, + /** + * An enum member indicating that [Verdict] 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) { + AUTHENTIC -> Value.AUTHENTIC + DOCTORED -> Value.DOCTORED + LIKELY_DOCTORED -> Value.LIKELY_DOCTORED + NO_STRONG_SIGNAL -> Value.NO_STRONG_SIGNAL + SUSPICIOUS -> Value.SUSPICIOUS + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + AUTHENTIC -> Known.AUTHENTIC + DOCTORED -> Known.DOCTORED + LIKELY_DOCTORED -> Known.LIKELY_DOCTORED + NO_STRONG_SIGNAL -> Known.NO_STRONG_SIGNAL + SUSPICIOUS -> Known.SUSPICIOUS + else -> throw LlamaCloudInvalidDataException("Unknown Verdict: $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 LlamaCloudInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Verdict = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Verdict && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Composite scores, each answering one question about the document */ + class CompositeScores + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val aiGenerated: JsonField, + private val documentCoherence: JsonField, + private val documentMetadata: JsonField, + private val knownFraud: JsonField, + private val manuallyEdited: JsonField, + private val recapture: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("ai_generated") + @ExcludeMissing + aiGenerated: JsonField = JsonMissing.of(), + @JsonProperty("document_coherence") + @ExcludeMissing + documentCoherence: JsonField = JsonMissing.of(), + @JsonProperty("document_metadata") + @ExcludeMissing + documentMetadata: JsonField = JsonMissing.of(), + @JsonProperty("known_fraud") + @ExcludeMissing + knownFraud: JsonField = JsonMissing.of(), + @JsonProperty("manually_edited") + @ExcludeMissing + manuallyEdited: JsonField = JsonMissing.of(), + @JsonProperty("recapture") + @ExcludeMissing + recapture: JsonField = JsonMissing.of(), + ) : this( + aiGenerated, + documentCoherence, + documentMetadata, + knownFraud, + manuallyEdited, + recapture, + mutableMapOf(), + ) + + /** + * Was this content synthesized by a generative model? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun aiGenerated(): Optional = aiGenerated.getOptional("ai_generated") + + /** + * Does the document's content agree with itself (checksums, arithmetic, + * machine-readable zones)? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun documentCoherence(): Optional = + documentCoherence.getOptional("document_coherence") + + /** + * Does the file's provenance / toolchain history look suspicious? Advisory: + * individually weak workflow-hygiene signals + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun documentMetadata(): Optional = + documentMetadata.getOptional("document_metadata") + + /** + * Has this asset (or its template) been seen in fraud before? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun knownFraud(): Optional = knownFraud.getOptional("known_fraud") + + /** + * Was this document altered after creation (splice, retype, redact, inpaint)? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun manuallyEdited(): Optional = + manuallyEdited.getOptional("manually_edited") + + /** + * Was the document captured through a channel that destroys forensic evidence (photo of + * a screen, print-then-rescan)? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun recapture(): Optional = recapture.getOptional("recapture") + + /** + * Returns the raw JSON value of [aiGenerated]. + * + * Unlike [aiGenerated], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("ai_generated") + @ExcludeMissing + fun _aiGenerated(): JsonField = aiGenerated + + /** + * Returns the raw JSON value of [documentCoherence]. + * + * Unlike [documentCoherence], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("document_coherence") + @ExcludeMissing + fun _documentCoherence(): JsonField = documentCoherence + + /** + * Returns the raw JSON value of [documentMetadata]. + * + * Unlike [documentMetadata], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("document_metadata") + @ExcludeMissing + fun _documentMetadata(): JsonField = documentMetadata + + /** + * Returns the raw JSON value of [knownFraud]. + * + * Unlike [knownFraud], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("known_fraud") + @ExcludeMissing + fun _knownFraud(): JsonField = knownFraud + + /** + * Returns the raw JSON value of [manuallyEdited]. + * + * Unlike [manuallyEdited], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("manually_edited") + @ExcludeMissing + fun _manuallyEdited(): JsonField = manuallyEdited + + /** + * Returns the raw JSON value of [recapture]. + * + * Unlike [recapture], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("recapture") + @ExcludeMissing + fun _recapture(): JsonField = recapture + + @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 [CompositeScores]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CompositeScores]. */ + class Builder internal constructor() { + + private var aiGenerated: JsonField = JsonMissing.of() + private var documentCoherence: JsonField = JsonMissing.of() + private var documentMetadata: JsonField = JsonMissing.of() + private var knownFraud: JsonField = JsonMissing.of() + private var manuallyEdited: JsonField = JsonMissing.of() + private var recapture: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(compositeScores: CompositeScores) = apply { + aiGenerated = compositeScores.aiGenerated + documentCoherence = compositeScores.documentCoherence + documentMetadata = compositeScores.documentMetadata + knownFraud = compositeScores.knownFraud + manuallyEdited = compositeScores.manuallyEdited + recapture = compositeScores.recapture + additionalProperties = compositeScores.additionalProperties.toMutableMap() + } + + /** Was this content synthesized by a generative model? */ + fun aiGenerated(aiGenerated: AiGenerated) = aiGenerated(JsonField.of(aiGenerated)) + + /** + * Sets [Builder.aiGenerated] to an arbitrary JSON value. + * + * You should usually call [Builder.aiGenerated] with a well-typed [AiGenerated] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun aiGenerated(aiGenerated: JsonField) = apply { + this.aiGenerated = aiGenerated + } + + /** + * Does the document's content agree with itself (checksums, arithmetic, + * machine-readable zones)? + */ + fun documentCoherence(documentCoherence: DocumentCoherence) = + documentCoherence(JsonField.of(documentCoherence)) + + /** + * Sets [Builder.documentCoherence] to an arbitrary JSON value. + * + * You should usually call [Builder.documentCoherence] with a well-typed + * [DocumentCoherence] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun documentCoherence(documentCoherence: JsonField) = apply { + this.documentCoherence = documentCoherence + } + + /** + * Does the file's provenance / toolchain history look suspicious? Advisory: + * individually weak workflow-hygiene signals + */ + fun documentMetadata(documentMetadata: DocumentMetadata) = + documentMetadata(JsonField.of(documentMetadata)) + + /** + * Sets [Builder.documentMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.documentMetadata] with a well-typed + * [DocumentMetadata] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun documentMetadata(documentMetadata: JsonField) = apply { + this.documentMetadata = documentMetadata + } + + /** Has this asset (or its template) been seen in fraud before? */ + fun knownFraud(knownFraud: KnownFraud) = knownFraud(JsonField.of(knownFraud)) + + /** + * Sets [Builder.knownFraud] to an arbitrary JSON value. + * + * You should usually call [Builder.knownFraud] with a well-typed [KnownFraud] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun knownFraud(knownFraud: JsonField) = apply { + this.knownFraud = knownFraud + } + + /** Was this document altered after creation (splice, retype, redact, inpaint)? */ + fun manuallyEdited(manuallyEdited: ManuallyEdited) = + manuallyEdited(JsonField.of(manuallyEdited)) + + /** + * Sets [Builder.manuallyEdited] to an arbitrary JSON value. + * + * You should usually call [Builder.manuallyEdited] with a well-typed + * [ManuallyEdited] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun manuallyEdited(manuallyEdited: JsonField) = apply { + this.manuallyEdited = manuallyEdited + } + + /** + * Was the document captured through a channel that destroys forensic evidence + * (photo of a screen, print-then-rescan)? + */ + fun recapture(recapture: Recapture) = recapture(JsonField.of(recapture)) + + /** + * Sets [Builder.recapture] to an arbitrary JSON value. + * + * You should usually call [Builder.recapture] with a well-typed [Recapture] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun recapture(recapture: JsonField) = apply { + this.recapture = recapture + } + + 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 [CompositeScores]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CompositeScores = + CompositeScores( + aiGenerated, + documentCoherence, + documentMetadata, + knownFraud, + manuallyEdited, + recapture, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): CompositeScores = apply { + if (validated) { + return@apply + } + + aiGenerated().ifPresent { it.validate() } + documentCoherence().ifPresent { it.validate() } + documentMetadata().ifPresent { it.validate() } + knownFraud().ifPresent { it.validate() } + manuallyEdited().ifPresent { it.validate() } + recapture().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (aiGenerated.asKnown().getOrNull()?.validity() ?: 0) + + (documentCoherence.asKnown().getOrNull()?.validity() ?: 0) + + (documentMetadata.asKnown().getOrNull()?.validity() ?: 0) + + (knownFraud.asKnown().getOrNull()?.validity() ?: 0) + + (manuallyEdited.asKnown().getOrNull()?.validity() ?: 0) + + (recapture.asKnown().getOrNull()?.validity() ?: 0) + + /** Was this content synthesized by a generative model? */ + class AiGenerated + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [AiGenerated]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AiGenerated]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(aiGenerated: AiGenerated) = apply { + applicable = aiGenerated.applicable + score = aiGenerated.score + additionalProperties = aiGenerated.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [AiGenerated]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): AiGenerated = + AiGenerated(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AiGenerated = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AiGenerated && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AiGenerated{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Does the document's content agree with itself (checksums, arithmetic, + * machine-readable zones)? + */ + class DocumentCoherence + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 + * [DocumentCoherence]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DocumentCoherence]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(documentCoherence: DocumentCoherence) = apply { + applicable = documentCoherence.applicable + score = documentCoherence.score + additionalProperties = documentCoherence.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [DocumentCoherence]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DocumentCoherence = + DocumentCoherence(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): DocumentCoherence = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DocumentCoherence && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DocumentCoherence{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Does the file's provenance / toolchain history look suspicious? Advisory: + * individually weak workflow-hygiene signals + */ + class DocumentMetadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [DocumentMetadata]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DocumentMetadata]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(documentMetadata: DocumentMetadata) = apply { + applicable = documentMetadata.applicable + score = documentMetadata.score + additionalProperties = documentMetadata.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [DocumentMetadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DocumentMetadata = + DocumentMetadata(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): DocumentMetadata = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DocumentMetadata && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DocumentMetadata{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** Has this asset (or its template) been seen in fraud before? */ + class KnownFraud + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [KnownFraud]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [KnownFraud]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(knownFraud: KnownFraud) = apply { + applicable = knownFraud.applicable + score = knownFraud.score + additionalProperties = knownFraud.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [KnownFraud]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): KnownFraud = + KnownFraud(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): KnownFraud = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is KnownFraud && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "KnownFraud{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** Was this document altered after creation (splice, retype, redact, inpaint)? */ + class ManuallyEdited + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [ManuallyEdited]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ManuallyEdited]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(manuallyEdited: ManuallyEdited) = apply { + applicable = manuallyEdited.applicable + score = manuallyEdited.score + additionalProperties = manuallyEdited.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [ManuallyEdited]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ManuallyEdited = + ManuallyEdited(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): ManuallyEdited = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ManuallyEdited && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ManuallyEdited{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Was the document captured through a channel that destroys forensic evidence (photo of + * a screen, print-then-rescan)? + */ + class Recapture + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [Recapture]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Recapture]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(recapture: Recapture) = apply { + applicable = recapture.applicable + score = recapture.score + additionalProperties = recapture.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [Recapture]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Recapture = + Recapture(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Recapture = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Recapture && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Recapture{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CompositeScores && + aiGenerated == other.aiGenerated && + documentCoherence == other.documentCoherence && + documentMetadata == other.documentMetadata && + knownFraud == other.knownFraud && + manuallyEdited == other.manuallyEdited && + recapture == other.recapture && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + aiGenerated, + documentCoherence, + documentMetadata, + knownFraud, + manuallyEdited, + recapture, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositeScores{aiGenerated=$aiGenerated, documentCoherence=$documentCoherence, documentMetadata=$documentMetadata, knownFraud=$knownFraud, manuallyEdited=$manuallyEdited, recapture=$recapture, additionalProperties=$additionalProperties}" + } + + /** + * Rendered pixel size of a page — the coordinate space region bboxes use, so the UI can + * scale the suspect-region overlay onto the displayed page. + */ + class PageDimension + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val height: JsonField, + private val page: JsonField, + private val width: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("height") @ExcludeMissing height: JsonField = JsonMissing.of(), + @JsonProperty("page") @ExcludeMissing page: JsonField = JsonMissing.of(), + @JsonProperty("width") @ExcludeMissing width: JsonField = JsonMissing.of(), + ) : this(height, page, width, mutableMapOf()) + + /** + * Rendered page height in pixels + * + * @throws LlamaCloudInvalidDataException 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 height(): Long = height.getRequired("height") + + /** + * 0-based page index (0 for standalone images) + * + * @throws LlamaCloudInvalidDataException 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 page(): Long = page.getRequired("page") + + /** + * Rendered page width in pixels + * + * @throws LlamaCloudInvalidDataException 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 width(): Long = width.getRequired("width") + + /** + * Returns the raw JSON value of [height]. + * + * Unlike [height], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("height") @ExcludeMissing fun _height(): JsonField = height + + /** + * Returns the raw JSON value of [page]. + * + * Unlike [page], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page") @ExcludeMissing fun _page(): JsonField = page + + /** + * Returns the raw JSON value of [width]. + * + * Unlike [width], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("width") @ExcludeMissing fun _width(): JsonField = width + + @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 [PageDimension]. + * + * The following fields are required: + * ```java + * .height() + * .page() + * .width() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PageDimension]. */ + class Builder internal constructor() { + + private var height: JsonField? = null + private var page: JsonField? = null + private var width: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(pageDimension: PageDimension) = apply { + height = pageDimension.height + page = pageDimension.page + width = pageDimension.width + additionalProperties = pageDimension.additionalProperties.toMutableMap() + } + + /** Rendered page height in pixels */ + fun height(height: Long) = height(JsonField.of(height)) + + /** + * Sets [Builder.height] to an arbitrary JSON value. + * + * You should usually call [Builder.height] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun height(height: JsonField) = apply { this.height = height } + + /** 0-based page index (0 for standalone images) */ + fun page(page: Long) = page(JsonField.of(page)) + + /** + * Sets [Builder.page] to an arbitrary JSON value. + * + * You should usually call [Builder.page] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun page(page: JsonField) = apply { this.page = page } + + /** Rendered page width in pixels */ + fun width(width: Long) = width(JsonField.of(width)) + + /** + * Sets [Builder.width] to an arbitrary JSON value. + * + * You should usually call [Builder.width] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun width(width: JsonField) = apply { this.width = width } + + 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 [PageDimension]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .height() + * .page() + * .width() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PageDimension = + PageDimension( + checkRequired("height", height), + checkRequired("page", page), + checkRequired("width", width), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): PageDimension = apply { + if (validated) { + return@apply + } + + height() + page() + width() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (height.asKnown().isPresent) 1 else 0) + + (if (page.asKnown().isPresent) 1 else 0) + + (if (width.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PageDimension && + height == other.height && + page == other.page && + width == other.width && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(height, page, width, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PageDimension{height=$height, page=$page, width=$width, additionalProperties=$additionalProperties}" + } + + /** + * A region that led to the suspected fraud, with why it is suspect. + * + * A curated, high-signal subset of ``regions``: reviewer-dismissed candidates are dropped + * and the remainder is ranked by suspicion, so consumers can act on ``verdict`` + + * ``confidence`` + this list without reading the raw signals. + */ + class SuspectRegion + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bbox: JsonField>, + private val explanation: JsonField, + private val kind: JsonField, + private val page: JsonField, + private val score: JsonField, + private val source: JsonField, + private val primary: JsonField, + private val review: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bbox") + @ExcludeMissing + bbox: JsonField> = JsonMissing.of(), + @JsonProperty("explanation") + @ExcludeMissing + explanation: JsonField = JsonMissing.of(), + @JsonProperty("kind") @ExcludeMissing kind: JsonField = JsonMissing.of(), + @JsonProperty("page") @ExcludeMissing page: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + @JsonProperty("source") + @ExcludeMissing + source: JsonField = JsonMissing.of(), + @JsonProperty("primary") + @ExcludeMissing + primary: JsonField = JsonMissing.of(), + @JsonProperty("review") @ExcludeMissing review: JsonField = JsonMissing.of(), + ) : this(bbox, explanation, kind, page, score, source, primary, review, mutableMapOf()) + + /** + * Region bounding box as [x, y, w, h] in page-render pixels + * + * @throws LlamaCloudInvalidDataException 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 bbox(): List = bbox.getRequired("bbox") + + /** + * Human-readable explanation of what makes this region suspect + * + * @throws LlamaCloudInvalidDataException 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 explanation(): String = explanation.getRequired("explanation") + + /** + * Kind of anomaly detected in this region + * + * @throws LlamaCloudInvalidDataException 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 kind(): String = kind.getRequired("kind") + + /** + * 0-based page index (0 for standalone images) + * + * @throws LlamaCloudInvalidDataException 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 page(): Long = page.getRequired("page") + + /** + * Suspicion score for this region (0 to 1) + * + * @throws LlamaCloudInvalidDataException 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 score(): Double = score.getRequired("score") + + /** + * Detector that flagged this region + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun source(): String = source.getRequired("source") + + /** + * Whether this region is part of the small set of decisive evidence behind the verdict + * — the boxes a reviewer should look at first + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun primary(): Optional = primary.getOptional("primary") + + /** + * Automated reviewer verdict for this region (confirmed, dismissed, unsure, or empty). + * A dismissed region can still be surfaced when it is the only place to look; this + * label says how to read it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun review(): Optional = review.getOptional("review") + + /** + * Returns the raw JSON value of [bbox]. + * + * Unlike [bbox], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("bbox") @ExcludeMissing fun _bbox(): JsonField> = bbox + + /** + * Returns the raw JSON value of [explanation]. + * + * Unlike [explanation], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("explanation") + @ExcludeMissing + fun _explanation(): JsonField = explanation + + /** + * Returns the raw JSON value of [kind]. + * + * Unlike [kind], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("kind") @ExcludeMissing fun _kind(): JsonField = kind + + /** + * Returns the raw JSON value of [page]. + * + * Unlike [page], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page") @ExcludeMissing fun _page(): JsonField = page + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + /** + * Returns the raw JSON value of [primary]. + * + * Unlike [primary], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("primary") @ExcludeMissing fun _primary(): JsonField = primary + + /** + * Returns the raw JSON value of [review]. + * + * Unlike [review], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("review") @ExcludeMissing fun _review(): JsonField = review + + @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 [SuspectRegion]. + * + * The following fields are required: + * ```java + * .bbox() + * .explanation() + * .kind() + * .page() + * .score() + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SuspectRegion]. */ + class Builder internal constructor() { + + private var bbox: JsonField>? = null + private var explanation: JsonField? = null + private var kind: JsonField? = null + private var page: JsonField? = null + private var score: JsonField? = null + private var source: JsonField? = null + private var primary: JsonField = JsonMissing.of() + private var review: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(suspectRegion: SuspectRegion) = apply { + bbox = suspectRegion.bbox.map { it.toMutableList() } + explanation = suspectRegion.explanation + kind = suspectRegion.kind + page = suspectRegion.page + score = suspectRegion.score + source = suspectRegion.source + primary = suspectRegion.primary + review = suspectRegion.review + additionalProperties = suspectRegion.additionalProperties.toMutableMap() + } + + /** Region bounding box as [x, y, w, h] in page-render pixels */ + fun bbox(bbox: List) = bbox(JsonField.of(bbox)) + + /** + * Sets [Builder.bbox] to an arbitrary JSON value. + * + * You should usually call [Builder.bbox] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun bbox(bbox: JsonField>) = apply { + this.bbox = bbox.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.bbox]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addBbox(bbox: Long) = apply { + this.bbox = + (this.bbox ?: JsonField.of(mutableListOf())).also { + checkKnown("bbox", it).add(bbox) + } + } + + /** Human-readable explanation of what makes this region suspect */ + fun explanation(explanation: String) = explanation(JsonField.of(explanation)) + + /** + * Sets [Builder.explanation] to an arbitrary JSON value. + * + * You should usually call [Builder.explanation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun explanation(explanation: JsonField) = apply { + this.explanation = explanation + } + + /** Kind of anomaly detected in this region */ + fun kind(kind: String) = kind(JsonField.of(kind)) + + /** + * Sets [Builder.kind] to an arbitrary JSON value. + * + * You should usually call [Builder.kind] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun kind(kind: JsonField) = apply { this.kind = kind } + + /** 0-based page index (0 for standalone images) */ + fun page(page: Long) = page(JsonField.of(page)) + + /** + * Sets [Builder.page] to an arbitrary JSON value. + * + * You should usually call [Builder.page] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun page(page: JsonField) = apply { this.page = page } + + /** Suspicion score for this region (0 to 1) */ + fun score(score: Double) = score(JsonField.of(score)) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + /** Detector that flagged this region */ + fun source(source: String) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + /** + * Whether this region is part of the small set of decisive evidence behind the + * verdict — the boxes a reviewer should look at first + */ + fun primary(primary: Boolean) = primary(JsonField.of(primary)) + + /** + * Sets [Builder.primary] to an arbitrary JSON value. + * + * You should usually call [Builder.primary] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun primary(primary: JsonField) = apply { this.primary = primary } + + /** + * Automated reviewer verdict for this region (confirmed, dismissed, unsure, or + * empty). A dismissed region can still be surfaced when it is the only place to + * look; this label says how to read it + */ + fun review(review: String) = review(JsonField.of(review)) + + /** + * Sets [Builder.review] to an arbitrary JSON value. + * + * You should usually call [Builder.review] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun review(review: JsonField) = apply { this.review = review } + + 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 [SuspectRegion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .bbox() + * .explanation() + * .kind() + * .page() + * .score() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SuspectRegion = + SuspectRegion( + checkRequired("bbox", bbox).map { it.toImmutable() }, + checkRequired("explanation", explanation), + checkRequired("kind", kind), + checkRequired("page", page), + checkRequired("score", score), + checkRequired("source", source), + primary, + review, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): SuspectRegion = apply { + if (validated) { + return@apply + } + + bbox() + explanation() + kind() + page() + score() + source() + primary() + review() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (bbox.asKnown().getOrNull()?.size ?: 0) + + (if (explanation.asKnown().isPresent) 1 else 0) + + (if (kind.asKnown().isPresent) 1 else 0) + + (if (page.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + (if (source.asKnown().isPresent) 1 else 0) + + (if (primary.asKnown().isPresent) 1 else 0) + + (if (review.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SuspectRegion && + bbox == other.bbox && + explanation == other.explanation && + kind == other.kind && + page == other.page && + score == other.score && + source == other.source && + primary == other.primary && + review == other.review && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bbox, + explanation, + kind, + page, + score, + source, + primary, + review, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SuspectRegion{bbox=$bbox, explanation=$explanation, kind=$kind, page=$page, score=$score, source=$source, primary=$primary, review=$review, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Result && + detectorVersion == other.detectorVersion && + overallScore == other.overallScore && + verdict == other.verdict && + compositeScores == other.compositeScores && + confidence == other.confidence && + error == other.error && + pageCount == other.pageCount && + pageDimensions == other.pageDimensions && + reasoning == other.reasoning && + suspectRegions == other.suspectRegions && + syntheticScore == other.syntheticScore && + tamperingScore == other.tamperingScore && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + detectorVersion, + overallScore, + verdict, + compositeScores, + confidence, + error, + pageCount, + pageDimensions, + reasoning, + suspectRegions, + syntheticScore, + tamperingScore, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Result{detectorVersion=$detectorVersion, overallScore=$overallScore, verdict=$verdict, compositeScores=$compositeScores, confidence=$confidence, error=$error, pageCount=$pageCount, pageDimensions=$pageDimensions, reasoning=$reasoning, suspectRegions=$suspectRegions, syntheticScore=$syntheticScore, tamperingScore=$tamperingScore, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyCancelResponse && + id == other.id && + configuration == other.configuration && + documentInputType == other.documentInputType && + fileInput == other.fileInput && + projectId == other.projectId && + status == other.status && + userId == other.userId && + createdAt == other.createdAt && + errorMessage == other.errorMessage && + result == other.result && + transactionId == other.transactionId && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + configuration, + documentInputType, + fileInput, + projectId, + status, + userId, + createdAt, + errorMessage, + result, + transactionId, + updatedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VerifyCancelResponse{id=$id, configuration=$configuration, documentInputType=$documentInputType, fileInput=$fileInput, projectId=$projectId, status=$status, userId=$userId, createdAt=$createdAt, errorMessage=$errorMessage, result=$result, transactionId=$transactionId, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateParams.kt new file mode 100644 index 0000000..36f3f95 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateParams.kt @@ -0,0 +1,2173 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Create a Verify job. + * + * Analyzes a document for signs of doctoring (splicing, copy-move, AI generation, metadata + * tampering, ...). Set `file_input` to a file ID (`dfl-...`). Optionally provide a `configuration` + * object to control the semantic agent. + * + * The job runs asynchronously. Poll `GET /verify/{job_id}` with `expand=result` to check status and + * retrieve results. + */ +class VerifyCreateParams +private constructor( + private val organizationId: String?, + private val projectId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * Configuration for a Verify job. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun configuration(): Optional = body.configuration() + + /** + * Deprecated: use file_input instead + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + @Deprecated("deprecated") fun fileId(): Optional = body.fileId() + + /** + * File ID of the document to analyze + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fileInput(): Optional = body.fileInput() + + /** + * Idempotency key scoped to the project. Reusing a key returns the original job; the new + * request body is ignored. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun transactionId(): Optional = body.transactionId() + + /** + * IDs of saved webhook configurations to notify for this job. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun webhookConfigurationIds(): Optional> = body.webhookConfigurationIds() + + /** + * Outbound webhook endpoints to notify on job status changes + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun webhookConfigurations(): Optional> = body.webhookConfigurations() + + /** + * Returns the raw JSON value of [configuration]. + * + * Unlike [configuration], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _configuration(): JsonField = body._configuration() + + /** + * Returns the raw JSON value of [fileId]. + * + * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. + */ + @Deprecated("deprecated") fun _fileId(): JsonField = body._fileId() + + /** + * Returns the raw JSON value of [fileInput]. + * + * Unlike [fileInput], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _fileInput(): JsonField = body._fileInput() + + /** + * Returns the raw JSON value of [transactionId]. + * + * Unlike [transactionId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _transactionId(): JsonField = body._transactionId() + + /** + * Returns the raw JSON value of [webhookConfigurationIds]. + * + * Unlike [webhookConfigurationIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + fun _webhookConfigurationIds(): JsonField> = body._webhookConfigurationIds() + + /** + * Returns the raw JSON value of [webhookConfigurations]. + * + * Unlike [webhookConfigurations], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _webhookConfigurations(): JsonField> = + body._webhookConfigurations() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): VerifyCreateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [VerifyCreateParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyCreateParams]. */ + class Builder internal constructor() { + + private var organizationId: String? = null + private var projectId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(verifyCreateParams: VerifyCreateParams) = apply { + organizationId = verifyCreateParams.organizationId + projectId = verifyCreateParams.projectId + body = verifyCreateParams.body.toBuilder() + additionalHeaders = verifyCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = verifyCreateParams.additionalQueryParams.toBuilder() + } + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [configuration] + * - [fileId] + * - [fileInput] + * - [transactionId] + * - [webhookConfigurationIds] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** Configuration for a Verify job. */ + fun configuration(configuration: Configuration?) = apply { + body.configuration(configuration) + } + + /** Alias for calling [Builder.configuration] with `configuration.orElse(null)`. */ + fun configuration(configuration: Optional) = + configuration(configuration.getOrNull()) + + /** + * Sets [Builder.configuration] to an arbitrary JSON value. + * + * You should usually call [Builder.configuration] with a well-typed [Configuration] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun configuration(configuration: JsonField) = apply { + body.configuration(configuration) + } + + /** Deprecated: use file_input instead */ + @Deprecated("deprecated") fun fileId(fileId: String?) = apply { body.fileId(fileId) } + + /** Alias for calling [Builder.fileId] with `fileId.orElse(null)`. */ + @Deprecated("deprecated") fun fileId(fileId: Optional) = fileId(fileId.getOrNull()) + + /** + * Sets [Builder.fileId] to an arbitrary JSON value. + * + * You should usually call [Builder.fileId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + @Deprecated("deprecated") + fun fileId(fileId: JsonField) = apply { body.fileId(fileId) } + + /** File ID of the document to analyze */ + fun fileInput(fileInput: String?) = apply { body.fileInput(fileInput) } + + /** Alias for calling [Builder.fileInput] with `fileInput.orElse(null)`. */ + fun fileInput(fileInput: Optional) = fileInput(fileInput.getOrNull()) + + /** + * Sets [Builder.fileInput] to an arbitrary JSON value. + * + * You should usually call [Builder.fileInput] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun fileInput(fileInput: JsonField) = apply { body.fileInput(fileInput) } + + /** + * Idempotency key scoped to the project. Reusing a key returns the original job; the new + * request body is ignored. + */ + fun transactionId(transactionId: String?) = apply { body.transactionId(transactionId) } + + /** Alias for calling [Builder.transactionId] with `transactionId.orElse(null)`. */ + fun transactionId(transactionId: Optional) = + transactionId(transactionId.getOrNull()) + + /** + * Sets [Builder.transactionId] to an arbitrary JSON value. + * + * You should usually call [Builder.transactionId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun transactionId(transactionId: JsonField) = apply { + body.transactionId(transactionId) + } + + /** IDs of saved webhook configurations to notify for this job. */ + fun webhookConfigurationIds(webhookConfigurationIds: List?) = apply { + body.webhookConfigurationIds(webhookConfigurationIds) + } + + /** + * Alias for calling [Builder.webhookConfigurationIds] with + * `webhookConfigurationIds.orElse(null)`. + */ + fun webhookConfigurationIds(webhookConfigurationIds: Optional>) = + webhookConfigurationIds(webhookConfigurationIds.getOrNull()) + + /** + * Sets [Builder.webhookConfigurationIds] to an arbitrary JSON value. + * + * You should usually call [Builder.webhookConfigurationIds] with a well-typed + * `List` value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun webhookConfigurationIds(webhookConfigurationIds: JsonField>) = apply { + body.webhookConfigurationIds(webhookConfigurationIds) + } + + /** + * Adds a single [String] to [webhookConfigurationIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addWebhookConfigurationId(webhookConfigurationId: String) = apply { + body.addWebhookConfigurationId(webhookConfigurationId) + } + + /** Outbound webhook endpoints to notify on job status changes */ + fun webhookConfigurations(webhookConfigurations: List?) = apply { + body.webhookConfigurations(webhookConfigurations) + } + + /** + * Alias for calling [Builder.webhookConfigurations] with + * `webhookConfigurations.orElse(null)`. + */ + fun webhookConfigurations(webhookConfigurations: Optional>) = + webhookConfigurations(webhookConfigurations.getOrNull()) + + /** + * Sets [Builder.webhookConfigurations] to an arbitrary JSON value. + * + * You should usually call [Builder.webhookConfigurations] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun webhookConfigurations(webhookConfigurations: JsonField>) = + apply { + body.webhookConfigurations(webhookConfigurations) + } + + /** + * Adds a single [WebhookConfiguration] to [webhookConfigurations]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addWebhookConfiguration(webhookConfiguration: WebhookConfiguration) = apply { + body.addWebhookConfiguration(webhookConfiguration) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [VerifyCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): VerifyCreateParams = + VerifyCreateParams( + organizationId, + projectId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + /** Request to create a Verify job. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val configuration: JsonField, + private val fileId: JsonField, + private val fileInput: JsonField, + private val transactionId: JsonField, + private val webhookConfigurationIds: JsonField>, + private val webhookConfigurations: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("configuration") + @ExcludeMissing + configuration: JsonField = JsonMissing.of(), + @JsonProperty("file_id") @ExcludeMissing fileId: JsonField = JsonMissing.of(), + @JsonProperty("file_input") + @ExcludeMissing + fileInput: JsonField = JsonMissing.of(), + @JsonProperty("transaction_id") + @ExcludeMissing + transactionId: JsonField = JsonMissing.of(), + @JsonProperty("webhook_configuration_ids") + @ExcludeMissing + webhookConfigurationIds: JsonField> = JsonMissing.of(), + @JsonProperty("webhook_configurations") + @ExcludeMissing + webhookConfigurations: JsonField> = JsonMissing.of(), + ) : this( + configuration, + fileId, + fileInput, + transactionId, + webhookConfigurationIds, + webhookConfigurations, + mutableMapOf(), + ) + + /** + * Configuration for a Verify job. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun configuration(): Optional = configuration.getOptional("configuration") + + /** + * Deprecated: use file_input instead + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + @Deprecated("deprecated") fun fileId(): Optional = fileId.getOptional("file_id") + + /** + * File ID of the document to analyze + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fileInput(): Optional = fileInput.getOptional("file_input") + + /** + * Idempotency key scoped to the project. Reusing a key returns the original job; the new + * request body is ignored. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun transactionId(): Optional = transactionId.getOptional("transaction_id") + + /** + * IDs of saved webhook configurations to notify for this job. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun webhookConfigurationIds(): Optional> = + webhookConfigurationIds.getOptional("webhook_configuration_ids") + + /** + * Outbound webhook endpoints to notify on job status changes + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun webhookConfigurations(): Optional> = + webhookConfigurations.getOptional("webhook_configurations") + + /** + * Returns the raw JSON value of [configuration]. + * + * Unlike [configuration], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("configuration") + @ExcludeMissing + fun _configuration(): JsonField = configuration + + /** + * Returns the raw JSON value of [fileId]. + * + * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. + */ + @Deprecated("deprecated") + @JsonProperty("file_id") + @ExcludeMissing + fun _fileId(): JsonField = fileId + + /** + * Returns the raw JSON value of [fileInput]. + * + * Unlike [fileInput], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_input") @ExcludeMissing fun _fileInput(): JsonField = fileInput + + /** + * Returns the raw JSON value of [transactionId]. + * + * Unlike [transactionId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("transaction_id") + @ExcludeMissing + fun _transactionId(): JsonField = transactionId + + /** + * Returns the raw JSON value of [webhookConfigurationIds]. + * + * Unlike [webhookConfigurationIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("webhook_configuration_ids") + @ExcludeMissing + fun _webhookConfigurationIds(): JsonField> = webhookConfigurationIds + + /** + * Returns the raw JSON value of [webhookConfigurations]. + * + * Unlike [webhookConfigurations], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("webhook_configurations") + @ExcludeMissing + fun _webhookConfigurations(): JsonField> = webhookConfigurations + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var configuration: JsonField = JsonMissing.of() + private var fileId: JsonField = JsonMissing.of() + private var fileInput: JsonField = JsonMissing.of() + private var transactionId: JsonField = JsonMissing.of() + private var webhookConfigurationIds: JsonField>? = null + private var webhookConfigurations: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + configuration = body.configuration + fileId = body.fileId + fileInput = body.fileInput + transactionId = body.transactionId + webhookConfigurationIds = body.webhookConfigurationIds.map { it.toMutableList() } + webhookConfigurations = body.webhookConfigurations.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Configuration for a Verify job. */ + fun configuration(configuration: Configuration?) = + configuration(JsonField.ofNullable(configuration)) + + /** Alias for calling [Builder.configuration] with `configuration.orElse(null)`. */ + fun configuration(configuration: Optional) = + configuration(configuration.getOrNull()) + + /** + * Sets [Builder.configuration] to an arbitrary JSON value. + * + * You should usually call [Builder.configuration] with a well-typed [Configuration] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun configuration(configuration: JsonField) = apply { + this.configuration = configuration + } + + /** Deprecated: use file_input instead */ + @Deprecated("deprecated") + fun fileId(fileId: String?) = fileId(JsonField.ofNullable(fileId)) + + /** Alias for calling [Builder.fileId] with `fileId.orElse(null)`. */ + @Deprecated("deprecated") + fun fileId(fileId: Optional) = fileId(fileId.getOrNull()) + + /** + * Sets [Builder.fileId] to an arbitrary JSON value. + * + * You should usually call [Builder.fileId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun fileId(fileId: JsonField) = apply { this.fileId = fileId } + + /** File ID of the document to analyze */ + fun fileInput(fileInput: String?) = fileInput(JsonField.ofNullable(fileInput)) + + /** Alias for calling [Builder.fileInput] with `fileInput.orElse(null)`. */ + fun fileInput(fileInput: Optional) = fileInput(fileInput.getOrNull()) + + /** + * Sets [Builder.fileInput] to an arbitrary JSON value. + * + * You should usually call [Builder.fileInput] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileInput(fileInput: JsonField) = apply { this.fileInput = fileInput } + + /** + * Idempotency key scoped to the project. Reusing a key returns the original job; the + * new request body is ignored. + */ + fun transactionId(transactionId: String?) = + transactionId(JsonField.ofNullable(transactionId)) + + /** Alias for calling [Builder.transactionId] with `transactionId.orElse(null)`. */ + fun transactionId(transactionId: Optional) = + transactionId(transactionId.getOrNull()) + + /** + * Sets [Builder.transactionId] to an arbitrary JSON value. + * + * You should usually call [Builder.transactionId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun transactionId(transactionId: JsonField) = apply { + this.transactionId = transactionId + } + + /** IDs of saved webhook configurations to notify for this job. */ + fun webhookConfigurationIds(webhookConfigurationIds: List?) = + webhookConfigurationIds(JsonField.ofNullable(webhookConfigurationIds)) + + /** + * Alias for calling [Builder.webhookConfigurationIds] with + * `webhookConfigurationIds.orElse(null)`. + */ + fun webhookConfigurationIds(webhookConfigurationIds: Optional>) = + webhookConfigurationIds(webhookConfigurationIds.getOrNull()) + + /** + * Sets [Builder.webhookConfigurationIds] to an arbitrary JSON value. + * + * You should usually call [Builder.webhookConfigurationIds] with a well-typed + * `List` value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun webhookConfigurationIds(webhookConfigurationIds: JsonField>) = apply { + this.webhookConfigurationIds = webhookConfigurationIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [webhookConfigurationIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addWebhookConfigurationId(webhookConfigurationId: String) = apply { + webhookConfigurationIds = + (webhookConfigurationIds ?: JsonField.of(mutableListOf())).also { + checkKnown("webhookConfigurationIds", it).add(webhookConfigurationId) + } + } + + /** Outbound webhook endpoints to notify on job status changes */ + fun webhookConfigurations(webhookConfigurations: List?) = + webhookConfigurations(JsonField.ofNullable(webhookConfigurations)) + + /** + * Alias for calling [Builder.webhookConfigurations] with + * `webhookConfigurations.orElse(null)`. + */ + fun webhookConfigurations(webhookConfigurations: Optional>) = + webhookConfigurations(webhookConfigurations.getOrNull()) + + /** + * Sets [Builder.webhookConfigurations] to an arbitrary JSON value. + * + * You should usually call [Builder.webhookConfigurations] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun webhookConfigurations( + webhookConfigurations: JsonField> + ) = apply { + this.webhookConfigurations = webhookConfigurations.map { it.toMutableList() } + } + + /** + * Adds a single [WebhookConfiguration] to [webhookConfigurations]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addWebhookConfiguration(webhookConfiguration: WebhookConfiguration) = apply { + webhookConfigurations = + (webhookConfigurations ?: JsonField.of(mutableListOf())).also { + checkKnown("webhookConfigurations", it).add(webhookConfiguration) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body( + configuration, + fileId, + fileInput, + transactionId, + (webhookConfigurationIds ?: JsonMissing.of()).map { it.toImmutable() }, + (webhookConfigurations ?: JsonMissing.of()).map { it.toImmutable() }, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + configuration().ifPresent { it.validate() } + fileId() + fileInput() + transactionId() + webhookConfigurationIds() + webhookConfigurations().ifPresent { it.forEach { it.validate() } } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (configuration.asKnown().getOrNull()?.validity() ?: 0) + + (if (fileId.asKnown().isPresent) 1 else 0) + + (if (fileInput.asKnown().isPresent) 1 else 0) + + (if (transactionId.asKnown().isPresent) 1 else 0) + + (webhookConfigurationIds.asKnown().getOrNull()?.size ?: 0) + + (webhookConfigurations.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + configuration == other.configuration && + fileId == other.fileId && + fileInput == other.fileInput && + transactionId == other.transactionId && + webhookConfigurationIds == other.webhookConfigurationIds && + webhookConfigurations == other.webhookConfigurations && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + configuration, + fileId, + fileInput, + transactionId, + webhookConfigurationIds, + webhookConfigurations, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{configuration=$configuration, fileId=$fileId, fileInput=$fileInput, transactionId=$transactionId, webhookConfigurationIds=$webhookConfigurationIds, webhookConfigurations=$webhookConfigurations, additionalProperties=$additionalProperties}" + } + + /** Configuration for a Verify job. */ + class Configuration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val targetPages: JsonField, + private val tier: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("target_pages") + @ExcludeMissing + targetPages: JsonField = JsonMissing.of(), + @JsonProperty("tier") @ExcludeMissing tier: JsonField = JsonMissing.of(), + ) : this(targetPages, tier, mutableMapOf()) + + /** + * Comma-separated page numbers or ranges to analyze (1-based). Omit to analyze all pages. + * Ignored for non-PDF inputs. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun targetPages(): Optional = targetPages.getOptional("target_pages") + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, content + * integrity, container structure, pixel statistics); 'agentic' (default) runs the full + * pipeline including the learned detectors and the semantic review pass. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tier(): Optional = tier.getOptional("tier") + + /** + * Returns the raw JSON value of [targetPages]. + * + * Unlike [targetPages], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("target_pages") + @ExcludeMissing + fun _targetPages(): JsonField = targetPages + + /** + * Returns the raw JSON value of [tier]. + * + * Unlike [tier], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tier") @ExcludeMissing fun _tier(): JsonField = tier + + @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 [Configuration]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Configuration]. */ + class Builder internal constructor() { + + private var targetPages: JsonField = JsonMissing.of() + private var tier: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(configuration: Configuration) = apply { + targetPages = configuration.targetPages + tier = configuration.tier + additionalProperties = configuration.additionalProperties.toMutableMap() + } + + /** + * Comma-separated page numbers or ranges to analyze (1-based). Omit to analyze all + * pages. Ignored for non-PDF inputs. + */ + fun targetPages(targetPages: String?) = targetPages(JsonField.ofNullable(targetPages)) + + /** Alias for calling [Builder.targetPages] with `targetPages.orElse(null)`. */ + fun targetPages(targetPages: Optional) = targetPages(targetPages.getOrNull()) + + /** + * Sets [Builder.targetPages] to an arbitrary JSON value. + * + * You should usually call [Builder.targetPages] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun targetPages(targetPages: JsonField) = apply { + this.targetPages = targetPages + } + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, + * content integrity, container structure, pixel statistics); 'agentic' (default) runs + * the full pipeline including the learned detectors and the semantic review pass. + */ + fun tier(tier: Tier) = tier(JsonField.of(tier)) + + /** + * Sets [Builder.tier] to an arbitrary JSON value. + * + * You should usually call [Builder.tier] with a well-typed [Tier] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tier(tier: JsonField) = apply { this.tier = tier } + + 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 [Configuration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Configuration = + Configuration(targetPages, tier, 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Configuration = apply { + if (validated) { + return@apply + } + + targetPages() + tier().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (targetPages.asKnown().isPresent) 1 else 0) + + (tier.asKnown().getOrNull()?.validity() ?: 0) + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, content + * integrity, container structure, pixel statistics); 'agentic' (default) runs the full + * pipeline including the learned detectors and the semantic review pass. + */ + class Tier @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 AGENTIC = of("agentic") + + @JvmField val FAST = of("fast") + + @JvmStatic fun of(value: String) = Tier(JsonField.of(value)) + } + + /** An enum containing [Tier]'s known values. */ + enum class Known { + AGENTIC, + FAST, + } + + /** + * An enum containing [Tier]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Tier] 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 { + AGENTIC, + FAST, + /** An enum member indicating that [Tier] 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) { + AGENTIC -> Value.AGENTIC + FAST -> Value.FAST + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + AGENTIC -> Known.AGENTIC + FAST -> Known.FAST + else -> throw LlamaCloudInvalidDataException("Unknown Tier: $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 LlamaCloudInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Tier && 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 Configuration && + targetPages == other.targetPages && + tier == other.tier && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(targetPages, tier, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Configuration{targetPages=$targetPages, tier=$tier, additionalProperties=$additionalProperties}" + } + + /** Configuration for a single outbound webhook endpoint. */ + class WebhookConfiguration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val webhookEvents: JsonField>, + private val webhookHeaders: JsonField, + private val webhookOutputFormat: JsonField, + private val webhookSigningSecret: JsonField, + private val webhookUrl: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("webhook_events") + @ExcludeMissing + webhookEvents: JsonField> = JsonMissing.of(), + @JsonProperty("webhook_headers") + @ExcludeMissing + webhookHeaders: JsonField = JsonMissing.of(), + @JsonProperty("webhook_output_format") + @ExcludeMissing + webhookOutputFormat: JsonField = JsonMissing.of(), + @JsonProperty("webhook_signing_secret") + @ExcludeMissing + webhookSigningSecret: JsonField = JsonMissing.of(), + @JsonProperty("webhook_url") + @ExcludeMissing + webhookUrl: JsonField = JsonMissing.of(), + ) : this( + webhookEvents, + webhookHeaders, + webhookOutputFormat, + webhookSigningSecret, + webhookUrl, + mutableMapOf(), + ) + + /** + * Events to subscribe to (e.g. 'parse.success', 'extract.error'). If null, all events are + * delivered. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun webhookEvents(): Optional> = + webhookEvents.getOptional("webhook_events") + + /** + * Custom HTTP headers sent with each webhook request (e.g. auth tokens) + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun webhookHeaders(): Optional = + webhookHeaders.getOptional("webhook_headers") + + /** + * Response format sent to the webhook: 'string' (default) or 'json' + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun webhookOutputFormat(): Optional = + webhookOutputFormat.getOptional("webhook_output_format") + + /** + * Shared signing secret used to sign webhook deliveries. When set, each request includes an + * HMAC-SHA256 signature of the request body in the 'LC-Signature' header (value + * 'sha256='). Recompute the HMAC over the raw request body with this secret to verify + * the delivery is authentic. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun webhookSigningSecret(): Optional = + webhookSigningSecret.getOptional("webhook_signing_secret") + + /** + * URL to receive webhook POST notifications + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun webhookUrl(): Optional = webhookUrl.getOptional("webhook_url") + + /** + * Returns the raw JSON value of [webhookEvents]. + * + * Unlike [webhookEvents], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("webhook_events") + @ExcludeMissing + fun _webhookEvents(): JsonField> = webhookEvents + + /** + * Returns the raw JSON value of [webhookHeaders]. + * + * Unlike [webhookHeaders], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("webhook_headers") + @ExcludeMissing + fun _webhookHeaders(): JsonField = webhookHeaders + + /** + * Returns the raw JSON value of [webhookOutputFormat]. + * + * Unlike [webhookOutputFormat], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("webhook_output_format") + @ExcludeMissing + fun _webhookOutputFormat(): JsonField = webhookOutputFormat + + /** + * Returns the raw JSON value of [webhookSigningSecret]. + * + * Unlike [webhookSigningSecret], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("webhook_signing_secret") + @ExcludeMissing + fun _webhookSigningSecret(): JsonField = webhookSigningSecret + + /** + * Returns the raw JSON value of [webhookUrl]. + * + * Unlike [webhookUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("webhook_url") + @ExcludeMissing + fun _webhookUrl(): JsonField = webhookUrl + + @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 [WebhookConfiguration]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [WebhookConfiguration]. */ + class Builder internal constructor() { + + private var webhookEvents: JsonField>? = null + private var webhookHeaders: JsonField = JsonMissing.of() + private var webhookOutputFormat: JsonField = JsonMissing.of() + private var webhookSigningSecret: JsonField = JsonMissing.of() + private var webhookUrl: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(webhookConfiguration: WebhookConfiguration) = apply { + webhookEvents = webhookConfiguration.webhookEvents.map { it.toMutableList() } + webhookHeaders = webhookConfiguration.webhookHeaders + webhookOutputFormat = webhookConfiguration.webhookOutputFormat + webhookSigningSecret = webhookConfiguration.webhookSigningSecret + webhookUrl = webhookConfiguration.webhookUrl + additionalProperties = webhookConfiguration.additionalProperties.toMutableMap() + } + + /** + * Events to subscribe to (e.g. 'parse.success', 'extract.error'). If null, all events + * are delivered. + */ + fun webhookEvents(webhookEvents: List?) = + webhookEvents(JsonField.ofNullable(webhookEvents)) + + /** Alias for calling [Builder.webhookEvents] with `webhookEvents.orElse(null)`. */ + fun webhookEvents(webhookEvents: Optional>) = + webhookEvents(webhookEvents.getOrNull()) + + /** + * Sets [Builder.webhookEvents] to an arbitrary JSON value. + * + * You should usually call [Builder.webhookEvents] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun webhookEvents(webhookEvents: JsonField>) = apply { + this.webhookEvents = webhookEvents.map { it.toMutableList() } + } + + /** + * Adds a single [WebhookEvent] to [webhookEvents]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addWebhookEvent(webhookEvent: WebhookEvent) = apply { + webhookEvents = + (webhookEvents ?: JsonField.of(mutableListOf())).also { + checkKnown("webhookEvents", it).add(webhookEvent) + } + } + + /** Custom HTTP headers sent with each webhook request (e.g. auth tokens) */ + fun webhookHeaders(webhookHeaders: WebhookHeaders?) = + webhookHeaders(JsonField.ofNullable(webhookHeaders)) + + /** Alias for calling [Builder.webhookHeaders] with `webhookHeaders.orElse(null)`. */ + fun webhookHeaders(webhookHeaders: Optional) = + webhookHeaders(webhookHeaders.getOrNull()) + + /** + * Sets [Builder.webhookHeaders] to an arbitrary JSON value. + * + * You should usually call [Builder.webhookHeaders] with a well-typed [WebhookHeaders] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun webhookHeaders(webhookHeaders: JsonField) = apply { + this.webhookHeaders = webhookHeaders + } + + /** Response format sent to the webhook: 'string' (default) or 'json' */ + fun webhookOutputFormat(webhookOutputFormat: String?) = + webhookOutputFormat(JsonField.ofNullable(webhookOutputFormat)) + + /** + * Alias for calling [Builder.webhookOutputFormat] with + * `webhookOutputFormat.orElse(null)`. + */ + fun webhookOutputFormat(webhookOutputFormat: Optional) = + webhookOutputFormat(webhookOutputFormat.getOrNull()) + + /** + * Sets [Builder.webhookOutputFormat] to an arbitrary JSON value. + * + * You should usually call [Builder.webhookOutputFormat] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun webhookOutputFormat(webhookOutputFormat: JsonField) = apply { + this.webhookOutputFormat = webhookOutputFormat + } + + /** + * Shared signing secret used to sign webhook deliveries. When set, each request + * includes an HMAC-SHA256 signature of the request body in the 'LC-Signature' header + * (value 'sha256='). Recompute the HMAC over the raw request body with this secret + * to verify the delivery is authentic. + */ + fun webhookSigningSecret(webhookSigningSecret: String?) = + webhookSigningSecret(JsonField.ofNullable(webhookSigningSecret)) + + /** + * Alias for calling [Builder.webhookSigningSecret] with + * `webhookSigningSecret.orElse(null)`. + */ + fun webhookSigningSecret(webhookSigningSecret: Optional) = + webhookSigningSecret(webhookSigningSecret.getOrNull()) + + /** + * Sets [Builder.webhookSigningSecret] to an arbitrary JSON value. + * + * You should usually call [Builder.webhookSigningSecret] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun webhookSigningSecret(webhookSigningSecret: JsonField) = apply { + this.webhookSigningSecret = webhookSigningSecret + } + + /** URL to receive webhook POST notifications */ + fun webhookUrl(webhookUrl: String?) = webhookUrl(JsonField.ofNullable(webhookUrl)) + + /** Alias for calling [Builder.webhookUrl] with `webhookUrl.orElse(null)`. */ + fun webhookUrl(webhookUrl: Optional) = webhookUrl(webhookUrl.getOrNull()) + + /** + * Sets [Builder.webhookUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.webhookUrl] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun webhookUrl(webhookUrl: JsonField) = apply { this.webhookUrl = webhookUrl } + + 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 [WebhookConfiguration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): WebhookConfiguration = + WebhookConfiguration( + (webhookEvents ?: JsonMissing.of()).map { it.toImmutable() }, + webhookHeaders, + webhookOutputFormat, + webhookSigningSecret, + webhookUrl, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): WebhookConfiguration = apply { + if (validated) { + return@apply + } + + webhookEvents().ifPresent { it.forEach { it.validate() } } + webhookHeaders().ifPresent { it.validate() } + webhookOutputFormat() + webhookSigningSecret() + webhookUrl() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (webhookEvents.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (webhookHeaders.asKnown().getOrNull()?.validity() ?: 0) + + (if (webhookOutputFormat.asKnown().isPresent) 1 else 0) + + (if (webhookSigningSecret.asKnown().isPresent) 1 else 0) + + (if (webhookUrl.asKnown().isPresent) 1 else 0) + + class WebhookEvent @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 BATCH_CANCELLED = of("batch.cancelled") + + @JvmField val BATCH_ERROR = of("batch.error") + + @JvmField val BATCH_PENDING = of("batch.pending") + + @JvmField val BATCH_RUNNING = of("batch.running") + + @JvmField val BATCH_SUCCESS = of("batch.success") + + @JvmField val CLASSIFY_CANCELLED = of("classify.cancelled") + + @JvmField val CLASSIFY_ERROR = of("classify.error") + + @JvmField val CLASSIFY_PARTIAL_SUCCESS = of("classify.partial_success") + + @JvmField val CLASSIFY_PENDING = of("classify.pending") + + @JvmField val CLASSIFY_RUNNING = of("classify.running") + + @JvmField val CLASSIFY_SUCCESS = of("classify.success") + + @JvmField val EXTRACT_CANCELLED = of("extract.cancelled") + + @JvmField val EXTRACT_ERROR = of("extract.error") + + @JvmField val EXTRACT_PARTIAL_SUCCESS = of("extract.partial_success") + + @JvmField val EXTRACT_PENDING = of("extract.pending") + + @JvmField val EXTRACT_SUCCESS = of("extract.success") + + @JvmField val PARSE_CANCELLED = of("parse.cancelled") + + @JvmField val PARSE_ERROR = of("parse.error") + + @JvmField val PARSE_PARTIAL_SUCCESS = of("parse.partial_success") + + @JvmField val PARSE_PENDING = of("parse.pending") + + @JvmField val PARSE_RUNNING = of("parse.running") + + @JvmField val PARSE_SUCCESS = of("parse.success") + + @JvmField val SHEETS_CANCELLED = of("sheets.cancelled") + + @JvmField val SHEETS_ERROR = of("sheets.error") + + @JvmField val SHEETS_PARTIAL_SUCCESS = of("sheets.partial_success") + + @JvmField val SHEETS_PENDING = of("sheets.pending") + + @JvmField val SHEETS_SUCCESS = of("sheets.success") + + @JvmField val SPLIT_CANCELLED = of("split.cancelled") + + @JvmField val SPLIT_ERROR = of("split.error") + + @JvmField val SPLIT_PENDING = of("split.pending") + + @JvmField val SPLIT_PROCESSING = of("split.processing") + + @JvmField val SPLIT_SUCCESS = of("split.success") + + @JvmField val UNMAPPED_EVENT = of("unmapped_event") + + @JvmField val VERIFY_CANCELLED = of("verify.cancelled") + + @JvmField val VERIFY_ERROR = of("verify.error") + + @JvmField val VERIFY_PENDING = of("verify.pending") + + @JvmField val VERIFY_RUNNING = of("verify.running") + + @JvmField val VERIFY_SUCCESS = of("verify.success") + + @JvmStatic fun of(value: String) = WebhookEvent(JsonField.of(value)) + } + + /** An enum containing [WebhookEvent]'s known values. */ + enum class Known { + BATCH_CANCELLED, + BATCH_ERROR, + BATCH_PENDING, + BATCH_RUNNING, + BATCH_SUCCESS, + CLASSIFY_CANCELLED, + CLASSIFY_ERROR, + CLASSIFY_PARTIAL_SUCCESS, + CLASSIFY_PENDING, + CLASSIFY_RUNNING, + CLASSIFY_SUCCESS, + EXTRACT_CANCELLED, + EXTRACT_ERROR, + EXTRACT_PARTIAL_SUCCESS, + EXTRACT_PENDING, + EXTRACT_SUCCESS, + PARSE_CANCELLED, + PARSE_ERROR, + PARSE_PARTIAL_SUCCESS, + PARSE_PENDING, + PARSE_RUNNING, + PARSE_SUCCESS, + SHEETS_CANCELLED, + SHEETS_ERROR, + SHEETS_PARTIAL_SUCCESS, + SHEETS_PENDING, + SHEETS_SUCCESS, + SPLIT_CANCELLED, + SPLIT_ERROR, + SPLIT_PENDING, + SPLIT_PROCESSING, + SPLIT_SUCCESS, + UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, + } + + /** + * An enum containing [WebhookEvent]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [WebhookEvent] 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 { + BATCH_CANCELLED, + BATCH_ERROR, + BATCH_PENDING, + BATCH_RUNNING, + BATCH_SUCCESS, + CLASSIFY_CANCELLED, + CLASSIFY_ERROR, + CLASSIFY_PARTIAL_SUCCESS, + CLASSIFY_PENDING, + CLASSIFY_RUNNING, + CLASSIFY_SUCCESS, + EXTRACT_CANCELLED, + EXTRACT_ERROR, + EXTRACT_PARTIAL_SUCCESS, + EXTRACT_PENDING, + EXTRACT_SUCCESS, + PARSE_CANCELLED, + PARSE_ERROR, + PARSE_PARTIAL_SUCCESS, + PARSE_PENDING, + PARSE_RUNNING, + PARSE_SUCCESS, + SHEETS_CANCELLED, + SHEETS_ERROR, + SHEETS_PARTIAL_SUCCESS, + SHEETS_PENDING, + SHEETS_SUCCESS, + SPLIT_CANCELLED, + SPLIT_ERROR, + SPLIT_PENDING, + SPLIT_PROCESSING, + SPLIT_SUCCESS, + UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, + /** + * An enum member indicating that [WebhookEvent] 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) { + BATCH_CANCELLED -> Value.BATCH_CANCELLED + BATCH_ERROR -> Value.BATCH_ERROR + BATCH_PENDING -> Value.BATCH_PENDING + BATCH_RUNNING -> Value.BATCH_RUNNING + BATCH_SUCCESS -> Value.BATCH_SUCCESS + CLASSIFY_CANCELLED -> Value.CLASSIFY_CANCELLED + CLASSIFY_ERROR -> Value.CLASSIFY_ERROR + CLASSIFY_PARTIAL_SUCCESS -> Value.CLASSIFY_PARTIAL_SUCCESS + CLASSIFY_PENDING -> Value.CLASSIFY_PENDING + CLASSIFY_RUNNING -> Value.CLASSIFY_RUNNING + CLASSIFY_SUCCESS -> Value.CLASSIFY_SUCCESS + EXTRACT_CANCELLED -> Value.EXTRACT_CANCELLED + EXTRACT_ERROR -> Value.EXTRACT_ERROR + EXTRACT_PARTIAL_SUCCESS -> Value.EXTRACT_PARTIAL_SUCCESS + EXTRACT_PENDING -> Value.EXTRACT_PENDING + EXTRACT_SUCCESS -> Value.EXTRACT_SUCCESS + PARSE_CANCELLED -> Value.PARSE_CANCELLED + PARSE_ERROR -> Value.PARSE_ERROR + PARSE_PARTIAL_SUCCESS -> Value.PARSE_PARTIAL_SUCCESS + PARSE_PENDING -> Value.PARSE_PENDING + PARSE_RUNNING -> Value.PARSE_RUNNING + PARSE_SUCCESS -> Value.PARSE_SUCCESS + SHEETS_CANCELLED -> Value.SHEETS_CANCELLED + SHEETS_ERROR -> Value.SHEETS_ERROR + SHEETS_PARTIAL_SUCCESS -> Value.SHEETS_PARTIAL_SUCCESS + SHEETS_PENDING -> Value.SHEETS_PENDING + SHEETS_SUCCESS -> Value.SHEETS_SUCCESS + SPLIT_CANCELLED -> Value.SPLIT_CANCELLED + SPLIT_ERROR -> Value.SPLIT_ERROR + SPLIT_PENDING -> Value.SPLIT_PENDING + SPLIT_PROCESSING -> Value.SPLIT_PROCESSING + SPLIT_SUCCESS -> Value.SPLIT_SUCCESS + UNMAPPED_EVENT -> Value.UNMAPPED_EVENT + VERIFY_CANCELLED -> Value.VERIFY_CANCELLED + VERIFY_ERROR -> Value.VERIFY_ERROR + VERIFY_PENDING -> Value.VERIFY_PENDING + VERIFY_RUNNING -> Value.VERIFY_RUNNING + VERIFY_SUCCESS -> Value.VERIFY_SUCCESS + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + BATCH_CANCELLED -> Known.BATCH_CANCELLED + BATCH_ERROR -> Known.BATCH_ERROR + BATCH_PENDING -> Known.BATCH_PENDING + BATCH_RUNNING -> Known.BATCH_RUNNING + BATCH_SUCCESS -> Known.BATCH_SUCCESS + CLASSIFY_CANCELLED -> Known.CLASSIFY_CANCELLED + CLASSIFY_ERROR -> Known.CLASSIFY_ERROR + CLASSIFY_PARTIAL_SUCCESS -> Known.CLASSIFY_PARTIAL_SUCCESS + CLASSIFY_PENDING -> Known.CLASSIFY_PENDING + CLASSIFY_RUNNING -> Known.CLASSIFY_RUNNING + CLASSIFY_SUCCESS -> Known.CLASSIFY_SUCCESS + EXTRACT_CANCELLED -> Known.EXTRACT_CANCELLED + EXTRACT_ERROR -> Known.EXTRACT_ERROR + EXTRACT_PARTIAL_SUCCESS -> Known.EXTRACT_PARTIAL_SUCCESS + EXTRACT_PENDING -> Known.EXTRACT_PENDING + EXTRACT_SUCCESS -> Known.EXTRACT_SUCCESS + PARSE_CANCELLED -> Known.PARSE_CANCELLED + PARSE_ERROR -> Known.PARSE_ERROR + PARSE_PARTIAL_SUCCESS -> Known.PARSE_PARTIAL_SUCCESS + PARSE_PENDING -> Known.PARSE_PENDING + PARSE_RUNNING -> Known.PARSE_RUNNING + PARSE_SUCCESS -> Known.PARSE_SUCCESS + SHEETS_CANCELLED -> Known.SHEETS_CANCELLED + SHEETS_ERROR -> Known.SHEETS_ERROR + SHEETS_PARTIAL_SUCCESS -> Known.SHEETS_PARTIAL_SUCCESS + SHEETS_PENDING -> Known.SHEETS_PENDING + SHEETS_SUCCESS -> Known.SHEETS_SUCCESS + SPLIT_CANCELLED -> Known.SPLIT_CANCELLED + SPLIT_ERROR -> Known.SPLIT_ERROR + SPLIT_PENDING -> Known.SPLIT_PENDING + SPLIT_PROCESSING -> Known.SPLIT_PROCESSING + SPLIT_SUCCESS -> Known.SPLIT_SUCCESS + UNMAPPED_EVENT -> Known.UNMAPPED_EVENT + VERIFY_CANCELLED -> Known.VERIFY_CANCELLED + VERIFY_ERROR -> Known.VERIFY_ERROR + VERIFY_PENDING -> Known.VERIFY_PENDING + VERIFY_RUNNING -> Known.VERIFY_RUNNING + VERIFY_SUCCESS -> Known.VERIFY_SUCCESS + else -> throw LlamaCloudInvalidDataException("Unknown WebhookEvent: $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 LlamaCloudInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): WebhookEvent = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 WebhookEvent && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Custom HTTP headers sent with each webhook request (e.g. auth tokens) */ + class WebhookHeaders + @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 [WebhookHeaders]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [WebhookHeaders]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(webhookHeaders: WebhookHeaders) = apply { + additionalProperties = webhookHeaders.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 [WebhookHeaders]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): WebhookHeaders = WebhookHeaders(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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): WebhookHeaders = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 WebhookHeaders && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "WebhookHeaders{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is WebhookConfiguration && + webhookEvents == other.webhookEvents && + webhookHeaders == other.webhookHeaders && + webhookOutputFormat == other.webhookOutputFormat && + webhookSigningSecret == other.webhookSigningSecret && + webhookUrl == other.webhookUrl && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + webhookEvents, + webhookHeaders, + webhookOutputFormat, + webhookSigningSecret, + webhookUrl, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "WebhookConfiguration{webhookEvents=$webhookEvents, webhookHeaders=$webhookHeaders, webhookOutputFormat=$webhookOutputFormat, webhookSigningSecret=$webhookSigningSecret, webhookUrl=$webhookUrl, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyCreateParams && + organizationId == other.organizationId && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(organizationId, projectId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "VerifyCreateParams{organizationId=$organizationId, projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateResponse.kt new file mode 100644 index 0000000..763ad2c --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateResponse.kt @@ -0,0 +1,4698 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Response for a Verify job. */ +class VerifyCreateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val configuration: JsonField, + private val documentInputType: JsonField, + private val fileInput: JsonField, + private val projectId: JsonField, + private val status: JsonField, + private val userId: JsonField, + private val createdAt: JsonField, + private val errorMessage: JsonField, + private val result: JsonField, + private val transactionId: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("configuration") + @ExcludeMissing + configuration: JsonField = JsonMissing.of(), + @JsonProperty("document_input_type") + @ExcludeMissing + documentInputType: JsonField = JsonMissing.of(), + @JsonProperty("file_input") @ExcludeMissing fileInput: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("error_message") + @ExcludeMissing + errorMessage: JsonField = JsonMissing.of(), + @JsonProperty("result") @ExcludeMissing result: JsonField = JsonMissing.of(), + @JsonProperty("transaction_id") + @ExcludeMissing + transactionId: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + ) : this( + id, + configuration, + documentInputType, + fileInput, + projectId, + status, + userId, + createdAt, + errorMessage, + result, + transactionId, + updatedAt, + mutableMapOf(), + ) + + /** + * Unique identifier + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * Verify configuration used for this job + * + * @throws LlamaCloudInvalidDataException 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 configuration(): Configuration = configuration.getRequired("configuration") + + /** + * Type of the document input (FILE) + * + * @throws LlamaCloudInvalidDataException 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 documentInputType(): DocumentInputType = + documentInputType.getRequired("document_input_type") + + /** + * ID of the input file + * + * @throws LlamaCloudInvalidDataException 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 fileInput(): String = fileInput.getRequired("file_input") + + /** + * Project this job belongs to + * + * @throws LlamaCloudInvalidDataException 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 projectId(): String = projectId.getRequired("project_id") + + /** + * Current job status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun status(): Status = status.getRequired("status") + + /** + * User who created this job + * + * @throws LlamaCloudInvalidDataException 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 userId(): String = userId.getRequired("user_id") + + /** + * Creation datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * Error message if job failed + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun errorMessage(): Optional = errorMessage.getOptional("error_message") + + /** + * Result of a Verify (doctored-document) analysis. + * + * Raw per-signal detail (evidence list, per-family sub-scores, raw regions, forensic heatmaps) + * is available separately via the job's details endpoint. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun result(): Optional = result.getOptional("result") + + /** + * Idempotency key + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun transactionId(): Optional = transactionId.getOptional("transaction_id") + + /** + * Update datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [configuration]. + * + * Unlike [configuration], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("configuration") + @ExcludeMissing + fun _configuration(): JsonField = configuration + + /** + * Returns the raw JSON value of [documentInputType]. + * + * Unlike [documentInputType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("document_input_type") + @ExcludeMissing + fun _documentInputType(): JsonField = documentInputType + + /** + * Returns the raw JSON value of [fileInput]. + * + * Unlike [fileInput], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_input") @ExcludeMissing fun _fileInput(): JsonField = fileInput + + /** + * 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 [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [errorMessage]. + * + * Unlike [errorMessage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error_message") + @ExcludeMissing + fun _errorMessage(): JsonField = errorMessage + + /** + * Returns the raw JSON value of [result]. + * + * Unlike [result], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("result") @ExcludeMissing fun _result(): JsonField = result + + /** + * Returns the raw JSON value of [transactionId]. + * + * Unlike [transactionId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("transaction_id") + @ExcludeMissing + fun _transactionId(): JsonField = transactionId + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") + @ExcludeMissing + fun _updatedAt(): JsonField = updatedAt + + @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 [VerifyCreateResponse]. + * + * The following fields are required: + * ```java + * .id() + * .configuration() + * .documentInputType() + * .fileInput() + * .projectId() + * .status() + * .userId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyCreateResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var configuration: JsonField? = null + private var documentInputType: JsonField? = null + private var fileInput: JsonField? = null + private var projectId: JsonField? = null + private var status: JsonField? = null + private var userId: JsonField? = null + private var createdAt: JsonField = JsonMissing.of() + private var errorMessage: JsonField = JsonMissing.of() + private var result: JsonField = JsonMissing.of() + private var transactionId: JsonField = JsonMissing.of() + private var updatedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(verifyCreateResponse: VerifyCreateResponse) = apply { + id = verifyCreateResponse.id + configuration = verifyCreateResponse.configuration + documentInputType = verifyCreateResponse.documentInputType + fileInput = verifyCreateResponse.fileInput + projectId = verifyCreateResponse.projectId + status = verifyCreateResponse.status + userId = verifyCreateResponse.userId + createdAt = verifyCreateResponse.createdAt + errorMessage = verifyCreateResponse.errorMessage + result = verifyCreateResponse.result + transactionId = verifyCreateResponse.transactionId + updatedAt = verifyCreateResponse.updatedAt + additionalProperties = verifyCreateResponse.additionalProperties.toMutableMap() + } + + /** Unique identifier */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Verify configuration used for this job */ + fun configuration(configuration: Configuration) = configuration(JsonField.of(configuration)) + + /** + * Sets [Builder.configuration] to an arbitrary JSON value. + * + * You should usually call [Builder.configuration] with a well-typed [Configuration] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun configuration(configuration: JsonField) = apply { + this.configuration = configuration + } + + /** Type of the document input (FILE) */ + fun documentInputType(documentInputType: DocumentInputType) = + documentInputType(JsonField.of(documentInputType)) + + /** + * Sets [Builder.documentInputType] to an arbitrary JSON value. + * + * You should usually call [Builder.documentInputType] with a well-typed [DocumentInputType] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun documentInputType(documentInputType: JsonField) = apply { + this.documentInputType = documentInputType + } + + /** ID of the input file */ + fun fileInput(fileInput: String) = fileInput(JsonField.of(fileInput)) + + /** + * Sets [Builder.fileInput] to an arbitrary JSON value. + * + * You should usually call [Builder.fileInput] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun fileInput(fileInput: JsonField) = apply { this.fileInput = fileInput } + + /** Project this job belongs to */ + 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 } + + /** Current job status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED */ + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** User who created this job */ + fun userId(userId: String) = userId(JsonField.of(userId)) + + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } + + /** Creation datetime */ + fun createdAt(createdAt: OffsetDateTime?) = createdAt(JsonField.ofNullable(createdAt)) + + /** Alias for calling [Builder.createdAt] with `createdAt.orElse(null)`. */ + fun createdAt(createdAt: Optional) = createdAt(createdAt.getOrNull()) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Error message if job failed */ + fun errorMessage(errorMessage: String?) = errorMessage(JsonField.ofNullable(errorMessage)) + + /** Alias for calling [Builder.errorMessage] with `errorMessage.orElse(null)`. */ + fun errorMessage(errorMessage: Optional) = errorMessage(errorMessage.getOrNull()) + + /** + * Sets [Builder.errorMessage] to an arbitrary JSON value. + * + * You should usually call [Builder.errorMessage] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun errorMessage(errorMessage: JsonField) = apply { + this.errorMessage = errorMessage + } + + /** + * Result of a Verify (doctored-document) analysis. + * + * Raw per-signal detail (evidence list, per-family sub-scores, raw regions, forensic + * heatmaps) is available separately via the job's details endpoint. + */ + fun result(result: Result?) = result(JsonField.ofNullable(result)) + + /** Alias for calling [Builder.result] with `result.orElse(null)`. */ + fun result(result: Optional) = result(result.getOrNull()) + + /** + * Sets [Builder.result] to an arbitrary JSON value. + * + * You should usually call [Builder.result] with a well-typed [Result] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun result(result: JsonField) = apply { this.result = result } + + /** Idempotency key */ + fun transactionId(transactionId: String?) = + transactionId(JsonField.ofNullable(transactionId)) + + /** Alias for calling [Builder.transactionId] with `transactionId.orElse(null)`. */ + fun transactionId(transactionId: Optional) = + transactionId(transactionId.getOrNull()) + + /** + * Sets [Builder.transactionId] to an arbitrary JSON value. + * + * You should usually call [Builder.transactionId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun transactionId(transactionId: JsonField) = apply { + this.transactionId = transactionId + } + + /** Update datetime */ + fun updatedAt(updatedAt: OffsetDateTime?) = updatedAt(JsonField.ofNullable(updatedAt)) + + /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ + fun updatedAt(updatedAt: Optional) = updatedAt(updatedAt.getOrNull()) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + 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 [VerifyCreateResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .configuration() + * .documentInputType() + * .fileInput() + * .projectId() + * .status() + * .userId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VerifyCreateResponse = + VerifyCreateResponse( + checkRequired("id", id), + checkRequired("configuration", configuration), + checkRequired("documentInputType", documentInputType), + checkRequired("fileInput", fileInput), + checkRequired("projectId", projectId), + checkRequired("status", status), + checkRequired("userId", userId), + createdAt, + errorMessage, + result, + transactionId, + updatedAt, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): VerifyCreateResponse = apply { + if (validated) { + return@apply + } + + id() + configuration().validate() + documentInputType().validate() + fileInput() + projectId() + status().validate() + userId() + createdAt() + errorMessage() + result().ifPresent { it.validate() } + transactionId() + updatedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (configuration.asKnown().getOrNull()?.validity() ?: 0) + + (documentInputType.asKnown().getOrNull()?.validity() ?: 0) + + (if (fileInput.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (errorMessage.asKnown().isPresent) 1 else 0) + + (result.asKnown().getOrNull()?.validity() ?: 0) + + (if (transactionId.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + /** Verify configuration used for this job */ + class Configuration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val targetPages: JsonField, + private val tier: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("target_pages") + @ExcludeMissing + targetPages: JsonField = JsonMissing.of(), + @JsonProperty("tier") @ExcludeMissing tier: JsonField = JsonMissing.of(), + ) : this(targetPages, tier, mutableMapOf()) + + /** + * Comma-separated page numbers or ranges to analyze (1-based). Omit to analyze all pages. + * Ignored for non-PDF inputs. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun targetPages(): Optional = targetPages.getOptional("target_pages") + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, content + * integrity, container structure, pixel statistics); 'agentic' (default) runs the full + * pipeline including the learned detectors and the semantic review pass. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tier(): Optional = tier.getOptional("tier") + + /** + * Returns the raw JSON value of [targetPages]. + * + * Unlike [targetPages], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("target_pages") + @ExcludeMissing + fun _targetPages(): JsonField = targetPages + + /** + * Returns the raw JSON value of [tier]. + * + * Unlike [tier], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tier") @ExcludeMissing fun _tier(): JsonField = tier + + @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 [Configuration]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Configuration]. */ + class Builder internal constructor() { + + private var targetPages: JsonField = JsonMissing.of() + private var tier: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(configuration: Configuration) = apply { + targetPages = configuration.targetPages + tier = configuration.tier + additionalProperties = configuration.additionalProperties.toMutableMap() + } + + /** + * Comma-separated page numbers or ranges to analyze (1-based). Omit to analyze all + * pages. Ignored for non-PDF inputs. + */ + fun targetPages(targetPages: String?) = targetPages(JsonField.ofNullable(targetPages)) + + /** Alias for calling [Builder.targetPages] with `targetPages.orElse(null)`. */ + fun targetPages(targetPages: Optional) = targetPages(targetPages.getOrNull()) + + /** + * Sets [Builder.targetPages] to an arbitrary JSON value. + * + * You should usually call [Builder.targetPages] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun targetPages(targetPages: JsonField) = apply { + this.targetPages = targetPages + } + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, + * content integrity, container structure, pixel statistics); 'agentic' (default) runs + * the full pipeline including the learned detectors and the semantic review pass. + */ + fun tier(tier: Tier) = tier(JsonField.of(tier)) + + /** + * Sets [Builder.tier] to an arbitrary JSON value. + * + * You should usually call [Builder.tier] with a well-typed [Tier] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tier(tier: JsonField) = apply { this.tier = tier } + + 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 [Configuration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Configuration = + Configuration(targetPages, tier, 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Configuration = apply { + if (validated) { + return@apply + } + + targetPages() + tier().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (targetPages.asKnown().isPresent) 1 else 0) + + (tier.asKnown().getOrNull()?.validity() ?: 0) + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, content + * integrity, container structure, pixel statistics); 'agentic' (default) runs the full + * pipeline including the learned detectors and the semantic review pass. + */ + class Tier @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 AGENTIC = of("agentic") + + @JvmField val FAST = of("fast") + + @JvmStatic fun of(value: String) = Tier(JsonField.of(value)) + } + + /** An enum containing [Tier]'s known values. */ + enum class Known { + AGENTIC, + FAST, + } + + /** + * An enum containing [Tier]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Tier] 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 { + AGENTIC, + FAST, + /** An enum member indicating that [Tier] 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) { + AGENTIC -> Value.AGENTIC + FAST -> Value.FAST + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + AGENTIC -> Known.AGENTIC + FAST -> Known.FAST + else -> throw LlamaCloudInvalidDataException("Unknown Tier: $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 LlamaCloudInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Tier && 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 Configuration && + targetPages == other.targetPages && + tier == other.tier && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(targetPages, tier, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Configuration{targetPages=$targetPages, tier=$tier, additionalProperties=$additionalProperties}" + } + + /** Type of the document input (FILE) */ + class DocumentInputType @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 FILE_ID = of("file_id") + + @JvmField val PARSE_JOB_ID = of("parse_job_id") + + @JvmField val URL = of("url") + + @JvmStatic fun of(value: String) = DocumentInputType(JsonField.of(value)) + } + + /** An enum containing [DocumentInputType]'s known values. */ + enum class Known { + FILE_ID, + PARSE_JOB_ID, + URL, + } + + /** + * An enum containing [DocumentInputType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [DocumentInputType] 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 { + FILE_ID, + PARSE_JOB_ID, + URL, + /** + * An enum member indicating that [DocumentInputType] 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) { + FILE_ID -> Value.FILE_ID + PARSE_JOB_ID -> Value.PARSE_JOB_ID + URL -> Value.URL + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + FILE_ID -> Known.FILE_ID + PARSE_JOB_ID -> Known.PARSE_JOB_ID + URL -> Known.URL + else -> throw LlamaCloudInvalidDataException("Unknown DocumentInputType: $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 LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): DocumentInputType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 DocumentInputType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Current job status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED */ + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val CANCELLED = of("CANCELLED") + + @JvmField val COMPLETED = of("COMPLETED") + + @JvmField val FAILED = of("FAILED") + + @JvmField val PENDING = of("PENDING") + + @JvmField val RUNNING = of("RUNNING") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + CANCELLED, + COMPLETED, + FAILED, + PENDING, + RUNNING, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + CANCELLED, + COMPLETED, + FAILED, + PENDING, + RUNNING, + /** An enum member indicating that [Status] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + CANCELLED -> Value.CANCELLED + COMPLETED -> Value.COMPLETED + FAILED -> Value.FAILED + PENDING -> Value.PENDING + RUNNING -> Value.RUNNING + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + CANCELLED -> Known.CANCELLED + COMPLETED -> Known.COMPLETED + FAILED -> Known.FAILED + PENDING -> Known.PENDING + RUNNING -> Known.RUNNING + else -> throw LlamaCloudInvalidDataException("Unknown Status: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Status = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Status && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * Result of a Verify (doctored-document) analysis. + * + * Raw per-signal detail (evidence list, per-family sub-scores, raw regions, forensic heatmaps) + * is available separately via the job's details endpoint. + */ + class Result + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val detectorVersion: JsonField, + private val overallScore: JsonField, + private val verdict: JsonField, + private val compositeScores: JsonField, + private val confidence: JsonField, + private val error: JsonField, + private val pageCount: JsonField, + private val pageDimensions: JsonField>, + private val reasoning: JsonField, + private val suspectRegions: JsonField>, + private val syntheticScore: JsonField, + private val tamperingScore: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("detector_version") + @ExcludeMissing + detectorVersion: JsonField = JsonMissing.of(), + @JsonProperty("overall_score") + @ExcludeMissing + overallScore: JsonField = JsonMissing.of(), + @JsonProperty("verdict") @ExcludeMissing verdict: JsonField = JsonMissing.of(), + @JsonProperty("composite_scores") + @ExcludeMissing + compositeScores: JsonField = JsonMissing.of(), + @JsonProperty("confidence") + @ExcludeMissing + confidence: JsonField = JsonMissing.of(), + @JsonProperty("error") @ExcludeMissing error: JsonField = JsonMissing.of(), + @JsonProperty("page_count") + @ExcludeMissing + pageCount: JsonField = JsonMissing.of(), + @JsonProperty("page_dimensions") + @ExcludeMissing + pageDimensions: JsonField> = JsonMissing.of(), + @JsonProperty("reasoning") + @ExcludeMissing + reasoning: JsonField = JsonMissing.of(), + @JsonProperty("suspect_regions") + @ExcludeMissing + suspectRegions: JsonField> = JsonMissing.of(), + @JsonProperty("synthetic_score") + @ExcludeMissing + syntheticScore: JsonField = JsonMissing.of(), + @JsonProperty("tampering_score") + @ExcludeMissing + tamperingScore: JsonField = JsonMissing.of(), + ) : this( + detectorVersion, + overallScore, + verdict, + compositeScores, + confidence, + error, + pageCount, + pageDimensions, + reasoning, + suspectRegions, + syntheticScore, + tamperingScore, + mutableMapOf(), + ) + + /** + * Version of the detector that produced the result + * + * @throws LlamaCloudInvalidDataException 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 detectorVersion(): String = detectorVersion.getRequired("detector_version") + + /** + * Overall doctoring likelihood (0 to 1) + * + * @throws LlamaCloudInvalidDataException 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 overallScore(): Double = overallScore.getRequired("overall_score") + + /** + * Overall verdict for the document + * + * @throws LlamaCloudInvalidDataException 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 verdict(): Verdict = verdict.getRequired("verdict") + + /** + * Composite scores, each answering one question about the document + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun compositeScores(): Optional = + compositeScores.getOptional("composite_scores") + + /** + * Confidence in the verdict (0 to 1): how firmly the detected signals support the verdict + * bucket, independent of the doctoring likelihood itself + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun confidence(): Optional = confidence.getOptional("confidence") + + /** + * Error detail when the analysis could not complete + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun error(): Optional = error.getOptional("error") + + /** + * Number of analysed pages (1 for images/docx) + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun pageCount(): Optional = pageCount.getOptional("page_count") + + /** + * Rendered pixel size per page, so region bboxes can be scaled onto the page + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun pageDimensions(): Optional> = + pageDimensions.getOptional("page_dimensions") + + /** + * Explanation of the verdict + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun reasoning(): Optional = reasoning.getOptional("reasoning") + + /** + * Regions that led to the suspected fraud, ranked most-suspect first, each with an + * explanation of what makes it suspect + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun suspectRegions(): Optional> = + suspectRegions.getOptional("suspect_regions") + + /** + * Likelihood (0 to 1) that the document is wholly generated or fabricated rather than a + * capture of a real document. Null for jobs completed before this score was introduced + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun syntheticScore(): Optional = syntheticScore.getOptional("synthetic_score") + + /** + * Likelihood (0 to 1) that a real captured document was locally edited — a genuine capture + * with regions altered after the fact. Null for jobs completed before this score was + * introduced + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tamperingScore(): Optional = tamperingScore.getOptional("tampering_score") + + /** + * Returns the raw JSON value of [detectorVersion]. + * + * Unlike [detectorVersion], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("detector_version") + @ExcludeMissing + fun _detectorVersion(): JsonField = detectorVersion + + /** + * Returns the raw JSON value of [overallScore]. + * + * Unlike [overallScore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("overall_score") + @ExcludeMissing + fun _overallScore(): JsonField = overallScore + + /** + * Returns the raw JSON value of [verdict]. + * + * Unlike [verdict], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("verdict") @ExcludeMissing fun _verdict(): JsonField = verdict + + /** + * Returns the raw JSON value of [compositeScores]. + * + * Unlike [compositeScores], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("composite_scores") + @ExcludeMissing + fun _compositeScores(): JsonField = compositeScores + + /** + * Returns the raw JSON value of [confidence]. + * + * Unlike [confidence], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("confidence") + @ExcludeMissing + fun _confidence(): JsonField = confidence + + /** + * Returns the raw JSON value of [error]. + * + * Unlike [error], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error") @ExcludeMissing fun _error(): JsonField = error + + /** + * Returns the raw JSON value of [pageCount]. + * + * Unlike [pageCount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page_count") @ExcludeMissing fun _pageCount(): JsonField = pageCount + + /** + * Returns the raw JSON value of [pageDimensions]. + * + * Unlike [pageDimensions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("page_dimensions") + @ExcludeMissing + fun _pageDimensions(): JsonField> = pageDimensions + + /** + * Returns the raw JSON value of [reasoning]. + * + * Unlike [reasoning], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("reasoning") @ExcludeMissing fun _reasoning(): JsonField = reasoning + + /** + * Returns the raw JSON value of [suspectRegions]. + * + * Unlike [suspectRegions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("suspect_regions") + @ExcludeMissing + fun _suspectRegions(): JsonField> = suspectRegions + + /** + * Returns the raw JSON value of [syntheticScore]. + * + * Unlike [syntheticScore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("synthetic_score") + @ExcludeMissing + fun _syntheticScore(): JsonField = syntheticScore + + /** + * Returns the raw JSON value of [tamperingScore]. + * + * Unlike [tamperingScore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tampering_score") + @ExcludeMissing + fun _tamperingScore(): JsonField = tamperingScore + + @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 [Result]. + * + * The following fields are required: + * ```java + * .detectorVersion() + * .overallScore() + * .verdict() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Result]. */ + class Builder internal constructor() { + + private var detectorVersion: JsonField? = null + private var overallScore: JsonField? = null + private var verdict: JsonField? = null + private var compositeScores: JsonField = JsonMissing.of() + private var confidence: JsonField = JsonMissing.of() + private var error: JsonField = JsonMissing.of() + private var pageCount: JsonField = JsonMissing.of() + private var pageDimensions: JsonField>? = null + private var reasoning: JsonField = JsonMissing.of() + private var suspectRegions: JsonField>? = null + private var syntheticScore: JsonField = JsonMissing.of() + private var tamperingScore: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(result: Result) = apply { + detectorVersion = result.detectorVersion + overallScore = result.overallScore + verdict = result.verdict + compositeScores = result.compositeScores + confidence = result.confidence + error = result.error + pageCount = result.pageCount + pageDimensions = result.pageDimensions.map { it.toMutableList() } + reasoning = result.reasoning + suspectRegions = result.suspectRegions.map { it.toMutableList() } + syntheticScore = result.syntheticScore + tamperingScore = result.tamperingScore + additionalProperties = result.additionalProperties.toMutableMap() + } + + /** Version of the detector that produced the result */ + fun detectorVersion(detectorVersion: String) = + detectorVersion(JsonField.of(detectorVersion)) + + /** + * Sets [Builder.detectorVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.detectorVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun detectorVersion(detectorVersion: JsonField) = apply { + this.detectorVersion = detectorVersion + } + + /** Overall doctoring likelihood (0 to 1) */ + fun overallScore(overallScore: Double) = overallScore(JsonField.of(overallScore)) + + /** + * Sets [Builder.overallScore] to an arbitrary JSON value. + * + * You should usually call [Builder.overallScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun overallScore(overallScore: JsonField) = apply { + this.overallScore = overallScore + } + + /** Overall verdict for the document */ + fun verdict(verdict: Verdict) = verdict(JsonField.of(verdict)) + + /** + * Sets [Builder.verdict] to an arbitrary JSON value. + * + * You should usually call [Builder.verdict] with a well-typed [Verdict] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun verdict(verdict: JsonField) = apply { this.verdict = verdict } + + /** Composite scores, each answering one question about the document */ + fun compositeScores(compositeScores: CompositeScores) = + compositeScores(JsonField.of(compositeScores)) + + /** + * Sets [Builder.compositeScores] to an arbitrary JSON value. + * + * You should usually call [Builder.compositeScores] with a well-typed [CompositeScores] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun compositeScores(compositeScores: JsonField) = apply { + this.compositeScores = compositeScores + } + + /** + * Confidence in the verdict (0 to 1): how firmly the detected signals support the + * verdict bucket, independent of the doctoring likelihood itself + */ + fun confidence(confidence: Double) = confidence(JsonField.of(confidence)) + + /** + * Sets [Builder.confidence] to an arbitrary JSON value. + * + * You should usually call [Builder.confidence] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun confidence(confidence: JsonField) = apply { this.confidence = confidence } + + /** Error detail when the analysis could not complete */ + fun error(error: String?) = error(JsonField.ofNullable(error)) + + /** Alias for calling [Builder.error] with `error.orElse(null)`. */ + fun error(error: Optional) = error(error.getOrNull()) + + /** + * Sets [Builder.error] to an arbitrary JSON value. + * + * You should usually call [Builder.error] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun error(error: JsonField) = apply { this.error = error } + + /** Number of analysed pages (1 for images/docx) */ + fun pageCount(pageCount: Long) = pageCount(JsonField.of(pageCount)) + + /** + * Sets [Builder.pageCount] to an arbitrary JSON value. + * + * You should usually call [Builder.pageCount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pageCount(pageCount: JsonField) = apply { this.pageCount = pageCount } + + /** Rendered pixel size per page, so region bboxes can be scaled onto the page */ + fun pageDimensions(pageDimensions: List) = + pageDimensions(JsonField.of(pageDimensions)) + + /** + * Sets [Builder.pageDimensions] to an arbitrary JSON value. + * + * You should usually call [Builder.pageDimensions] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun pageDimensions(pageDimensions: JsonField>) = apply { + this.pageDimensions = pageDimensions.map { it.toMutableList() } + } + + /** + * Adds a single [PageDimension] to [pageDimensions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPageDimension(pageDimension: PageDimension) = apply { + pageDimensions = + (pageDimensions ?: JsonField.of(mutableListOf())).also { + checkKnown("pageDimensions", it).add(pageDimension) + } + } + + /** Explanation of the verdict */ + fun reasoning(reasoning: String) = reasoning(JsonField.of(reasoning)) + + /** + * Sets [Builder.reasoning] to an arbitrary JSON value. + * + * You should usually call [Builder.reasoning] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun reasoning(reasoning: JsonField) = apply { this.reasoning = reasoning } + + /** + * Regions that led to the suspected fraud, ranked most-suspect first, each with an + * explanation of what makes it suspect + */ + fun suspectRegions(suspectRegions: List) = + suspectRegions(JsonField.of(suspectRegions)) + + /** + * Sets [Builder.suspectRegions] to an arbitrary JSON value. + * + * You should usually call [Builder.suspectRegions] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun suspectRegions(suspectRegions: JsonField>) = apply { + this.suspectRegions = suspectRegions.map { it.toMutableList() } + } + + /** + * Adds a single [SuspectRegion] to [suspectRegions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSuspectRegion(suspectRegion: SuspectRegion) = apply { + suspectRegions = + (suspectRegions ?: JsonField.of(mutableListOf())).also { + checkKnown("suspectRegions", it).add(suspectRegion) + } + } + + /** + * Likelihood (0 to 1) that the document is wholly generated or fabricated rather than a + * capture of a real document. Null for jobs completed before this score was introduced + */ + fun syntheticScore(syntheticScore: Double?) = + syntheticScore(JsonField.ofNullable(syntheticScore)) + + /** + * Alias for [Builder.syntheticScore]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun syntheticScore(syntheticScore: Double) = syntheticScore(syntheticScore as Double?) + + /** Alias for calling [Builder.syntheticScore] with `syntheticScore.orElse(null)`. */ + fun syntheticScore(syntheticScore: Optional) = + syntheticScore(syntheticScore.getOrNull()) + + /** + * Sets [Builder.syntheticScore] to an arbitrary JSON value. + * + * You should usually call [Builder.syntheticScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun syntheticScore(syntheticScore: JsonField) = apply { + this.syntheticScore = syntheticScore + } + + /** + * Likelihood (0 to 1) that a real captured document was locally edited — a genuine + * capture with regions altered after the fact. Null for jobs completed before this + * score was introduced + */ + fun tamperingScore(tamperingScore: Double?) = + tamperingScore(JsonField.ofNullable(tamperingScore)) + + /** + * Alias for [Builder.tamperingScore]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun tamperingScore(tamperingScore: Double) = tamperingScore(tamperingScore as Double?) + + /** Alias for calling [Builder.tamperingScore] with `tamperingScore.orElse(null)`. */ + fun tamperingScore(tamperingScore: Optional) = + tamperingScore(tamperingScore.getOrNull()) + + /** + * Sets [Builder.tamperingScore] to an arbitrary JSON value. + * + * You should usually call [Builder.tamperingScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tamperingScore(tamperingScore: JsonField) = apply { + this.tamperingScore = tamperingScore + } + + 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 [Result]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .detectorVersion() + * .overallScore() + * .verdict() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Result = + Result( + checkRequired("detectorVersion", detectorVersion), + checkRequired("overallScore", overallScore), + checkRequired("verdict", verdict), + compositeScores, + confidence, + error, + pageCount, + (pageDimensions ?: JsonMissing.of()).map { it.toImmutable() }, + reasoning, + (suspectRegions ?: JsonMissing.of()).map { it.toImmutable() }, + syntheticScore, + tamperingScore, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Result = apply { + if (validated) { + return@apply + } + + detectorVersion() + overallScore() + verdict().validate() + compositeScores().ifPresent { it.validate() } + confidence() + error() + pageCount() + pageDimensions().ifPresent { it.forEach { it.validate() } } + reasoning() + suspectRegions().ifPresent { it.forEach { it.validate() } } + syntheticScore() + tamperingScore() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (detectorVersion.asKnown().isPresent) 1 else 0) + + (if (overallScore.asKnown().isPresent) 1 else 0) + + (verdict.asKnown().getOrNull()?.validity() ?: 0) + + (compositeScores.asKnown().getOrNull()?.validity() ?: 0) + + (if (confidence.asKnown().isPresent) 1 else 0) + + (if (error.asKnown().isPresent) 1 else 0) + + (if (pageCount.asKnown().isPresent) 1 else 0) + + (pageDimensions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (reasoning.asKnown().isPresent) 1 else 0) + + (suspectRegions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (syntheticScore.asKnown().isPresent) 1 else 0) + + (if (tamperingScore.asKnown().isPresent) 1 else 0) + + /** Overall verdict for the document */ + class Verdict @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 AUTHENTIC = of("AUTHENTIC") + + @JvmField val DOCTORED = of("DOCTORED") + + @JvmField val LIKELY_DOCTORED = of("LIKELY_DOCTORED") + + @JvmField val NO_STRONG_SIGNAL = of("NO_STRONG_SIGNAL") + + @JvmField val SUSPICIOUS = of("SUSPICIOUS") + + @JvmStatic fun of(value: String) = Verdict(JsonField.of(value)) + } + + /** An enum containing [Verdict]'s known values. */ + enum class Known { + AUTHENTIC, + DOCTORED, + LIKELY_DOCTORED, + NO_STRONG_SIGNAL, + SUSPICIOUS, + } + + /** + * An enum containing [Verdict]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Verdict] 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 { + AUTHENTIC, + DOCTORED, + LIKELY_DOCTORED, + NO_STRONG_SIGNAL, + SUSPICIOUS, + /** + * An enum member indicating that [Verdict] 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) { + AUTHENTIC -> Value.AUTHENTIC + DOCTORED -> Value.DOCTORED + LIKELY_DOCTORED -> Value.LIKELY_DOCTORED + NO_STRONG_SIGNAL -> Value.NO_STRONG_SIGNAL + SUSPICIOUS -> Value.SUSPICIOUS + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + AUTHENTIC -> Known.AUTHENTIC + DOCTORED -> Known.DOCTORED + LIKELY_DOCTORED -> Known.LIKELY_DOCTORED + NO_STRONG_SIGNAL -> Known.NO_STRONG_SIGNAL + SUSPICIOUS -> Known.SUSPICIOUS + else -> throw LlamaCloudInvalidDataException("Unknown Verdict: $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 LlamaCloudInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Verdict = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Verdict && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Composite scores, each answering one question about the document */ + class CompositeScores + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val aiGenerated: JsonField, + private val documentCoherence: JsonField, + private val documentMetadata: JsonField, + private val knownFraud: JsonField, + private val manuallyEdited: JsonField, + private val recapture: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("ai_generated") + @ExcludeMissing + aiGenerated: JsonField = JsonMissing.of(), + @JsonProperty("document_coherence") + @ExcludeMissing + documentCoherence: JsonField = JsonMissing.of(), + @JsonProperty("document_metadata") + @ExcludeMissing + documentMetadata: JsonField = JsonMissing.of(), + @JsonProperty("known_fraud") + @ExcludeMissing + knownFraud: JsonField = JsonMissing.of(), + @JsonProperty("manually_edited") + @ExcludeMissing + manuallyEdited: JsonField = JsonMissing.of(), + @JsonProperty("recapture") + @ExcludeMissing + recapture: JsonField = JsonMissing.of(), + ) : this( + aiGenerated, + documentCoherence, + documentMetadata, + knownFraud, + manuallyEdited, + recapture, + mutableMapOf(), + ) + + /** + * Was this content synthesized by a generative model? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun aiGenerated(): Optional = aiGenerated.getOptional("ai_generated") + + /** + * Does the document's content agree with itself (checksums, arithmetic, + * machine-readable zones)? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun documentCoherence(): Optional = + documentCoherence.getOptional("document_coherence") + + /** + * Does the file's provenance / toolchain history look suspicious? Advisory: + * individually weak workflow-hygiene signals + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun documentMetadata(): Optional = + documentMetadata.getOptional("document_metadata") + + /** + * Has this asset (or its template) been seen in fraud before? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun knownFraud(): Optional = knownFraud.getOptional("known_fraud") + + /** + * Was this document altered after creation (splice, retype, redact, inpaint)? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun manuallyEdited(): Optional = + manuallyEdited.getOptional("manually_edited") + + /** + * Was the document captured through a channel that destroys forensic evidence (photo of + * a screen, print-then-rescan)? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun recapture(): Optional = recapture.getOptional("recapture") + + /** + * Returns the raw JSON value of [aiGenerated]. + * + * Unlike [aiGenerated], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("ai_generated") + @ExcludeMissing + fun _aiGenerated(): JsonField = aiGenerated + + /** + * Returns the raw JSON value of [documentCoherence]. + * + * Unlike [documentCoherence], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("document_coherence") + @ExcludeMissing + fun _documentCoherence(): JsonField = documentCoherence + + /** + * Returns the raw JSON value of [documentMetadata]. + * + * Unlike [documentMetadata], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("document_metadata") + @ExcludeMissing + fun _documentMetadata(): JsonField = documentMetadata + + /** + * Returns the raw JSON value of [knownFraud]. + * + * Unlike [knownFraud], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("known_fraud") + @ExcludeMissing + fun _knownFraud(): JsonField = knownFraud + + /** + * Returns the raw JSON value of [manuallyEdited]. + * + * Unlike [manuallyEdited], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("manually_edited") + @ExcludeMissing + fun _manuallyEdited(): JsonField = manuallyEdited + + /** + * Returns the raw JSON value of [recapture]. + * + * Unlike [recapture], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("recapture") + @ExcludeMissing + fun _recapture(): JsonField = recapture + + @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 [CompositeScores]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CompositeScores]. */ + class Builder internal constructor() { + + private var aiGenerated: JsonField = JsonMissing.of() + private var documentCoherence: JsonField = JsonMissing.of() + private var documentMetadata: JsonField = JsonMissing.of() + private var knownFraud: JsonField = JsonMissing.of() + private var manuallyEdited: JsonField = JsonMissing.of() + private var recapture: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(compositeScores: CompositeScores) = apply { + aiGenerated = compositeScores.aiGenerated + documentCoherence = compositeScores.documentCoherence + documentMetadata = compositeScores.documentMetadata + knownFraud = compositeScores.knownFraud + manuallyEdited = compositeScores.manuallyEdited + recapture = compositeScores.recapture + additionalProperties = compositeScores.additionalProperties.toMutableMap() + } + + /** Was this content synthesized by a generative model? */ + fun aiGenerated(aiGenerated: AiGenerated) = aiGenerated(JsonField.of(aiGenerated)) + + /** + * Sets [Builder.aiGenerated] to an arbitrary JSON value. + * + * You should usually call [Builder.aiGenerated] with a well-typed [AiGenerated] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun aiGenerated(aiGenerated: JsonField) = apply { + this.aiGenerated = aiGenerated + } + + /** + * Does the document's content agree with itself (checksums, arithmetic, + * machine-readable zones)? + */ + fun documentCoherence(documentCoherence: DocumentCoherence) = + documentCoherence(JsonField.of(documentCoherence)) + + /** + * Sets [Builder.documentCoherence] to an arbitrary JSON value. + * + * You should usually call [Builder.documentCoherence] with a well-typed + * [DocumentCoherence] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun documentCoherence(documentCoherence: JsonField) = apply { + this.documentCoherence = documentCoherence + } + + /** + * Does the file's provenance / toolchain history look suspicious? Advisory: + * individually weak workflow-hygiene signals + */ + fun documentMetadata(documentMetadata: DocumentMetadata) = + documentMetadata(JsonField.of(documentMetadata)) + + /** + * Sets [Builder.documentMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.documentMetadata] with a well-typed + * [DocumentMetadata] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun documentMetadata(documentMetadata: JsonField) = apply { + this.documentMetadata = documentMetadata + } + + /** Has this asset (or its template) been seen in fraud before? */ + fun knownFraud(knownFraud: KnownFraud) = knownFraud(JsonField.of(knownFraud)) + + /** + * Sets [Builder.knownFraud] to an arbitrary JSON value. + * + * You should usually call [Builder.knownFraud] with a well-typed [KnownFraud] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun knownFraud(knownFraud: JsonField) = apply { + this.knownFraud = knownFraud + } + + /** Was this document altered after creation (splice, retype, redact, inpaint)? */ + fun manuallyEdited(manuallyEdited: ManuallyEdited) = + manuallyEdited(JsonField.of(manuallyEdited)) + + /** + * Sets [Builder.manuallyEdited] to an arbitrary JSON value. + * + * You should usually call [Builder.manuallyEdited] with a well-typed + * [ManuallyEdited] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun manuallyEdited(manuallyEdited: JsonField) = apply { + this.manuallyEdited = manuallyEdited + } + + /** + * Was the document captured through a channel that destroys forensic evidence + * (photo of a screen, print-then-rescan)? + */ + fun recapture(recapture: Recapture) = recapture(JsonField.of(recapture)) + + /** + * Sets [Builder.recapture] to an arbitrary JSON value. + * + * You should usually call [Builder.recapture] with a well-typed [Recapture] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun recapture(recapture: JsonField) = apply { + this.recapture = recapture + } + + 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 [CompositeScores]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CompositeScores = + CompositeScores( + aiGenerated, + documentCoherence, + documentMetadata, + knownFraud, + manuallyEdited, + recapture, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): CompositeScores = apply { + if (validated) { + return@apply + } + + aiGenerated().ifPresent { it.validate() } + documentCoherence().ifPresent { it.validate() } + documentMetadata().ifPresent { it.validate() } + knownFraud().ifPresent { it.validate() } + manuallyEdited().ifPresent { it.validate() } + recapture().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (aiGenerated.asKnown().getOrNull()?.validity() ?: 0) + + (documentCoherence.asKnown().getOrNull()?.validity() ?: 0) + + (documentMetadata.asKnown().getOrNull()?.validity() ?: 0) + + (knownFraud.asKnown().getOrNull()?.validity() ?: 0) + + (manuallyEdited.asKnown().getOrNull()?.validity() ?: 0) + + (recapture.asKnown().getOrNull()?.validity() ?: 0) + + /** Was this content synthesized by a generative model? */ + class AiGenerated + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [AiGenerated]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AiGenerated]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(aiGenerated: AiGenerated) = apply { + applicable = aiGenerated.applicable + score = aiGenerated.score + additionalProperties = aiGenerated.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [AiGenerated]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): AiGenerated = + AiGenerated(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AiGenerated = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AiGenerated && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AiGenerated{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Does the document's content agree with itself (checksums, arithmetic, + * machine-readable zones)? + */ + class DocumentCoherence + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 + * [DocumentCoherence]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DocumentCoherence]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(documentCoherence: DocumentCoherence) = apply { + applicable = documentCoherence.applicable + score = documentCoherence.score + additionalProperties = documentCoherence.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [DocumentCoherence]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DocumentCoherence = + DocumentCoherence(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): DocumentCoherence = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DocumentCoherence && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DocumentCoherence{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Does the file's provenance / toolchain history look suspicious? Advisory: + * individually weak workflow-hygiene signals + */ + class DocumentMetadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [DocumentMetadata]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DocumentMetadata]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(documentMetadata: DocumentMetadata) = apply { + applicable = documentMetadata.applicable + score = documentMetadata.score + additionalProperties = documentMetadata.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [DocumentMetadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DocumentMetadata = + DocumentMetadata(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): DocumentMetadata = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DocumentMetadata && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DocumentMetadata{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** Has this asset (or its template) been seen in fraud before? */ + class KnownFraud + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [KnownFraud]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [KnownFraud]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(knownFraud: KnownFraud) = apply { + applicable = knownFraud.applicable + score = knownFraud.score + additionalProperties = knownFraud.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [KnownFraud]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): KnownFraud = + KnownFraud(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): KnownFraud = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is KnownFraud && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "KnownFraud{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** Was this document altered after creation (splice, retype, redact, inpaint)? */ + class ManuallyEdited + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [ManuallyEdited]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ManuallyEdited]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(manuallyEdited: ManuallyEdited) = apply { + applicable = manuallyEdited.applicable + score = manuallyEdited.score + additionalProperties = manuallyEdited.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [ManuallyEdited]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ManuallyEdited = + ManuallyEdited(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): ManuallyEdited = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ManuallyEdited && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ManuallyEdited{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Was the document captured through a channel that destroys forensic evidence (photo of + * a screen, print-then-rescan)? + */ + class Recapture + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [Recapture]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Recapture]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(recapture: Recapture) = apply { + applicable = recapture.applicable + score = recapture.score + additionalProperties = recapture.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [Recapture]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Recapture = + Recapture(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Recapture = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Recapture && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Recapture{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CompositeScores && + aiGenerated == other.aiGenerated && + documentCoherence == other.documentCoherence && + documentMetadata == other.documentMetadata && + knownFraud == other.knownFraud && + manuallyEdited == other.manuallyEdited && + recapture == other.recapture && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + aiGenerated, + documentCoherence, + documentMetadata, + knownFraud, + manuallyEdited, + recapture, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositeScores{aiGenerated=$aiGenerated, documentCoherence=$documentCoherence, documentMetadata=$documentMetadata, knownFraud=$knownFraud, manuallyEdited=$manuallyEdited, recapture=$recapture, additionalProperties=$additionalProperties}" + } + + /** + * Rendered pixel size of a page — the coordinate space region bboxes use, so the UI can + * scale the suspect-region overlay onto the displayed page. + */ + class PageDimension + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val height: JsonField, + private val page: JsonField, + private val width: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("height") @ExcludeMissing height: JsonField = JsonMissing.of(), + @JsonProperty("page") @ExcludeMissing page: JsonField = JsonMissing.of(), + @JsonProperty("width") @ExcludeMissing width: JsonField = JsonMissing.of(), + ) : this(height, page, width, mutableMapOf()) + + /** + * Rendered page height in pixels + * + * @throws LlamaCloudInvalidDataException 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 height(): Long = height.getRequired("height") + + /** + * 0-based page index (0 for standalone images) + * + * @throws LlamaCloudInvalidDataException 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 page(): Long = page.getRequired("page") + + /** + * Rendered page width in pixels + * + * @throws LlamaCloudInvalidDataException 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 width(): Long = width.getRequired("width") + + /** + * Returns the raw JSON value of [height]. + * + * Unlike [height], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("height") @ExcludeMissing fun _height(): JsonField = height + + /** + * Returns the raw JSON value of [page]. + * + * Unlike [page], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page") @ExcludeMissing fun _page(): JsonField = page + + /** + * Returns the raw JSON value of [width]. + * + * Unlike [width], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("width") @ExcludeMissing fun _width(): JsonField = width + + @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 [PageDimension]. + * + * The following fields are required: + * ```java + * .height() + * .page() + * .width() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PageDimension]. */ + class Builder internal constructor() { + + private var height: JsonField? = null + private var page: JsonField? = null + private var width: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(pageDimension: PageDimension) = apply { + height = pageDimension.height + page = pageDimension.page + width = pageDimension.width + additionalProperties = pageDimension.additionalProperties.toMutableMap() + } + + /** Rendered page height in pixels */ + fun height(height: Long) = height(JsonField.of(height)) + + /** + * Sets [Builder.height] to an arbitrary JSON value. + * + * You should usually call [Builder.height] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun height(height: JsonField) = apply { this.height = height } + + /** 0-based page index (0 for standalone images) */ + fun page(page: Long) = page(JsonField.of(page)) + + /** + * Sets [Builder.page] to an arbitrary JSON value. + * + * You should usually call [Builder.page] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun page(page: JsonField) = apply { this.page = page } + + /** Rendered page width in pixels */ + fun width(width: Long) = width(JsonField.of(width)) + + /** + * Sets [Builder.width] to an arbitrary JSON value. + * + * You should usually call [Builder.width] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun width(width: JsonField) = apply { this.width = width } + + 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 [PageDimension]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .height() + * .page() + * .width() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PageDimension = + PageDimension( + checkRequired("height", height), + checkRequired("page", page), + checkRequired("width", width), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): PageDimension = apply { + if (validated) { + return@apply + } + + height() + page() + width() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (height.asKnown().isPresent) 1 else 0) + + (if (page.asKnown().isPresent) 1 else 0) + + (if (width.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PageDimension && + height == other.height && + page == other.page && + width == other.width && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(height, page, width, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PageDimension{height=$height, page=$page, width=$width, additionalProperties=$additionalProperties}" + } + + /** + * A region that led to the suspected fraud, with why it is suspect. + * + * A curated, high-signal subset of ``regions``: reviewer-dismissed candidates are dropped + * and the remainder is ranked by suspicion, so consumers can act on ``verdict`` + + * ``confidence`` + this list without reading the raw signals. + */ + class SuspectRegion + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bbox: JsonField>, + private val explanation: JsonField, + private val kind: JsonField, + private val page: JsonField, + private val score: JsonField, + private val source: JsonField, + private val primary: JsonField, + private val review: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bbox") + @ExcludeMissing + bbox: JsonField> = JsonMissing.of(), + @JsonProperty("explanation") + @ExcludeMissing + explanation: JsonField = JsonMissing.of(), + @JsonProperty("kind") @ExcludeMissing kind: JsonField = JsonMissing.of(), + @JsonProperty("page") @ExcludeMissing page: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + @JsonProperty("source") + @ExcludeMissing + source: JsonField = JsonMissing.of(), + @JsonProperty("primary") + @ExcludeMissing + primary: JsonField = JsonMissing.of(), + @JsonProperty("review") @ExcludeMissing review: JsonField = JsonMissing.of(), + ) : this(bbox, explanation, kind, page, score, source, primary, review, mutableMapOf()) + + /** + * Region bounding box as [x, y, w, h] in page-render pixels + * + * @throws LlamaCloudInvalidDataException 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 bbox(): List = bbox.getRequired("bbox") + + /** + * Human-readable explanation of what makes this region suspect + * + * @throws LlamaCloudInvalidDataException 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 explanation(): String = explanation.getRequired("explanation") + + /** + * Kind of anomaly detected in this region + * + * @throws LlamaCloudInvalidDataException 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 kind(): String = kind.getRequired("kind") + + /** + * 0-based page index (0 for standalone images) + * + * @throws LlamaCloudInvalidDataException 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 page(): Long = page.getRequired("page") + + /** + * Suspicion score for this region (0 to 1) + * + * @throws LlamaCloudInvalidDataException 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 score(): Double = score.getRequired("score") + + /** + * Detector that flagged this region + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun source(): String = source.getRequired("source") + + /** + * Whether this region is part of the small set of decisive evidence behind the verdict + * — the boxes a reviewer should look at first + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun primary(): Optional = primary.getOptional("primary") + + /** + * Automated reviewer verdict for this region (confirmed, dismissed, unsure, or empty). + * A dismissed region can still be surfaced when it is the only place to look; this + * label says how to read it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun review(): Optional = review.getOptional("review") + + /** + * Returns the raw JSON value of [bbox]. + * + * Unlike [bbox], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("bbox") @ExcludeMissing fun _bbox(): JsonField> = bbox + + /** + * Returns the raw JSON value of [explanation]. + * + * Unlike [explanation], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("explanation") + @ExcludeMissing + fun _explanation(): JsonField = explanation + + /** + * Returns the raw JSON value of [kind]. + * + * Unlike [kind], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("kind") @ExcludeMissing fun _kind(): JsonField = kind + + /** + * Returns the raw JSON value of [page]. + * + * Unlike [page], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page") @ExcludeMissing fun _page(): JsonField = page + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + /** + * Returns the raw JSON value of [primary]. + * + * Unlike [primary], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("primary") @ExcludeMissing fun _primary(): JsonField = primary + + /** + * Returns the raw JSON value of [review]. + * + * Unlike [review], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("review") @ExcludeMissing fun _review(): JsonField = review + + @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 [SuspectRegion]. + * + * The following fields are required: + * ```java + * .bbox() + * .explanation() + * .kind() + * .page() + * .score() + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SuspectRegion]. */ + class Builder internal constructor() { + + private var bbox: JsonField>? = null + private var explanation: JsonField? = null + private var kind: JsonField? = null + private var page: JsonField? = null + private var score: JsonField? = null + private var source: JsonField? = null + private var primary: JsonField = JsonMissing.of() + private var review: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(suspectRegion: SuspectRegion) = apply { + bbox = suspectRegion.bbox.map { it.toMutableList() } + explanation = suspectRegion.explanation + kind = suspectRegion.kind + page = suspectRegion.page + score = suspectRegion.score + source = suspectRegion.source + primary = suspectRegion.primary + review = suspectRegion.review + additionalProperties = suspectRegion.additionalProperties.toMutableMap() + } + + /** Region bounding box as [x, y, w, h] in page-render pixels */ + fun bbox(bbox: List) = bbox(JsonField.of(bbox)) + + /** + * Sets [Builder.bbox] to an arbitrary JSON value. + * + * You should usually call [Builder.bbox] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun bbox(bbox: JsonField>) = apply { + this.bbox = bbox.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.bbox]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addBbox(bbox: Long) = apply { + this.bbox = + (this.bbox ?: JsonField.of(mutableListOf())).also { + checkKnown("bbox", it).add(bbox) + } + } + + /** Human-readable explanation of what makes this region suspect */ + fun explanation(explanation: String) = explanation(JsonField.of(explanation)) + + /** + * Sets [Builder.explanation] to an arbitrary JSON value. + * + * You should usually call [Builder.explanation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun explanation(explanation: JsonField) = apply { + this.explanation = explanation + } + + /** Kind of anomaly detected in this region */ + fun kind(kind: String) = kind(JsonField.of(kind)) + + /** + * Sets [Builder.kind] to an arbitrary JSON value. + * + * You should usually call [Builder.kind] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun kind(kind: JsonField) = apply { this.kind = kind } + + /** 0-based page index (0 for standalone images) */ + fun page(page: Long) = page(JsonField.of(page)) + + /** + * Sets [Builder.page] to an arbitrary JSON value. + * + * You should usually call [Builder.page] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun page(page: JsonField) = apply { this.page = page } + + /** Suspicion score for this region (0 to 1) */ + fun score(score: Double) = score(JsonField.of(score)) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + /** Detector that flagged this region */ + fun source(source: String) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + /** + * Whether this region is part of the small set of decisive evidence behind the + * verdict — the boxes a reviewer should look at first + */ + fun primary(primary: Boolean) = primary(JsonField.of(primary)) + + /** + * Sets [Builder.primary] to an arbitrary JSON value. + * + * You should usually call [Builder.primary] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun primary(primary: JsonField) = apply { this.primary = primary } + + /** + * Automated reviewer verdict for this region (confirmed, dismissed, unsure, or + * empty). A dismissed region can still be surfaced when it is the only place to + * look; this label says how to read it + */ + fun review(review: String) = review(JsonField.of(review)) + + /** + * Sets [Builder.review] to an arbitrary JSON value. + * + * You should usually call [Builder.review] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun review(review: JsonField) = apply { this.review = review } + + 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 [SuspectRegion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .bbox() + * .explanation() + * .kind() + * .page() + * .score() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SuspectRegion = + SuspectRegion( + checkRequired("bbox", bbox).map { it.toImmutable() }, + checkRequired("explanation", explanation), + checkRequired("kind", kind), + checkRequired("page", page), + checkRequired("score", score), + checkRequired("source", source), + primary, + review, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): SuspectRegion = apply { + if (validated) { + return@apply + } + + bbox() + explanation() + kind() + page() + score() + source() + primary() + review() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (bbox.asKnown().getOrNull()?.size ?: 0) + + (if (explanation.asKnown().isPresent) 1 else 0) + + (if (kind.asKnown().isPresent) 1 else 0) + + (if (page.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + (if (source.asKnown().isPresent) 1 else 0) + + (if (primary.asKnown().isPresent) 1 else 0) + + (if (review.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SuspectRegion && + bbox == other.bbox && + explanation == other.explanation && + kind == other.kind && + page == other.page && + score == other.score && + source == other.source && + primary == other.primary && + review == other.review && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bbox, + explanation, + kind, + page, + score, + source, + primary, + review, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SuspectRegion{bbox=$bbox, explanation=$explanation, kind=$kind, page=$page, score=$score, source=$source, primary=$primary, review=$review, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Result && + detectorVersion == other.detectorVersion && + overallScore == other.overallScore && + verdict == other.verdict && + compositeScores == other.compositeScores && + confidence == other.confidence && + error == other.error && + pageCount == other.pageCount && + pageDimensions == other.pageDimensions && + reasoning == other.reasoning && + suspectRegions == other.suspectRegions && + syntheticScore == other.syntheticScore && + tamperingScore == other.tamperingScore && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + detectorVersion, + overallScore, + verdict, + compositeScores, + confidence, + error, + pageCount, + pageDimensions, + reasoning, + suspectRegions, + syntheticScore, + tamperingScore, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Result{detectorVersion=$detectorVersion, overallScore=$overallScore, verdict=$verdict, compositeScores=$compositeScores, confidence=$confidence, error=$error, pageCount=$pageCount, pageDimensions=$pageDimensions, reasoning=$reasoning, suspectRegions=$suspectRegions, syntheticScore=$syntheticScore, tamperingScore=$tamperingScore, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyCreateResponse && + id == other.id && + configuration == other.configuration && + documentInputType == other.documentInputType && + fileInput == other.fileInput && + projectId == other.projectId && + status == other.status && + userId == other.userId && + createdAt == other.createdAt && + errorMessage == other.errorMessage && + result == other.result && + transactionId == other.transactionId && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + configuration, + documentInputType, + fileInput, + projectId, + status, + userId, + createdAt, + errorMessage, + result, + transactionId, + updatedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VerifyCreateResponse{id=$id, configuration=$configuration, documentInputType=$documentInputType, fileInput=$fileInput, projectId=$projectId, status=$status, userId=$userId, createdAt=$createdAt, errorMessage=$errorMessage, result=$result, transactionId=$transactionId, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsParams.kt new file mode 100644 index 0000000..fb3717c --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsParams.kt @@ -0,0 +1,231 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Get the raw per-signal detail for a completed Verify job. + * + * Forensic drill-down behind the simplified result: the full evidence list, per-family sub-scores, + * raw localized regions, and per-page forensic heatmap overlays (presigned image URLs). + */ +class VerifyGetDetailsParams +private constructor( + private val jobId: String?, + private val organizationId: String?, + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun jobId(): Optional = Optional.ofNullable(jobId) + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): VerifyGetDetailsParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [VerifyGetDetailsParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyGetDetailsParams]. */ + class Builder internal constructor() { + + private var jobId: String? = null + private var organizationId: String? = null + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(verifyGetDetailsParams: VerifyGetDetailsParams) = apply { + jobId = verifyGetDetailsParams.jobId + organizationId = verifyGetDetailsParams.organizationId + projectId = verifyGetDetailsParams.projectId + additionalHeaders = verifyGetDetailsParams.additionalHeaders.toBuilder() + additionalQueryParams = verifyGetDetailsParams.additionalQueryParams.toBuilder() + } + + fun jobId(jobId: String?) = apply { this.jobId = jobId } + + /** Alias for calling [Builder.jobId] with `jobId.orElse(null)`. */ + fun jobId(jobId: Optional) = jobId(jobId.getOrNull()) + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [VerifyGetDetailsParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): VerifyGetDetailsParams = + VerifyGetDetailsParams( + jobId, + organizationId, + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> jobId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyGetDetailsParams && + jobId == other.jobId && + organizationId == other.organizationId && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(jobId, organizationId, projectId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "VerifyGetDetailsParams{jobId=$jobId, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsResponse.kt new file mode 100644 index 0000000..49e242a --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsResponse.kt @@ -0,0 +1,2424 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Raw per-signal detail for a completed Verify job. + * + * Forensic drill-down behind the simplified result: the full evidence list, per-family sub-scores, + * raw localized regions, and heatmap overlays. + */ +class VerifyGetDetailsResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val jobId: JsonField, + private val degradedTools: JsonField>, + private val evidence: JsonField>, + private val heatmaps: JsonField>, + private val pageDimensions: JsonField>, + private val regions: JsonField>, + private val subScores: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("job_id") @ExcludeMissing jobId: JsonField = JsonMissing.of(), + @JsonProperty("degraded_tools") + @ExcludeMissing + degradedTools: JsonField> = JsonMissing.of(), + @JsonProperty("evidence") + @ExcludeMissing + evidence: JsonField> = JsonMissing.of(), + @JsonProperty("heatmaps") + @ExcludeMissing + heatmaps: JsonField> = JsonMissing.of(), + @JsonProperty("page_dimensions") + @ExcludeMissing + pageDimensions: JsonField> = JsonMissing.of(), + @JsonProperty("regions") + @ExcludeMissing + regions: JsonField> = JsonMissing.of(), + @JsonProperty("sub_scores") + @ExcludeMissing + subScores: JsonField = JsonMissing.of(), + ) : this( + jobId, + degradedTools, + evidence, + heatmaps, + pageDimensions, + regions, + subScores, + mutableMapOf(), + ) + + /** + * ID of the Verify job + * + * @throws LlamaCloudInvalidDataException 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 jobId(): String = jobId.getRequired("job_id") + + /** + * Checks that could not run on this job (with the reason). A check listed here produced no + * findings because it could not run, not because the document is clean + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun degradedTools(): Optional> = degradedTools.getOptional("degraded_tools") + + /** + * Evidence items produced by detection tools + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun evidence(): Optional> = evidence.getOptional("evidence") + + /** + * Per-page forensic heatmap overlays as presigned image URLs + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun heatmaps(): Optional> = heatmaps.getOptional("heatmaps") + + /** + * Rendered pixel size per page, so region bboxes can be scaled onto the page + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun pageDimensions(): Optional> = + pageDimensions.getOptional("page_dimensions") + + /** + * Suspicious regions localized on rendered pages + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun regions(): Optional> = regions.getOptional("regions") + + /** + * Per-family scores (metadata, ai_generation, splicing, copy_move, compression, noise, + * coherence, pdf_structure) + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun subScores(): Optional = subScores.getOptional("sub_scores") + + /** + * Returns the raw JSON value of [jobId]. + * + * Unlike [jobId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("job_id") @ExcludeMissing fun _jobId(): JsonField = jobId + + /** + * Returns the raw JSON value of [degradedTools]. + * + * Unlike [degradedTools], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("degraded_tools") + @ExcludeMissing + fun _degradedTools(): JsonField> = degradedTools + + /** + * Returns the raw JSON value of [evidence]. + * + * Unlike [evidence], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("evidence") @ExcludeMissing fun _evidence(): JsonField> = evidence + + /** + * Returns the raw JSON value of [heatmaps]. + * + * Unlike [heatmaps], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("heatmaps") @ExcludeMissing fun _heatmaps(): JsonField> = heatmaps + + /** + * Returns the raw JSON value of [pageDimensions]. + * + * Unlike [pageDimensions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page_dimensions") + @ExcludeMissing + fun _pageDimensions(): JsonField> = pageDimensions + + /** + * Returns the raw JSON value of [regions]. + * + * Unlike [regions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("regions") @ExcludeMissing fun _regions(): JsonField> = regions + + /** + * Returns the raw JSON value of [subScores]. + * + * Unlike [subScores], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sub_scores") @ExcludeMissing fun _subScores(): JsonField = subScores + + @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 [VerifyGetDetailsResponse]. + * + * The following fields are required: + * ```java + * .jobId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyGetDetailsResponse]. */ + class Builder internal constructor() { + + private var jobId: JsonField? = null + private var degradedTools: JsonField>? = null + private var evidence: JsonField>? = null + private var heatmaps: JsonField>? = null + private var pageDimensions: JsonField>? = null + private var regions: JsonField>? = null + private var subScores: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(verifyGetDetailsResponse: VerifyGetDetailsResponse) = apply { + jobId = verifyGetDetailsResponse.jobId + degradedTools = verifyGetDetailsResponse.degradedTools.map { it.toMutableList() } + evidence = verifyGetDetailsResponse.evidence.map { it.toMutableList() } + heatmaps = verifyGetDetailsResponse.heatmaps.map { it.toMutableList() } + pageDimensions = verifyGetDetailsResponse.pageDimensions.map { it.toMutableList() } + regions = verifyGetDetailsResponse.regions.map { it.toMutableList() } + subScores = verifyGetDetailsResponse.subScores + additionalProperties = verifyGetDetailsResponse.additionalProperties.toMutableMap() + } + + /** ID of the Verify job */ + fun jobId(jobId: String) = jobId(JsonField.of(jobId)) + + /** + * Sets [Builder.jobId] to an arbitrary JSON value. + * + * You should usually call [Builder.jobId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun jobId(jobId: JsonField) = apply { this.jobId = jobId } + + /** + * Checks that could not run on this job (with the reason). A check listed here produced no + * findings because it could not run, not because the document is clean + */ + fun degradedTools(degradedTools: List) = + degradedTools(JsonField.of(degradedTools)) + + /** + * Sets [Builder.degradedTools] to an arbitrary JSON value. + * + * You should usually call [Builder.degradedTools] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun degradedTools(degradedTools: JsonField>) = apply { + this.degradedTools = degradedTools.map { it.toMutableList() } + } + + /** + * Adds a single [DegradedTool] to [degradedTools]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDegradedTool(degradedTool: DegradedTool) = apply { + degradedTools = + (degradedTools ?: JsonField.of(mutableListOf())).also { + checkKnown("degradedTools", it).add(degradedTool) + } + } + + /** Evidence items produced by detection tools */ + fun evidence(evidence: List) = evidence(JsonField.of(evidence)) + + /** + * Sets [Builder.evidence] to an arbitrary JSON value. + * + * You should usually call [Builder.evidence] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun evidence(evidence: JsonField>) = apply { + this.evidence = evidence.map { it.toMutableList() } + } + + /** + * Adds a single [Evidence] to [Builder.evidence]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEvidence(evidence: Evidence) = apply { + this.evidence = + (this.evidence ?: JsonField.of(mutableListOf())).also { + checkKnown("evidence", it).add(evidence) + } + } + + /** Per-page forensic heatmap overlays as presigned image URLs */ + fun heatmaps(heatmaps: List) = heatmaps(JsonField.of(heatmaps)) + + /** + * Sets [Builder.heatmaps] to an arbitrary JSON value. + * + * You should usually call [Builder.heatmaps] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun heatmaps(heatmaps: JsonField>) = apply { + this.heatmaps = heatmaps.map { it.toMutableList() } + } + + /** + * Adds a single [Heatmap] to [heatmaps]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addHeatmap(heatmap: Heatmap) = apply { + heatmaps = + (heatmaps ?: JsonField.of(mutableListOf())).also { + checkKnown("heatmaps", it).add(heatmap) + } + } + + /** Rendered pixel size per page, so region bboxes can be scaled onto the page */ + fun pageDimensions(pageDimensions: List) = + pageDimensions(JsonField.of(pageDimensions)) + + /** + * Sets [Builder.pageDimensions] to an arbitrary JSON value. + * + * You should usually call [Builder.pageDimensions] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun pageDimensions(pageDimensions: JsonField>) = apply { + this.pageDimensions = pageDimensions.map { it.toMutableList() } + } + + /** + * Adds a single [PageDimension] to [pageDimensions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPageDimension(pageDimension: PageDimension) = apply { + pageDimensions = + (pageDimensions ?: JsonField.of(mutableListOf())).also { + checkKnown("pageDimensions", it).add(pageDimension) + } + } + + /** Suspicious regions localized on rendered pages */ + fun regions(regions: List) = regions(JsonField.of(regions)) + + /** + * Sets [Builder.regions] to an arbitrary JSON value. + * + * You should usually call [Builder.regions] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun regions(regions: JsonField>) = apply { + this.regions = regions.map { it.toMutableList() } + } + + /** + * Adds a single [Region] to [regions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRegion(region: Region) = apply { + regions = + (regions ?: JsonField.of(mutableListOf())).also { + checkKnown("regions", it).add(region) + } + } + + /** + * Per-family scores (metadata, ai_generation, splicing, copy_move, compression, noise, + * coherence, pdf_structure) + */ + fun subScores(subScores: SubScores) = subScores(JsonField.of(subScores)) + + /** + * Sets [Builder.subScores] to an arbitrary JSON value. + * + * You should usually call [Builder.subScores] with a well-typed [SubScores] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun subScores(subScores: JsonField) = apply { this.subScores = subScores } + + 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 [VerifyGetDetailsResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .jobId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VerifyGetDetailsResponse = + VerifyGetDetailsResponse( + checkRequired("jobId", jobId), + (degradedTools ?: JsonMissing.of()).map { it.toImmutable() }, + (evidence ?: JsonMissing.of()).map { it.toImmutable() }, + (heatmaps ?: JsonMissing.of()).map { it.toImmutable() }, + (pageDimensions ?: JsonMissing.of()).map { it.toImmutable() }, + (regions ?: JsonMissing.of()).map { it.toImmutable() }, + subScores, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): VerifyGetDetailsResponse = apply { + if (validated) { + return@apply + } + + jobId() + degradedTools().ifPresent { it.forEach { it.validate() } } + evidence().ifPresent { it.forEach { it.validate() } } + heatmaps().ifPresent { it.forEach { it.validate() } } + pageDimensions().ifPresent { it.forEach { it.validate() } } + regions().ifPresent { it.forEach { it.validate() } } + subScores().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (jobId.asKnown().isPresent) 1 else 0) + + (degradedTools.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (evidence.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (heatmaps.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (pageDimensions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (regions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (subScores.asKnown().getOrNull()?.validity() ?: 0) + + /** A check that was attempted but could not run on this job. */ + class DegradedTool + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val tool: JsonField, + private val reason: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tool") @ExcludeMissing tool: JsonField = JsonMissing.of(), + @JsonProperty("reason") @ExcludeMissing reason: JsonField = JsonMissing.of(), + ) : this(tool, reason, mutableMapOf()) + + /** + * Name of the check + * + * @throws LlamaCloudInvalidDataException 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 tool(): String = tool.getRequired("tool") + + /** + * Why the check could not run + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun reason(): Optional = reason.getOptional("reason") + + /** + * Returns the raw JSON value of [tool]. + * + * Unlike [tool], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tool") @ExcludeMissing fun _tool(): JsonField = tool + + /** + * Returns the raw JSON value of [reason]. + * + * Unlike [reason], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("reason") @ExcludeMissing fun _reason(): JsonField = reason + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [DegradedTool]. + * + * The following fields are required: + * ```java + * .tool() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DegradedTool]. */ + class Builder internal constructor() { + + private var tool: JsonField? = null + private var reason: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(degradedTool: DegradedTool) = apply { + tool = degradedTool.tool + reason = degradedTool.reason + additionalProperties = degradedTool.additionalProperties.toMutableMap() + } + + /** Name of the check */ + fun tool(tool: String) = tool(JsonField.of(tool)) + + /** + * Sets [Builder.tool] to an arbitrary JSON value. + * + * You should usually call [Builder.tool] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tool(tool: JsonField) = apply { this.tool = tool } + + /** Why the check could not run */ + fun reason(reason: String) = reason(JsonField.of(reason)) + + /** + * Sets [Builder.reason] to an arbitrary JSON value. + * + * You should usually call [Builder.reason] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun reason(reason: JsonField) = apply { this.reason = reason } + + 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 [DegradedTool]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .tool() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DegradedTool = + DegradedTool( + checkRequired("tool", tool), + reason, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): DegradedTool = apply { + if (validated) { + return@apply + } + + tool() + reason() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (tool.asKnown().isPresent) 1 else 0) + (if (reason.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DegradedTool && + tool == other.tool && + reason == other.reason && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(tool, reason, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DegradedTool{tool=$tool, reason=$reason, additionalProperties=$additionalProperties}" + } + + /** A single piece of evidence produced by a detection tool. */ + class Evidence + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val code: JsonField, + private val detail: JsonField, + private val family: JsonField, + private val score: JsonField, + private val tool: JsonField, + private val data: JsonField, + private val hard: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("code") @ExcludeMissing code: JsonField = JsonMissing.of(), + @JsonProperty("detail") @ExcludeMissing detail: JsonField = JsonMissing.of(), + @JsonProperty("family") @ExcludeMissing family: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + @JsonProperty("tool") @ExcludeMissing tool: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("hard") @ExcludeMissing hard: JsonField = JsonMissing.of(), + ) : this(code, detail, family, score, tool, data, hard, mutableMapOf()) + + /** + * Machine-readable evidence code + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun code(): String = code.getRequired("code") + + /** + * Human-readable evidence detail + * + * @throws LlamaCloudInvalidDataException 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 detail(): String = detail.getRequired("detail") + + /** + * Signal family (e.g. metadata, splicing, compression) + * + * @throws LlamaCloudInvalidDataException 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 family(): String = family.getRequired("family") + + /** + * Evidence strength score + * + * @throws LlamaCloudInvalidDataException 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 score(): Double = score.getRequired("score") + + /** + * Tool that produced this evidence + * + * @throws LlamaCloudInvalidDataException 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 tool(): String = tool.getRequired("tool") + + /** + * Tool-specific structured payload + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun data(): Optional = data.getOptional("data") + + /** + * Whether this is hard (conclusive) evidence + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun hard(): Optional = hard.getOptional("hard") + + /** + * Returns the raw JSON value of [code]. + * + * Unlike [code], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code + + /** + * Returns the raw JSON value of [detail]. + * + * Unlike [detail], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("detail") @ExcludeMissing fun _detail(): JsonField = detail + + /** + * Returns the raw JSON value of [family]. + * + * Unlike [family], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("family") @ExcludeMissing fun _family(): JsonField = family + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + /** + * Returns the raw JSON value of [tool]. + * + * Unlike [tool], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tool") @ExcludeMissing fun _tool(): JsonField = tool + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + + /** + * Returns the raw JSON value of [hard]. + * + * Unlike [hard], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("hard") @ExcludeMissing fun _hard(): JsonField = hard + + @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 [Evidence]. + * + * The following fields are required: + * ```java + * .code() + * .detail() + * .family() + * .score() + * .tool() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Evidence]. */ + class Builder internal constructor() { + + private var code: JsonField? = null + private var detail: JsonField? = null + private var family: JsonField? = null + private var score: JsonField? = null + private var tool: JsonField? = null + private var data: JsonField = JsonMissing.of() + private var hard: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(evidence: Evidence) = apply { + code = evidence.code + detail = evidence.detail + family = evidence.family + score = evidence.score + tool = evidence.tool + data = evidence.data + hard = evidence.hard + additionalProperties = evidence.additionalProperties.toMutableMap() + } + + /** Machine-readable evidence code */ + fun code(code: String) = code(JsonField.of(code)) + + /** + * Sets [Builder.code] to an arbitrary JSON value. + * + * You should usually call [Builder.code] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun code(code: JsonField) = apply { this.code = code } + + /** Human-readable evidence detail */ + fun detail(detail: String) = detail(JsonField.of(detail)) + + /** + * Sets [Builder.detail] to an arbitrary JSON value. + * + * You should usually call [Builder.detail] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun detail(detail: JsonField) = apply { this.detail = detail } + + /** Signal family (e.g. metadata, splicing, compression) */ + fun family(family: String) = family(JsonField.of(family)) + + /** + * Sets [Builder.family] to an arbitrary JSON value. + * + * You should usually call [Builder.family] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun family(family: JsonField) = apply { this.family = family } + + /** Evidence strength score */ + fun score(score: Double) = score(JsonField.of(score)) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + /** Tool that produced this evidence */ + fun tool(tool: String) = tool(JsonField.of(tool)) + + /** + * Sets [Builder.tool] to an arbitrary JSON value. + * + * You should usually call [Builder.tool] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tool(tool: JsonField) = apply { this.tool = tool } + + /** Tool-specific structured payload */ + fun data(data: Data) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [Data] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField) = apply { this.data = data } + + /** Whether this is hard (conclusive) evidence */ + fun hard(hard: Boolean) = hard(JsonField.of(hard)) + + /** + * Sets [Builder.hard] to an arbitrary JSON value. + * + * You should usually call [Builder.hard] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun hard(hard: JsonField) = apply { this.hard = hard } + + 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 [Evidence]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .code() + * .detail() + * .family() + * .score() + * .tool() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Evidence = + Evidence( + checkRequired("code", code), + checkRequired("detail", detail), + checkRequired("family", family), + checkRequired("score", score), + checkRequired("tool", tool), + data, + hard, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Evidence = apply { + if (validated) { + return@apply + } + + code() + detail() + family() + score() + tool() + data().ifPresent { it.validate() } + hard() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (code.asKnown().isPresent) 1 else 0) + + (if (detail.asKnown().isPresent) 1 else 0) + + (if (family.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + (if (tool.asKnown().isPresent) 1 else 0) + + (data.asKnown().getOrNull()?.validity() ?: 0) + + (if (hard.asKnown().isPresent) 1 else 0) + + /** Tool-specific structured payload */ + class Data + @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 [Data]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + additionalProperties = data.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 [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Data = Data(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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Data = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Data && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Data{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Evidence && + code == other.code && + detail == other.detail && + family == other.family && + score == other.score && + tool == other.tool && + data == other.data && + hard == other.hard && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(code, detail, family, score, tool, data, hard, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Evidence{code=$code, detail=$detail, family=$family, score=$score, tool=$tool, data=$data, hard=$hard, additionalProperties=$additionalProperties}" + } + + /** A per-page forensic heatmap overlay, as a presigned image URL. */ + class Heatmap + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val expiresAt: JsonField, + private val kind: JsonField, + private val page: JsonField, + private val url: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("expires_at") + @ExcludeMissing + expiresAt: JsonField = JsonMissing.of(), + @JsonProperty("kind") @ExcludeMissing kind: JsonField = JsonMissing.of(), + @JsonProperty("page") @ExcludeMissing page: JsonField = JsonMissing.of(), + @JsonProperty("url") @ExcludeMissing url: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + ) : this(expiresAt, kind, page, url, score, mutableMapOf()) + + /** + * The time at which the presigned URL expires + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun expiresAt(): OffsetDateTime = expiresAt.getRequired("expires_at") + + /** + * Producing signal, e.g. double_compression, ela, noise + * + * @throws LlamaCloudInvalidDataException 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 kind(): String = kind.getRequired("kind") + + /** + * 0-based page index (0 for standalone images) + * + * @throws LlamaCloudInvalidDataException 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 page(): Long = page.getRequired("page") + + /** + * Presigned URL to the heatmap PNG (page overlay) + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun url(): String = url.getRequired("url") + + /** + * Producing tool's max score (for ranking) + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [expiresAt]. + * + * Unlike [expiresAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("expires_at") + @ExcludeMissing + fun _expiresAt(): JsonField = expiresAt + + /** + * Returns the raw JSON value of [kind]. + * + * Unlike [kind], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("kind") @ExcludeMissing fun _kind(): JsonField = kind + + /** + * Returns the raw JSON value of [page]. + * + * Unlike [page], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page") @ExcludeMissing fun _page(): JsonField = page + + /** + * Returns the raw JSON value of [url]. + * + * Unlike [url], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [Heatmap]. + * + * The following fields are required: + * ```java + * .expiresAt() + * .kind() + * .page() + * .url() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Heatmap]. */ + class Builder internal constructor() { + + private var expiresAt: JsonField? = null + private var kind: JsonField? = null + private var page: JsonField? = null + private var url: JsonField? = null + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(heatmap: Heatmap) = apply { + expiresAt = heatmap.expiresAt + kind = heatmap.kind + page = heatmap.page + url = heatmap.url + score = heatmap.score + additionalProperties = heatmap.additionalProperties.toMutableMap() + } + + /** The time at which the presigned URL expires */ + fun expiresAt(expiresAt: OffsetDateTime) = expiresAt(JsonField.of(expiresAt)) + + /** + * Sets [Builder.expiresAt] to an arbitrary JSON value. + * + * You should usually call [Builder.expiresAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun expiresAt(expiresAt: JsonField) = apply { + this.expiresAt = expiresAt + } + + /** Producing signal, e.g. double_compression, ela, noise */ + fun kind(kind: String) = kind(JsonField.of(kind)) + + /** + * Sets [Builder.kind] to an arbitrary JSON value. + * + * You should usually call [Builder.kind] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun kind(kind: JsonField) = apply { this.kind = kind } + + /** 0-based page index (0 for standalone images) */ + fun page(page: Long) = page(JsonField.of(page)) + + /** + * Sets [Builder.page] to an arbitrary JSON value. + * + * You should usually call [Builder.page] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun page(page: JsonField) = apply { this.page = page } + + /** Presigned URL to the heatmap PNG (page overlay) */ + fun url(url: String) = url(JsonField.of(url)) + + /** + * Sets [Builder.url] to an arbitrary JSON value. + * + * You should usually call [Builder.url] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun url(url: JsonField) = apply { this.url = url } + + /** Producing tool's max score (for ranking) */ + fun score(score: Double) = score(JsonField.of(score)) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [Heatmap]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .expiresAt() + * .kind() + * .page() + * .url() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Heatmap = + Heatmap( + checkRequired("expiresAt", expiresAt), + checkRequired("kind", kind), + checkRequired("page", page), + checkRequired("url", url), + score, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Heatmap = apply { + if (validated) { + return@apply + } + + expiresAt() + kind() + page() + url() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (expiresAt.asKnown().isPresent) 1 else 0) + + (if (kind.asKnown().isPresent) 1 else 0) + + (if (page.asKnown().isPresent) 1 else 0) + + (if (url.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Heatmap && + expiresAt == other.expiresAt && + kind == other.kind && + page == other.page && + url == other.url && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(expiresAt, kind, page, url, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Heatmap{expiresAt=$expiresAt, kind=$kind, page=$page, url=$url, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Rendered pixel size of a page — the coordinate space region bboxes use, so the UI can scale + * the suspect-region overlay onto the displayed page. + */ + class PageDimension + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val height: JsonField, + private val page: JsonField, + private val width: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("height") @ExcludeMissing height: JsonField = JsonMissing.of(), + @JsonProperty("page") @ExcludeMissing page: JsonField = JsonMissing.of(), + @JsonProperty("width") @ExcludeMissing width: JsonField = JsonMissing.of(), + ) : this(height, page, width, mutableMapOf()) + + /** + * Rendered page height in pixels + * + * @throws LlamaCloudInvalidDataException 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 height(): Long = height.getRequired("height") + + /** + * 0-based page index (0 for standalone images) + * + * @throws LlamaCloudInvalidDataException 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 page(): Long = page.getRequired("page") + + /** + * Rendered page width in pixels + * + * @throws LlamaCloudInvalidDataException 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 width(): Long = width.getRequired("width") + + /** + * Returns the raw JSON value of [height]. + * + * Unlike [height], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("height") @ExcludeMissing fun _height(): JsonField = height + + /** + * Returns the raw JSON value of [page]. + * + * Unlike [page], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page") @ExcludeMissing fun _page(): JsonField = page + + /** + * Returns the raw JSON value of [width]. + * + * Unlike [width], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("width") @ExcludeMissing fun _width(): JsonField = width + + @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 [PageDimension]. + * + * The following fields are required: + * ```java + * .height() + * .page() + * .width() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PageDimension]. */ + class Builder internal constructor() { + + private var height: JsonField? = null + private var page: JsonField? = null + private var width: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(pageDimension: PageDimension) = apply { + height = pageDimension.height + page = pageDimension.page + width = pageDimension.width + additionalProperties = pageDimension.additionalProperties.toMutableMap() + } + + /** Rendered page height in pixels */ + fun height(height: Long) = height(JsonField.of(height)) + + /** + * Sets [Builder.height] to an arbitrary JSON value. + * + * You should usually call [Builder.height] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun height(height: JsonField) = apply { this.height = height } + + /** 0-based page index (0 for standalone images) */ + fun page(page: Long) = page(JsonField.of(page)) + + /** + * Sets [Builder.page] to an arbitrary JSON value. + * + * You should usually call [Builder.page] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun page(page: JsonField) = apply { this.page = page } + + /** Rendered page width in pixels */ + fun width(width: Long) = width(JsonField.of(width)) + + /** + * Sets [Builder.width] to an arbitrary JSON value. + * + * You should usually call [Builder.width] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun width(width: JsonField) = apply { this.width = width } + + 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 [PageDimension]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .height() + * .page() + * .width() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PageDimension = + PageDimension( + checkRequired("height", height), + checkRequired("page", page), + checkRequired("width", width), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PageDimension = apply { + if (validated) { + return@apply + } + + height() + page() + width() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (height.asKnown().isPresent) 1 else 0) + + (if (page.asKnown().isPresent) 1 else 0) + + (if (width.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PageDimension && + height == other.height && + page == other.page && + width == other.width && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(height, page, width, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PageDimension{height=$height, page=$page, width=$width, additionalProperties=$additionalProperties}" + } + + /** A suspicious region localized on a rendered page. */ + class Region + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bbox: JsonField>, + private val detail: JsonField, + private val kind: JsonField, + private val page: JsonField, + private val score: JsonField, + private val source: JsonField, + private val primary: JsonField, + private val review: JsonField, + private val reviewNote: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bbox") @ExcludeMissing bbox: JsonField> = JsonMissing.of(), + @JsonProperty("detail") @ExcludeMissing detail: JsonField = JsonMissing.of(), + @JsonProperty("kind") @ExcludeMissing kind: JsonField = JsonMissing.of(), + @JsonProperty("page") @ExcludeMissing page: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField = JsonMissing.of(), + @JsonProperty("primary") @ExcludeMissing primary: JsonField = JsonMissing.of(), + @JsonProperty("review") @ExcludeMissing review: JsonField = JsonMissing.of(), + @JsonProperty("review_note") + @ExcludeMissing + reviewNote: JsonField = JsonMissing.of(), + ) : this( + bbox, + detail, + kind, + page, + score, + source, + primary, + review, + reviewNote, + mutableMapOf(), + ) + + /** + * Region bounding box as [x, y, w, h] in page-render pixels + * + * @throws LlamaCloudInvalidDataException 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 bbox(): List = bbox.getRequired("bbox") + + /** + * Human-readable detail about the region + * + * @throws LlamaCloudInvalidDataException 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 detail(): String = detail.getRequired("detail") + + /** + * Kind of anomaly detected in this region + * + * @throws LlamaCloudInvalidDataException 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 kind(): String = kind.getRequired("kind") + + /** + * 0-based page index (0 for standalone images) + * + * @throws LlamaCloudInvalidDataException 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 page(): Long = page.getRequired("page") + + /** + * Region-level doctoring likelihood score + * + * @throws LlamaCloudInvalidDataException 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 score(): Double = score.getRequired("score") + + /** + * Detector/tool that produced this region + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun source(): String = source.getRequired("source") + + /** + * Whether this region is part of the small set of decisive evidence behind the verdict — + * the boxes a reviewer should look at first + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun primary(): Optional = primary.getOptional("primary") + + /** + * Review status/verdict for this region + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun review(): Optional = review.getOptional("review") + + /** + * Free-form review note for this region + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun reviewNote(): Optional = reviewNote.getOptional("review_note") + + /** + * Returns the raw JSON value of [bbox]. + * + * Unlike [bbox], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("bbox") @ExcludeMissing fun _bbox(): JsonField> = bbox + + /** + * Returns the raw JSON value of [detail]. + * + * Unlike [detail], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("detail") @ExcludeMissing fun _detail(): JsonField = detail + + /** + * Returns the raw JSON value of [kind]. + * + * Unlike [kind], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("kind") @ExcludeMissing fun _kind(): JsonField = kind + + /** + * Returns the raw JSON value of [page]. + * + * Unlike [page], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page") @ExcludeMissing fun _page(): JsonField = page + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + /** + * Returns the raw JSON value of [primary]. + * + * Unlike [primary], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("primary") @ExcludeMissing fun _primary(): JsonField = primary + + /** + * Returns the raw JSON value of [review]. + * + * Unlike [review], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("review") @ExcludeMissing fun _review(): JsonField = review + + /** + * Returns the raw JSON value of [reviewNote]. + * + * Unlike [reviewNote], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("review_note") + @ExcludeMissing + fun _reviewNote(): JsonField = reviewNote + + @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 [Region]. + * + * The following fields are required: + * ```java + * .bbox() + * .detail() + * .kind() + * .page() + * .score() + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Region]. */ + class Builder internal constructor() { + + private var bbox: JsonField>? = null + private var detail: JsonField? = null + private var kind: JsonField? = null + private var page: JsonField? = null + private var score: JsonField? = null + private var source: JsonField? = null + private var primary: JsonField = JsonMissing.of() + private var review: JsonField = JsonMissing.of() + private var reviewNote: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(region: Region) = apply { + bbox = region.bbox.map { it.toMutableList() } + detail = region.detail + kind = region.kind + page = region.page + score = region.score + source = region.source + primary = region.primary + review = region.review + reviewNote = region.reviewNote + additionalProperties = region.additionalProperties.toMutableMap() + } + + /** Region bounding box as [x, y, w, h] in page-render pixels */ + fun bbox(bbox: List) = bbox(JsonField.of(bbox)) + + /** + * Sets [Builder.bbox] to an arbitrary JSON value. + * + * You should usually call [Builder.bbox] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun bbox(bbox: JsonField>) = apply { + this.bbox = bbox.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.bbox]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addBbox(bbox: Long) = apply { + this.bbox = + (this.bbox ?: JsonField.of(mutableListOf())).also { + checkKnown("bbox", it).add(bbox) + } + } + + /** Human-readable detail about the region */ + fun detail(detail: String) = detail(JsonField.of(detail)) + + /** + * Sets [Builder.detail] to an arbitrary JSON value. + * + * You should usually call [Builder.detail] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun detail(detail: JsonField) = apply { this.detail = detail } + + /** Kind of anomaly detected in this region */ + fun kind(kind: String) = kind(JsonField.of(kind)) + + /** + * Sets [Builder.kind] to an arbitrary JSON value. + * + * You should usually call [Builder.kind] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun kind(kind: JsonField) = apply { this.kind = kind } + + /** 0-based page index (0 for standalone images) */ + fun page(page: Long) = page(JsonField.of(page)) + + /** + * Sets [Builder.page] to an arbitrary JSON value. + * + * You should usually call [Builder.page] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun page(page: JsonField) = apply { this.page = page } + + /** Region-level doctoring likelihood score */ + fun score(score: Double) = score(JsonField.of(score)) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + /** Detector/tool that produced this region */ + fun source(source: String) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + /** + * Whether this region is part of the small set of decisive evidence behind the verdict + * — the boxes a reviewer should look at first + */ + fun primary(primary: Boolean) = primary(JsonField.of(primary)) + + /** + * Sets [Builder.primary] to an arbitrary JSON value. + * + * You should usually call [Builder.primary] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun primary(primary: JsonField) = apply { this.primary = primary } + + /** Review status/verdict for this region */ + fun review(review: String) = review(JsonField.of(review)) + + /** + * Sets [Builder.review] to an arbitrary JSON value. + * + * You should usually call [Builder.review] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun review(review: JsonField) = apply { this.review = review } + + /** Free-form review note for this region */ + fun reviewNote(reviewNote: String) = reviewNote(JsonField.of(reviewNote)) + + /** + * Sets [Builder.reviewNote] to an arbitrary JSON value. + * + * You should usually call [Builder.reviewNote] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun reviewNote(reviewNote: JsonField) = apply { this.reviewNote = reviewNote } + + 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 [Region]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .bbox() + * .detail() + * .kind() + * .page() + * .score() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Region = + Region( + checkRequired("bbox", bbox).map { it.toImmutable() }, + checkRequired("detail", detail), + checkRequired("kind", kind), + checkRequired("page", page), + checkRequired("score", score), + checkRequired("source", source), + primary, + review, + reviewNote, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Region = apply { + if (validated) { + return@apply + } + + bbox() + detail() + kind() + page() + score() + source() + primary() + review() + reviewNote() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (bbox.asKnown().getOrNull()?.size ?: 0) + + (if (detail.asKnown().isPresent) 1 else 0) + + (if (kind.asKnown().isPresent) 1 else 0) + + (if (page.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + (if (source.asKnown().isPresent) 1 else 0) + + (if (primary.asKnown().isPresent) 1 else 0) + + (if (review.asKnown().isPresent) 1 else 0) + + (if (reviewNote.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Region && + bbox == other.bbox && + detail == other.detail && + kind == other.kind && + page == other.page && + score == other.score && + source == other.source && + primary == other.primary && + review == other.review && + reviewNote == other.reviewNote && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bbox, + detail, + kind, + page, + score, + source, + primary, + review, + reviewNote, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Region{bbox=$bbox, detail=$detail, kind=$kind, page=$page, score=$score, source=$source, primary=$primary, review=$review, reviewNote=$reviewNote, additionalProperties=$additionalProperties}" + } + + /** + * Per-family scores (metadata, ai_generation, splicing, copy_move, compression, noise, + * coherence, pdf_structure) + */ + class SubScores + @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 [SubScores]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SubScores]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(subScores: SubScores) = apply { + additionalProperties = subScores.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 [SubScores]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): SubScores = SubScores(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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SubScores = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 SubScores && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "SubScores{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyGetDetailsResponse && + jobId == other.jobId && + degradedTools == other.degradedTools && + evidence == other.evidence && + heatmaps == other.heatmaps && + pageDimensions == other.pageDimensions && + regions == other.regions && + subScores == other.subScores && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + jobId, + degradedTools, + evidence, + heatmaps, + pageDimensions, + regions, + subScores, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VerifyGetDetailsResponse{jobId=$jobId, degradedTools=$degradedTools, evidence=$evidence, heatmaps=$heatmaps, pageDimensions=$pageDimensions, regions=$regions, subScores=$subScores, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetParams.kt new file mode 100644 index 0000000..4411150 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetParams.kt @@ -0,0 +1,266 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Get a Verify job by ID. + * + * Returns the job status and configuration. Pass `expand=result` to include the Verify result + * (overall score, verdict, confidence, composite scores, and suspect regions) when the job is + * complete. + * + * Raw per-signal detail is available via `GET /verify/{job_id}/details`. + */ +class VerifyGetParams +private constructor( + private val jobId: String?, + private val expand: List?, + private val organizationId: String?, + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun jobId(): Optional = Optional.ofNullable(jobId) + + /** Optional fields to include (e.g. `result`). */ + fun expand(): Optional> = Optional.ofNullable(expand) + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): VerifyGetParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [VerifyGetParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyGetParams]. */ + class Builder internal constructor() { + + private var jobId: String? = null + private var expand: MutableList? = null + private var organizationId: String? = null + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(verifyGetParams: VerifyGetParams) = apply { + jobId = verifyGetParams.jobId + expand = verifyGetParams.expand?.toMutableList() + organizationId = verifyGetParams.organizationId + projectId = verifyGetParams.projectId + additionalHeaders = verifyGetParams.additionalHeaders.toBuilder() + additionalQueryParams = verifyGetParams.additionalQueryParams.toBuilder() + } + + fun jobId(jobId: String?) = apply { this.jobId = jobId } + + /** Alias for calling [Builder.jobId] with `jobId.orElse(null)`. */ + fun jobId(jobId: Optional) = jobId(jobId.getOrNull()) + + /** Optional fields to include (e.g. `result`). */ + fun expand(expand: List?) = apply { this.expand = expand?.toMutableList() } + + /** Alias for calling [Builder.expand] with `expand.orElse(null)`. */ + fun expand(expand: Optional>) = expand(expand.getOrNull()) + + /** + * Adds a single [String] to [Builder.expand]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExpand(expand: String) = apply { + this.expand = (this.expand ?: mutableListOf()).apply { add(expand) } + } + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [VerifyGetParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): VerifyGetParams = + VerifyGetParams( + jobId, + expand?.toImmutable(), + organizationId, + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> jobId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + expand?.forEach { put("expand", it) } + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyGetParams && + jobId == other.jobId && + expand == other.expand && + organizationId == other.organizationId && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + jobId, + expand, + organizationId, + projectId, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "VerifyGetParams{jobId=$jobId, expand=$expand, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetResponse.kt new file mode 100644 index 0000000..fdbe592 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetResponse.kt @@ -0,0 +1,4698 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Response for a Verify job. */ +class VerifyGetResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val configuration: JsonField, + private val documentInputType: JsonField, + private val fileInput: JsonField, + private val projectId: JsonField, + private val status: JsonField, + private val userId: JsonField, + private val createdAt: JsonField, + private val errorMessage: JsonField, + private val result: JsonField, + private val transactionId: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("configuration") + @ExcludeMissing + configuration: JsonField = JsonMissing.of(), + @JsonProperty("document_input_type") + @ExcludeMissing + documentInputType: JsonField = JsonMissing.of(), + @JsonProperty("file_input") @ExcludeMissing fileInput: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("error_message") + @ExcludeMissing + errorMessage: JsonField = JsonMissing.of(), + @JsonProperty("result") @ExcludeMissing result: JsonField = JsonMissing.of(), + @JsonProperty("transaction_id") + @ExcludeMissing + transactionId: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + ) : this( + id, + configuration, + documentInputType, + fileInput, + projectId, + status, + userId, + createdAt, + errorMessage, + result, + transactionId, + updatedAt, + mutableMapOf(), + ) + + /** + * Unique identifier + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * Verify configuration used for this job + * + * @throws LlamaCloudInvalidDataException 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 configuration(): Configuration = configuration.getRequired("configuration") + + /** + * Type of the document input (FILE) + * + * @throws LlamaCloudInvalidDataException 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 documentInputType(): DocumentInputType = + documentInputType.getRequired("document_input_type") + + /** + * ID of the input file + * + * @throws LlamaCloudInvalidDataException 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 fileInput(): String = fileInput.getRequired("file_input") + + /** + * Project this job belongs to + * + * @throws LlamaCloudInvalidDataException 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 projectId(): String = projectId.getRequired("project_id") + + /** + * Current job status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun status(): Status = status.getRequired("status") + + /** + * User who created this job + * + * @throws LlamaCloudInvalidDataException 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 userId(): String = userId.getRequired("user_id") + + /** + * Creation datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * Error message if job failed + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun errorMessage(): Optional = errorMessage.getOptional("error_message") + + /** + * Result of a Verify (doctored-document) analysis. + * + * Raw per-signal detail (evidence list, per-family sub-scores, raw regions, forensic heatmaps) + * is available separately via the job's details endpoint. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun result(): Optional = result.getOptional("result") + + /** + * Idempotency key + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun transactionId(): Optional = transactionId.getOptional("transaction_id") + + /** + * Update datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [configuration]. + * + * Unlike [configuration], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("configuration") + @ExcludeMissing + fun _configuration(): JsonField = configuration + + /** + * Returns the raw JSON value of [documentInputType]. + * + * Unlike [documentInputType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("document_input_type") + @ExcludeMissing + fun _documentInputType(): JsonField = documentInputType + + /** + * Returns the raw JSON value of [fileInput]. + * + * Unlike [fileInput], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_input") @ExcludeMissing fun _fileInput(): JsonField = fileInput + + /** + * 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 [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [errorMessage]. + * + * Unlike [errorMessage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error_message") + @ExcludeMissing + fun _errorMessage(): JsonField = errorMessage + + /** + * Returns the raw JSON value of [result]. + * + * Unlike [result], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("result") @ExcludeMissing fun _result(): JsonField = result + + /** + * Returns the raw JSON value of [transactionId]. + * + * Unlike [transactionId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("transaction_id") + @ExcludeMissing + fun _transactionId(): JsonField = transactionId + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") + @ExcludeMissing + fun _updatedAt(): JsonField = updatedAt + + @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 [VerifyGetResponse]. + * + * The following fields are required: + * ```java + * .id() + * .configuration() + * .documentInputType() + * .fileInput() + * .projectId() + * .status() + * .userId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyGetResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var configuration: JsonField? = null + private var documentInputType: JsonField? = null + private var fileInput: JsonField? = null + private var projectId: JsonField? = null + private var status: JsonField? = null + private var userId: JsonField? = null + private var createdAt: JsonField = JsonMissing.of() + private var errorMessage: JsonField = JsonMissing.of() + private var result: JsonField = JsonMissing.of() + private var transactionId: JsonField = JsonMissing.of() + private var updatedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(verifyGetResponse: VerifyGetResponse) = apply { + id = verifyGetResponse.id + configuration = verifyGetResponse.configuration + documentInputType = verifyGetResponse.documentInputType + fileInput = verifyGetResponse.fileInput + projectId = verifyGetResponse.projectId + status = verifyGetResponse.status + userId = verifyGetResponse.userId + createdAt = verifyGetResponse.createdAt + errorMessage = verifyGetResponse.errorMessage + result = verifyGetResponse.result + transactionId = verifyGetResponse.transactionId + updatedAt = verifyGetResponse.updatedAt + additionalProperties = verifyGetResponse.additionalProperties.toMutableMap() + } + + /** Unique identifier */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Verify configuration used for this job */ + fun configuration(configuration: Configuration) = configuration(JsonField.of(configuration)) + + /** + * Sets [Builder.configuration] to an arbitrary JSON value. + * + * You should usually call [Builder.configuration] with a well-typed [Configuration] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun configuration(configuration: JsonField) = apply { + this.configuration = configuration + } + + /** Type of the document input (FILE) */ + fun documentInputType(documentInputType: DocumentInputType) = + documentInputType(JsonField.of(documentInputType)) + + /** + * Sets [Builder.documentInputType] to an arbitrary JSON value. + * + * You should usually call [Builder.documentInputType] with a well-typed [DocumentInputType] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun documentInputType(documentInputType: JsonField) = apply { + this.documentInputType = documentInputType + } + + /** ID of the input file */ + fun fileInput(fileInput: String) = fileInput(JsonField.of(fileInput)) + + /** + * Sets [Builder.fileInput] to an arbitrary JSON value. + * + * You should usually call [Builder.fileInput] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun fileInput(fileInput: JsonField) = apply { this.fileInput = fileInput } + + /** Project this job belongs to */ + 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 } + + /** Current job status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED */ + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** User who created this job */ + fun userId(userId: String) = userId(JsonField.of(userId)) + + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } + + /** Creation datetime */ + fun createdAt(createdAt: OffsetDateTime?) = createdAt(JsonField.ofNullable(createdAt)) + + /** Alias for calling [Builder.createdAt] with `createdAt.orElse(null)`. */ + fun createdAt(createdAt: Optional) = createdAt(createdAt.getOrNull()) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Error message if job failed */ + fun errorMessage(errorMessage: String?) = errorMessage(JsonField.ofNullable(errorMessage)) + + /** Alias for calling [Builder.errorMessage] with `errorMessage.orElse(null)`. */ + fun errorMessage(errorMessage: Optional) = errorMessage(errorMessage.getOrNull()) + + /** + * Sets [Builder.errorMessage] to an arbitrary JSON value. + * + * You should usually call [Builder.errorMessage] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun errorMessage(errorMessage: JsonField) = apply { + this.errorMessage = errorMessage + } + + /** + * Result of a Verify (doctored-document) analysis. + * + * Raw per-signal detail (evidence list, per-family sub-scores, raw regions, forensic + * heatmaps) is available separately via the job's details endpoint. + */ + fun result(result: Result?) = result(JsonField.ofNullable(result)) + + /** Alias for calling [Builder.result] with `result.orElse(null)`. */ + fun result(result: Optional) = result(result.getOrNull()) + + /** + * Sets [Builder.result] to an arbitrary JSON value. + * + * You should usually call [Builder.result] with a well-typed [Result] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun result(result: JsonField) = apply { this.result = result } + + /** Idempotency key */ + fun transactionId(transactionId: String?) = + transactionId(JsonField.ofNullable(transactionId)) + + /** Alias for calling [Builder.transactionId] with `transactionId.orElse(null)`. */ + fun transactionId(transactionId: Optional) = + transactionId(transactionId.getOrNull()) + + /** + * Sets [Builder.transactionId] to an arbitrary JSON value. + * + * You should usually call [Builder.transactionId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun transactionId(transactionId: JsonField) = apply { + this.transactionId = transactionId + } + + /** Update datetime */ + fun updatedAt(updatedAt: OffsetDateTime?) = updatedAt(JsonField.ofNullable(updatedAt)) + + /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ + fun updatedAt(updatedAt: Optional) = updatedAt(updatedAt.getOrNull()) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + 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 [VerifyGetResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .configuration() + * .documentInputType() + * .fileInput() + * .projectId() + * .status() + * .userId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VerifyGetResponse = + VerifyGetResponse( + checkRequired("id", id), + checkRequired("configuration", configuration), + checkRequired("documentInputType", documentInputType), + checkRequired("fileInput", fileInput), + checkRequired("projectId", projectId), + checkRequired("status", status), + checkRequired("userId", userId), + createdAt, + errorMessage, + result, + transactionId, + updatedAt, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): VerifyGetResponse = apply { + if (validated) { + return@apply + } + + id() + configuration().validate() + documentInputType().validate() + fileInput() + projectId() + status().validate() + userId() + createdAt() + errorMessage() + result().ifPresent { it.validate() } + transactionId() + updatedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (configuration.asKnown().getOrNull()?.validity() ?: 0) + + (documentInputType.asKnown().getOrNull()?.validity() ?: 0) + + (if (fileInput.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (errorMessage.asKnown().isPresent) 1 else 0) + + (result.asKnown().getOrNull()?.validity() ?: 0) + + (if (transactionId.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + /** Verify configuration used for this job */ + class Configuration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val targetPages: JsonField, + private val tier: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("target_pages") + @ExcludeMissing + targetPages: JsonField = JsonMissing.of(), + @JsonProperty("tier") @ExcludeMissing tier: JsonField = JsonMissing.of(), + ) : this(targetPages, tier, mutableMapOf()) + + /** + * Comma-separated page numbers or ranges to analyze (1-based). Omit to analyze all pages. + * Ignored for non-PDF inputs. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun targetPages(): Optional = targetPages.getOptional("target_pages") + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, content + * integrity, container structure, pixel statistics); 'agentic' (default) runs the full + * pipeline including the learned detectors and the semantic review pass. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tier(): Optional = tier.getOptional("tier") + + /** + * Returns the raw JSON value of [targetPages]. + * + * Unlike [targetPages], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("target_pages") + @ExcludeMissing + fun _targetPages(): JsonField = targetPages + + /** + * Returns the raw JSON value of [tier]. + * + * Unlike [tier], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tier") @ExcludeMissing fun _tier(): JsonField = tier + + @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 [Configuration]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Configuration]. */ + class Builder internal constructor() { + + private var targetPages: JsonField = JsonMissing.of() + private var tier: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(configuration: Configuration) = apply { + targetPages = configuration.targetPages + tier = configuration.tier + additionalProperties = configuration.additionalProperties.toMutableMap() + } + + /** + * Comma-separated page numbers or ranges to analyze (1-based). Omit to analyze all + * pages. Ignored for non-PDF inputs. + */ + fun targetPages(targetPages: String?) = targetPages(JsonField.ofNullable(targetPages)) + + /** Alias for calling [Builder.targetPages] with `targetPages.orElse(null)`. */ + fun targetPages(targetPages: Optional) = targetPages(targetPages.getOrNull()) + + /** + * Sets [Builder.targetPages] to an arbitrary JSON value. + * + * You should usually call [Builder.targetPages] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun targetPages(targetPages: JsonField) = apply { + this.targetPages = targetPages + } + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, + * content integrity, container structure, pixel statistics); 'agentic' (default) runs + * the full pipeline including the learned detectors and the semantic review pass. + */ + fun tier(tier: Tier) = tier(JsonField.of(tier)) + + /** + * Sets [Builder.tier] to an arbitrary JSON value. + * + * You should usually call [Builder.tier] with a well-typed [Tier] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tier(tier: JsonField) = apply { this.tier = tier } + + 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 [Configuration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Configuration = + Configuration(targetPages, tier, 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Configuration = apply { + if (validated) { + return@apply + } + + targetPages() + tier().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (targetPages.asKnown().isPresent) 1 else 0) + + (tier.asKnown().getOrNull()?.validity() ?: 0) + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, content + * integrity, container structure, pixel statistics); 'agentic' (default) runs the full + * pipeline including the learned detectors and the semantic review pass. + */ + class Tier @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 AGENTIC = of("agentic") + + @JvmField val FAST = of("fast") + + @JvmStatic fun of(value: String) = Tier(JsonField.of(value)) + } + + /** An enum containing [Tier]'s known values. */ + enum class Known { + AGENTIC, + FAST, + } + + /** + * An enum containing [Tier]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Tier] 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 { + AGENTIC, + FAST, + /** An enum member indicating that [Tier] 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) { + AGENTIC -> Value.AGENTIC + FAST -> Value.FAST + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + AGENTIC -> Known.AGENTIC + FAST -> Known.FAST + else -> throw LlamaCloudInvalidDataException("Unknown Tier: $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 LlamaCloudInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Tier && 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 Configuration && + targetPages == other.targetPages && + tier == other.tier && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(targetPages, tier, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Configuration{targetPages=$targetPages, tier=$tier, additionalProperties=$additionalProperties}" + } + + /** Type of the document input (FILE) */ + class DocumentInputType @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 FILE_ID = of("file_id") + + @JvmField val PARSE_JOB_ID = of("parse_job_id") + + @JvmField val URL = of("url") + + @JvmStatic fun of(value: String) = DocumentInputType(JsonField.of(value)) + } + + /** An enum containing [DocumentInputType]'s known values. */ + enum class Known { + FILE_ID, + PARSE_JOB_ID, + URL, + } + + /** + * An enum containing [DocumentInputType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [DocumentInputType] 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 { + FILE_ID, + PARSE_JOB_ID, + URL, + /** + * An enum member indicating that [DocumentInputType] 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) { + FILE_ID -> Value.FILE_ID + PARSE_JOB_ID -> Value.PARSE_JOB_ID + URL -> Value.URL + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + FILE_ID -> Known.FILE_ID + PARSE_JOB_ID -> Known.PARSE_JOB_ID + URL -> Known.URL + else -> throw LlamaCloudInvalidDataException("Unknown DocumentInputType: $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 LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): DocumentInputType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 DocumentInputType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Current job status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED */ + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val CANCELLED = of("CANCELLED") + + @JvmField val COMPLETED = of("COMPLETED") + + @JvmField val FAILED = of("FAILED") + + @JvmField val PENDING = of("PENDING") + + @JvmField val RUNNING = of("RUNNING") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + CANCELLED, + COMPLETED, + FAILED, + PENDING, + RUNNING, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + CANCELLED, + COMPLETED, + FAILED, + PENDING, + RUNNING, + /** An enum member indicating that [Status] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + CANCELLED -> Value.CANCELLED + COMPLETED -> Value.COMPLETED + FAILED -> Value.FAILED + PENDING -> Value.PENDING + RUNNING -> Value.RUNNING + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + CANCELLED -> Known.CANCELLED + COMPLETED -> Known.COMPLETED + FAILED -> Known.FAILED + PENDING -> Known.PENDING + RUNNING -> Known.RUNNING + else -> throw LlamaCloudInvalidDataException("Unknown Status: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Status = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Status && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * Result of a Verify (doctored-document) analysis. + * + * Raw per-signal detail (evidence list, per-family sub-scores, raw regions, forensic heatmaps) + * is available separately via the job's details endpoint. + */ + class Result + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val detectorVersion: JsonField, + private val overallScore: JsonField, + private val verdict: JsonField, + private val compositeScores: JsonField, + private val confidence: JsonField, + private val error: JsonField, + private val pageCount: JsonField, + private val pageDimensions: JsonField>, + private val reasoning: JsonField, + private val suspectRegions: JsonField>, + private val syntheticScore: JsonField, + private val tamperingScore: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("detector_version") + @ExcludeMissing + detectorVersion: JsonField = JsonMissing.of(), + @JsonProperty("overall_score") + @ExcludeMissing + overallScore: JsonField = JsonMissing.of(), + @JsonProperty("verdict") @ExcludeMissing verdict: JsonField = JsonMissing.of(), + @JsonProperty("composite_scores") + @ExcludeMissing + compositeScores: JsonField = JsonMissing.of(), + @JsonProperty("confidence") + @ExcludeMissing + confidence: JsonField = JsonMissing.of(), + @JsonProperty("error") @ExcludeMissing error: JsonField = JsonMissing.of(), + @JsonProperty("page_count") + @ExcludeMissing + pageCount: JsonField = JsonMissing.of(), + @JsonProperty("page_dimensions") + @ExcludeMissing + pageDimensions: JsonField> = JsonMissing.of(), + @JsonProperty("reasoning") + @ExcludeMissing + reasoning: JsonField = JsonMissing.of(), + @JsonProperty("suspect_regions") + @ExcludeMissing + suspectRegions: JsonField> = JsonMissing.of(), + @JsonProperty("synthetic_score") + @ExcludeMissing + syntheticScore: JsonField = JsonMissing.of(), + @JsonProperty("tampering_score") + @ExcludeMissing + tamperingScore: JsonField = JsonMissing.of(), + ) : this( + detectorVersion, + overallScore, + verdict, + compositeScores, + confidence, + error, + pageCount, + pageDimensions, + reasoning, + suspectRegions, + syntheticScore, + tamperingScore, + mutableMapOf(), + ) + + /** + * Version of the detector that produced the result + * + * @throws LlamaCloudInvalidDataException 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 detectorVersion(): String = detectorVersion.getRequired("detector_version") + + /** + * Overall doctoring likelihood (0 to 1) + * + * @throws LlamaCloudInvalidDataException 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 overallScore(): Double = overallScore.getRequired("overall_score") + + /** + * Overall verdict for the document + * + * @throws LlamaCloudInvalidDataException 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 verdict(): Verdict = verdict.getRequired("verdict") + + /** + * Composite scores, each answering one question about the document + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun compositeScores(): Optional = + compositeScores.getOptional("composite_scores") + + /** + * Confidence in the verdict (0 to 1): how firmly the detected signals support the verdict + * bucket, independent of the doctoring likelihood itself + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun confidence(): Optional = confidence.getOptional("confidence") + + /** + * Error detail when the analysis could not complete + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun error(): Optional = error.getOptional("error") + + /** + * Number of analysed pages (1 for images/docx) + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun pageCount(): Optional = pageCount.getOptional("page_count") + + /** + * Rendered pixel size per page, so region bboxes can be scaled onto the page + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun pageDimensions(): Optional> = + pageDimensions.getOptional("page_dimensions") + + /** + * Explanation of the verdict + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun reasoning(): Optional = reasoning.getOptional("reasoning") + + /** + * Regions that led to the suspected fraud, ranked most-suspect first, each with an + * explanation of what makes it suspect + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun suspectRegions(): Optional> = + suspectRegions.getOptional("suspect_regions") + + /** + * Likelihood (0 to 1) that the document is wholly generated or fabricated rather than a + * capture of a real document. Null for jobs completed before this score was introduced + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun syntheticScore(): Optional = syntheticScore.getOptional("synthetic_score") + + /** + * Likelihood (0 to 1) that a real captured document was locally edited — a genuine capture + * with regions altered after the fact. Null for jobs completed before this score was + * introduced + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tamperingScore(): Optional = tamperingScore.getOptional("tampering_score") + + /** + * Returns the raw JSON value of [detectorVersion]. + * + * Unlike [detectorVersion], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("detector_version") + @ExcludeMissing + fun _detectorVersion(): JsonField = detectorVersion + + /** + * Returns the raw JSON value of [overallScore]. + * + * Unlike [overallScore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("overall_score") + @ExcludeMissing + fun _overallScore(): JsonField = overallScore + + /** + * Returns the raw JSON value of [verdict]. + * + * Unlike [verdict], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("verdict") @ExcludeMissing fun _verdict(): JsonField = verdict + + /** + * Returns the raw JSON value of [compositeScores]. + * + * Unlike [compositeScores], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("composite_scores") + @ExcludeMissing + fun _compositeScores(): JsonField = compositeScores + + /** + * Returns the raw JSON value of [confidence]. + * + * Unlike [confidence], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("confidence") + @ExcludeMissing + fun _confidence(): JsonField = confidence + + /** + * Returns the raw JSON value of [error]. + * + * Unlike [error], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error") @ExcludeMissing fun _error(): JsonField = error + + /** + * Returns the raw JSON value of [pageCount]. + * + * Unlike [pageCount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page_count") @ExcludeMissing fun _pageCount(): JsonField = pageCount + + /** + * Returns the raw JSON value of [pageDimensions]. + * + * Unlike [pageDimensions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("page_dimensions") + @ExcludeMissing + fun _pageDimensions(): JsonField> = pageDimensions + + /** + * Returns the raw JSON value of [reasoning]. + * + * Unlike [reasoning], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("reasoning") @ExcludeMissing fun _reasoning(): JsonField = reasoning + + /** + * Returns the raw JSON value of [suspectRegions]. + * + * Unlike [suspectRegions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("suspect_regions") + @ExcludeMissing + fun _suspectRegions(): JsonField> = suspectRegions + + /** + * Returns the raw JSON value of [syntheticScore]. + * + * Unlike [syntheticScore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("synthetic_score") + @ExcludeMissing + fun _syntheticScore(): JsonField = syntheticScore + + /** + * Returns the raw JSON value of [tamperingScore]. + * + * Unlike [tamperingScore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tampering_score") + @ExcludeMissing + fun _tamperingScore(): JsonField = tamperingScore + + @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 [Result]. + * + * The following fields are required: + * ```java + * .detectorVersion() + * .overallScore() + * .verdict() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Result]. */ + class Builder internal constructor() { + + private var detectorVersion: JsonField? = null + private var overallScore: JsonField? = null + private var verdict: JsonField? = null + private var compositeScores: JsonField = JsonMissing.of() + private var confidence: JsonField = JsonMissing.of() + private var error: JsonField = JsonMissing.of() + private var pageCount: JsonField = JsonMissing.of() + private var pageDimensions: JsonField>? = null + private var reasoning: JsonField = JsonMissing.of() + private var suspectRegions: JsonField>? = null + private var syntheticScore: JsonField = JsonMissing.of() + private var tamperingScore: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(result: Result) = apply { + detectorVersion = result.detectorVersion + overallScore = result.overallScore + verdict = result.verdict + compositeScores = result.compositeScores + confidence = result.confidence + error = result.error + pageCount = result.pageCount + pageDimensions = result.pageDimensions.map { it.toMutableList() } + reasoning = result.reasoning + suspectRegions = result.suspectRegions.map { it.toMutableList() } + syntheticScore = result.syntheticScore + tamperingScore = result.tamperingScore + additionalProperties = result.additionalProperties.toMutableMap() + } + + /** Version of the detector that produced the result */ + fun detectorVersion(detectorVersion: String) = + detectorVersion(JsonField.of(detectorVersion)) + + /** + * Sets [Builder.detectorVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.detectorVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun detectorVersion(detectorVersion: JsonField) = apply { + this.detectorVersion = detectorVersion + } + + /** Overall doctoring likelihood (0 to 1) */ + fun overallScore(overallScore: Double) = overallScore(JsonField.of(overallScore)) + + /** + * Sets [Builder.overallScore] to an arbitrary JSON value. + * + * You should usually call [Builder.overallScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun overallScore(overallScore: JsonField) = apply { + this.overallScore = overallScore + } + + /** Overall verdict for the document */ + fun verdict(verdict: Verdict) = verdict(JsonField.of(verdict)) + + /** + * Sets [Builder.verdict] to an arbitrary JSON value. + * + * You should usually call [Builder.verdict] with a well-typed [Verdict] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun verdict(verdict: JsonField) = apply { this.verdict = verdict } + + /** Composite scores, each answering one question about the document */ + fun compositeScores(compositeScores: CompositeScores) = + compositeScores(JsonField.of(compositeScores)) + + /** + * Sets [Builder.compositeScores] to an arbitrary JSON value. + * + * You should usually call [Builder.compositeScores] with a well-typed [CompositeScores] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun compositeScores(compositeScores: JsonField) = apply { + this.compositeScores = compositeScores + } + + /** + * Confidence in the verdict (0 to 1): how firmly the detected signals support the + * verdict bucket, independent of the doctoring likelihood itself + */ + fun confidence(confidence: Double) = confidence(JsonField.of(confidence)) + + /** + * Sets [Builder.confidence] to an arbitrary JSON value. + * + * You should usually call [Builder.confidence] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun confidence(confidence: JsonField) = apply { this.confidence = confidence } + + /** Error detail when the analysis could not complete */ + fun error(error: String?) = error(JsonField.ofNullable(error)) + + /** Alias for calling [Builder.error] with `error.orElse(null)`. */ + fun error(error: Optional) = error(error.getOrNull()) + + /** + * Sets [Builder.error] to an arbitrary JSON value. + * + * You should usually call [Builder.error] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun error(error: JsonField) = apply { this.error = error } + + /** Number of analysed pages (1 for images/docx) */ + fun pageCount(pageCount: Long) = pageCount(JsonField.of(pageCount)) + + /** + * Sets [Builder.pageCount] to an arbitrary JSON value. + * + * You should usually call [Builder.pageCount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pageCount(pageCount: JsonField) = apply { this.pageCount = pageCount } + + /** Rendered pixel size per page, so region bboxes can be scaled onto the page */ + fun pageDimensions(pageDimensions: List) = + pageDimensions(JsonField.of(pageDimensions)) + + /** + * Sets [Builder.pageDimensions] to an arbitrary JSON value. + * + * You should usually call [Builder.pageDimensions] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun pageDimensions(pageDimensions: JsonField>) = apply { + this.pageDimensions = pageDimensions.map { it.toMutableList() } + } + + /** + * Adds a single [PageDimension] to [pageDimensions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPageDimension(pageDimension: PageDimension) = apply { + pageDimensions = + (pageDimensions ?: JsonField.of(mutableListOf())).also { + checkKnown("pageDimensions", it).add(pageDimension) + } + } + + /** Explanation of the verdict */ + fun reasoning(reasoning: String) = reasoning(JsonField.of(reasoning)) + + /** + * Sets [Builder.reasoning] to an arbitrary JSON value. + * + * You should usually call [Builder.reasoning] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun reasoning(reasoning: JsonField) = apply { this.reasoning = reasoning } + + /** + * Regions that led to the suspected fraud, ranked most-suspect first, each with an + * explanation of what makes it suspect + */ + fun suspectRegions(suspectRegions: List) = + suspectRegions(JsonField.of(suspectRegions)) + + /** + * Sets [Builder.suspectRegions] to an arbitrary JSON value. + * + * You should usually call [Builder.suspectRegions] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun suspectRegions(suspectRegions: JsonField>) = apply { + this.suspectRegions = suspectRegions.map { it.toMutableList() } + } + + /** + * Adds a single [SuspectRegion] to [suspectRegions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSuspectRegion(suspectRegion: SuspectRegion) = apply { + suspectRegions = + (suspectRegions ?: JsonField.of(mutableListOf())).also { + checkKnown("suspectRegions", it).add(suspectRegion) + } + } + + /** + * Likelihood (0 to 1) that the document is wholly generated or fabricated rather than a + * capture of a real document. Null for jobs completed before this score was introduced + */ + fun syntheticScore(syntheticScore: Double?) = + syntheticScore(JsonField.ofNullable(syntheticScore)) + + /** + * Alias for [Builder.syntheticScore]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun syntheticScore(syntheticScore: Double) = syntheticScore(syntheticScore as Double?) + + /** Alias for calling [Builder.syntheticScore] with `syntheticScore.orElse(null)`. */ + fun syntheticScore(syntheticScore: Optional) = + syntheticScore(syntheticScore.getOrNull()) + + /** + * Sets [Builder.syntheticScore] to an arbitrary JSON value. + * + * You should usually call [Builder.syntheticScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun syntheticScore(syntheticScore: JsonField) = apply { + this.syntheticScore = syntheticScore + } + + /** + * Likelihood (0 to 1) that a real captured document was locally edited — a genuine + * capture with regions altered after the fact. Null for jobs completed before this + * score was introduced + */ + fun tamperingScore(tamperingScore: Double?) = + tamperingScore(JsonField.ofNullable(tamperingScore)) + + /** + * Alias for [Builder.tamperingScore]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun tamperingScore(tamperingScore: Double) = tamperingScore(tamperingScore as Double?) + + /** Alias for calling [Builder.tamperingScore] with `tamperingScore.orElse(null)`. */ + fun tamperingScore(tamperingScore: Optional) = + tamperingScore(tamperingScore.getOrNull()) + + /** + * Sets [Builder.tamperingScore] to an arbitrary JSON value. + * + * You should usually call [Builder.tamperingScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tamperingScore(tamperingScore: JsonField) = apply { + this.tamperingScore = tamperingScore + } + + 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 [Result]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .detectorVersion() + * .overallScore() + * .verdict() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Result = + Result( + checkRequired("detectorVersion", detectorVersion), + checkRequired("overallScore", overallScore), + checkRequired("verdict", verdict), + compositeScores, + confidence, + error, + pageCount, + (pageDimensions ?: JsonMissing.of()).map { it.toImmutable() }, + reasoning, + (suspectRegions ?: JsonMissing.of()).map { it.toImmutable() }, + syntheticScore, + tamperingScore, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Result = apply { + if (validated) { + return@apply + } + + detectorVersion() + overallScore() + verdict().validate() + compositeScores().ifPresent { it.validate() } + confidence() + error() + pageCount() + pageDimensions().ifPresent { it.forEach { it.validate() } } + reasoning() + suspectRegions().ifPresent { it.forEach { it.validate() } } + syntheticScore() + tamperingScore() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (detectorVersion.asKnown().isPresent) 1 else 0) + + (if (overallScore.asKnown().isPresent) 1 else 0) + + (verdict.asKnown().getOrNull()?.validity() ?: 0) + + (compositeScores.asKnown().getOrNull()?.validity() ?: 0) + + (if (confidence.asKnown().isPresent) 1 else 0) + + (if (error.asKnown().isPresent) 1 else 0) + + (if (pageCount.asKnown().isPresent) 1 else 0) + + (pageDimensions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (reasoning.asKnown().isPresent) 1 else 0) + + (suspectRegions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (syntheticScore.asKnown().isPresent) 1 else 0) + + (if (tamperingScore.asKnown().isPresent) 1 else 0) + + /** Overall verdict for the document */ + class Verdict @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 AUTHENTIC = of("AUTHENTIC") + + @JvmField val DOCTORED = of("DOCTORED") + + @JvmField val LIKELY_DOCTORED = of("LIKELY_DOCTORED") + + @JvmField val NO_STRONG_SIGNAL = of("NO_STRONG_SIGNAL") + + @JvmField val SUSPICIOUS = of("SUSPICIOUS") + + @JvmStatic fun of(value: String) = Verdict(JsonField.of(value)) + } + + /** An enum containing [Verdict]'s known values. */ + enum class Known { + AUTHENTIC, + DOCTORED, + LIKELY_DOCTORED, + NO_STRONG_SIGNAL, + SUSPICIOUS, + } + + /** + * An enum containing [Verdict]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Verdict] 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 { + AUTHENTIC, + DOCTORED, + LIKELY_DOCTORED, + NO_STRONG_SIGNAL, + SUSPICIOUS, + /** + * An enum member indicating that [Verdict] 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) { + AUTHENTIC -> Value.AUTHENTIC + DOCTORED -> Value.DOCTORED + LIKELY_DOCTORED -> Value.LIKELY_DOCTORED + NO_STRONG_SIGNAL -> Value.NO_STRONG_SIGNAL + SUSPICIOUS -> Value.SUSPICIOUS + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + AUTHENTIC -> Known.AUTHENTIC + DOCTORED -> Known.DOCTORED + LIKELY_DOCTORED -> Known.LIKELY_DOCTORED + NO_STRONG_SIGNAL -> Known.NO_STRONG_SIGNAL + SUSPICIOUS -> Known.SUSPICIOUS + else -> throw LlamaCloudInvalidDataException("Unknown Verdict: $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 LlamaCloudInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Verdict = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Verdict && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Composite scores, each answering one question about the document */ + class CompositeScores + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val aiGenerated: JsonField, + private val documentCoherence: JsonField, + private val documentMetadata: JsonField, + private val knownFraud: JsonField, + private val manuallyEdited: JsonField, + private val recapture: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("ai_generated") + @ExcludeMissing + aiGenerated: JsonField = JsonMissing.of(), + @JsonProperty("document_coherence") + @ExcludeMissing + documentCoherence: JsonField = JsonMissing.of(), + @JsonProperty("document_metadata") + @ExcludeMissing + documentMetadata: JsonField = JsonMissing.of(), + @JsonProperty("known_fraud") + @ExcludeMissing + knownFraud: JsonField = JsonMissing.of(), + @JsonProperty("manually_edited") + @ExcludeMissing + manuallyEdited: JsonField = JsonMissing.of(), + @JsonProperty("recapture") + @ExcludeMissing + recapture: JsonField = JsonMissing.of(), + ) : this( + aiGenerated, + documentCoherence, + documentMetadata, + knownFraud, + manuallyEdited, + recapture, + mutableMapOf(), + ) + + /** + * Was this content synthesized by a generative model? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun aiGenerated(): Optional = aiGenerated.getOptional("ai_generated") + + /** + * Does the document's content agree with itself (checksums, arithmetic, + * machine-readable zones)? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun documentCoherence(): Optional = + documentCoherence.getOptional("document_coherence") + + /** + * Does the file's provenance / toolchain history look suspicious? Advisory: + * individually weak workflow-hygiene signals + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun documentMetadata(): Optional = + documentMetadata.getOptional("document_metadata") + + /** + * Has this asset (or its template) been seen in fraud before? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun knownFraud(): Optional = knownFraud.getOptional("known_fraud") + + /** + * Was this document altered after creation (splice, retype, redact, inpaint)? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun manuallyEdited(): Optional = + manuallyEdited.getOptional("manually_edited") + + /** + * Was the document captured through a channel that destroys forensic evidence (photo of + * a screen, print-then-rescan)? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun recapture(): Optional = recapture.getOptional("recapture") + + /** + * Returns the raw JSON value of [aiGenerated]. + * + * Unlike [aiGenerated], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("ai_generated") + @ExcludeMissing + fun _aiGenerated(): JsonField = aiGenerated + + /** + * Returns the raw JSON value of [documentCoherence]. + * + * Unlike [documentCoherence], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("document_coherence") + @ExcludeMissing + fun _documentCoherence(): JsonField = documentCoherence + + /** + * Returns the raw JSON value of [documentMetadata]. + * + * Unlike [documentMetadata], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("document_metadata") + @ExcludeMissing + fun _documentMetadata(): JsonField = documentMetadata + + /** + * Returns the raw JSON value of [knownFraud]. + * + * Unlike [knownFraud], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("known_fraud") + @ExcludeMissing + fun _knownFraud(): JsonField = knownFraud + + /** + * Returns the raw JSON value of [manuallyEdited]. + * + * Unlike [manuallyEdited], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("manually_edited") + @ExcludeMissing + fun _manuallyEdited(): JsonField = manuallyEdited + + /** + * Returns the raw JSON value of [recapture]. + * + * Unlike [recapture], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("recapture") + @ExcludeMissing + fun _recapture(): JsonField = recapture + + @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 [CompositeScores]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CompositeScores]. */ + class Builder internal constructor() { + + private var aiGenerated: JsonField = JsonMissing.of() + private var documentCoherence: JsonField = JsonMissing.of() + private var documentMetadata: JsonField = JsonMissing.of() + private var knownFraud: JsonField = JsonMissing.of() + private var manuallyEdited: JsonField = JsonMissing.of() + private var recapture: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(compositeScores: CompositeScores) = apply { + aiGenerated = compositeScores.aiGenerated + documentCoherence = compositeScores.documentCoherence + documentMetadata = compositeScores.documentMetadata + knownFraud = compositeScores.knownFraud + manuallyEdited = compositeScores.manuallyEdited + recapture = compositeScores.recapture + additionalProperties = compositeScores.additionalProperties.toMutableMap() + } + + /** Was this content synthesized by a generative model? */ + fun aiGenerated(aiGenerated: AiGenerated) = aiGenerated(JsonField.of(aiGenerated)) + + /** + * Sets [Builder.aiGenerated] to an arbitrary JSON value. + * + * You should usually call [Builder.aiGenerated] with a well-typed [AiGenerated] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun aiGenerated(aiGenerated: JsonField) = apply { + this.aiGenerated = aiGenerated + } + + /** + * Does the document's content agree with itself (checksums, arithmetic, + * machine-readable zones)? + */ + fun documentCoherence(documentCoherence: DocumentCoherence) = + documentCoherence(JsonField.of(documentCoherence)) + + /** + * Sets [Builder.documentCoherence] to an arbitrary JSON value. + * + * You should usually call [Builder.documentCoherence] with a well-typed + * [DocumentCoherence] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun documentCoherence(documentCoherence: JsonField) = apply { + this.documentCoherence = documentCoherence + } + + /** + * Does the file's provenance / toolchain history look suspicious? Advisory: + * individually weak workflow-hygiene signals + */ + fun documentMetadata(documentMetadata: DocumentMetadata) = + documentMetadata(JsonField.of(documentMetadata)) + + /** + * Sets [Builder.documentMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.documentMetadata] with a well-typed + * [DocumentMetadata] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun documentMetadata(documentMetadata: JsonField) = apply { + this.documentMetadata = documentMetadata + } + + /** Has this asset (or its template) been seen in fraud before? */ + fun knownFraud(knownFraud: KnownFraud) = knownFraud(JsonField.of(knownFraud)) + + /** + * Sets [Builder.knownFraud] to an arbitrary JSON value. + * + * You should usually call [Builder.knownFraud] with a well-typed [KnownFraud] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun knownFraud(knownFraud: JsonField) = apply { + this.knownFraud = knownFraud + } + + /** Was this document altered after creation (splice, retype, redact, inpaint)? */ + fun manuallyEdited(manuallyEdited: ManuallyEdited) = + manuallyEdited(JsonField.of(manuallyEdited)) + + /** + * Sets [Builder.manuallyEdited] to an arbitrary JSON value. + * + * You should usually call [Builder.manuallyEdited] with a well-typed + * [ManuallyEdited] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun manuallyEdited(manuallyEdited: JsonField) = apply { + this.manuallyEdited = manuallyEdited + } + + /** + * Was the document captured through a channel that destroys forensic evidence + * (photo of a screen, print-then-rescan)? + */ + fun recapture(recapture: Recapture) = recapture(JsonField.of(recapture)) + + /** + * Sets [Builder.recapture] to an arbitrary JSON value. + * + * You should usually call [Builder.recapture] with a well-typed [Recapture] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun recapture(recapture: JsonField) = apply { + this.recapture = recapture + } + + 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 [CompositeScores]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CompositeScores = + CompositeScores( + aiGenerated, + documentCoherence, + documentMetadata, + knownFraud, + manuallyEdited, + recapture, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): CompositeScores = apply { + if (validated) { + return@apply + } + + aiGenerated().ifPresent { it.validate() } + documentCoherence().ifPresent { it.validate() } + documentMetadata().ifPresent { it.validate() } + knownFraud().ifPresent { it.validate() } + manuallyEdited().ifPresent { it.validate() } + recapture().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (aiGenerated.asKnown().getOrNull()?.validity() ?: 0) + + (documentCoherence.asKnown().getOrNull()?.validity() ?: 0) + + (documentMetadata.asKnown().getOrNull()?.validity() ?: 0) + + (knownFraud.asKnown().getOrNull()?.validity() ?: 0) + + (manuallyEdited.asKnown().getOrNull()?.validity() ?: 0) + + (recapture.asKnown().getOrNull()?.validity() ?: 0) + + /** Was this content synthesized by a generative model? */ + class AiGenerated + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [AiGenerated]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AiGenerated]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(aiGenerated: AiGenerated) = apply { + applicable = aiGenerated.applicable + score = aiGenerated.score + additionalProperties = aiGenerated.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [AiGenerated]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): AiGenerated = + AiGenerated(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AiGenerated = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AiGenerated && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AiGenerated{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Does the document's content agree with itself (checksums, arithmetic, + * machine-readable zones)? + */ + class DocumentCoherence + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 + * [DocumentCoherence]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DocumentCoherence]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(documentCoherence: DocumentCoherence) = apply { + applicable = documentCoherence.applicable + score = documentCoherence.score + additionalProperties = documentCoherence.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [DocumentCoherence]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DocumentCoherence = + DocumentCoherence(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): DocumentCoherence = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DocumentCoherence && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DocumentCoherence{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Does the file's provenance / toolchain history look suspicious? Advisory: + * individually weak workflow-hygiene signals + */ + class DocumentMetadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [DocumentMetadata]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DocumentMetadata]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(documentMetadata: DocumentMetadata) = apply { + applicable = documentMetadata.applicable + score = documentMetadata.score + additionalProperties = documentMetadata.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [DocumentMetadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DocumentMetadata = + DocumentMetadata(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): DocumentMetadata = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DocumentMetadata && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DocumentMetadata{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** Has this asset (or its template) been seen in fraud before? */ + class KnownFraud + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [KnownFraud]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [KnownFraud]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(knownFraud: KnownFraud) = apply { + applicable = knownFraud.applicable + score = knownFraud.score + additionalProperties = knownFraud.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [KnownFraud]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): KnownFraud = + KnownFraud(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): KnownFraud = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is KnownFraud && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "KnownFraud{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** Was this document altered after creation (splice, retype, redact, inpaint)? */ + class ManuallyEdited + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [ManuallyEdited]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ManuallyEdited]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(manuallyEdited: ManuallyEdited) = apply { + applicable = manuallyEdited.applicable + score = manuallyEdited.score + additionalProperties = manuallyEdited.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [ManuallyEdited]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ManuallyEdited = + ManuallyEdited(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): ManuallyEdited = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ManuallyEdited && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ManuallyEdited{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Was the document captured through a channel that destroys forensic evidence (photo of + * a screen, print-then-rescan)? + */ + class Recapture + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [Recapture]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Recapture]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(recapture: Recapture) = apply { + applicable = recapture.applicable + score = recapture.score + additionalProperties = recapture.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [Recapture]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Recapture = + Recapture(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Recapture = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Recapture && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Recapture{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CompositeScores && + aiGenerated == other.aiGenerated && + documentCoherence == other.documentCoherence && + documentMetadata == other.documentMetadata && + knownFraud == other.knownFraud && + manuallyEdited == other.manuallyEdited && + recapture == other.recapture && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + aiGenerated, + documentCoherence, + documentMetadata, + knownFraud, + manuallyEdited, + recapture, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositeScores{aiGenerated=$aiGenerated, documentCoherence=$documentCoherence, documentMetadata=$documentMetadata, knownFraud=$knownFraud, manuallyEdited=$manuallyEdited, recapture=$recapture, additionalProperties=$additionalProperties}" + } + + /** + * Rendered pixel size of a page — the coordinate space region bboxes use, so the UI can + * scale the suspect-region overlay onto the displayed page. + */ + class PageDimension + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val height: JsonField, + private val page: JsonField, + private val width: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("height") @ExcludeMissing height: JsonField = JsonMissing.of(), + @JsonProperty("page") @ExcludeMissing page: JsonField = JsonMissing.of(), + @JsonProperty("width") @ExcludeMissing width: JsonField = JsonMissing.of(), + ) : this(height, page, width, mutableMapOf()) + + /** + * Rendered page height in pixels + * + * @throws LlamaCloudInvalidDataException 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 height(): Long = height.getRequired("height") + + /** + * 0-based page index (0 for standalone images) + * + * @throws LlamaCloudInvalidDataException 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 page(): Long = page.getRequired("page") + + /** + * Rendered page width in pixels + * + * @throws LlamaCloudInvalidDataException 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 width(): Long = width.getRequired("width") + + /** + * Returns the raw JSON value of [height]. + * + * Unlike [height], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("height") @ExcludeMissing fun _height(): JsonField = height + + /** + * Returns the raw JSON value of [page]. + * + * Unlike [page], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page") @ExcludeMissing fun _page(): JsonField = page + + /** + * Returns the raw JSON value of [width]. + * + * Unlike [width], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("width") @ExcludeMissing fun _width(): JsonField = width + + @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 [PageDimension]. + * + * The following fields are required: + * ```java + * .height() + * .page() + * .width() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PageDimension]. */ + class Builder internal constructor() { + + private var height: JsonField? = null + private var page: JsonField? = null + private var width: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(pageDimension: PageDimension) = apply { + height = pageDimension.height + page = pageDimension.page + width = pageDimension.width + additionalProperties = pageDimension.additionalProperties.toMutableMap() + } + + /** Rendered page height in pixels */ + fun height(height: Long) = height(JsonField.of(height)) + + /** + * Sets [Builder.height] to an arbitrary JSON value. + * + * You should usually call [Builder.height] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun height(height: JsonField) = apply { this.height = height } + + /** 0-based page index (0 for standalone images) */ + fun page(page: Long) = page(JsonField.of(page)) + + /** + * Sets [Builder.page] to an arbitrary JSON value. + * + * You should usually call [Builder.page] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun page(page: JsonField) = apply { this.page = page } + + /** Rendered page width in pixels */ + fun width(width: Long) = width(JsonField.of(width)) + + /** + * Sets [Builder.width] to an arbitrary JSON value. + * + * You should usually call [Builder.width] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun width(width: JsonField) = apply { this.width = width } + + 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 [PageDimension]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .height() + * .page() + * .width() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PageDimension = + PageDimension( + checkRequired("height", height), + checkRequired("page", page), + checkRequired("width", width), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): PageDimension = apply { + if (validated) { + return@apply + } + + height() + page() + width() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (height.asKnown().isPresent) 1 else 0) + + (if (page.asKnown().isPresent) 1 else 0) + + (if (width.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PageDimension && + height == other.height && + page == other.page && + width == other.width && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(height, page, width, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PageDimension{height=$height, page=$page, width=$width, additionalProperties=$additionalProperties}" + } + + /** + * A region that led to the suspected fraud, with why it is suspect. + * + * A curated, high-signal subset of ``regions``: reviewer-dismissed candidates are dropped + * and the remainder is ranked by suspicion, so consumers can act on ``verdict`` + + * ``confidence`` + this list without reading the raw signals. + */ + class SuspectRegion + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bbox: JsonField>, + private val explanation: JsonField, + private val kind: JsonField, + private val page: JsonField, + private val score: JsonField, + private val source: JsonField, + private val primary: JsonField, + private val review: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bbox") + @ExcludeMissing + bbox: JsonField> = JsonMissing.of(), + @JsonProperty("explanation") + @ExcludeMissing + explanation: JsonField = JsonMissing.of(), + @JsonProperty("kind") @ExcludeMissing kind: JsonField = JsonMissing.of(), + @JsonProperty("page") @ExcludeMissing page: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + @JsonProperty("source") + @ExcludeMissing + source: JsonField = JsonMissing.of(), + @JsonProperty("primary") + @ExcludeMissing + primary: JsonField = JsonMissing.of(), + @JsonProperty("review") @ExcludeMissing review: JsonField = JsonMissing.of(), + ) : this(bbox, explanation, kind, page, score, source, primary, review, mutableMapOf()) + + /** + * Region bounding box as [x, y, w, h] in page-render pixels + * + * @throws LlamaCloudInvalidDataException 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 bbox(): List = bbox.getRequired("bbox") + + /** + * Human-readable explanation of what makes this region suspect + * + * @throws LlamaCloudInvalidDataException 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 explanation(): String = explanation.getRequired("explanation") + + /** + * Kind of anomaly detected in this region + * + * @throws LlamaCloudInvalidDataException 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 kind(): String = kind.getRequired("kind") + + /** + * 0-based page index (0 for standalone images) + * + * @throws LlamaCloudInvalidDataException 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 page(): Long = page.getRequired("page") + + /** + * Suspicion score for this region (0 to 1) + * + * @throws LlamaCloudInvalidDataException 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 score(): Double = score.getRequired("score") + + /** + * Detector that flagged this region + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun source(): String = source.getRequired("source") + + /** + * Whether this region is part of the small set of decisive evidence behind the verdict + * — the boxes a reviewer should look at first + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun primary(): Optional = primary.getOptional("primary") + + /** + * Automated reviewer verdict for this region (confirmed, dismissed, unsure, or empty). + * A dismissed region can still be surfaced when it is the only place to look; this + * label says how to read it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun review(): Optional = review.getOptional("review") + + /** + * Returns the raw JSON value of [bbox]. + * + * Unlike [bbox], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("bbox") @ExcludeMissing fun _bbox(): JsonField> = bbox + + /** + * Returns the raw JSON value of [explanation]. + * + * Unlike [explanation], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("explanation") + @ExcludeMissing + fun _explanation(): JsonField = explanation + + /** + * Returns the raw JSON value of [kind]. + * + * Unlike [kind], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("kind") @ExcludeMissing fun _kind(): JsonField = kind + + /** + * Returns the raw JSON value of [page]. + * + * Unlike [page], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page") @ExcludeMissing fun _page(): JsonField = page + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + /** + * Returns the raw JSON value of [primary]. + * + * Unlike [primary], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("primary") @ExcludeMissing fun _primary(): JsonField = primary + + /** + * Returns the raw JSON value of [review]. + * + * Unlike [review], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("review") @ExcludeMissing fun _review(): JsonField = review + + @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 [SuspectRegion]. + * + * The following fields are required: + * ```java + * .bbox() + * .explanation() + * .kind() + * .page() + * .score() + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SuspectRegion]. */ + class Builder internal constructor() { + + private var bbox: JsonField>? = null + private var explanation: JsonField? = null + private var kind: JsonField? = null + private var page: JsonField? = null + private var score: JsonField? = null + private var source: JsonField? = null + private var primary: JsonField = JsonMissing.of() + private var review: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(suspectRegion: SuspectRegion) = apply { + bbox = suspectRegion.bbox.map { it.toMutableList() } + explanation = suspectRegion.explanation + kind = suspectRegion.kind + page = suspectRegion.page + score = suspectRegion.score + source = suspectRegion.source + primary = suspectRegion.primary + review = suspectRegion.review + additionalProperties = suspectRegion.additionalProperties.toMutableMap() + } + + /** Region bounding box as [x, y, w, h] in page-render pixels */ + fun bbox(bbox: List) = bbox(JsonField.of(bbox)) + + /** + * Sets [Builder.bbox] to an arbitrary JSON value. + * + * You should usually call [Builder.bbox] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun bbox(bbox: JsonField>) = apply { + this.bbox = bbox.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.bbox]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addBbox(bbox: Long) = apply { + this.bbox = + (this.bbox ?: JsonField.of(mutableListOf())).also { + checkKnown("bbox", it).add(bbox) + } + } + + /** Human-readable explanation of what makes this region suspect */ + fun explanation(explanation: String) = explanation(JsonField.of(explanation)) + + /** + * Sets [Builder.explanation] to an arbitrary JSON value. + * + * You should usually call [Builder.explanation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun explanation(explanation: JsonField) = apply { + this.explanation = explanation + } + + /** Kind of anomaly detected in this region */ + fun kind(kind: String) = kind(JsonField.of(kind)) + + /** + * Sets [Builder.kind] to an arbitrary JSON value. + * + * You should usually call [Builder.kind] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun kind(kind: JsonField) = apply { this.kind = kind } + + /** 0-based page index (0 for standalone images) */ + fun page(page: Long) = page(JsonField.of(page)) + + /** + * Sets [Builder.page] to an arbitrary JSON value. + * + * You should usually call [Builder.page] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun page(page: JsonField) = apply { this.page = page } + + /** Suspicion score for this region (0 to 1) */ + fun score(score: Double) = score(JsonField.of(score)) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + /** Detector that flagged this region */ + fun source(source: String) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + /** + * Whether this region is part of the small set of decisive evidence behind the + * verdict — the boxes a reviewer should look at first + */ + fun primary(primary: Boolean) = primary(JsonField.of(primary)) + + /** + * Sets [Builder.primary] to an arbitrary JSON value. + * + * You should usually call [Builder.primary] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun primary(primary: JsonField) = apply { this.primary = primary } + + /** + * Automated reviewer verdict for this region (confirmed, dismissed, unsure, or + * empty). A dismissed region can still be surfaced when it is the only place to + * look; this label says how to read it + */ + fun review(review: String) = review(JsonField.of(review)) + + /** + * Sets [Builder.review] to an arbitrary JSON value. + * + * You should usually call [Builder.review] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun review(review: JsonField) = apply { this.review = review } + + 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 [SuspectRegion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .bbox() + * .explanation() + * .kind() + * .page() + * .score() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SuspectRegion = + SuspectRegion( + checkRequired("bbox", bbox).map { it.toImmutable() }, + checkRequired("explanation", explanation), + checkRequired("kind", kind), + checkRequired("page", page), + checkRequired("score", score), + checkRequired("source", source), + primary, + review, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): SuspectRegion = apply { + if (validated) { + return@apply + } + + bbox() + explanation() + kind() + page() + score() + source() + primary() + review() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (bbox.asKnown().getOrNull()?.size ?: 0) + + (if (explanation.asKnown().isPresent) 1 else 0) + + (if (kind.asKnown().isPresent) 1 else 0) + + (if (page.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + (if (source.asKnown().isPresent) 1 else 0) + + (if (primary.asKnown().isPresent) 1 else 0) + + (if (review.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SuspectRegion && + bbox == other.bbox && + explanation == other.explanation && + kind == other.kind && + page == other.page && + score == other.score && + source == other.source && + primary == other.primary && + review == other.review && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bbox, + explanation, + kind, + page, + score, + source, + primary, + review, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SuspectRegion{bbox=$bbox, explanation=$explanation, kind=$kind, page=$page, score=$score, source=$source, primary=$primary, review=$review, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Result && + detectorVersion == other.detectorVersion && + overallScore == other.overallScore && + verdict == other.verdict && + compositeScores == other.compositeScores && + confidence == other.confidence && + error == other.error && + pageCount == other.pageCount && + pageDimensions == other.pageDimensions && + reasoning == other.reasoning && + suspectRegions == other.suspectRegions && + syntheticScore == other.syntheticScore && + tamperingScore == other.tamperingScore && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + detectorVersion, + overallScore, + verdict, + compositeScores, + confidence, + error, + pageCount, + pageDimensions, + reasoning, + suspectRegions, + syntheticScore, + tamperingScore, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Result{detectorVersion=$detectorVersion, overallScore=$overallScore, verdict=$verdict, compositeScores=$compositeScores, confidence=$confidence, error=$error, pageCount=$pageCount, pageDimensions=$pageDimensions, reasoning=$reasoning, suspectRegions=$suspectRegions, syntheticScore=$syntheticScore, tamperingScore=$tamperingScore, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyGetResponse && + id == other.id && + configuration == other.configuration && + documentInputType == other.documentInputType && + fileInput == other.fileInput && + projectId == other.projectId && + status == other.status && + userId == other.userId && + createdAt == other.createdAt && + errorMessage == other.errorMessage && + result == other.result && + transactionId == other.transactionId && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + configuration, + documentInputType, + fileInput, + projectId, + status, + userId, + createdAt, + errorMessage, + result, + transactionId, + updatedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VerifyGetResponse{id=$id, configuration=$configuration, documentInputType=$documentInputType, fileInput=$fileInput, projectId=$projectId, status=$status, userId=$userId, createdAt=$createdAt, errorMessage=$errorMessage, result=$result, transactionId=$transactionId, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListPage.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListPage.kt new file mode 100644 index 0000000..b784fd5 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListPage.kt @@ -0,0 +1,130 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.AutoPager +import ai.llamaindex.llamacloud.core.Page +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.services.blocking.alpha.VerifyService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see VerifyService.list */ +class VerifyListPage +private constructor( + private val service: VerifyService, + private val params: VerifyListParams, + private val response: VerifyListPageResponse, +) : Page { + + /** + * Delegates to [VerifyListPageResponse], but gracefully handles missing data. + * + * @see VerifyListPageResponse.items + */ + override fun items(): List = + response._items().getOptional("items").getOrNull() ?: emptyList() + + /** + * Delegates to [VerifyListPageResponse], but gracefully handles missing data. + * + * @see VerifyListPageResponse.nextPageToken + */ + fun nextPageToken(): Optional = response._nextPageToken().getOptional("next_page_token") + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageToken().isPresent + + fun nextPageParams(): VerifyListParams { + val nextCursor = + nextPageToken().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().pageToken(nextCursor).build() + } + + override fun nextPage(): VerifyListPage = service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): VerifyListParams = params + + /** The response that this page was parsed from. */ + fun response(): VerifyListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [VerifyListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyListPage]. */ + class Builder internal constructor() { + + private var service: VerifyService? = null + private var params: VerifyListParams? = null + private var response: VerifyListPageResponse? = null + + @JvmSynthetic + internal fun from(verifyListPage: VerifyListPage) = apply { + service = verifyListPage.service + params = verifyListPage.params + response = verifyListPage.response + } + + fun service(service: VerifyService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: VerifyListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: VerifyListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [VerifyListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VerifyListPage = + VerifyListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyListPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = "VerifyListPage{service=$service, params=$params, response=$response}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListPageAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListPageAsync.kt new file mode 100644 index 0000000..ae59dd6 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListPageAsync.kt @@ -0,0 +1,145 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.AutoPagerAsync +import ai.llamaindex.llamacloud.core.PageAsync +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.services.async.alpha.VerifyServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see VerifyServiceAsync.list */ +class VerifyListPageAsync +private constructor( + private val service: VerifyServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: VerifyListParams, + private val response: VerifyListPageResponse, +) : PageAsync { + + /** + * Delegates to [VerifyListPageResponse], but gracefully handles missing data. + * + * @see VerifyListPageResponse.items + */ + override fun items(): List = + response._items().getOptional("items").getOrNull() ?: emptyList() + + /** + * Delegates to [VerifyListPageResponse], but gracefully handles missing data. + * + * @see VerifyListPageResponse.nextPageToken + */ + fun nextPageToken(): Optional = response._nextPageToken().getOptional("next_page_token") + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageToken().isPresent + + fun nextPageParams(): VerifyListParams { + val nextCursor = + nextPageToken().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().pageToken(nextCursor).build() + } + + override fun nextPage(): CompletableFuture = service.list(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) + + /** The parameters that were used to request this page. */ + fun params(): VerifyListParams = params + + /** The response that this page was parsed from. */ + fun response(): VerifyListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [VerifyListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyListPageAsync]. */ + class Builder internal constructor() { + + private var service: VerifyServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: VerifyListParams? = null + private var response: VerifyListPageResponse? = null + + @JvmSynthetic + internal fun from(verifyListPageAsync: VerifyListPageAsync) = apply { + service = verifyListPageAsync.service + streamHandlerExecutor = verifyListPageAsync.streamHandlerExecutor + params = verifyListPageAsync.params + response = verifyListPageAsync.response + } + + fun service(service: VerifyServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: VerifyListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: VerifyListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [VerifyListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VerifyListPageAsync = + VerifyListPageAsync( + checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) + + override fun toString() = + "VerifyListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListPageResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListPageResponse.kt new file mode 100644 index 0000000..1cc832c --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListPageResponse.kt @@ -0,0 +1,303 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Response schema for paginated Verify job queries. */ +class VerifyListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val items: JsonField>, + private val nextPageToken: JsonField, + private val totalSize: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("items") + @ExcludeMissing + items: JsonField> = JsonMissing.of(), + @JsonProperty("next_page_token") + @ExcludeMissing + nextPageToken: JsonField = JsonMissing.of(), + @JsonProperty("total_size") @ExcludeMissing totalSize: JsonField = JsonMissing.of(), + ) : this(items, nextPageToken, totalSize, mutableMapOf()) + + /** + * The list of items. + * + * @throws LlamaCloudInvalidDataException 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 items(): List = items.getRequired("items") + + /** + * A token, which can be sent as page_token to retrieve the next page. If this field is omitted, + * there are no subsequent pages. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextPageToken(): Optional = nextPageToken.getOptional("next_page_token") + + /** + * The total number of items available. This is only populated when specifically requested. The + * value may be an estimate and can be used for display purposes only. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun totalSize(): Optional = totalSize.getOptional("total_size") + + /** + * Returns the raw JSON value of [items]. + * + * Unlike [items], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("items") @ExcludeMissing fun _items(): JsonField> = items + + /** + * Returns the raw JSON value of [nextPageToken]. + * + * Unlike [nextPageToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_page_token") + @ExcludeMissing + fun _nextPageToken(): JsonField = nextPageToken + + /** + * Returns the raw JSON value of [totalSize]. + * + * Unlike [totalSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("total_size") @ExcludeMissing fun _totalSize(): JsonField = totalSize + + @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 [VerifyListPageResponse]. + * + * The following fields are required: + * ```java + * .items() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyListPageResponse]. */ + class Builder internal constructor() { + + private var items: JsonField>? = null + private var nextPageToken: JsonField = JsonMissing.of() + private var totalSize: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(verifyListPageResponse: VerifyListPageResponse) = apply { + items = verifyListPageResponse.items.map { it.toMutableList() } + nextPageToken = verifyListPageResponse.nextPageToken + totalSize = verifyListPageResponse.totalSize + additionalProperties = verifyListPageResponse.additionalProperties.toMutableMap() + } + + /** The list of items. */ + fun items(items: List) = items(JsonField.of(items)) + + /** + * Sets [Builder.items] to an arbitrary JSON value. + * + * You should usually call [Builder.items] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun items(items: JsonField>) = apply { + this.items = items.map { it.toMutableList() } + } + + /** + * Adds a single [VerifyListResponse] to [items]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addItem(item: VerifyListResponse) = apply { + items = + (items ?: JsonField.of(mutableListOf())).also { checkKnown("items", it).add(item) } + } + + /** + * A token, which can be sent as page_token to retrieve the next page. If this field is + * omitted, there are no subsequent pages. + */ + fun nextPageToken(nextPageToken: String?) = + nextPageToken(JsonField.ofNullable(nextPageToken)) + + /** Alias for calling [Builder.nextPageToken] with `nextPageToken.orElse(null)`. */ + fun nextPageToken(nextPageToken: Optional) = + nextPageToken(nextPageToken.getOrNull()) + + /** + * Sets [Builder.nextPageToken] to an arbitrary JSON value. + * + * You should usually call [Builder.nextPageToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun nextPageToken(nextPageToken: JsonField) = apply { + this.nextPageToken = nextPageToken + } + + /** + * The total number of items available. This is only populated when specifically requested. + * The value may be an estimate and can be used for display purposes only. + */ + fun totalSize(totalSize: Long?) = totalSize(JsonField.ofNullable(totalSize)) + + /** + * Alias for [Builder.totalSize]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalSize(totalSize: Long) = totalSize(totalSize as Long?) + + /** Alias for calling [Builder.totalSize] with `totalSize.orElse(null)`. */ + fun totalSize(totalSize: Optional) = totalSize(totalSize.getOrNull()) + + /** + * Sets [Builder.totalSize] to an arbitrary JSON value. + * + * You should usually call [Builder.totalSize] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun totalSize(totalSize: JsonField) = apply { this.totalSize = totalSize } + + 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 [VerifyListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .items() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VerifyListPageResponse = + VerifyListPageResponse( + checkRequired("items", items).map { it.toImmutable() }, + nextPageToken, + totalSize, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): VerifyListPageResponse = apply { + if (validated) { + return@apply + } + + items().forEach { it.validate() } + nextPageToken() + totalSize() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (items.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (nextPageToken.asKnown().isPresent) 1 else 0) + + (if (totalSize.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyListPageResponse && + items == other.items && + nextPageToken == other.nextPageToken && + totalSize == other.totalSize && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(items, nextPageToken, totalSize, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VerifyListPageResponse{items=$items, nextPageToken=$nextPageToken, totalSize=$totalSize, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListParams.kt new file mode 100644 index 0000000..bc18db4 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListParams.kt @@ -0,0 +1,533 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator +import java.time.OffsetDateTime +import java.time.format.DateTimeFormatter +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * List Verify jobs with optional filtering and pagination. + * + * Filter by `status`, specific `job_ids`, or creation date range. + */ +class VerifyListParams +private constructor( + private val createdAtOnOrAfter: OffsetDateTime?, + private val createdAtOnOrBefore: OffsetDateTime?, + private val expand: List?, + private val jobIds: List?, + private val organizationId: String?, + private val pageSize: Long?, + private val pageToken: String?, + private val projectId: String?, + private val status: Status?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Include items created at or after this timestamp (inclusive) */ + fun createdAtOnOrAfter(): Optional = Optional.ofNullable(createdAtOnOrAfter) + + /** Include items created at or before this timestamp (inclusive) */ + fun createdAtOnOrBefore(): Optional = Optional.ofNullable(createdAtOnOrBefore) + + /** Optional fields to include (e.g. `result`). */ + fun expand(): Optional> = Optional.ofNullable(expand) + + /** Filter by specific job IDs */ + fun jobIds(): Optional> = Optional.ofNullable(jobIds) + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + /** Number of items per page */ + fun pageSize(): Optional = Optional.ofNullable(pageSize) + + /** Token for pagination */ + fun pageToken(): Optional = Optional.ofNullable(pageToken) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Filter by job status */ + fun status(): Optional = Optional.ofNullable(status) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): VerifyListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [VerifyListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyListParams]. */ + class Builder internal constructor() { + + private var createdAtOnOrAfter: OffsetDateTime? = null + private var createdAtOnOrBefore: OffsetDateTime? = null + private var expand: MutableList? = null + private var jobIds: MutableList? = null + private var organizationId: String? = null + private var pageSize: Long? = null + private var pageToken: String? = null + private var projectId: String? = null + private var status: Status? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(verifyListParams: VerifyListParams) = apply { + createdAtOnOrAfter = verifyListParams.createdAtOnOrAfter + createdAtOnOrBefore = verifyListParams.createdAtOnOrBefore + expand = verifyListParams.expand?.toMutableList() + jobIds = verifyListParams.jobIds?.toMutableList() + organizationId = verifyListParams.organizationId + pageSize = verifyListParams.pageSize + pageToken = verifyListParams.pageToken + projectId = verifyListParams.projectId + status = verifyListParams.status + additionalHeaders = verifyListParams.additionalHeaders.toBuilder() + additionalQueryParams = verifyListParams.additionalQueryParams.toBuilder() + } + + /** Include items created at or after this timestamp (inclusive) */ + fun createdAtOnOrAfter(createdAtOnOrAfter: OffsetDateTime?) = apply { + this.createdAtOnOrAfter = createdAtOnOrAfter + } + + /** + * Alias for calling [Builder.createdAtOnOrAfter] with `createdAtOnOrAfter.orElse(null)`. + */ + fun createdAtOnOrAfter(createdAtOnOrAfter: Optional) = + createdAtOnOrAfter(createdAtOnOrAfter.getOrNull()) + + /** Include items created at or before this timestamp (inclusive) */ + fun createdAtOnOrBefore(createdAtOnOrBefore: OffsetDateTime?) = apply { + this.createdAtOnOrBefore = createdAtOnOrBefore + } + + /** + * Alias for calling [Builder.createdAtOnOrBefore] with `createdAtOnOrBefore.orElse(null)`. + */ + fun createdAtOnOrBefore(createdAtOnOrBefore: Optional) = + createdAtOnOrBefore(createdAtOnOrBefore.getOrNull()) + + /** Optional fields to include (e.g. `result`). */ + fun expand(expand: List?) = apply { this.expand = expand?.toMutableList() } + + /** Alias for calling [Builder.expand] with `expand.orElse(null)`. */ + fun expand(expand: Optional>) = expand(expand.getOrNull()) + + /** + * Adds a single [String] to [Builder.expand]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExpand(expand: String) = apply { + this.expand = (this.expand ?: mutableListOf()).apply { add(expand) } + } + + /** Filter by specific job IDs */ + fun jobIds(jobIds: List?) = apply { this.jobIds = jobIds?.toMutableList() } + + /** Alias for calling [Builder.jobIds] with `jobIds.orElse(null)`. */ + fun jobIds(jobIds: Optional>) = jobIds(jobIds.getOrNull()) + + /** + * Adds a single [String] to [jobIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addJobId(jobId: String) = apply { + jobIds = (jobIds ?: mutableListOf()).apply { add(jobId) } + } + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + /** Number of items per page */ + fun pageSize(pageSize: Long?) = apply { this.pageSize = pageSize } + + /** + * Alias for [Builder.pageSize]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun pageSize(pageSize: Long) = pageSize(pageSize as Long?) + + /** Alias for calling [Builder.pageSize] with `pageSize.orElse(null)`. */ + fun pageSize(pageSize: Optional) = pageSize(pageSize.getOrNull()) + + /** Token for pagination */ + fun pageToken(pageToken: String?) = apply { this.pageToken = pageToken } + + /** Alias for calling [Builder.pageToken] with `pageToken.orElse(null)`. */ + fun pageToken(pageToken: Optional) = pageToken(pageToken.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** Filter by job status */ + fun status(status: Status?) = apply { this.status = status } + + /** Alias for calling [Builder.status] with `status.orElse(null)`. */ + fun status(status: Optional) = status(status.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [VerifyListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): VerifyListParams = + VerifyListParams( + createdAtOnOrAfter, + createdAtOnOrBefore, + expand?.toImmutable(), + jobIds?.toImmutable(), + organizationId, + pageSize, + pageToken, + projectId, + status, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + createdAtOnOrAfter?.let { + put("created_at_on_or_after", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(it)) + } + createdAtOnOrBefore?.let { + put( + "created_at_on_or_before", + DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(it), + ) + } + expand?.forEach { put("expand", it) } + jobIds?.forEach { put("job_ids", it) } + organizationId?.let { put("organization_id", it) } + pageSize?.let { put("page_size", it.toString()) } + pageToken?.let { put("page_token", it) } + projectId?.let { put("project_id", it) } + status?.let { put("status", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + /** Filter by job status */ + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val CANCELLED = of("CANCELLED") + + @JvmField val COMPLETED = of("COMPLETED") + + @JvmField val FAILED = of("FAILED") + + @JvmField val PENDING = of("PENDING") + + @JvmField val RUNNING = of("RUNNING") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + CANCELLED, + COMPLETED, + FAILED, + PENDING, + RUNNING, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + CANCELLED, + COMPLETED, + FAILED, + PENDING, + RUNNING, + /** An enum member indicating that [Status] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + CANCELLED -> Value.CANCELLED + COMPLETED -> Value.COMPLETED + FAILED -> Value.FAILED + PENDING -> Value.PENDING + RUNNING -> Value.RUNNING + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + CANCELLED -> Known.CANCELLED + COMPLETED -> Known.COMPLETED + FAILED -> Known.FAILED + PENDING -> Known.PENDING + RUNNING -> Known.RUNNING + else -> throw LlamaCloudInvalidDataException("Unknown Status: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Status = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Status && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyListParams && + createdAtOnOrAfter == other.createdAtOnOrAfter && + createdAtOnOrBefore == other.createdAtOnOrBefore && + expand == other.expand && + jobIds == other.jobIds && + organizationId == other.organizationId && + pageSize == other.pageSize && + pageToken == other.pageToken && + projectId == other.projectId && + status == other.status && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + createdAtOnOrAfter, + createdAtOnOrBefore, + expand, + jobIds, + organizationId, + pageSize, + pageToken, + projectId, + status, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "VerifyListParams{createdAtOnOrAfter=$createdAtOnOrAfter, createdAtOnOrBefore=$createdAtOnOrBefore, expand=$expand, jobIds=$jobIds, organizationId=$organizationId, pageSize=$pageSize, pageToken=$pageToken, projectId=$projectId, status=$status, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListResponse.kt new file mode 100644 index 0000000..d8c6f2d --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListResponse.kt @@ -0,0 +1,4698 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Response for a Verify job. */ +class VerifyListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val configuration: JsonField, + private val documentInputType: JsonField, + private val fileInput: JsonField, + private val projectId: JsonField, + private val status: JsonField, + private val userId: JsonField, + private val createdAt: JsonField, + private val errorMessage: JsonField, + private val result: JsonField, + private val transactionId: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("configuration") + @ExcludeMissing + configuration: JsonField = JsonMissing.of(), + @JsonProperty("document_input_type") + @ExcludeMissing + documentInputType: JsonField = JsonMissing.of(), + @JsonProperty("file_input") @ExcludeMissing fileInput: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("error_message") + @ExcludeMissing + errorMessage: JsonField = JsonMissing.of(), + @JsonProperty("result") @ExcludeMissing result: JsonField = JsonMissing.of(), + @JsonProperty("transaction_id") + @ExcludeMissing + transactionId: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + ) : this( + id, + configuration, + documentInputType, + fileInput, + projectId, + status, + userId, + createdAt, + errorMessage, + result, + transactionId, + updatedAt, + mutableMapOf(), + ) + + /** + * Unique identifier + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * Verify configuration used for this job + * + * @throws LlamaCloudInvalidDataException 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 configuration(): Configuration = configuration.getRequired("configuration") + + /** + * Type of the document input (FILE) + * + * @throws LlamaCloudInvalidDataException 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 documentInputType(): DocumentInputType = + documentInputType.getRequired("document_input_type") + + /** + * ID of the input file + * + * @throws LlamaCloudInvalidDataException 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 fileInput(): String = fileInput.getRequired("file_input") + + /** + * Project this job belongs to + * + * @throws LlamaCloudInvalidDataException 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 projectId(): String = projectId.getRequired("project_id") + + /** + * Current job status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun status(): Status = status.getRequired("status") + + /** + * User who created this job + * + * @throws LlamaCloudInvalidDataException 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 userId(): String = userId.getRequired("user_id") + + /** + * Creation datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * Error message if job failed + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun errorMessage(): Optional = errorMessage.getOptional("error_message") + + /** + * Result of a Verify (doctored-document) analysis. + * + * Raw per-signal detail (evidence list, per-family sub-scores, raw regions, forensic heatmaps) + * is available separately via the job's details endpoint. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun result(): Optional = result.getOptional("result") + + /** + * Idempotency key + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun transactionId(): Optional = transactionId.getOptional("transaction_id") + + /** + * Update datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [configuration]. + * + * Unlike [configuration], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("configuration") + @ExcludeMissing + fun _configuration(): JsonField = configuration + + /** + * Returns the raw JSON value of [documentInputType]. + * + * Unlike [documentInputType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("document_input_type") + @ExcludeMissing + fun _documentInputType(): JsonField = documentInputType + + /** + * Returns the raw JSON value of [fileInput]. + * + * Unlike [fileInput], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_input") @ExcludeMissing fun _fileInput(): JsonField = fileInput + + /** + * 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 [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [errorMessage]. + * + * Unlike [errorMessage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error_message") + @ExcludeMissing + fun _errorMessage(): JsonField = errorMessage + + /** + * Returns the raw JSON value of [result]. + * + * Unlike [result], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("result") @ExcludeMissing fun _result(): JsonField = result + + /** + * Returns the raw JSON value of [transactionId]. + * + * Unlike [transactionId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("transaction_id") + @ExcludeMissing + fun _transactionId(): JsonField = transactionId + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") + @ExcludeMissing + fun _updatedAt(): JsonField = updatedAt + + @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 [VerifyListResponse]. + * + * The following fields are required: + * ```java + * .id() + * .configuration() + * .documentInputType() + * .fileInput() + * .projectId() + * .status() + * .userId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VerifyListResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var configuration: JsonField? = null + private var documentInputType: JsonField? = null + private var fileInput: JsonField? = null + private var projectId: JsonField? = null + private var status: JsonField? = null + private var userId: JsonField? = null + private var createdAt: JsonField = JsonMissing.of() + private var errorMessage: JsonField = JsonMissing.of() + private var result: JsonField = JsonMissing.of() + private var transactionId: JsonField = JsonMissing.of() + private var updatedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(verifyListResponse: VerifyListResponse) = apply { + id = verifyListResponse.id + configuration = verifyListResponse.configuration + documentInputType = verifyListResponse.documentInputType + fileInput = verifyListResponse.fileInput + projectId = verifyListResponse.projectId + status = verifyListResponse.status + userId = verifyListResponse.userId + createdAt = verifyListResponse.createdAt + errorMessage = verifyListResponse.errorMessage + result = verifyListResponse.result + transactionId = verifyListResponse.transactionId + updatedAt = verifyListResponse.updatedAt + additionalProperties = verifyListResponse.additionalProperties.toMutableMap() + } + + /** Unique identifier */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** Verify configuration used for this job */ + fun configuration(configuration: Configuration) = configuration(JsonField.of(configuration)) + + /** + * Sets [Builder.configuration] to an arbitrary JSON value. + * + * You should usually call [Builder.configuration] with a well-typed [Configuration] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun configuration(configuration: JsonField) = apply { + this.configuration = configuration + } + + /** Type of the document input (FILE) */ + fun documentInputType(documentInputType: DocumentInputType) = + documentInputType(JsonField.of(documentInputType)) + + /** + * Sets [Builder.documentInputType] to an arbitrary JSON value. + * + * You should usually call [Builder.documentInputType] with a well-typed [DocumentInputType] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun documentInputType(documentInputType: JsonField) = apply { + this.documentInputType = documentInputType + } + + /** ID of the input file */ + fun fileInput(fileInput: String) = fileInput(JsonField.of(fileInput)) + + /** + * Sets [Builder.fileInput] to an arbitrary JSON value. + * + * You should usually call [Builder.fileInput] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun fileInput(fileInput: JsonField) = apply { this.fileInput = fileInput } + + /** Project this job belongs to */ + 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 } + + /** Current job status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED */ + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** User who created this job */ + fun userId(userId: String) = userId(JsonField.of(userId)) + + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } + + /** Creation datetime */ + fun createdAt(createdAt: OffsetDateTime?) = createdAt(JsonField.ofNullable(createdAt)) + + /** Alias for calling [Builder.createdAt] with `createdAt.orElse(null)`. */ + fun createdAt(createdAt: Optional) = createdAt(createdAt.getOrNull()) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Error message if job failed */ + fun errorMessage(errorMessage: String?) = errorMessage(JsonField.ofNullable(errorMessage)) + + /** Alias for calling [Builder.errorMessage] with `errorMessage.orElse(null)`. */ + fun errorMessage(errorMessage: Optional) = errorMessage(errorMessage.getOrNull()) + + /** + * Sets [Builder.errorMessage] to an arbitrary JSON value. + * + * You should usually call [Builder.errorMessage] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun errorMessage(errorMessage: JsonField) = apply { + this.errorMessage = errorMessage + } + + /** + * Result of a Verify (doctored-document) analysis. + * + * Raw per-signal detail (evidence list, per-family sub-scores, raw regions, forensic + * heatmaps) is available separately via the job's details endpoint. + */ + fun result(result: Result?) = result(JsonField.ofNullable(result)) + + /** Alias for calling [Builder.result] with `result.orElse(null)`. */ + fun result(result: Optional) = result(result.getOrNull()) + + /** + * Sets [Builder.result] to an arbitrary JSON value. + * + * You should usually call [Builder.result] with a well-typed [Result] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun result(result: JsonField) = apply { this.result = result } + + /** Idempotency key */ + fun transactionId(transactionId: String?) = + transactionId(JsonField.ofNullable(transactionId)) + + /** Alias for calling [Builder.transactionId] with `transactionId.orElse(null)`. */ + fun transactionId(transactionId: Optional) = + transactionId(transactionId.getOrNull()) + + /** + * Sets [Builder.transactionId] to an arbitrary JSON value. + * + * You should usually call [Builder.transactionId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun transactionId(transactionId: JsonField) = apply { + this.transactionId = transactionId + } + + /** Update datetime */ + fun updatedAt(updatedAt: OffsetDateTime?) = updatedAt(JsonField.ofNullable(updatedAt)) + + /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ + fun updatedAt(updatedAt: Optional) = updatedAt(updatedAt.getOrNull()) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + 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 [VerifyListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .configuration() + * .documentInputType() + * .fileInput() + * .projectId() + * .status() + * .userId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VerifyListResponse = + VerifyListResponse( + checkRequired("id", id), + checkRequired("configuration", configuration), + checkRequired("documentInputType", documentInputType), + checkRequired("fileInput", fileInput), + checkRequired("projectId", projectId), + checkRequired("status", status), + checkRequired("userId", userId), + createdAt, + errorMessage, + result, + transactionId, + updatedAt, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): VerifyListResponse = apply { + if (validated) { + return@apply + } + + id() + configuration().validate() + documentInputType().validate() + fileInput() + projectId() + status().validate() + userId() + createdAt() + errorMessage() + result().ifPresent { it.validate() } + transactionId() + updatedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (configuration.asKnown().getOrNull()?.validity() ?: 0) + + (documentInputType.asKnown().getOrNull()?.validity() ?: 0) + + (if (fileInput.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (errorMessage.asKnown().isPresent) 1 else 0) + + (result.asKnown().getOrNull()?.validity() ?: 0) + + (if (transactionId.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + /** Verify configuration used for this job */ + class Configuration + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val targetPages: JsonField, + private val tier: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("target_pages") + @ExcludeMissing + targetPages: JsonField = JsonMissing.of(), + @JsonProperty("tier") @ExcludeMissing tier: JsonField = JsonMissing.of(), + ) : this(targetPages, tier, mutableMapOf()) + + /** + * Comma-separated page numbers or ranges to analyze (1-based). Omit to analyze all pages. + * Ignored for non-PDF inputs. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun targetPages(): Optional = targetPages.getOptional("target_pages") + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, content + * integrity, container structure, pixel statistics); 'agentic' (default) runs the full + * pipeline including the learned detectors and the semantic review pass. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tier(): Optional = tier.getOptional("tier") + + /** + * Returns the raw JSON value of [targetPages]. + * + * Unlike [targetPages], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("target_pages") + @ExcludeMissing + fun _targetPages(): JsonField = targetPages + + /** + * Returns the raw JSON value of [tier]. + * + * Unlike [tier], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tier") @ExcludeMissing fun _tier(): JsonField = tier + + @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 [Configuration]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Configuration]. */ + class Builder internal constructor() { + + private var targetPages: JsonField = JsonMissing.of() + private var tier: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(configuration: Configuration) = apply { + targetPages = configuration.targetPages + tier = configuration.tier + additionalProperties = configuration.additionalProperties.toMutableMap() + } + + /** + * Comma-separated page numbers or ranges to analyze (1-based). Omit to analyze all + * pages. Ignored for non-PDF inputs. + */ + fun targetPages(targetPages: String?) = targetPages(JsonField.ofNullable(targetPages)) + + /** Alias for calling [Builder.targetPages] with `targetPages.orElse(null)`. */ + fun targetPages(targetPages: Optional) = targetPages(targetPages.getOrNull()) + + /** + * Sets [Builder.targetPages] to an arbitrary JSON value. + * + * You should usually call [Builder.targetPages] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun targetPages(targetPages: JsonField) = apply { + this.targetPages = targetPages + } + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, + * content integrity, container structure, pixel statistics); 'agentic' (default) runs + * the full pipeline including the learned detectors and the semantic review pass. + */ + fun tier(tier: Tier) = tier(JsonField.of(tier)) + + /** + * Sets [Builder.tier] to an arbitrary JSON value. + * + * You should usually call [Builder.tier] with a well-typed [Tier] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tier(tier: JsonField) = apply { this.tier = tier } + + 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 [Configuration]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Configuration = + Configuration(targetPages, tier, 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Configuration = apply { + if (validated) { + return@apply + } + + targetPages() + tier().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (targetPages.asKnown().isPresent) 1 else 0) + + (tier.asKnown().getOrNull()?.validity() ?: 0) + + /** + * Verify tier: 'fast' runs only the quick deterministic forensic checks (metadata, content + * integrity, container structure, pixel statistics); 'agentic' (default) runs the full + * pipeline including the learned detectors and the semantic review pass. + */ + class Tier @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 AGENTIC = of("agentic") + + @JvmField val FAST = of("fast") + + @JvmStatic fun of(value: String) = Tier(JsonField.of(value)) + } + + /** An enum containing [Tier]'s known values. */ + enum class Known { + AGENTIC, + FAST, + } + + /** + * An enum containing [Tier]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Tier] 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 { + AGENTIC, + FAST, + /** An enum member indicating that [Tier] 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) { + AGENTIC -> Value.AGENTIC + FAST -> Value.FAST + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + AGENTIC -> Known.AGENTIC + FAST -> Known.FAST + else -> throw LlamaCloudInvalidDataException("Unknown Tier: $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 LlamaCloudInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Tier && 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 Configuration && + targetPages == other.targetPages && + tier == other.tier && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(targetPages, tier, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Configuration{targetPages=$targetPages, tier=$tier, additionalProperties=$additionalProperties}" + } + + /** Type of the document input (FILE) */ + class DocumentInputType @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 FILE_ID = of("file_id") + + @JvmField val PARSE_JOB_ID = of("parse_job_id") + + @JvmField val URL = of("url") + + @JvmStatic fun of(value: String) = DocumentInputType(JsonField.of(value)) + } + + /** An enum containing [DocumentInputType]'s known values. */ + enum class Known { + FILE_ID, + PARSE_JOB_ID, + URL, + } + + /** + * An enum containing [DocumentInputType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [DocumentInputType] 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 { + FILE_ID, + PARSE_JOB_ID, + URL, + /** + * An enum member indicating that [DocumentInputType] 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) { + FILE_ID -> Value.FILE_ID + PARSE_JOB_ID -> Value.PARSE_JOB_ID + URL -> Value.URL + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + FILE_ID -> Known.FILE_ID + PARSE_JOB_ID -> Known.PARSE_JOB_ID + URL -> Known.URL + else -> throw LlamaCloudInvalidDataException("Unknown DocumentInputType: $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 LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): DocumentInputType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 DocumentInputType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Current job status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED */ + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val CANCELLED = of("CANCELLED") + + @JvmField val COMPLETED = of("COMPLETED") + + @JvmField val FAILED = of("FAILED") + + @JvmField val PENDING = of("PENDING") + + @JvmField val RUNNING = of("RUNNING") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + CANCELLED, + COMPLETED, + FAILED, + PENDING, + RUNNING, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + CANCELLED, + COMPLETED, + FAILED, + PENDING, + RUNNING, + /** An enum member indicating that [Status] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + CANCELLED -> Value.CANCELLED + COMPLETED -> Value.COMPLETED + FAILED -> Value.FAILED + PENDING -> Value.PENDING + RUNNING -> Value.RUNNING + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + CANCELLED -> Known.CANCELLED + COMPLETED -> Known.COMPLETED + FAILED -> Known.FAILED + PENDING -> Known.PENDING + RUNNING -> Known.RUNNING + else -> throw LlamaCloudInvalidDataException("Unknown Status: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Status = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Status && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * Result of a Verify (doctored-document) analysis. + * + * Raw per-signal detail (evidence list, per-family sub-scores, raw regions, forensic heatmaps) + * is available separately via the job's details endpoint. + */ + class Result + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val detectorVersion: JsonField, + private val overallScore: JsonField, + private val verdict: JsonField, + private val compositeScores: JsonField, + private val confidence: JsonField, + private val error: JsonField, + private val pageCount: JsonField, + private val pageDimensions: JsonField>, + private val reasoning: JsonField, + private val suspectRegions: JsonField>, + private val syntheticScore: JsonField, + private val tamperingScore: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("detector_version") + @ExcludeMissing + detectorVersion: JsonField = JsonMissing.of(), + @JsonProperty("overall_score") + @ExcludeMissing + overallScore: JsonField = JsonMissing.of(), + @JsonProperty("verdict") @ExcludeMissing verdict: JsonField = JsonMissing.of(), + @JsonProperty("composite_scores") + @ExcludeMissing + compositeScores: JsonField = JsonMissing.of(), + @JsonProperty("confidence") + @ExcludeMissing + confidence: JsonField = JsonMissing.of(), + @JsonProperty("error") @ExcludeMissing error: JsonField = JsonMissing.of(), + @JsonProperty("page_count") + @ExcludeMissing + pageCount: JsonField = JsonMissing.of(), + @JsonProperty("page_dimensions") + @ExcludeMissing + pageDimensions: JsonField> = JsonMissing.of(), + @JsonProperty("reasoning") + @ExcludeMissing + reasoning: JsonField = JsonMissing.of(), + @JsonProperty("suspect_regions") + @ExcludeMissing + suspectRegions: JsonField> = JsonMissing.of(), + @JsonProperty("synthetic_score") + @ExcludeMissing + syntheticScore: JsonField = JsonMissing.of(), + @JsonProperty("tampering_score") + @ExcludeMissing + tamperingScore: JsonField = JsonMissing.of(), + ) : this( + detectorVersion, + overallScore, + verdict, + compositeScores, + confidence, + error, + pageCount, + pageDimensions, + reasoning, + suspectRegions, + syntheticScore, + tamperingScore, + mutableMapOf(), + ) + + /** + * Version of the detector that produced the result + * + * @throws LlamaCloudInvalidDataException 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 detectorVersion(): String = detectorVersion.getRequired("detector_version") + + /** + * Overall doctoring likelihood (0 to 1) + * + * @throws LlamaCloudInvalidDataException 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 overallScore(): Double = overallScore.getRequired("overall_score") + + /** + * Overall verdict for the document + * + * @throws LlamaCloudInvalidDataException 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 verdict(): Verdict = verdict.getRequired("verdict") + + /** + * Composite scores, each answering one question about the document + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun compositeScores(): Optional = + compositeScores.getOptional("composite_scores") + + /** + * Confidence in the verdict (0 to 1): how firmly the detected signals support the verdict + * bucket, independent of the doctoring likelihood itself + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun confidence(): Optional = confidence.getOptional("confidence") + + /** + * Error detail when the analysis could not complete + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun error(): Optional = error.getOptional("error") + + /** + * Number of analysed pages (1 for images/docx) + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun pageCount(): Optional = pageCount.getOptional("page_count") + + /** + * Rendered pixel size per page, so region bboxes can be scaled onto the page + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun pageDimensions(): Optional> = + pageDimensions.getOptional("page_dimensions") + + /** + * Explanation of the verdict + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun reasoning(): Optional = reasoning.getOptional("reasoning") + + /** + * Regions that led to the suspected fraud, ranked most-suspect first, each with an + * explanation of what makes it suspect + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun suspectRegions(): Optional> = + suspectRegions.getOptional("suspect_regions") + + /** + * Likelihood (0 to 1) that the document is wholly generated or fabricated rather than a + * capture of a real document. Null for jobs completed before this score was introduced + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun syntheticScore(): Optional = syntheticScore.getOptional("synthetic_score") + + /** + * Likelihood (0 to 1) that a real captured document was locally edited — a genuine capture + * with regions altered after the fact. Null for jobs completed before this score was + * introduced + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun tamperingScore(): Optional = tamperingScore.getOptional("tampering_score") + + /** + * Returns the raw JSON value of [detectorVersion]. + * + * Unlike [detectorVersion], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("detector_version") + @ExcludeMissing + fun _detectorVersion(): JsonField = detectorVersion + + /** + * Returns the raw JSON value of [overallScore]. + * + * Unlike [overallScore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("overall_score") + @ExcludeMissing + fun _overallScore(): JsonField = overallScore + + /** + * Returns the raw JSON value of [verdict]. + * + * Unlike [verdict], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("verdict") @ExcludeMissing fun _verdict(): JsonField = verdict + + /** + * Returns the raw JSON value of [compositeScores]. + * + * Unlike [compositeScores], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("composite_scores") + @ExcludeMissing + fun _compositeScores(): JsonField = compositeScores + + /** + * Returns the raw JSON value of [confidence]. + * + * Unlike [confidence], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("confidence") + @ExcludeMissing + fun _confidence(): JsonField = confidence + + /** + * Returns the raw JSON value of [error]. + * + * Unlike [error], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error") @ExcludeMissing fun _error(): JsonField = error + + /** + * Returns the raw JSON value of [pageCount]. + * + * Unlike [pageCount], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page_count") @ExcludeMissing fun _pageCount(): JsonField = pageCount + + /** + * Returns the raw JSON value of [pageDimensions]. + * + * Unlike [pageDimensions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("page_dimensions") + @ExcludeMissing + fun _pageDimensions(): JsonField> = pageDimensions + + /** + * Returns the raw JSON value of [reasoning]. + * + * Unlike [reasoning], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("reasoning") @ExcludeMissing fun _reasoning(): JsonField = reasoning + + /** + * Returns the raw JSON value of [suspectRegions]. + * + * Unlike [suspectRegions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("suspect_regions") + @ExcludeMissing + fun _suspectRegions(): JsonField> = suspectRegions + + /** + * Returns the raw JSON value of [syntheticScore]. + * + * Unlike [syntheticScore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("synthetic_score") + @ExcludeMissing + fun _syntheticScore(): JsonField = syntheticScore + + /** + * Returns the raw JSON value of [tamperingScore]. + * + * Unlike [tamperingScore], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("tampering_score") + @ExcludeMissing + fun _tamperingScore(): JsonField = tamperingScore + + @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 [Result]. + * + * The following fields are required: + * ```java + * .detectorVersion() + * .overallScore() + * .verdict() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Result]. */ + class Builder internal constructor() { + + private var detectorVersion: JsonField? = null + private var overallScore: JsonField? = null + private var verdict: JsonField? = null + private var compositeScores: JsonField = JsonMissing.of() + private var confidence: JsonField = JsonMissing.of() + private var error: JsonField = JsonMissing.of() + private var pageCount: JsonField = JsonMissing.of() + private var pageDimensions: JsonField>? = null + private var reasoning: JsonField = JsonMissing.of() + private var suspectRegions: JsonField>? = null + private var syntheticScore: JsonField = JsonMissing.of() + private var tamperingScore: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(result: Result) = apply { + detectorVersion = result.detectorVersion + overallScore = result.overallScore + verdict = result.verdict + compositeScores = result.compositeScores + confidence = result.confidence + error = result.error + pageCount = result.pageCount + pageDimensions = result.pageDimensions.map { it.toMutableList() } + reasoning = result.reasoning + suspectRegions = result.suspectRegions.map { it.toMutableList() } + syntheticScore = result.syntheticScore + tamperingScore = result.tamperingScore + additionalProperties = result.additionalProperties.toMutableMap() + } + + /** Version of the detector that produced the result */ + fun detectorVersion(detectorVersion: String) = + detectorVersion(JsonField.of(detectorVersion)) + + /** + * Sets [Builder.detectorVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.detectorVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun detectorVersion(detectorVersion: JsonField) = apply { + this.detectorVersion = detectorVersion + } + + /** Overall doctoring likelihood (0 to 1) */ + fun overallScore(overallScore: Double) = overallScore(JsonField.of(overallScore)) + + /** + * Sets [Builder.overallScore] to an arbitrary JSON value. + * + * You should usually call [Builder.overallScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun overallScore(overallScore: JsonField) = apply { + this.overallScore = overallScore + } + + /** Overall verdict for the document */ + fun verdict(verdict: Verdict) = verdict(JsonField.of(verdict)) + + /** + * Sets [Builder.verdict] to an arbitrary JSON value. + * + * You should usually call [Builder.verdict] with a well-typed [Verdict] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun verdict(verdict: JsonField) = apply { this.verdict = verdict } + + /** Composite scores, each answering one question about the document */ + fun compositeScores(compositeScores: CompositeScores) = + compositeScores(JsonField.of(compositeScores)) + + /** + * Sets [Builder.compositeScores] to an arbitrary JSON value. + * + * You should usually call [Builder.compositeScores] with a well-typed [CompositeScores] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun compositeScores(compositeScores: JsonField) = apply { + this.compositeScores = compositeScores + } + + /** + * Confidence in the verdict (0 to 1): how firmly the detected signals support the + * verdict bucket, independent of the doctoring likelihood itself + */ + fun confidence(confidence: Double) = confidence(JsonField.of(confidence)) + + /** + * Sets [Builder.confidence] to an arbitrary JSON value. + * + * You should usually call [Builder.confidence] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun confidence(confidence: JsonField) = apply { this.confidence = confidence } + + /** Error detail when the analysis could not complete */ + fun error(error: String?) = error(JsonField.ofNullable(error)) + + /** Alias for calling [Builder.error] with `error.orElse(null)`. */ + fun error(error: Optional) = error(error.getOrNull()) + + /** + * Sets [Builder.error] to an arbitrary JSON value. + * + * You should usually call [Builder.error] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun error(error: JsonField) = apply { this.error = error } + + /** Number of analysed pages (1 for images/docx) */ + fun pageCount(pageCount: Long) = pageCount(JsonField.of(pageCount)) + + /** + * Sets [Builder.pageCount] to an arbitrary JSON value. + * + * You should usually call [Builder.pageCount] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pageCount(pageCount: JsonField) = apply { this.pageCount = pageCount } + + /** Rendered pixel size per page, so region bboxes can be scaled onto the page */ + fun pageDimensions(pageDimensions: List) = + pageDimensions(JsonField.of(pageDimensions)) + + /** + * Sets [Builder.pageDimensions] to an arbitrary JSON value. + * + * You should usually call [Builder.pageDimensions] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun pageDimensions(pageDimensions: JsonField>) = apply { + this.pageDimensions = pageDimensions.map { it.toMutableList() } + } + + /** + * Adds a single [PageDimension] to [pageDimensions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPageDimension(pageDimension: PageDimension) = apply { + pageDimensions = + (pageDimensions ?: JsonField.of(mutableListOf())).also { + checkKnown("pageDimensions", it).add(pageDimension) + } + } + + /** Explanation of the verdict */ + fun reasoning(reasoning: String) = reasoning(JsonField.of(reasoning)) + + /** + * Sets [Builder.reasoning] to an arbitrary JSON value. + * + * You should usually call [Builder.reasoning] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun reasoning(reasoning: JsonField) = apply { this.reasoning = reasoning } + + /** + * Regions that led to the suspected fraud, ranked most-suspect first, each with an + * explanation of what makes it suspect + */ + fun suspectRegions(suspectRegions: List) = + suspectRegions(JsonField.of(suspectRegions)) + + /** + * Sets [Builder.suspectRegions] to an arbitrary JSON value. + * + * You should usually call [Builder.suspectRegions] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun suspectRegions(suspectRegions: JsonField>) = apply { + this.suspectRegions = suspectRegions.map { it.toMutableList() } + } + + /** + * Adds a single [SuspectRegion] to [suspectRegions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSuspectRegion(suspectRegion: SuspectRegion) = apply { + suspectRegions = + (suspectRegions ?: JsonField.of(mutableListOf())).also { + checkKnown("suspectRegions", it).add(suspectRegion) + } + } + + /** + * Likelihood (0 to 1) that the document is wholly generated or fabricated rather than a + * capture of a real document. Null for jobs completed before this score was introduced + */ + fun syntheticScore(syntheticScore: Double?) = + syntheticScore(JsonField.ofNullable(syntheticScore)) + + /** + * Alias for [Builder.syntheticScore]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun syntheticScore(syntheticScore: Double) = syntheticScore(syntheticScore as Double?) + + /** Alias for calling [Builder.syntheticScore] with `syntheticScore.orElse(null)`. */ + fun syntheticScore(syntheticScore: Optional) = + syntheticScore(syntheticScore.getOrNull()) + + /** + * Sets [Builder.syntheticScore] to an arbitrary JSON value. + * + * You should usually call [Builder.syntheticScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun syntheticScore(syntheticScore: JsonField) = apply { + this.syntheticScore = syntheticScore + } + + /** + * Likelihood (0 to 1) that a real captured document was locally edited — a genuine + * capture with regions altered after the fact. Null for jobs completed before this + * score was introduced + */ + fun tamperingScore(tamperingScore: Double?) = + tamperingScore(JsonField.ofNullable(tamperingScore)) + + /** + * Alias for [Builder.tamperingScore]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun tamperingScore(tamperingScore: Double) = tamperingScore(tamperingScore as Double?) + + /** Alias for calling [Builder.tamperingScore] with `tamperingScore.orElse(null)`. */ + fun tamperingScore(tamperingScore: Optional) = + tamperingScore(tamperingScore.getOrNull()) + + /** + * Sets [Builder.tamperingScore] to an arbitrary JSON value. + * + * You should usually call [Builder.tamperingScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tamperingScore(tamperingScore: JsonField) = apply { + this.tamperingScore = tamperingScore + } + + 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 [Result]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .detectorVersion() + * .overallScore() + * .verdict() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Result = + Result( + checkRequired("detectorVersion", detectorVersion), + checkRequired("overallScore", overallScore), + checkRequired("verdict", verdict), + compositeScores, + confidence, + error, + pageCount, + (pageDimensions ?: JsonMissing.of()).map { it.toImmutable() }, + reasoning, + (suspectRegions ?: JsonMissing.of()).map { it.toImmutable() }, + syntheticScore, + tamperingScore, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Result = apply { + if (validated) { + return@apply + } + + detectorVersion() + overallScore() + verdict().validate() + compositeScores().ifPresent { it.validate() } + confidence() + error() + pageCount() + pageDimensions().ifPresent { it.forEach { it.validate() } } + reasoning() + suspectRegions().ifPresent { it.forEach { it.validate() } } + syntheticScore() + tamperingScore() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (detectorVersion.asKnown().isPresent) 1 else 0) + + (if (overallScore.asKnown().isPresent) 1 else 0) + + (verdict.asKnown().getOrNull()?.validity() ?: 0) + + (compositeScores.asKnown().getOrNull()?.validity() ?: 0) + + (if (confidence.asKnown().isPresent) 1 else 0) + + (if (error.asKnown().isPresent) 1 else 0) + + (if (pageCount.asKnown().isPresent) 1 else 0) + + (pageDimensions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (reasoning.asKnown().isPresent) 1 else 0) + + (suspectRegions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (syntheticScore.asKnown().isPresent) 1 else 0) + + (if (tamperingScore.asKnown().isPresent) 1 else 0) + + /** Overall verdict for the document */ + class Verdict @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 AUTHENTIC = of("AUTHENTIC") + + @JvmField val DOCTORED = of("DOCTORED") + + @JvmField val LIKELY_DOCTORED = of("LIKELY_DOCTORED") + + @JvmField val NO_STRONG_SIGNAL = of("NO_STRONG_SIGNAL") + + @JvmField val SUSPICIOUS = of("SUSPICIOUS") + + @JvmStatic fun of(value: String) = Verdict(JsonField.of(value)) + } + + /** An enum containing [Verdict]'s known values. */ + enum class Known { + AUTHENTIC, + DOCTORED, + LIKELY_DOCTORED, + NO_STRONG_SIGNAL, + SUSPICIOUS, + } + + /** + * An enum containing [Verdict]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Verdict] 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 { + AUTHENTIC, + DOCTORED, + LIKELY_DOCTORED, + NO_STRONG_SIGNAL, + SUSPICIOUS, + /** + * An enum member indicating that [Verdict] 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) { + AUTHENTIC -> Value.AUTHENTIC + DOCTORED -> Value.DOCTORED + LIKELY_DOCTORED -> Value.LIKELY_DOCTORED + NO_STRONG_SIGNAL -> Value.NO_STRONG_SIGNAL + SUSPICIOUS -> Value.SUSPICIOUS + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + AUTHENTIC -> Known.AUTHENTIC + DOCTORED -> Known.DOCTORED + LIKELY_DOCTORED -> Known.LIKELY_DOCTORED + NO_STRONG_SIGNAL -> Known.NO_STRONG_SIGNAL + SUSPICIOUS -> Known.SUSPICIOUS + else -> throw LlamaCloudInvalidDataException("Unknown Verdict: $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 LlamaCloudInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Verdict = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Verdict && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Composite scores, each answering one question about the document */ + class CompositeScores + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val aiGenerated: JsonField, + private val documentCoherence: JsonField, + private val documentMetadata: JsonField, + private val knownFraud: JsonField, + private val manuallyEdited: JsonField, + private val recapture: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("ai_generated") + @ExcludeMissing + aiGenerated: JsonField = JsonMissing.of(), + @JsonProperty("document_coherence") + @ExcludeMissing + documentCoherence: JsonField = JsonMissing.of(), + @JsonProperty("document_metadata") + @ExcludeMissing + documentMetadata: JsonField = JsonMissing.of(), + @JsonProperty("known_fraud") + @ExcludeMissing + knownFraud: JsonField = JsonMissing.of(), + @JsonProperty("manually_edited") + @ExcludeMissing + manuallyEdited: JsonField = JsonMissing.of(), + @JsonProperty("recapture") + @ExcludeMissing + recapture: JsonField = JsonMissing.of(), + ) : this( + aiGenerated, + documentCoherence, + documentMetadata, + knownFraud, + manuallyEdited, + recapture, + mutableMapOf(), + ) + + /** + * Was this content synthesized by a generative model? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun aiGenerated(): Optional = aiGenerated.getOptional("ai_generated") + + /** + * Does the document's content agree with itself (checksums, arithmetic, + * machine-readable zones)? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun documentCoherence(): Optional = + documentCoherence.getOptional("document_coherence") + + /** + * Does the file's provenance / toolchain history look suspicious? Advisory: + * individually weak workflow-hygiene signals + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun documentMetadata(): Optional = + documentMetadata.getOptional("document_metadata") + + /** + * Has this asset (or its template) been seen in fraud before? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun knownFraud(): Optional = knownFraud.getOptional("known_fraud") + + /** + * Was this document altered after creation (splice, retype, redact, inpaint)? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun manuallyEdited(): Optional = + manuallyEdited.getOptional("manually_edited") + + /** + * Was the document captured through a channel that destroys forensic evidence (photo of + * a screen, print-then-rescan)? + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun recapture(): Optional = recapture.getOptional("recapture") + + /** + * Returns the raw JSON value of [aiGenerated]. + * + * Unlike [aiGenerated], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("ai_generated") + @ExcludeMissing + fun _aiGenerated(): JsonField = aiGenerated + + /** + * Returns the raw JSON value of [documentCoherence]. + * + * Unlike [documentCoherence], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("document_coherence") + @ExcludeMissing + fun _documentCoherence(): JsonField = documentCoherence + + /** + * Returns the raw JSON value of [documentMetadata]. + * + * Unlike [documentMetadata], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("document_metadata") + @ExcludeMissing + fun _documentMetadata(): JsonField = documentMetadata + + /** + * Returns the raw JSON value of [knownFraud]. + * + * Unlike [knownFraud], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("known_fraud") + @ExcludeMissing + fun _knownFraud(): JsonField = knownFraud + + /** + * Returns the raw JSON value of [manuallyEdited]. + * + * Unlike [manuallyEdited], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("manually_edited") + @ExcludeMissing + fun _manuallyEdited(): JsonField = manuallyEdited + + /** + * Returns the raw JSON value of [recapture]. + * + * Unlike [recapture], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("recapture") + @ExcludeMissing + fun _recapture(): JsonField = recapture + + @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 [CompositeScores]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CompositeScores]. */ + class Builder internal constructor() { + + private var aiGenerated: JsonField = JsonMissing.of() + private var documentCoherence: JsonField = JsonMissing.of() + private var documentMetadata: JsonField = JsonMissing.of() + private var knownFraud: JsonField = JsonMissing.of() + private var manuallyEdited: JsonField = JsonMissing.of() + private var recapture: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(compositeScores: CompositeScores) = apply { + aiGenerated = compositeScores.aiGenerated + documentCoherence = compositeScores.documentCoherence + documentMetadata = compositeScores.documentMetadata + knownFraud = compositeScores.knownFraud + manuallyEdited = compositeScores.manuallyEdited + recapture = compositeScores.recapture + additionalProperties = compositeScores.additionalProperties.toMutableMap() + } + + /** Was this content synthesized by a generative model? */ + fun aiGenerated(aiGenerated: AiGenerated) = aiGenerated(JsonField.of(aiGenerated)) + + /** + * Sets [Builder.aiGenerated] to an arbitrary JSON value. + * + * You should usually call [Builder.aiGenerated] with a well-typed [AiGenerated] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun aiGenerated(aiGenerated: JsonField) = apply { + this.aiGenerated = aiGenerated + } + + /** + * Does the document's content agree with itself (checksums, arithmetic, + * machine-readable zones)? + */ + fun documentCoherence(documentCoherence: DocumentCoherence) = + documentCoherence(JsonField.of(documentCoherence)) + + /** + * Sets [Builder.documentCoherence] to an arbitrary JSON value. + * + * You should usually call [Builder.documentCoherence] with a well-typed + * [DocumentCoherence] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun documentCoherence(documentCoherence: JsonField) = apply { + this.documentCoherence = documentCoherence + } + + /** + * Does the file's provenance / toolchain history look suspicious? Advisory: + * individually weak workflow-hygiene signals + */ + fun documentMetadata(documentMetadata: DocumentMetadata) = + documentMetadata(JsonField.of(documentMetadata)) + + /** + * Sets [Builder.documentMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.documentMetadata] with a well-typed + * [DocumentMetadata] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun documentMetadata(documentMetadata: JsonField) = apply { + this.documentMetadata = documentMetadata + } + + /** Has this asset (or its template) been seen in fraud before? */ + fun knownFraud(knownFraud: KnownFraud) = knownFraud(JsonField.of(knownFraud)) + + /** + * Sets [Builder.knownFraud] to an arbitrary JSON value. + * + * You should usually call [Builder.knownFraud] with a well-typed [KnownFraud] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun knownFraud(knownFraud: JsonField) = apply { + this.knownFraud = knownFraud + } + + /** Was this document altered after creation (splice, retype, redact, inpaint)? */ + fun manuallyEdited(manuallyEdited: ManuallyEdited) = + manuallyEdited(JsonField.of(manuallyEdited)) + + /** + * Sets [Builder.manuallyEdited] to an arbitrary JSON value. + * + * You should usually call [Builder.manuallyEdited] with a well-typed + * [ManuallyEdited] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun manuallyEdited(manuallyEdited: JsonField) = apply { + this.manuallyEdited = manuallyEdited + } + + /** + * Was the document captured through a channel that destroys forensic evidence + * (photo of a screen, print-then-rescan)? + */ + fun recapture(recapture: Recapture) = recapture(JsonField.of(recapture)) + + /** + * Sets [Builder.recapture] to an arbitrary JSON value. + * + * You should usually call [Builder.recapture] with a well-typed [Recapture] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun recapture(recapture: JsonField) = apply { + this.recapture = recapture + } + + 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 [CompositeScores]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CompositeScores = + CompositeScores( + aiGenerated, + documentCoherence, + documentMetadata, + knownFraud, + manuallyEdited, + recapture, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): CompositeScores = apply { + if (validated) { + return@apply + } + + aiGenerated().ifPresent { it.validate() } + documentCoherence().ifPresent { it.validate() } + documentMetadata().ifPresent { it.validate() } + knownFraud().ifPresent { it.validate() } + manuallyEdited().ifPresent { it.validate() } + recapture().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (aiGenerated.asKnown().getOrNull()?.validity() ?: 0) + + (documentCoherence.asKnown().getOrNull()?.validity() ?: 0) + + (documentMetadata.asKnown().getOrNull()?.validity() ?: 0) + + (knownFraud.asKnown().getOrNull()?.validity() ?: 0) + + (manuallyEdited.asKnown().getOrNull()?.validity() ?: 0) + + (recapture.asKnown().getOrNull()?.validity() ?: 0) + + /** Was this content synthesized by a generative model? */ + class AiGenerated + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [AiGenerated]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AiGenerated]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(aiGenerated: AiGenerated) = apply { + applicable = aiGenerated.applicable + score = aiGenerated.score + additionalProperties = aiGenerated.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [AiGenerated]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): AiGenerated = + AiGenerated(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): AiGenerated = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AiGenerated && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AiGenerated{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Does the document's content agree with itself (checksums, arithmetic, + * machine-readable zones)? + */ + class DocumentCoherence + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 + * [DocumentCoherence]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DocumentCoherence]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(documentCoherence: DocumentCoherence) = apply { + applicable = documentCoherence.applicable + score = documentCoherence.score + additionalProperties = documentCoherence.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [DocumentCoherence]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DocumentCoherence = + DocumentCoherence(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): DocumentCoherence = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DocumentCoherence && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DocumentCoherence{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Does the file's provenance / toolchain history look suspicious? Advisory: + * individually weak workflow-hygiene signals + */ + class DocumentMetadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [DocumentMetadata]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DocumentMetadata]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(documentMetadata: DocumentMetadata) = apply { + applicable = documentMetadata.applicable + score = documentMetadata.score + additionalProperties = documentMetadata.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [DocumentMetadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): DocumentMetadata = + DocumentMetadata(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): DocumentMetadata = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DocumentMetadata && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DocumentMetadata{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** Has this asset (or its template) been seen in fraud before? */ + class KnownFraud + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [KnownFraud]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [KnownFraud]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(knownFraud: KnownFraud) = apply { + applicable = knownFraud.applicable + score = knownFraud.score + additionalProperties = knownFraud.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [KnownFraud]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): KnownFraud = + KnownFraud(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): KnownFraud = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is KnownFraud && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "KnownFraud{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** Was this document altered after creation (splice, retype, redact, inpaint)? */ + class ManuallyEdited + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [ManuallyEdited]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ManuallyEdited]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(manuallyEdited: ManuallyEdited) = apply { + applicable = manuallyEdited.applicable + score = manuallyEdited.score + additionalProperties = manuallyEdited.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [ManuallyEdited]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ManuallyEdited = + ManuallyEdited(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): ManuallyEdited = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ManuallyEdited && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ManuallyEdited{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + /** + * Was the document captured through a channel that destroys forensic evidence (photo of + * a screen, print-then-rescan)? + */ + class Recapture + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val applicable: JsonField, + private val score: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("applicable") + @ExcludeMissing + applicable: JsonField = JsonMissing.of(), + @JsonProperty("score") + @ExcludeMissing + score: JsonField = JsonMissing.of(), + ) : this(applicable, score, mutableMapOf()) + + /** + * Whether the checks feeding this composite ran on this document. When false the + * document was not checked for this — not cleared of it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun applicable(): Optional = applicable.getOptional("applicable") + + /** + * Score (0 to 1); null when the composite was not applicable + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Returns the raw JSON value of [applicable]. + * + * Unlike [applicable], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("applicable") + @ExcludeMissing + fun _applicable(): JsonField = applicable + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + @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 [Recapture]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Recapture]. */ + class Builder internal constructor() { + + private var applicable: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(recapture: Recapture) = apply { + applicable = recapture.applicable + score = recapture.score + additionalProperties = recapture.additionalProperties.toMutableMap() + } + + /** + * Whether the checks feeding this composite ran on this document. When false + * the document was not checked for this — not cleared of it + */ + fun applicable(applicable: Boolean) = applicable(JsonField.of(applicable)) + + /** + * Sets [Builder.applicable] to an arbitrary JSON value. + * + * You should usually call [Builder.applicable] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun applicable(applicable: JsonField) = apply { + this.applicable = applicable + } + + /** Score (0 to 1); null when the composite was not applicable */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + 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 [Recapture]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Recapture = + Recapture(applicable, score, 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Recapture = apply { + if (validated) { + return@apply + } + + applicable() + score() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (applicable.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Recapture && + applicable == other.applicable && + score == other.score && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(applicable, score, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Recapture{applicable=$applicable, score=$score, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CompositeScores && + aiGenerated == other.aiGenerated && + documentCoherence == other.documentCoherence && + documentMetadata == other.documentMetadata && + knownFraud == other.knownFraud && + manuallyEdited == other.manuallyEdited && + recapture == other.recapture && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + aiGenerated, + documentCoherence, + documentMetadata, + knownFraud, + manuallyEdited, + recapture, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CompositeScores{aiGenerated=$aiGenerated, documentCoherence=$documentCoherence, documentMetadata=$documentMetadata, knownFraud=$knownFraud, manuallyEdited=$manuallyEdited, recapture=$recapture, additionalProperties=$additionalProperties}" + } + + /** + * Rendered pixel size of a page — the coordinate space region bboxes use, so the UI can + * scale the suspect-region overlay onto the displayed page. + */ + class PageDimension + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val height: JsonField, + private val page: JsonField, + private val width: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("height") @ExcludeMissing height: JsonField = JsonMissing.of(), + @JsonProperty("page") @ExcludeMissing page: JsonField = JsonMissing.of(), + @JsonProperty("width") @ExcludeMissing width: JsonField = JsonMissing.of(), + ) : this(height, page, width, mutableMapOf()) + + /** + * Rendered page height in pixels + * + * @throws LlamaCloudInvalidDataException 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 height(): Long = height.getRequired("height") + + /** + * 0-based page index (0 for standalone images) + * + * @throws LlamaCloudInvalidDataException 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 page(): Long = page.getRequired("page") + + /** + * Rendered page width in pixels + * + * @throws LlamaCloudInvalidDataException 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 width(): Long = width.getRequired("width") + + /** + * Returns the raw JSON value of [height]. + * + * Unlike [height], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("height") @ExcludeMissing fun _height(): JsonField = height + + /** + * Returns the raw JSON value of [page]. + * + * Unlike [page], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page") @ExcludeMissing fun _page(): JsonField = page + + /** + * Returns the raw JSON value of [width]. + * + * Unlike [width], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("width") @ExcludeMissing fun _width(): JsonField = width + + @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 [PageDimension]. + * + * The following fields are required: + * ```java + * .height() + * .page() + * .width() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PageDimension]. */ + class Builder internal constructor() { + + private var height: JsonField? = null + private var page: JsonField? = null + private var width: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(pageDimension: PageDimension) = apply { + height = pageDimension.height + page = pageDimension.page + width = pageDimension.width + additionalProperties = pageDimension.additionalProperties.toMutableMap() + } + + /** Rendered page height in pixels */ + fun height(height: Long) = height(JsonField.of(height)) + + /** + * Sets [Builder.height] to an arbitrary JSON value. + * + * You should usually call [Builder.height] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun height(height: JsonField) = apply { this.height = height } + + /** 0-based page index (0 for standalone images) */ + fun page(page: Long) = page(JsonField.of(page)) + + /** + * Sets [Builder.page] to an arbitrary JSON value. + * + * You should usually call [Builder.page] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun page(page: JsonField) = apply { this.page = page } + + /** Rendered page width in pixels */ + fun width(width: Long) = width(JsonField.of(width)) + + /** + * Sets [Builder.width] to an arbitrary JSON value. + * + * You should usually call [Builder.width] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun width(width: JsonField) = apply { this.width = width } + + 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 [PageDimension]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .height() + * .page() + * .width() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PageDimension = + PageDimension( + checkRequired("height", height), + checkRequired("page", page), + checkRequired("width", width), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): PageDimension = apply { + if (validated) { + return@apply + } + + height() + page() + width() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (height.asKnown().isPresent) 1 else 0) + + (if (page.asKnown().isPresent) 1 else 0) + + (if (width.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PageDimension && + height == other.height && + page == other.page && + width == other.width && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(height, page, width, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PageDimension{height=$height, page=$page, width=$width, additionalProperties=$additionalProperties}" + } + + /** + * A region that led to the suspected fraud, with why it is suspect. + * + * A curated, high-signal subset of ``regions``: reviewer-dismissed candidates are dropped + * and the remainder is ranked by suspicion, so consumers can act on ``verdict`` + + * ``confidence`` + this list without reading the raw signals. + */ + class SuspectRegion + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val bbox: JsonField>, + private val explanation: JsonField, + private val kind: JsonField, + private val page: JsonField, + private val score: JsonField, + private val source: JsonField, + private val primary: JsonField, + private val review: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("bbox") + @ExcludeMissing + bbox: JsonField> = JsonMissing.of(), + @JsonProperty("explanation") + @ExcludeMissing + explanation: JsonField = JsonMissing.of(), + @JsonProperty("kind") @ExcludeMissing kind: JsonField = JsonMissing.of(), + @JsonProperty("page") @ExcludeMissing page: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + @JsonProperty("source") + @ExcludeMissing + source: JsonField = JsonMissing.of(), + @JsonProperty("primary") + @ExcludeMissing + primary: JsonField = JsonMissing.of(), + @JsonProperty("review") @ExcludeMissing review: JsonField = JsonMissing.of(), + ) : this(bbox, explanation, kind, page, score, source, primary, review, mutableMapOf()) + + /** + * Region bounding box as [x, y, w, h] in page-render pixels + * + * @throws LlamaCloudInvalidDataException 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 bbox(): List = bbox.getRequired("bbox") + + /** + * Human-readable explanation of what makes this region suspect + * + * @throws LlamaCloudInvalidDataException 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 explanation(): String = explanation.getRequired("explanation") + + /** + * Kind of anomaly detected in this region + * + * @throws LlamaCloudInvalidDataException 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 kind(): String = kind.getRequired("kind") + + /** + * 0-based page index (0 for standalone images) + * + * @throws LlamaCloudInvalidDataException 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 page(): Long = page.getRequired("page") + + /** + * Suspicion score for this region (0 to 1) + * + * @throws LlamaCloudInvalidDataException 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 score(): Double = score.getRequired("score") + + /** + * Detector that flagged this region + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun source(): String = source.getRequired("source") + + /** + * Whether this region is part of the small set of decisive evidence behind the verdict + * — the boxes a reviewer should look at first + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun primary(): Optional = primary.getOptional("primary") + + /** + * Automated reviewer verdict for this region (confirmed, dismissed, unsure, or empty). + * A dismissed region can still be surfaced when it is the only place to look; this + * label says how to read it + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun review(): Optional = review.getOptional("review") + + /** + * Returns the raw JSON value of [bbox]. + * + * Unlike [bbox], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("bbox") @ExcludeMissing fun _bbox(): JsonField> = bbox + + /** + * Returns the raw JSON value of [explanation]. + * + * Unlike [explanation], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("explanation") + @ExcludeMissing + fun _explanation(): JsonField = explanation + + /** + * Returns the raw JSON value of [kind]. + * + * Unlike [kind], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("kind") @ExcludeMissing fun _kind(): JsonField = kind + + /** + * Returns the raw JSON value of [page]. + * + * Unlike [page], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page") @ExcludeMissing fun _page(): JsonField = page + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + /** + * Returns the raw JSON value of [primary]. + * + * Unlike [primary], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("primary") @ExcludeMissing fun _primary(): JsonField = primary + + /** + * Returns the raw JSON value of [review]. + * + * Unlike [review], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("review") @ExcludeMissing fun _review(): JsonField = review + + @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 [SuspectRegion]. + * + * The following fields are required: + * ```java + * .bbox() + * .explanation() + * .kind() + * .page() + * .score() + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SuspectRegion]. */ + class Builder internal constructor() { + + private var bbox: JsonField>? = null + private var explanation: JsonField? = null + private var kind: JsonField? = null + private var page: JsonField? = null + private var score: JsonField? = null + private var source: JsonField? = null + private var primary: JsonField = JsonMissing.of() + private var review: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(suspectRegion: SuspectRegion) = apply { + bbox = suspectRegion.bbox.map { it.toMutableList() } + explanation = suspectRegion.explanation + kind = suspectRegion.kind + page = suspectRegion.page + score = suspectRegion.score + source = suspectRegion.source + primary = suspectRegion.primary + review = suspectRegion.review + additionalProperties = suspectRegion.additionalProperties.toMutableMap() + } + + /** Region bounding box as [x, y, w, h] in page-render pixels */ + fun bbox(bbox: List) = bbox(JsonField.of(bbox)) + + /** + * Sets [Builder.bbox] to an arbitrary JSON value. + * + * You should usually call [Builder.bbox] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun bbox(bbox: JsonField>) = apply { + this.bbox = bbox.map { it.toMutableList() } + } + + /** + * Adds a single [Long] to [Builder.bbox]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addBbox(bbox: Long) = apply { + this.bbox = + (this.bbox ?: JsonField.of(mutableListOf())).also { + checkKnown("bbox", it).add(bbox) + } + } + + /** Human-readable explanation of what makes this region suspect */ + fun explanation(explanation: String) = explanation(JsonField.of(explanation)) + + /** + * Sets [Builder.explanation] to an arbitrary JSON value. + * + * You should usually call [Builder.explanation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun explanation(explanation: JsonField) = apply { + this.explanation = explanation + } + + /** Kind of anomaly detected in this region */ + fun kind(kind: String) = kind(JsonField.of(kind)) + + /** + * Sets [Builder.kind] to an arbitrary JSON value. + * + * You should usually call [Builder.kind] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun kind(kind: JsonField) = apply { this.kind = kind } + + /** 0-based page index (0 for standalone images) */ + fun page(page: Long) = page(JsonField.of(page)) + + /** + * Sets [Builder.page] to an arbitrary JSON value. + * + * You should usually call [Builder.page] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun page(page: JsonField) = apply { this.page = page } + + /** Suspicion score for this region (0 to 1) */ + fun score(score: Double) = score(JsonField.of(score)) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + /** Detector that flagged this region */ + fun source(source: String) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + /** + * Whether this region is part of the small set of decisive evidence behind the + * verdict — the boxes a reviewer should look at first + */ + fun primary(primary: Boolean) = primary(JsonField.of(primary)) + + /** + * Sets [Builder.primary] to an arbitrary JSON value. + * + * You should usually call [Builder.primary] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun primary(primary: JsonField) = apply { this.primary = primary } + + /** + * Automated reviewer verdict for this region (confirmed, dismissed, unsure, or + * empty). A dismissed region can still be surfaced when it is the only place to + * look; this label says how to read it + */ + fun review(review: String) = review(JsonField.of(review)) + + /** + * Sets [Builder.review] to an arbitrary JSON value. + * + * You should usually call [Builder.review] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun review(review: JsonField) = apply { this.review = review } + + 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 [SuspectRegion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .bbox() + * .explanation() + * .kind() + * .page() + * .score() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SuspectRegion = + SuspectRegion( + checkRequired("bbox", bbox).map { it.toImmutable() }, + checkRequired("explanation", explanation), + checkRequired("kind", kind), + checkRequired("page", page), + checkRequired("score", score), + checkRequired("source", source), + primary, + review, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): SuspectRegion = apply { + if (validated) { + return@apply + } + + bbox() + explanation() + kind() + page() + score() + source() + primary() + review() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (bbox.asKnown().getOrNull()?.size ?: 0) + + (if (explanation.asKnown().isPresent) 1 else 0) + + (if (kind.asKnown().isPresent) 1 else 0) + + (if (page.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + (if (source.asKnown().isPresent) 1 else 0) + + (if (primary.asKnown().isPresent) 1 else 0) + + (if (review.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SuspectRegion && + bbox == other.bbox && + explanation == other.explanation && + kind == other.kind && + page == other.page && + score == other.score && + source == other.source && + primary == other.primary && + review == other.review && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + bbox, + explanation, + kind, + page, + score, + source, + primary, + review, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SuspectRegion{bbox=$bbox, explanation=$explanation, kind=$kind, page=$page, score=$score, source=$source, primary=$primary, review=$review, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Result && + detectorVersion == other.detectorVersion && + overallScore == other.overallScore && + verdict == other.verdict && + compositeScores == other.compositeScores && + confidence == other.confidence && + error == other.error && + pageCount == other.pageCount && + pageDimensions == other.pageDimensions && + reasoning == other.reasoning && + suspectRegions == other.suspectRegions && + syntheticScore == other.syntheticScore && + tamperingScore == other.tamperingScore && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + detectorVersion, + overallScore, + verdict, + compositeScores, + confidence, + error, + pageCount, + pageDimensions, + reasoning, + suspectRegions, + syntheticScore, + tamperingScore, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Result{detectorVersion=$detectorVersion, overallScore=$overallScore, verdict=$verdict, compositeScores=$compositeScores, confidence=$confidence, error=$error, pageCount=$pageCount, pageDimensions=$pageDimensions, reasoning=$reasoning, suspectRegions=$suspectRegions, syntheticScore=$syntheticScore, tamperingScore=$tamperingScore, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is VerifyListResponse && + id == other.id && + configuration == other.configuration && + documentInputType == other.documentInputType && + fileInput == other.fileInput && + projectId == other.projectId && + status == other.status && + userId == other.userId && + createdAt == other.createdAt && + errorMessage == other.errorMessage && + result == other.result && + transactionId == other.transactionId && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + configuration, + documentInputType, + fileInput, + projectId, + status, + userId, + createdAt, + errorMessage, + result, + transactionId, + updatedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VerifyListResponse{id=$id, configuration=$configuration, documentInputType=$documentInputType, fileInput=$fileInput, projectId=$projectId, status=$status, userId=$userId, createdAt=$createdAt, errorMessage=$errorMessage, result=$result, transactionId=$transactionId, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/batches/BatchCreateParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/batches/BatchCreateParams.kt index e88e1bd..f2fdbef 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/batches/BatchCreateParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/batches/BatchCreateParams.kt @@ -1772,6 +1772,16 @@ private constructor( @JvmField val UNMAPPED_EVENT = of("unmapped_event") + @JvmField val VERIFY_CANCELLED = of("verify.cancelled") + + @JvmField val VERIFY_ERROR = of("verify.error") + + @JvmField val VERIFY_PENDING = of("verify.pending") + + @JvmField val VERIFY_RUNNING = of("verify.running") + + @JvmField val VERIFY_SUCCESS = of("verify.success") + @JvmStatic fun of(value: String) = WebhookEvent(JsonField.of(value)) } @@ -1810,6 +1820,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, } /** @@ -1855,6 +1870,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, /** * An enum member indicating that [WebhookEvent] was instantiated with an unknown * value. @@ -1904,6 +1924,11 @@ private constructor( SPLIT_PROCESSING -> Value.SPLIT_PROCESSING SPLIT_SUCCESS -> Value.SPLIT_SUCCESS UNMAPPED_EVENT -> Value.UNMAPPED_EVENT + VERIFY_CANCELLED -> Value.VERIFY_CANCELLED + VERIFY_ERROR -> Value.VERIFY_ERROR + VERIFY_PENDING -> Value.VERIFY_PENDING + VERIFY_RUNNING -> Value.VERIFY_RUNNING + VERIFY_SUCCESS -> Value.VERIFY_SUCCESS else -> Value._UNKNOWN } @@ -1951,6 +1976,11 @@ private constructor( SPLIT_PROCESSING -> Known.SPLIT_PROCESSING SPLIT_SUCCESS -> Known.SPLIT_SUCCESS UNMAPPED_EVENT -> Known.UNMAPPED_EVENT + VERIFY_CANCELLED -> Known.VERIFY_CANCELLED + VERIFY_ERROR -> Known.VERIFY_ERROR + VERIFY_PENDING -> Known.VERIFY_PENDING + VERIFY_RUNNING -> Known.VERIFY_RUNNING + VERIFY_SUCCESS -> Known.VERIFY_SUCCESS else -> throw LlamaCloudInvalidDataException("Unknown WebhookEvent: $value") } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatCreateParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatCreateParams.kt index 283d2e0..92d6e1d 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatCreateParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatCreateParams.kt @@ -23,6 +23,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Create a chat session, optionally bound to indexes (locked after the first message). */ +@Deprecated("Moved out of beta. Use the top-level chat resource instead") class ChatCreateParams private constructor( private val organizationId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatDeleteParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatDeleteParams.kt index ef80851..4782f40 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatDeleteParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatDeleteParams.kt @@ -12,6 +12,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Delete a session. */ +@Deprecated("Moved out of beta. Use the top-level chat resource instead") class ChatDeleteParams private constructor( private val sessionId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatGetSummaryParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatGetSummaryParams.kt index ec3975b..8819fb1 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatGetSummaryParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatGetSummaryParams.kt @@ -10,6 +10,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Retrieve a session summary by ID. */ +@Deprecated("Moved out of beta. Use the top-level chat resource instead") class ChatGetSummaryParams private constructor( private val sessionId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatListPage.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatListPage.kt index cd295ae..5f57324 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatListPage.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatListPage.kt @@ -11,6 +11,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** @see ChatService.list */ +@Deprecated("Moved out of beta. Use the top-level chat resource instead") class ChatListPage private constructor( private val service: ChatService, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatListPageAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatListPageAsync.kt index 5c94678..f0c0cbd 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatListPageAsync.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatListPageAsync.kt @@ -13,6 +13,7 @@ import java.util.concurrent.Executor import kotlin.jvm.optionals.getOrNull /** @see ChatServiceAsync.list */ +@Deprecated("Moved out of beta. Use the top-level chat resource instead") class ChatListPageAsync private constructor( private val service: ChatServiceAsync, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatListParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatListParams.kt index 8470e86..d777b65 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatListParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatListParams.kt @@ -10,6 +10,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** List all chat sessions for the current project. */ +@Deprecated("Moved out of beta. Use the top-level chat resource instead") class ChatListParams private constructor( private val organizationId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatRetrieveParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatRetrieveParams.kt index f5dfd38..01cb383 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatRetrieveParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatRetrieveParams.kt @@ -10,6 +10,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Retrieve a full session by ID, including its event history. */ +@Deprecated("Moved out of beta. Use the top-level chat resource instead") class ChatRetrieveParams private constructor( private val sessionId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatStreamParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatStreamParams.kt index 4563bb2..5cfd5a6 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatStreamParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/chat/ChatStreamParams.kt @@ -23,6 +23,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Stream agent events for a chat turn as Server-Sent Events. */ +@Deprecated("Moved out of beta. Use the top-level chat resource instead") class ChatStreamParams private constructor( private val sessionId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexCreateParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexCreateParams.kt index c70a47b..5c25816 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexCreateParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexCreateParams.kt @@ -24,6 +24,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Create a searchable index over a source directory. */ +@Deprecated("Moved out of beta. Use the top-level indexes resource instead") class IndexCreateParams private constructor( private val organizationId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexCreateResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexCreateResponse.kt index 3daccd9..bcd2079 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexCreateResponse.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexCreateResponse.kt @@ -191,7 +191,8 @@ private constructor( fun metadata(): Optional = metadata.getOptional("metadata") /** - * Whether a sync is running. Set only when getting a single index. + * Whether the index is syncing its source or exporting the result. Requires + * `expand=sync_in_progress`. * * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -565,7 +566,10 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - /** Whether a sync is running. Set only when getting a single index. */ + /** + * Whether the index is syncing its source or exporting the result. Requires + * `expand=sync_in_progress`. + */ fun syncInProgress(syncInProgress: Boolean?) = syncInProgress(JsonField.ofNullable(syncInProgress)) diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexDeleteParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexDeleteParams.kt index 843b4fa..8fbaf50 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexDeleteParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexDeleteParams.kt @@ -12,6 +12,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Delete an index. */ +@Deprecated("Moved out of beta. Use the top-level indexes resource instead") class IndexDeleteParams private constructor( private val indexId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexGetParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexGetParams.kt index 636302a..537f45d 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexGetParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexGetParams.kt @@ -2,17 +2,24 @@ package ai.llamaindex.llamacloud.models.beta.indexes +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.JsonField import ai.llamaindex.llamacloud.core.Params import ai.llamaindex.llamacloud.core.http.Headers import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Get an index by ID. */ +@Deprecated("Moved out of beta. Use the top-level indexes resource instead") class IndexGetParams private constructor( private val indexId: String?, + private val expand: List?, private val organizationId: String?, private val projectId: String?, private val additionalHeaders: Headers, @@ -21,6 +28,9 @@ private constructor( fun indexId(): Optional = Optional.ofNullable(indexId) + /** Fields to expand. Supported value: sync_in_progress. */ + fun expand(): Optional> = Optional.ofNullable(expand) + fun organizationId(): Optional = Optional.ofNullable(organizationId) fun projectId(): Optional = Optional.ofNullable(projectId) @@ -45,6 +55,7 @@ private constructor( class Builder internal constructor() { private var indexId: String? = null + private var expand: MutableList? = null private var organizationId: String? = null private var projectId: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() @@ -53,6 +64,7 @@ private constructor( @JvmSynthetic internal fun from(indexGetParams: IndexGetParams) = apply { indexId = indexGetParams.indexId + expand = indexGetParams.expand?.toMutableList() organizationId = indexGetParams.organizationId projectId = indexGetParams.projectId additionalHeaders = indexGetParams.additionalHeaders.toBuilder() @@ -64,6 +76,21 @@ private constructor( /** Alias for calling [Builder.indexId] with `indexId.orElse(null)`. */ fun indexId(indexId: Optional) = indexId(indexId.getOrNull()) + /** Fields to expand. Supported value: sync_in_progress. */ + fun expand(expand: List?) = apply { this.expand = expand?.toMutableList() } + + /** Alias for calling [Builder.expand] with `expand.orElse(null)`. */ + fun expand(expand: Optional>) = expand(expand.getOrNull()) + + /** + * Adds a single [Expand] to [Builder.expand]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExpand(expand: Expand) = apply { + this.expand = (this.expand ?: mutableListOf()).apply { add(expand) } + } + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ @@ -181,6 +208,7 @@ private constructor( fun build(): IndexGetParams = IndexGetParams( indexId, + expand?.toImmutable(), organizationId, projectId, additionalHeaders.build(), @@ -199,12 +227,143 @@ private constructor( override fun _queryParams(): QueryParams = QueryParams.builder() .apply { + expand?.forEach { put("expand", it.toString()) } organizationId?.let { put("organization_id", it) } projectId?.let { put("project_id", it) } putAll(additionalQueryParams) } .build() + class Expand @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 SYNC_IN_PROGRESS = of("sync_in_progress") + + @JvmStatic fun of(value: String) = Expand(JsonField.of(value)) + } + + /** An enum containing [Expand]'s known values. */ + enum class Known { + SYNC_IN_PROGRESS + } + + /** + * An enum containing [Expand]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Expand] 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 { + SYNC_IN_PROGRESS, + /** An enum member indicating that [Expand] 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) { + SYNC_IN_PROGRESS -> Value.SYNC_IN_PROGRESS + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SYNC_IN_PROGRESS -> Known.SYNC_IN_PROGRESS + else -> throw LlamaCloudInvalidDataException("Unknown Expand: $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 LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Expand = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Expand && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -212,6 +371,7 @@ private constructor( return other is IndexGetParams && indexId == other.indexId && + expand == other.expand && organizationId == other.organizationId && projectId == other.projectId && additionalHeaders == other.additionalHeaders && @@ -219,8 +379,15 @@ private constructor( } override fun hashCode(): Int = - Objects.hash(indexId, organizationId, projectId, additionalHeaders, additionalQueryParams) + Objects.hash( + indexId, + expand, + organizationId, + projectId, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = - "IndexGetParams{indexId=$indexId, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "IndexGetParams{indexId=$indexId, expand=$expand, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexGetResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexGetResponse.kt index ca69669..e604c7e 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexGetResponse.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexGetResponse.kt @@ -191,7 +191,8 @@ private constructor( fun metadata(): Optional = metadata.getOptional("metadata") /** - * Whether a sync is running. Set only when getting a single index. + * Whether the index is syncing its source or exporting the result. Requires + * `expand=sync_in_progress`. * * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -565,7 +566,10 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - /** Whether a sync is running. Set only when getting a single index. */ + /** + * Whether the index is syncing its source or exporting the result. Requires + * `expand=sync_in_progress`. + */ fun syncInProgress(syncInProgress: Boolean?) = syncInProgress(JsonField.ofNullable(syncInProgress)) diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListPage.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListPage.kt index 0631e8f..8eeda12 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListPage.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListPage.kt @@ -11,6 +11,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** @see IndexService.list */ +@Deprecated("Moved out of beta. Use the top-level indexes resource instead") class IndexListPage private constructor( private val service: IndexService, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListPageAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListPageAsync.kt index 2079c25..4b6c8b4 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListPageAsync.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListPageAsync.kt @@ -13,6 +13,7 @@ import java.util.concurrent.Executor import kotlin.jvm.optionals.getOrNull /** @see IndexServiceAsync.list */ +@Deprecated("Moved out of beta. Use the top-level indexes resource instead") class IndexListPageAsync private constructor( private val service: IndexServiceAsync, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListParams.kt index 3d210bc..18fb738 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListParams.kt @@ -10,6 +10,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** List indexes for the current project. */ +@Deprecated("Moved out of beta. Use the top-level indexes resource instead") class IndexListParams private constructor( private val organizationId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListResponse.kt index b1ce1cb..dae2dbe 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListResponse.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexListResponse.kt @@ -191,7 +191,8 @@ private constructor( fun metadata(): Optional = metadata.getOptional("metadata") /** - * Whether a sync is running. Set only when getting a single index. + * Whether the index is syncing its source or exporting the result. Requires + * `expand=sync_in_progress`. * * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -565,7 +566,10 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - /** Whether a sync is running. Set only when getting a single index. */ + /** + * Whether the index is syncing its source or exporting the result. Requires + * `expand=sync_in_progress`. + */ fun syncInProgress(syncInProgress: Boolean?) = syncInProgress(JsonField.ofNullable(syncInProgress)) diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexSyncParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexSyncParams.kt index 7b2c270..313d160 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexSyncParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexSyncParams.kt @@ -15,6 +15,7 @@ import kotlin.jvm.optionals.getOrNull * Trigger a sync and export for an existing index, re-parsing changed files and exporting updated * chunks. */ +@Deprecated("Moved out of beta. Use the top-level indexes resource instead") class IndexSyncParams private constructor( private val indexId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalFindPage.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalFindPage.kt index b482c2c..41ada61 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalFindPage.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalFindPage.kt @@ -11,6 +11,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** @see RetrievalService.find */ +@Deprecated("Moved out of beta. Use the top-level retrieval resource instead") class RetrievalFindPage private constructor( private val service: RetrievalService, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalFindPageAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalFindPageAsync.kt index 46d93d5..9167c09 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalFindPageAsync.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalFindPageAsync.kt @@ -13,6 +13,7 @@ import java.util.concurrent.Executor import kotlin.jvm.optionals.getOrNull /** @see RetrievalServiceAsync.find */ +@Deprecated("Moved out of beta. Use the top-level retrieval resource instead") class RetrievalFindPageAsync private constructor( private val service: RetrievalServiceAsync, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalFindParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalFindParams.kt index dc3f276..fda3d7a 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalFindParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalFindParams.kt @@ -21,6 +21,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Search for files by name. */ +@Deprecated("Moved out of beta. Use the top-level retrieval resource instead") class RetrievalFindParams private constructor( private val organizationId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalGrepPage.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalGrepPage.kt index c19ba76..b70d1e0 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalGrepPage.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalGrepPage.kt @@ -11,6 +11,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** @see RetrievalService.grep */ +@Deprecated("Moved out of beta. Use the top-level retrieval resource instead") class RetrievalGrepPage private constructor( private val service: RetrievalService, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalGrepPageAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalGrepPageAsync.kt index 5241d70..9ee2d34 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalGrepPageAsync.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalGrepPageAsync.kt @@ -13,6 +13,7 @@ import java.util.concurrent.Executor import kotlin.jvm.optionals.getOrNull /** @see RetrievalServiceAsync.grep */ +@Deprecated("Moved out of beta. Use the top-level retrieval resource instead") class RetrievalGrepPageAsync private constructor( private val service: RetrievalServiceAsync, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalGrepParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalGrepParams.kt index a087e71..756f054 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalGrepParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalGrepParams.kt @@ -21,6 +21,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Grep within a file's parsed content using a regex pattern. */ +@Deprecated("Moved out of beta. Use the top-level retrieval resource instead") class RetrievalGrepParams private constructor( private val organizationId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalReadParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalReadParams.kt index 23b80b7..f3a6fec 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalReadParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalReadParams.kt @@ -21,6 +21,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Read the parsed text content of a specific file. */ +@Deprecated("Moved out of beta. Use the top-level retrieval resource instead") class RetrievalReadParams private constructor( private val organizationId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalRetrieveParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalRetrieveParams.kt index 86aa1e1..b60599b 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalRetrieveParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/beta/retrieval/RetrievalRetrieveParams.kt @@ -37,6 +37,7 @@ import kotlin.jvm.optionals.getOrNull * Retrieve relevant chunks via hybrid search (vector + full-text), with filtering on built-in or * user-defined metadata. */ +@Deprecated("Moved out of beta. Use the top-level retrieval resource instead") class RetrievalRetrieveParams private constructor( private val organizationId: String?, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatCreateParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatCreateParams.kt new file mode 100644 index 0000000..4a899c8 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatCreateParams.kt @@ -0,0 +1,718 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Create a chat session, optionally bound to indexes (locked after the first message). */ +class ChatCreateParams +private constructor( + private val organizationId: String?, + private val projectId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * Indexes this session will retrieve from. Once set and the first message has been sent, the + * source set is locked for the session's lifetime. Leave null to create an unbound session. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun indexIds(): Optional> = body.indexIds() + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask new + * questions). Null follows the deployment default. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun sharedAccess(): Optional = body.sharedAccess() + + /** + * Returns the raw JSON value of [indexIds]. + * + * Unlike [indexIds], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _indexIds(): JsonField> = body._indexIds() + + /** + * Returns the raw JSON value of [sharedAccess]. + * + * Unlike [sharedAccess], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _sharedAccess(): JsonField = body._sharedAccess() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): ChatCreateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ChatCreateParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatCreateParams]. */ + class Builder internal constructor() { + + private var organizationId: String? = null + private var projectId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(chatCreateParams: ChatCreateParams) = apply { + organizationId = chatCreateParams.organizationId + projectId = chatCreateParams.projectId + body = chatCreateParams.body.toBuilder() + additionalHeaders = chatCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = chatCreateParams.additionalQueryParams.toBuilder() + } + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [indexIds] + * - [sharedAccess] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** + * Indexes this session will retrieve from. Once set and the first message has been sent, + * the source set is locked for the session's lifetime. Leave null to create an unbound + * session. + */ + fun indexIds(indexIds: List?) = apply { body.indexIds(indexIds) } + + /** Alias for calling [Builder.indexIds] with `indexIds.orElse(null)`. */ + fun indexIds(indexIds: Optional>) = indexIds(indexIds.getOrNull()) + + /** + * Sets [Builder.indexIds] to an arbitrary JSON value. + * + * You should usually call [Builder.indexIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun indexIds(indexIds: JsonField>) = apply { body.indexIds(indexIds) } + + /** + * Adds a single [String] to [indexIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addIndexId(indexId: String) = apply { body.addIndexId(indexId) } + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask + * new questions). Null follows the deployment default. + */ + fun sharedAccess(sharedAccess: SharedAccess?) = apply { body.sharedAccess(sharedAccess) } + + /** Alias for calling [Builder.sharedAccess] with `sharedAccess.orElse(null)`. */ + fun sharedAccess(sharedAccess: Optional) = + sharedAccess(sharedAccess.getOrNull()) + + /** + * Sets [Builder.sharedAccess] to an arbitrary JSON value. + * + * You should usually call [Builder.sharedAccess] with a well-typed [SharedAccess] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sharedAccess(sharedAccess: JsonField) = apply { + body.sharedAccess(sharedAccess) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [ChatCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ChatCreateParams = + ChatCreateParams( + organizationId, + projectId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + /** Request body for creating a chat session. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val indexIds: JsonField>, + private val sharedAccess: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("index_ids") + @ExcludeMissing + indexIds: JsonField> = JsonMissing.of(), + @JsonProperty("shared_access") + @ExcludeMissing + sharedAccess: JsonField = JsonMissing.of(), + ) : this(indexIds, sharedAccess, mutableMapOf()) + + /** + * Indexes this session will retrieve from. Once set and the first message has been sent, + * the source set is locked for the session's lifetime. Leave null to create an unbound + * session. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun indexIds(): Optional> = indexIds.getOptional("index_ids") + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask + * new questions). Null follows the deployment default. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun sharedAccess(): Optional = sharedAccess.getOptional("shared_access") + + /** + * Returns the raw JSON value of [indexIds]. + * + * Unlike [indexIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("index_ids") + @ExcludeMissing + fun _indexIds(): JsonField> = indexIds + + /** + * Returns the raw JSON value of [sharedAccess]. + * + * Unlike [sharedAccess], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("shared_access") + @ExcludeMissing + fun _sharedAccess(): JsonField = sharedAccess + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var indexIds: JsonField>? = null + private var sharedAccess: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + indexIds = body.indexIds.map { it.toMutableList() } + sharedAccess = body.sharedAccess + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** + * Indexes this session will retrieve from. Once set and the first message has been + * sent, the source set is locked for the session's lifetime. Leave null to create an + * unbound session. + */ + fun indexIds(indexIds: List?) = indexIds(JsonField.ofNullable(indexIds)) + + /** Alias for calling [Builder.indexIds] with `indexIds.orElse(null)`. */ + fun indexIds(indexIds: Optional>) = indexIds(indexIds.getOrNull()) + + /** + * Sets [Builder.indexIds] to an arbitrary JSON value. + * + * You should usually call [Builder.indexIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun indexIds(indexIds: JsonField>) = apply { + this.indexIds = indexIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [indexIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addIndexId(indexId: String) = apply { + indexIds = + (indexIds ?: JsonField.of(mutableListOf())).also { + checkKnown("indexIds", it).add(indexId) + } + } + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may + * ask new questions). Null follows the deployment default. + */ + fun sharedAccess(sharedAccess: SharedAccess?) = + sharedAccess(JsonField.ofNullable(sharedAccess)) + + /** Alias for calling [Builder.sharedAccess] with `sharedAccess.orElse(null)`. */ + fun sharedAccess(sharedAccess: Optional) = + sharedAccess(sharedAccess.getOrNull()) + + /** + * Sets [Builder.sharedAccess] to an arbitrary JSON value. + * + * You should usually call [Builder.sharedAccess] with a well-typed [SharedAccess] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sharedAccess(sharedAccess: JsonField) = apply { + this.sharedAccess = sharedAccess + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = + Body( + (indexIds ?: JsonMissing.of()).map { it.toImmutable() }, + sharedAccess, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + indexIds() + sharedAccess().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (indexIds.asKnown().getOrNull()?.size ?: 0) + + (sharedAccess.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + indexIds == other.indexIds && + sharedAccess == other.sharedAccess && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(indexIds, sharedAccess, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{indexIds=$indexIds, sharedAccess=$sharedAccess, additionalProperties=$additionalProperties}" + } + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask new + * questions). Null follows the deployment default. + */ + class SharedAccess @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 QUERY = of("query") + + @JvmField val READ_ONLY = of("read_only") + + @JvmStatic fun of(value: String) = SharedAccess(JsonField.of(value)) + } + + /** An enum containing [SharedAccess]'s known values. */ + enum class Known { + QUERY, + READ_ONLY, + } + + /** + * An enum containing [SharedAccess]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [SharedAccess] 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 { + QUERY, + READ_ONLY, + /** + * An enum member indicating that [SharedAccess] 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) { + QUERY -> Value.QUERY + READ_ONLY -> Value.READ_ONLY + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + QUERY -> Known.QUERY + READ_ONLY -> Known.READ_ONLY + else -> throw LlamaCloudInvalidDataException("Unknown SharedAccess: $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 LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SharedAccess = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 SharedAccess && 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 ChatCreateParams && + organizationId == other.organizationId && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(organizationId, projectId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ChatCreateParams{organizationId=$organizationId, projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatCreateResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatCreateResponse.kt new file mode 100644 index 0000000..5030754 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatCreateResponse.kt @@ -0,0 +1,1035 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Summary of a chat session, including its title and last run metadata. */ +class ChatCreateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val lastUpdatedAt: JsonField, + private val sessionId: JsonField, + private val sharedAccess: JsonField, + private val generatedTitle: JsonField, + private val indexIds: JsonField>, + private val jobMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("last_updated_at") + @ExcludeMissing + lastUpdatedAt: JsonField = JsonMissing.of(), + @JsonProperty("session_id") @ExcludeMissing sessionId: JsonField = JsonMissing.of(), + @JsonProperty("shared_access") + @ExcludeMissing + sharedAccess: JsonField = JsonMissing.of(), + @JsonProperty("generated_title") + @ExcludeMissing + generatedTitle: JsonField = JsonMissing.of(), + @JsonProperty("index_ids") + @ExcludeMissing + indexIds: JsonField> = JsonMissing.of(), + @JsonProperty("job_metadata") + @ExcludeMissing + jobMetadata: JsonField = JsonMissing.of(), + ) : this( + lastUpdatedAt, + sessionId, + sharedAccess, + generatedTitle, + indexIds, + jobMetadata, + mutableMapOf(), + ) + + /** + * ISO-format timestamp showing when the session was last updated. + * + * @throws LlamaCloudInvalidDataException 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 lastUpdatedAt(): String = lastUpdatedAt.getRequired("last_updated_at") + + /** + * Unique session identifier. + * + * @throws LlamaCloudInvalidDataException 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 sessionId(): String = sessionId.getRequired("session_id") + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask new + * questions). + * + * @throws LlamaCloudInvalidDataException 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 sharedAccess(): SharedAccess = sharedAccess.getRequired("shared_access") + + /** + * Auto-generated title derived from the first user message. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun generatedTitle(): Optional = generatedTitle.getOptional("generated_title") + + /** + * Indexes this session is bound to. Null on unbound sessions. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun indexIds(): Optional> = indexIds.getOptional("index_ids") + + /** + * Token usage and status from the most recent run. Null if the session has not been run yet. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun jobMetadata(): Optional = jobMetadata.getOptional("job_metadata") + + /** + * Returns the raw JSON value of [lastUpdatedAt]. + * + * Unlike [lastUpdatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_updated_at") + @ExcludeMissing + fun _lastUpdatedAt(): JsonField = lastUpdatedAt + + /** + * Returns the raw JSON value of [sessionId]. + * + * Unlike [sessionId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_id") @ExcludeMissing fun _sessionId(): JsonField = sessionId + + /** + * Returns the raw JSON value of [sharedAccess]. + * + * Unlike [sharedAccess], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("shared_access") + @ExcludeMissing + fun _sharedAccess(): JsonField = sharedAccess + + /** + * Returns the raw JSON value of [generatedTitle]. + * + * Unlike [generatedTitle], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("generated_title") + @ExcludeMissing + fun _generatedTitle(): JsonField = generatedTitle + + /** + * Returns the raw JSON value of [indexIds]. + * + * Unlike [indexIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("index_ids") @ExcludeMissing fun _indexIds(): JsonField> = indexIds + + /** + * Returns the raw JSON value of [jobMetadata]. + * + * Unlike [jobMetadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("job_metadata") + @ExcludeMissing + fun _jobMetadata(): JsonField = jobMetadata + + @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 [ChatCreateResponse]. + * + * The following fields are required: + * ```java + * .lastUpdatedAt() + * .sessionId() + * .sharedAccess() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatCreateResponse]. */ + class Builder internal constructor() { + + private var lastUpdatedAt: JsonField? = null + private var sessionId: JsonField? = null + private var sharedAccess: JsonField? = null + private var generatedTitle: JsonField = JsonMissing.of() + private var indexIds: JsonField>? = null + private var jobMetadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatCreateResponse: ChatCreateResponse) = apply { + lastUpdatedAt = chatCreateResponse.lastUpdatedAt + sessionId = chatCreateResponse.sessionId + sharedAccess = chatCreateResponse.sharedAccess + generatedTitle = chatCreateResponse.generatedTitle + indexIds = chatCreateResponse.indexIds.map { it.toMutableList() } + jobMetadata = chatCreateResponse.jobMetadata + additionalProperties = chatCreateResponse.additionalProperties.toMutableMap() + } + + /** ISO-format timestamp showing when the session was last updated. */ + fun lastUpdatedAt(lastUpdatedAt: String) = lastUpdatedAt(JsonField.of(lastUpdatedAt)) + + /** + * Sets [Builder.lastUpdatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.lastUpdatedAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun lastUpdatedAt(lastUpdatedAt: JsonField) = apply { + this.lastUpdatedAt = lastUpdatedAt + } + + /** Unique session identifier. */ + fun sessionId(sessionId: String) = sessionId(JsonField.of(sessionId)) + + /** + * Sets [Builder.sessionId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun sessionId(sessionId: JsonField) = apply { this.sessionId = sessionId } + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask + * new questions). + */ + fun sharedAccess(sharedAccess: SharedAccess) = sharedAccess(JsonField.of(sharedAccess)) + + /** + * Sets [Builder.sharedAccess] to an arbitrary JSON value. + * + * You should usually call [Builder.sharedAccess] with a well-typed [SharedAccess] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sharedAccess(sharedAccess: JsonField) = apply { + this.sharedAccess = sharedAccess + } + + /** Auto-generated title derived from the first user message. */ + fun generatedTitle(generatedTitle: String?) = + generatedTitle(JsonField.ofNullable(generatedTitle)) + + /** Alias for calling [Builder.generatedTitle] with `generatedTitle.orElse(null)`. */ + fun generatedTitle(generatedTitle: Optional) = + generatedTitle(generatedTitle.getOrNull()) + + /** + * Sets [Builder.generatedTitle] to an arbitrary JSON value. + * + * You should usually call [Builder.generatedTitle] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun generatedTitle(generatedTitle: JsonField) = apply { + this.generatedTitle = generatedTitle + } + + /** Indexes this session is bound to. Null on unbound sessions. */ + fun indexIds(indexIds: List?) = indexIds(JsonField.ofNullable(indexIds)) + + /** Alias for calling [Builder.indexIds] with `indexIds.orElse(null)`. */ + fun indexIds(indexIds: Optional>) = indexIds(indexIds.getOrNull()) + + /** + * Sets [Builder.indexIds] to an arbitrary JSON value. + * + * You should usually call [Builder.indexIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun indexIds(indexIds: JsonField>) = apply { + this.indexIds = indexIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [indexIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addIndexId(indexId: String) = apply { + indexIds = + (indexIds ?: JsonField.of(mutableListOf())).also { + checkKnown("indexIds", it).add(indexId) + } + } + + /** + * Token usage and status from the most recent run. Null if the session has not been run + * yet. + */ + fun jobMetadata(jobMetadata: JobMetadata?) = jobMetadata(JsonField.ofNullable(jobMetadata)) + + /** Alias for calling [Builder.jobMetadata] with `jobMetadata.orElse(null)`. */ + fun jobMetadata(jobMetadata: Optional) = jobMetadata(jobMetadata.getOrNull()) + + /** + * Sets [Builder.jobMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.jobMetadata] with a well-typed [JobMetadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun jobMetadata(jobMetadata: JsonField) = apply { + this.jobMetadata = jobMetadata + } + + 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 [ChatCreateResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .lastUpdatedAt() + * .sessionId() + * .sharedAccess() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatCreateResponse = + ChatCreateResponse( + checkRequired("lastUpdatedAt", lastUpdatedAt), + checkRequired("sessionId", sessionId), + checkRequired("sharedAccess", sharedAccess), + generatedTitle, + (indexIds ?: JsonMissing.of()).map { it.toImmutable() }, + jobMetadata, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ChatCreateResponse = apply { + if (validated) { + return@apply + } + + lastUpdatedAt() + sessionId() + sharedAccess().validate() + generatedTitle() + indexIds() + jobMetadata().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (lastUpdatedAt.asKnown().isPresent) 1 else 0) + + (if (sessionId.asKnown().isPresent) 1 else 0) + + (sharedAccess.asKnown().getOrNull()?.validity() ?: 0) + + (if (generatedTitle.asKnown().isPresent) 1 else 0) + + (indexIds.asKnown().getOrNull()?.size ?: 0) + + (jobMetadata.asKnown().getOrNull()?.validity() ?: 0) + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask new + * questions). + */ + class SharedAccess @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 QUERY = of("query") + + @JvmField val READ_ONLY = of("read_only") + + @JvmStatic fun of(value: String) = SharedAccess(JsonField.of(value)) + } + + /** An enum containing [SharedAccess]'s known values. */ + enum class Known { + QUERY, + READ_ONLY, + } + + /** + * An enum containing [SharedAccess]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [SharedAccess] 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 { + QUERY, + READ_ONLY, + /** + * An enum member indicating that [SharedAccess] 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) { + QUERY -> Value.QUERY + READ_ONLY -> Value.READ_ONLY + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + QUERY -> Known.QUERY + READ_ONLY -> Known.READ_ONLY + else -> throw LlamaCloudInvalidDataException("Unknown SharedAccess: $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 LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SharedAccess = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 SharedAccess && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * Token usage and status from the most recent run. Null if the session has not been run yet. + */ + class JobMetadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val durationMs: JsonField, + private val error: JsonField, + private val exportConfigIds: JsonField>, + private val isError: JsonField, + private val totalInputTokens: JsonField, + private val totalOutputTokens: JsonField, + private val turns: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("duration_ms") + @ExcludeMissing + durationMs: JsonField = JsonMissing.of(), + @JsonProperty("error") @ExcludeMissing error: JsonField = JsonMissing.of(), + @JsonProperty("export_config_ids") + @ExcludeMissing + exportConfigIds: JsonField> = JsonMissing.of(), + @JsonProperty("is_error") + @ExcludeMissing + isError: JsonField = JsonMissing.of(), + @JsonProperty("total_input_tokens") + @ExcludeMissing + totalInputTokens: JsonField = JsonMissing.of(), + @JsonProperty("total_output_tokens") + @ExcludeMissing + totalOutputTokens: JsonField = JsonMissing.of(), + @JsonProperty("turns") @ExcludeMissing turns: JsonField = JsonMissing.of(), + ) : this( + durationMs, + error, + exportConfigIds, + isError, + totalInputTokens, + totalOutputTokens, + turns, + mutableMapOf(), + ) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun durationMs(): Optional = durationMs.getOptional("duration_ms") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun error(): Optional = error.getOptional("error") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun exportConfigIds(): Optional> = + exportConfigIds.getOptional("export_config_ids") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun isError(): Optional = isError.getOptional("is_error") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun totalInputTokens(): Optional = totalInputTokens.getOptional("total_input_tokens") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun totalOutputTokens(): Optional = + totalOutputTokens.getOptional("total_output_tokens") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun turns(): Optional = turns.getOptional("turns") + + /** + * Returns the raw JSON value of [durationMs]. + * + * Unlike [durationMs], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("duration_ms") + @ExcludeMissing + fun _durationMs(): JsonField = durationMs + + /** + * Returns the raw JSON value of [error]. + * + * Unlike [error], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error") @ExcludeMissing fun _error(): JsonField = error + + /** + * Returns the raw JSON value of [exportConfigIds]. + * + * Unlike [exportConfigIds], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("export_config_ids") + @ExcludeMissing + fun _exportConfigIds(): JsonField> = exportConfigIds + + /** + * Returns the raw JSON value of [isError]. + * + * Unlike [isError], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("is_error") @ExcludeMissing fun _isError(): JsonField = isError + + /** + * Returns the raw JSON value of [totalInputTokens]. + * + * Unlike [totalInputTokens], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("total_input_tokens") + @ExcludeMissing + fun _totalInputTokens(): JsonField = totalInputTokens + + /** + * Returns the raw JSON value of [totalOutputTokens]. + * + * Unlike [totalOutputTokens], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("total_output_tokens") + @ExcludeMissing + fun _totalOutputTokens(): JsonField = totalOutputTokens + + /** + * Returns the raw JSON value of [turns]. + * + * Unlike [turns], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("turns") @ExcludeMissing fun _turns(): JsonField = turns + + @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 [JobMetadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JobMetadata]. */ + class Builder internal constructor() { + + private var durationMs: JsonField = JsonMissing.of() + private var error: JsonField = JsonMissing.of() + private var exportConfigIds: JsonField>? = null + private var isError: JsonField = JsonMissing.of() + private var totalInputTokens: JsonField = JsonMissing.of() + private var totalOutputTokens: JsonField = JsonMissing.of() + private var turns: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(jobMetadata: JobMetadata) = apply { + durationMs = jobMetadata.durationMs + error = jobMetadata.error + exportConfigIds = jobMetadata.exportConfigIds.map { it.toMutableList() } + isError = jobMetadata.isError + totalInputTokens = jobMetadata.totalInputTokens + totalOutputTokens = jobMetadata.totalOutputTokens + turns = jobMetadata.turns + additionalProperties = jobMetadata.additionalProperties.toMutableMap() + } + + fun durationMs(durationMs: Double) = durationMs(JsonField.of(durationMs)) + + /** + * Sets [Builder.durationMs] to an arbitrary JSON value. + * + * You should usually call [Builder.durationMs] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun durationMs(durationMs: JsonField) = apply { this.durationMs = durationMs } + + fun error(error: String?) = error(JsonField.ofNullable(error)) + + /** Alias for calling [Builder.error] with `error.orElse(null)`. */ + fun error(error: Optional) = error(error.getOrNull()) + + /** + * Sets [Builder.error] to an arbitrary JSON value. + * + * You should usually call [Builder.error] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun error(error: JsonField) = apply { this.error = error } + + fun exportConfigIds(exportConfigIds: List?) = + exportConfigIds(JsonField.ofNullable(exportConfigIds)) + + /** Alias for calling [Builder.exportConfigIds] with `exportConfigIds.orElse(null)`. */ + fun exportConfigIds(exportConfigIds: Optional>) = + exportConfigIds(exportConfigIds.getOrNull()) + + /** + * Sets [Builder.exportConfigIds] to an arbitrary JSON value. + * + * You should usually call [Builder.exportConfigIds] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun exportConfigIds(exportConfigIds: JsonField>) = apply { + this.exportConfigIds = exportConfigIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [exportConfigIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExportConfigId(exportConfigId: String) = apply { + exportConfigIds = + (exportConfigIds ?: JsonField.of(mutableListOf())).also { + checkKnown("exportConfigIds", it).add(exportConfigId) + } + } + + fun isError(isError: Boolean) = isError(JsonField.of(isError)) + + /** + * Sets [Builder.isError] to an arbitrary JSON value. + * + * You should usually call [Builder.isError] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isError(isError: JsonField) = apply { this.isError = isError } + + fun totalInputTokens(totalInputTokens: Long?) = + totalInputTokens(JsonField.ofNullable(totalInputTokens)) + + /** + * Alias for [Builder.totalInputTokens]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalInputTokens(totalInputTokens: Long) = + totalInputTokens(totalInputTokens as Long?) + + /** + * Alias for calling [Builder.totalInputTokens] with `totalInputTokens.orElse(null)`. + */ + fun totalInputTokens(totalInputTokens: Optional) = + totalInputTokens(totalInputTokens.getOrNull()) + + /** + * Sets [Builder.totalInputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.totalInputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun totalInputTokens(totalInputTokens: JsonField) = apply { + this.totalInputTokens = totalInputTokens + } + + fun totalOutputTokens(totalOutputTokens: Long?) = + totalOutputTokens(JsonField.ofNullable(totalOutputTokens)) + + /** + * Alias for [Builder.totalOutputTokens]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalOutputTokens(totalOutputTokens: Long) = + totalOutputTokens(totalOutputTokens as Long?) + + /** + * Alias for calling [Builder.totalOutputTokens] with `totalOutputTokens.orElse(null)`. + */ + fun totalOutputTokens(totalOutputTokens: Optional) = + totalOutputTokens(totalOutputTokens.getOrNull()) + + /** + * Sets [Builder.totalOutputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.totalOutputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun totalOutputTokens(totalOutputTokens: JsonField) = apply { + this.totalOutputTokens = totalOutputTokens + } + + fun turns(turns: Long) = turns(JsonField.of(turns)) + + /** + * Sets [Builder.turns] to an arbitrary JSON value. + * + * You should usually call [Builder.turns] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun turns(turns: JsonField) = apply { this.turns = turns } + + 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 [JobMetadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): JobMetadata = + JobMetadata( + durationMs, + error, + (exportConfigIds ?: JsonMissing.of()).map { it.toImmutable() }, + isError, + totalInputTokens, + totalOutputTokens, + turns, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): JobMetadata = apply { + if (validated) { + return@apply + } + + durationMs() + error() + exportConfigIds() + isError() + totalInputTokens() + totalOutputTokens() + turns() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (durationMs.asKnown().isPresent) 1 else 0) + + (if (error.asKnown().isPresent) 1 else 0) + + (exportConfigIds.asKnown().getOrNull()?.size ?: 0) + + (if (isError.asKnown().isPresent) 1 else 0) + + (if (totalInputTokens.asKnown().isPresent) 1 else 0) + + (if (totalOutputTokens.asKnown().isPresent) 1 else 0) + + (if (turns.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JobMetadata && + durationMs == other.durationMs && + error == other.error && + exportConfigIds == other.exportConfigIds && + isError == other.isError && + totalInputTokens == other.totalInputTokens && + totalOutputTokens == other.totalOutputTokens && + turns == other.turns && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + durationMs, + error, + exportConfigIds, + isError, + totalInputTokens, + totalOutputTokens, + turns, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JobMetadata{durationMs=$durationMs, error=$error, exportConfigIds=$exportConfigIds, isError=$isError, totalInputTokens=$totalInputTokens, totalOutputTokens=$totalOutputTokens, turns=$turns, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatCreateResponse && + lastUpdatedAt == other.lastUpdatedAt && + sessionId == other.sessionId && + sharedAccess == other.sharedAccess && + generatedTitle == other.generatedTitle && + indexIds == other.indexIds && + jobMetadata == other.jobMetadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + lastUpdatedAt, + sessionId, + sharedAccess, + generatedTitle, + indexIds, + jobMetadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatCreateResponse{lastUpdatedAt=$lastUpdatedAt, sessionId=$sessionId, sharedAccess=$sharedAccess, generatedTitle=$generatedTitle, indexIds=$indexIds, jobMetadata=$jobMetadata, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatDeleteParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatDeleteParams.kt new file mode 100644 index 0000000..b3ccfb4 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatDeleteParams.kt @@ -0,0 +1,268 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Delete a session. */ +class ChatDeleteParams +private constructor( + private val sessionId: String?, + private val organizationId: String?, + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun sessionId(): Optional = Optional.ofNullable(sessionId) + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): ChatDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ChatDeleteParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatDeleteParams]. */ + class Builder internal constructor() { + + private var sessionId: String? = null + private var organizationId: String? = null + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatDeleteParams: ChatDeleteParams) = apply { + sessionId = chatDeleteParams.sessionId + organizationId = chatDeleteParams.organizationId + projectId = chatDeleteParams.projectId + additionalHeaders = chatDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = chatDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = chatDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun sessionId(sessionId: String?) = apply { this.sessionId = sessionId } + + /** Alias for calling [Builder.sessionId] with `sessionId.orElse(null)`. */ + fun sessionId(sessionId: Optional) = sessionId(sessionId.getOrNull()) + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [ChatDeleteParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ChatDeleteParams = + ChatDeleteParams( + sessionId, + organizationId, + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sessionId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatDeleteParams && + sessionId == other.sessionId && + organizationId == other.organizationId && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + sessionId, + organizationId, + projectId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "ChatDeleteParams{sessionId=$sessionId, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatGetSummaryParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatGetSummaryParams.kt new file mode 100644 index 0000000..35a9614 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatGetSummaryParams.kt @@ -0,0 +1,226 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieve a session summary by ID. */ +class ChatGetSummaryParams +private constructor( + private val sessionId: String?, + private val organizationId: String?, + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sessionId(): Optional = Optional.ofNullable(sessionId) + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): ChatGetSummaryParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ChatGetSummaryParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatGetSummaryParams]. */ + class Builder internal constructor() { + + private var sessionId: String? = null + private var organizationId: String? = null + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(chatGetSummaryParams: ChatGetSummaryParams) = apply { + sessionId = chatGetSummaryParams.sessionId + organizationId = chatGetSummaryParams.organizationId + projectId = chatGetSummaryParams.projectId + additionalHeaders = chatGetSummaryParams.additionalHeaders.toBuilder() + additionalQueryParams = chatGetSummaryParams.additionalQueryParams.toBuilder() + } + + fun sessionId(sessionId: String?) = apply { this.sessionId = sessionId } + + /** Alias for calling [Builder.sessionId] with `sessionId.orElse(null)`. */ + fun sessionId(sessionId: Optional) = sessionId(sessionId.getOrNull()) + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [ChatGetSummaryParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ChatGetSummaryParams = + ChatGetSummaryParams( + sessionId, + organizationId, + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sessionId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatGetSummaryParams && + sessionId == other.sessionId && + organizationId == other.organizationId && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(sessionId, organizationId, projectId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ChatGetSummaryParams{sessionId=$sessionId, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatGetSummaryResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatGetSummaryResponse.kt new file mode 100644 index 0000000..83ec156 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatGetSummaryResponse.kt @@ -0,0 +1,1035 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Summary of a chat session, including its title and last run metadata. */ +class ChatGetSummaryResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val lastUpdatedAt: JsonField, + private val sessionId: JsonField, + private val sharedAccess: JsonField, + private val generatedTitle: JsonField, + private val indexIds: JsonField>, + private val jobMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("last_updated_at") + @ExcludeMissing + lastUpdatedAt: JsonField = JsonMissing.of(), + @JsonProperty("session_id") @ExcludeMissing sessionId: JsonField = JsonMissing.of(), + @JsonProperty("shared_access") + @ExcludeMissing + sharedAccess: JsonField = JsonMissing.of(), + @JsonProperty("generated_title") + @ExcludeMissing + generatedTitle: JsonField = JsonMissing.of(), + @JsonProperty("index_ids") + @ExcludeMissing + indexIds: JsonField> = JsonMissing.of(), + @JsonProperty("job_metadata") + @ExcludeMissing + jobMetadata: JsonField = JsonMissing.of(), + ) : this( + lastUpdatedAt, + sessionId, + sharedAccess, + generatedTitle, + indexIds, + jobMetadata, + mutableMapOf(), + ) + + /** + * ISO-format timestamp showing when the session was last updated. + * + * @throws LlamaCloudInvalidDataException 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 lastUpdatedAt(): String = lastUpdatedAt.getRequired("last_updated_at") + + /** + * Unique session identifier. + * + * @throws LlamaCloudInvalidDataException 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 sessionId(): String = sessionId.getRequired("session_id") + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask new + * questions). + * + * @throws LlamaCloudInvalidDataException 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 sharedAccess(): SharedAccess = sharedAccess.getRequired("shared_access") + + /** + * Auto-generated title derived from the first user message. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun generatedTitle(): Optional = generatedTitle.getOptional("generated_title") + + /** + * Indexes this session is bound to. Null on unbound sessions. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun indexIds(): Optional> = indexIds.getOptional("index_ids") + + /** + * Token usage and status from the most recent run. Null if the session has not been run yet. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun jobMetadata(): Optional = jobMetadata.getOptional("job_metadata") + + /** + * Returns the raw JSON value of [lastUpdatedAt]. + * + * Unlike [lastUpdatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_updated_at") + @ExcludeMissing + fun _lastUpdatedAt(): JsonField = lastUpdatedAt + + /** + * Returns the raw JSON value of [sessionId]. + * + * Unlike [sessionId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_id") @ExcludeMissing fun _sessionId(): JsonField = sessionId + + /** + * Returns the raw JSON value of [sharedAccess]. + * + * Unlike [sharedAccess], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("shared_access") + @ExcludeMissing + fun _sharedAccess(): JsonField = sharedAccess + + /** + * Returns the raw JSON value of [generatedTitle]. + * + * Unlike [generatedTitle], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("generated_title") + @ExcludeMissing + fun _generatedTitle(): JsonField = generatedTitle + + /** + * Returns the raw JSON value of [indexIds]. + * + * Unlike [indexIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("index_ids") @ExcludeMissing fun _indexIds(): JsonField> = indexIds + + /** + * Returns the raw JSON value of [jobMetadata]. + * + * Unlike [jobMetadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("job_metadata") + @ExcludeMissing + fun _jobMetadata(): JsonField = jobMetadata + + @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 [ChatGetSummaryResponse]. + * + * The following fields are required: + * ```java + * .lastUpdatedAt() + * .sessionId() + * .sharedAccess() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatGetSummaryResponse]. */ + class Builder internal constructor() { + + private var lastUpdatedAt: JsonField? = null + private var sessionId: JsonField? = null + private var sharedAccess: JsonField? = null + private var generatedTitle: JsonField = JsonMissing.of() + private var indexIds: JsonField>? = null + private var jobMetadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatGetSummaryResponse: ChatGetSummaryResponse) = apply { + lastUpdatedAt = chatGetSummaryResponse.lastUpdatedAt + sessionId = chatGetSummaryResponse.sessionId + sharedAccess = chatGetSummaryResponse.sharedAccess + generatedTitle = chatGetSummaryResponse.generatedTitle + indexIds = chatGetSummaryResponse.indexIds.map { it.toMutableList() } + jobMetadata = chatGetSummaryResponse.jobMetadata + additionalProperties = chatGetSummaryResponse.additionalProperties.toMutableMap() + } + + /** ISO-format timestamp showing when the session was last updated. */ + fun lastUpdatedAt(lastUpdatedAt: String) = lastUpdatedAt(JsonField.of(lastUpdatedAt)) + + /** + * Sets [Builder.lastUpdatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.lastUpdatedAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun lastUpdatedAt(lastUpdatedAt: JsonField) = apply { + this.lastUpdatedAt = lastUpdatedAt + } + + /** Unique session identifier. */ + fun sessionId(sessionId: String) = sessionId(JsonField.of(sessionId)) + + /** + * Sets [Builder.sessionId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun sessionId(sessionId: JsonField) = apply { this.sessionId = sessionId } + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask + * new questions). + */ + fun sharedAccess(sharedAccess: SharedAccess) = sharedAccess(JsonField.of(sharedAccess)) + + /** + * Sets [Builder.sharedAccess] to an arbitrary JSON value. + * + * You should usually call [Builder.sharedAccess] with a well-typed [SharedAccess] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sharedAccess(sharedAccess: JsonField) = apply { + this.sharedAccess = sharedAccess + } + + /** Auto-generated title derived from the first user message. */ + fun generatedTitle(generatedTitle: String?) = + generatedTitle(JsonField.ofNullable(generatedTitle)) + + /** Alias for calling [Builder.generatedTitle] with `generatedTitle.orElse(null)`. */ + fun generatedTitle(generatedTitle: Optional) = + generatedTitle(generatedTitle.getOrNull()) + + /** + * Sets [Builder.generatedTitle] to an arbitrary JSON value. + * + * You should usually call [Builder.generatedTitle] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun generatedTitle(generatedTitle: JsonField) = apply { + this.generatedTitle = generatedTitle + } + + /** Indexes this session is bound to. Null on unbound sessions. */ + fun indexIds(indexIds: List?) = indexIds(JsonField.ofNullable(indexIds)) + + /** Alias for calling [Builder.indexIds] with `indexIds.orElse(null)`. */ + fun indexIds(indexIds: Optional>) = indexIds(indexIds.getOrNull()) + + /** + * Sets [Builder.indexIds] to an arbitrary JSON value. + * + * You should usually call [Builder.indexIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun indexIds(indexIds: JsonField>) = apply { + this.indexIds = indexIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [indexIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addIndexId(indexId: String) = apply { + indexIds = + (indexIds ?: JsonField.of(mutableListOf())).also { + checkKnown("indexIds", it).add(indexId) + } + } + + /** + * Token usage and status from the most recent run. Null if the session has not been run + * yet. + */ + fun jobMetadata(jobMetadata: JobMetadata?) = jobMetadata(JsonField.ofNullable(jobMetadata)) + + /** Alias for calling [Builder.jobMetadata] with `jobMetadata.orElse(null)`. */ + fun jobMetadata(jobMetadata: Optional) = jobMetadata(jobMetadata.getOrNull()) + + /** + * Sets [Builder.jobMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.jobMetadata] with a well-typed [JobMetadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun jobMetadata(jobMetadata: JsonField) = apply { + this.jobMetadata = jobMetadata + } + + 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 [ChatGetSummaryResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .lastUpdatedAt() + * .sessionId() + * .sharedAccess() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatGetSummaryResponse = + ChatGetSummaryResponse( + checkRequired("lastUpdatedAt", lastUpdatedAt), + checkRequired("sessionId", sessionId), + checkRequired("sharedAccess", sharedAccess), + generatedTitle, + (indexIds ?: JsonMissing.of()).map { it.toImmutable() }, + jobMetadata, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ChatGetSummaryResponse = apply { + if (validated) { + return@apply + } + + lastUpdatedAt() + sessionId() + sharedAccess().validate() + generatedTitle() + indexIds() + jobMetadata().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (lastUpdatedAt.asKnown().isPresent) 1 else 0) + + (if (sessionId.asKnown().isPresent) 1 else 0) + + (sharedAccess.asKnown().getOrNull()?.validity() ?: 0) + + (if (generatedTitle.asKnown().isPresent) 1 else 0) + + (indexIds.asKnown().getOrNull()?.size ?: 0) + + (jobMetadata.asKnown().getOrNull()?.validity() ?: 0) + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask new + * questions). + */ + class SharedAccess @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 QUERY = of("query") + + @JvmField val READ_ONLY = of("read_only") + + @JvmStatic fun of(value: String) = SharedAccess(JsonField.of(value)) + } + + /** An enum containing [SharedAccess]'s known values. */ + enum class Known { + QUERY, + READ_ONLY, + } + + /** + * An enum containing [SharedAccess]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [SharedAccess] 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 { + QUERY, + READ_ONLY, + /** + * An enum member indicating that [SharedAccess] 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) { + QUERY -> Value.QUERY + READ_ONLY -> Value.READ_ONLY + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + QUERY -> Known.QUERY + READ_ONLY -> Known.READ_ONLY + else -> throw LlamaCloudInvalidDataException("Unknown SharedAccess: $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 LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SharedAccess = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 SharedAccess && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * Token usage and status from the most recent run. Null if the session has not been run yet. + */ + class JobMetadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val durationMs: JsonField, + private val error: JsonField, + private val exportConfigIds: JsonField>, + private val isError: JsonField, + private val totalInputTokens: JsonField, + private val totalOutputTokens: JsonField, + private val turns: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("duration_ms") + @ExcludeMissing + durationMs: JsonField = JsonMissing.of(), + @JsonProperty("error") @ExcludeMissing error: JsonField = JsonMissing.of(), + @JsonProperty("export_config_ids") + @ExcludeMissing + exportConfigIds: JsonField> = JsonMissing.of(), + @JsonProperty("is_error") + @ExcludeMissing + isError: JsonField = JsonMissing.of(), + @JsonProperty("total_input_tokens") + @ExcludeMissing + totalInputTokens: JsonField = JsonMissing.of(), + @JsonProperty("total_output_tokens") + @ExcludeMissing + totalOutputTokens: JsonField = JsonMissing.of(), + @JsonProperty("turns") @ExcludeMissing turns: JsonField = JsonMissing.of(), + ) : this( + durationMs, + error, + exportConfigIds, + isError, + totalInputTokens, + totalOutputTokens, + turns, + mutableMapOf(), + ) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun durationMs(): Optional = durationMs.getOptional("duration_ms") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun error(): Optional = error.getOptional("error") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun exportConfigIds(): Optional> = + exportConfigIds.getOptional("export_config_ids") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun isError(): Optional = isError.getOptional("is_error") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun totalInputTokens(): Optional = totalInputTokens.getOptional("total_input_tokens") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun totalOutputTokens(): Optional = + totalOutputTokens.getOptional("total_output_tokens") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun turns(): Optional = turns.getOptional("turns") + + /** + * Returns the raw JSON value of [durationMs]. + * + * Unlike [durationMs], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("duration_ms") + @ExcludeMissing + fun _durationMs(): JsonField = durationMs + + /** + * Returns the raw JSON value of [error]. + * + * Unlike [error], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error") @ExcludeMissing fun _error(): JsonField = error + + /** + * Returns the raw JSON value of [exportConfigIds]. + * + * Unlike [exportConfigIds], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("export_config_ids") + @ExcludeMissing + fun _exportConfigIds(): JsonField> = exportConfigIds + + /** + * Returns the raw JSON value of [isError]. + * + * Unlike [isError], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("is_error") @ExcludeMissing fun _isError(): JsonField = isError + + /** + * Returns the raw JSON value of [totalInputTokens]. + * + * Unlike [totalInputTokens], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("total_input_tokens") + @ExcludeMissing + fun _totalInputTokens(): JsonField = totalInputTokens + + /** + * Returns the raw JSON value of [totalOutputTokens]. + * + * Unlike [totalOutputTokens], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("total_output_tokens") + @ExcludeMissing + fun _totalOutputTokens(): JsonField = totalOutputTokens + + /** + * Returns the raw JSON value of [turns]. + * + * Unlike [turns], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("turns") @ExcludeMissing fun _turns(): JsonField = turns + + @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 [JobMetadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JobMetadata]. */ + class Builder internal constructor() { + + private var durationMs: JsonField = JsonMissing.of() + private var error: JsonField = JsonMissing.of() + private var exportConfigIds: JsonField>? = null + private var isError: JsonField = JsonMissing.of() + private var totalInputTokens: JsonField = JsonMissing.of() + private var totalOutputTokens: JsonField = JsonMissing.of() + private var turns: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(jobMetadata: JobMetadata) = apply { + durationMs = jobMetadata.durationMs + error = jobMetadata.error + exportConfigIds = jobMetadata.exportConfigIds.map { it.toMutableList() } + isError = jobMetadata.isError + totalInputTokens = jobMetadata.totalInputTokens + totalOutputTokens = jobMetadata.totalOutputTokens + turns = jobMetadata.turns + additionalProperties = jobMetadata.additionalProperties.toMutableMap() + } + + fun durationMs(durationMs: Double) = durationMs(JsonField.of(durationMs)) + + /** + * Sets [Builder.durationMs] to an arbitrary JSON value. + * + * You should usually call [Builder.durationMs] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun durationMs(durationMs: JsonField) = apply { this.durationMs = durationMs } + + fun error(error: String?) = error(JsonField.ofNullable(error)) + + /** Alias for calling [Builder.error] with `error.orElse(null)`. */ + fun error(error: Optional) = error(error.getOrNull()) + + /** + * Sets [Builder.error] to an arbitrary JSON value. + * + * You should usually call [Builder.error] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun error(error: JsonField) = apply { this.error = error } + + fun exportConfigIds(exportConfigIds: List?) = + exportConfigIds(JsonField.ofNullable(exportConfigIds)) + + /** Alias for calling [Builder.exportConfigIds] with `exportConfigIds.orElse(null)`. */ + fun exportConfigIds(exportConfigIds: Optional>) = + exportConfigIds(exportConfigIds.getOrNull()) + + /** + * Sets [Builder.exportConfigIds] to an arbitrary JSON value. + * + * You should usually call [Builder.exportConfigIds] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun exportConfigIds(exportConfigIds: JsonField>) = apply { + this.exportConfigIds = exportConfigIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [exportConfigIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExportConfigId(exportConfigId: String) = apply { + exportConfigIds = + (exportConfigIds ?: JsonField.of(mutableListOf())).also { + checkKnown("exportConfigIds", it).add(exportConfigId) + } + } + + fun isError(isError: Boolean) = isError(JsonField.of(isError)) + + /** + * Sets [Builder.isError] to an arbitrary JSON value. + * + * You should usually call [Builder.isError] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isError(isError: JsonField) = apply { this.isError = isError } + + fun totalInputTokens(totalInputTokens: Long?) = + totalInputTokens(JsonField.ofNullable(totalInputTokens)) + + /** + * Alias for [Builder.totalInputTokens]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalInputTokens(totalInputTokens: Long) = + totalInputTokens(totalInputTokens as Long?) + + /** + * Alias for calling [Builder.totalInputTokens] with `totalInputTokens.orElse(null)`. + */ + fun totalInputTokens(totalInputTokens: Optional) = + totalInputTokens(totalInputTokens.getOrNull()) + + /** + * Sets [Builder.totalInputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.totalInputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun totalInputTokens(totalInputTokens: JsonField) = apply { + this.totalInputTokens = totalInputTokens + } + + fun totalOutputTokens(totalOutputTokens: Long?) = + totalOutputTokens(JsonField.ofNullable(totalOutputTokens)) + + /** + * Alias for [Builder.totalOutputTokens]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalOutputTokens(totalOutputTokens: Long) = + totalOutputTokens(totalOutputTokens as Long?) + + /** + * Alias for calling [Builder.totalOutputTokens] with `totalOutputTokens.orElse(null)`. + */ + fun totalOutputTokens(totalOutputTokens: Optional) = + totalOutputTokens(totalOutputTokens.getOrNull()) + + /** + * Sets [Builder.totalOutputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.totalOutputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun totalOutputTokens(totalOutputTokens: JsonField) = apply { + this.totalOutputTokens = totalOutputTokens + } + + fun turns(turns: Long) = turns(JsonField.of(turns)) + + /** + * Sets [Builder.turns] to an arbitrary JSON value. + * + * You should usually call [Builder.turns] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun turns(turns: JsonField) = apply { this.turns = turns } + + 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 [JobMetadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): JobMetadata = + JobMetadata( + durationMs, + error, + (exportConfigIds ?: JsonMissing.of()).map { it.toImmutable() }, + isError, + totalInputTokens, + totalOutputTokens, + turns, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): JobMetadata = apply { + if (validated) { + return@apply + } + + durationMs() + error() + exportConfigIds() + isError() + totalInputTokens() + totalOutputTokens() + turns() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (durationMs.asKnown().isPresent) 1 else 0) + + (if (error.asKnown().isPresent) 1 else 0) + + (exportConfigIds.asKnown().getOrNull()?.size ?: 0) + + (if (isError.asKnown().isPresent) 1 else 0) + + (if (totalInputTokens.asKnown().isPresent) 1 else 0) + + (if (totalOutputTokens.asKnown().isPresent) 1 else 0) + + (if (turns.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JobMetadata && + durationMs == other.durationMs && + error == other.error && + exportConfigIds == other.exportConfigIds && + isError == other.isError && + totalInputTokens == other.totalInputTokens && + totalOutputTokens == other.totalOutputTokens && + turns == other.turns && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + durationMs, + error, + exportConfigIds, + isError, + totalInputTokens, + totalOutputTokens, + turns, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JobMetadata{durationMs=$durationMs, error=$error, exportConfigIds=$exportConfigIds, isError=$isError, totalInputTokens=$totalInputTokens, totalOutputTokens=$totalOutputTokens, turns=$turns, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatGetSummaryResponse && + lastUpdatedAt == other.lastUpdatedAt && + sessionId == other.sessionId && + sharedAccess == other.sharedAccess && + generatedTitle == other.generatedTitle && + indexIds == other.indexIds && + jobMetadata == other.jobMetadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + lastUpdatedAt, + sessionId, + sharedAccess, + generatedTitle, + indexIds, + jobMetadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatGetSummaryResponse{lastUpdatedAt=$lastUpdatedAt, sessionId=$sessionId, sharedAccess=$sharedAccess, generatedTitle=$generatedTitle, indexIds=$indexIds, jobMetadata=$jobMetadata, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListPage.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListPage.kt new file mode 100644 index 0000000..3183ffb --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListPage.kt @@ -0,0 +1,130 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.AutoPager +import ai.llamaindex.llamacloud.core.Page +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.services.blocking.ChatService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see ChatService.list */ +class ChatListPage +private constructor( + private val service: ChatService, + private val params: ChatListParams, + private val response: ChatListPageResponse, +) : Page { + + /** + * Delegates to [ChatListPageResponse], but gracefully handles missing data. + * + * @see ChatListPageResponse.items + */ + override fun items(): List = + response._items().getOptional("items").getOrNull() ?: emptyList() + + /** + * Delegates to [ChatListPageResponse], but gracefully handles missing data. + * + * @see ChatListPageResponse.nextPageToken + */ + fun nextPageToken(): Optional = response._nextPageToken().getOptional("next_page_token") + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageToken().isPresent + + fun nextPageParams(): ChatListParams { + val nextCursor = + nextPageToken().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().pageToken(nextCursor).build() + } + + override fun nextPage(): ChatListPage = service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): ChatListParams = params + + /** The response that this page was parsed from. */ + fun response(): ChatListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ChatListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatListPage]. */ + class Builder internal constructor() { + + private var service: ChatService? = null + private var params: ChatListParams? = null + private var response: ChatListPageResponse? = null + + @JvmSynthetic + internal fun from(chatListPage: ChatListPage) = apply { + service = chatListPage.service + params = chatListPage.params + response = chatListPage.response + } + + fun service(service: ChatService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ChatListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ChatListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ChatListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatListPage = + ChatListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatListPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = "ChatListPage{service=$service, params=$params, response=$response}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListPageAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListPageAsync.kt new file mode 100644 index 0000000..d4f1fe4 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListPageAsync.kt @@ -0,0 +1,145 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.AutoPagerAsync +import ai.llamaindex.llamacloud.core.PageAsync +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.services.async.ChatServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see ChatServiceAsync.list */ +class ChatListPageAsync +private constructor( + private val service: ChatServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: ChatListParams, + private val response: ChatListPageResponse, +) : PageAsync { + + /** + * Delegates to [ChatListPageResponse], but gracefully handles missing data. + * + * @see ChatListPageResponse.items + */ + override fun items(): List = + response._items().getOptional("items").getOrNull() ?: emptyList() + + /** + * Delegates to [ChatListPageResponse], but gracefully handles missing data. + * + * @see ChatListPageResponse.nextPageToken + */ + fun nextPageToken(): Optional = response._nextPageToken().getOptional("next_page_token") + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageToken().isPresent + + fun nextPageParams(): ChatListParams { + val nextCursor = + nextPageToken().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().pageToken(nextCursor).build() + } + + override fun nextPage(): CompletableFuture = service.list(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) + + /** The parameters that were used to request this page. */ + fun params(): ChatListParams = params + + /** The response that this page was parsed from. */ + fun response(): ChatListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ChatListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatListPageAsync]. */ + class Builder internal constructor() { + + private var service: ChatServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: ChatListParams? = null + private var response: ChatListPageResponse? = null + + @JvmSynthetic + internal fun from(chatListPageAsync: ChatListPageAsync) = apply { + service = chatListPageAsync.service + streamHandlerExecutor = chatListPageAsync.streamHandlerExecutor + params = chatListPageAsync.params + response = chatListPageAsync.response + } + + fun service(service: ChatServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: ChatListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ChatListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ChatListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatListPageAsync = + ChatListPageAsync( + checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) + + override fun toString() = + "ChatListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListPageResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListPageResponse.kt new file mode 100644 index 0000000..229a9a4 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListPageResponse.kt @@ -0,0 +1,249 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Paginated list of chat sessions. */ +class ChatListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val items: JsonField>, + private val nextPageToken: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("items") + @ExcludeMissing + items: JsonField> = JsonMissing.of(), + @JsonProperty("next_page_token") + @ExcludeMissing + nextPageToken: JsonField = JsonMissing.of(), + ) : this(items, nextPageToken, mutableMapOf()) + + /** + * Chat sessions for the current page. + * + * @throws LlamaCloudInvalidDataException 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 items(): List = items.getRequired("items") + + /** + * Opaque token to retrieve the next page. Omitted when there are no further pages. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextPageToken(): Optional = nextPageToken.getOptional("next_page_token") + + /** + * Returns the raw JSON value of [items]. + * + * Unlike [items], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("items") @ExcludeMissing fun _items(): JsonField> = items + + /** + * Returns the raw JSON value of [nextPageToken]. + * + * Unlike [nextPageToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_page_token") + @ExcludeMissing + fun _nextPageToken(): JsonField = nextPageToken + + @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 [ChatListPageResponse]. + * + * The following fields are required: + * ```java + * .items() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatListPageResponse]. */ + class Builder internal constructor() { + + private var items: JsonField>? = null + private var nextPageToken: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatListPageResponse: ChatListPageResponse) = apply { + items = chatListPageResponse.items.map { it.toMutableList() } + nextPageToken = chatListPageResponse.nextPageToken + additionalProperties = chatListPageResponse.additionalProperties.toMutableMap() + } + + /** Chat sessions for the current page. */ + fun items(items: List) = items(JsonField.of(items)) + + /** + * Sets [Builder.items] to an arbitrary JSON value. + * + * You should usually call [Builder.items] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun items(items: JsonField>) = apply { + this.items = items.map { it.toMutableList() } + } + + /** + * Adds a single [ChatListResponse] to [items]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addItem(item: ChatListResponse) = apply { + items = + (items ?: JsonField.of(mutableListOf())).also { checkKnown("items", it).add(item) } + } + + /** Opaque token to retrieve the next page. Omitted when there are no further pages. */ + fun nextPageToken(nextPageToken: String?) = + nextPageToken(JsonField.ofNullable(nextPageToken)) + + /** Alias for calling [Builder.nextPageToken] with `nextPageToken.orElse(null)`. */ + fun nextPageToken(nextPageToken: Optional) = + nextPageToken(nextPageToken.getOrNull()) + + /** + * Sets [Builder.nextPageToken] to an arbitrary JSON value. + * + * You should usually call [Builder.nextPageToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun nextPageToken(nextPageToken: JsonField) = apply { + this.nextPageToken = nextPageToken + } + + 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 [ChatListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .items() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatListPageResponse = + ChatListPageResponse( + checkRequired("items", items).map { it.toImmutable() }, + nextPageToken, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ChatListPageResponse = apply { + if (validated) { + return@apply + } + + items().forEach { it.validate() } + nextPageToken() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (items.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (nextPageToken.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatListPageResponse && + items == other.items && + nextPageToken == other.nextPageToken && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(items, nextPageToken, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatListPageResponse{items=$items, nextPageToken=$nextPageToken, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListParams.kt new file mode 100644 index 0000000..b5ee03c --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListParams.kt @@ -0,0 +1,248 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** List all chat sessions for the current project. */ +class ChatListParams +private constructor( + private val organizationId: String?, + private val pageSize: Long?, + private val pageToken: String?, + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun pageSize(): Optional = Optional.ofNullable(pageSize) + + fun pageToken(): Optional = Optional.ofNullable(pageToken) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): ChatListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ChatListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatListParams]. */ + class Builder internal constructor() { + + private var organizationId: String? = null + private var pageSize: Long? = null + private var pageToken: String? = null + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(chatListParams: ChatListParams) = apply { + organizationId = chatListParams.organizationId + pageSize = chatListParams.pageSize + pageToken = chatListParams.pageToken + projectId = chatListParams.projectId + additionalHeaders = chatListParams.additionalHeaders.toBuilder() + additionalQueryParams = chatListParams.additionalQueryParams.toBuilder() + } + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun pageSize(pageSize: Long?) = apply { this.pageSize = pageSize } + + /** + * Alias for [Builder.pageSize]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun pageSize(pageSize: Long) = pageSize(pageSize as Long?) + + /** Alias for calling [Builder.pageSize] with `pageSize.orElse(null)`. */ + fun pageSize(pageSize: Optional) = pageSize(pageSize.getOrNull()) + + fun pageToken(pageToken: String?) = apply { this.pageToken = pageToken } + + /** Alias for calling [Builder.pageToken] with `pageToken.orElse(null)`. */ + fun pageToken(pageToken: Optional) = pageToken(pageToken.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [ChatListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ChatListParams = + ChatListParams( + organizationId, + pageSize, + pageToken, + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + pageSize?.let { put("page_size", it.toString()) } + pageToken?.let { put("page_token", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatListParams && + organizationId == other.organizationId && + pageSize == other.pageSize && + pageToken == other.pageToken && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + organizationId, + pageSize, + pageToken, + projectId, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "ChatListParams{organizationId=$organizationId, pageSize=$pageSize, pageToken=$pageToken, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListResponse.kt new file mode 100644 index 0000000..bb6bc31 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListResponse.kt @@ -0,0 +1,1035 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Summary of a chat session, including its title and last run metadata. */ +class ChatListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val lastUpdatedAt: JsonField, + private val sessionId: JsonField, + private val sharedAccess: JsonField, + private val generatedTitle: JsonField, + private val indexIds: JsonField>, + private val jobMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("last_updated_at") + @ExcludeMissing + lastUpdatedAt: JsonField = JsonMissing.of(), + @JsonProperty("session_id") @ExcludeMissing sessionId: JsonField = JsonMissing.of(), + @JsonProperty("shared_access") + @ExcludeMissing + sharedAccess: JsonField = JsonMissing.of(), + @JsonProperty("generated_title") + @ExcludeMissing + generatedTitle: JsonField = JsonMissing.of(), + @JsonProperty("index_ids") + @ExcludeMissing + indexIds: JsonField> = JsonMissing.of(), + @JsonProperty("job_metadata") + @ExcludeMissing + jobMetadata: JsonField = JsonMissing.of(), + ) : this( + lastUpdatedAt, + sessionId, + sharedAccess, + generatedTitle, + indexIds, + jobMetadata, + mutableMapOf(), + ) + + /** + * ISO-format timestamp showing when the session was last updated. + * + * @throws LlamaCloudInvalidDataException 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 lastUpdatedAt(): String = lastUpdatedAt.getRequired("last_updated_at") + + /** + * Unique session identifier. + * + * @throws LlamaCloudInvalidDataException 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 sessionId(): String = sessionId.getRequired("session_id") + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask new + * questions). + * + * @throws LlamaCloudInvalidDataException 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 sharedAccess(): SharedAccess = sharedAccess.getRequired("shared_access") + + /** + * Auto-generated title derived from the first user message. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun generatedTitle(): Optional = generatedTitle.getOptional("generated_title") + + /** + * Indexes this session is bound to. Null on unbound sessions. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun indexIds(): Optional> = indexIds.getOptional("index_ids") + + /** + * Token usage and status from the most recent run. Null if the session has not been run yet. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun jobMetadata(): Optional = jobMetadata.getOptional("job_metadata") + + /** + * Returns the raw JSON value of [lastUpdatedAt]. + * + * Unlike [lastUpdatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_updated_at") + @ExcludeMissing + fun _lastUpdatedAt(): JsonField = lastUpdatedAt + + /** + * Returns the raw JSON value of [sessionId]. + * + * Unlike [sessionId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_id") @ExcludeMissing fun _sessionId(): JsonField = sessionId + + /** + * Returns the raw JSON value of [sharedAccess]. + * + * Unlike [sharedAccess], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("shared_access") + @ExcludeMissing + fun _sharedAccess(): JsonField = sharedAccess + + /** + * Returns the raw JSON value of [generatedTitle]. + * + * Unlike [generatedTitle], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("generated_title") + @ExcludeMissing + fun _generatedTitle(): JsonField = generatedTitle + + /** + * Returns the raw JSON value of [indexIds]. + * + * Unlike [indexIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("index_ids") @ExcludeMissing fun _indexIds(): JsonField> = indexIds + + /** + * Returns the raw JSON value of [jobMetadata]. + * + * Unlike [jobMetadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("job_metadata") + @ExcludeMissing + fun _jobMetadata(): JsonField = jobMetadata + + @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 [ChatListResponse]. + * + * The following fields are required: + * ```java + * .lastUpdatedAt() + * .sessionId() + * .sharedAccess() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatListResponse]. */ + class Builder internal constructor() { + + private var lastUpdatedAt: JsonField? = null + private var sessionId: JsonField? = null + private var sharedAccess: JsonField? = null + private var generatedTitle: JsonField = JsonMissing.of() + private var indexIds: JsonField>? = null + private var jobMetadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatListResponse: ChatListResponse) = apply { + lastUpdatedAt = chatListResponse.lastUpdatedAt + sessionId = chatListResponse.sessionId + sharedAccess = chatListResponse.sharedAccess + generatedTitle = chatListResponse.generatedTitle + indexIds = chatListResponse.indexIds.map { it.toMutableList() } + jobMetadata = chatListResponse.jobMetadata + additionalProperties = chatListResponse.additionalProperties.toMutableMap() + } + + /** ISO-format timestamp showing when the session was last updated. */ + fun lastUpdatedAt(lastUpdatedAt: String) = lastUpdatedAt(JsonField.of(lastUpdatedAt)) + + /** + * Sets [Builder.lastUpdatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.lastUpdatedAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun lastUpdatedAt(lastUpdatedAt: JsonField) = apply { + this.lastUpdatedAt = lastUpdatedAt + } + + /** Unique session identifier. */ + fun sessionId(sessionId: String) = sessionId(JsonField.of(sessionId)) + + /** + * Sets [Builder.sessionId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun sessionId(sessionId: JsonField) = apply { this.sessionId = sessionId } + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask + * new questions). + */ + fun sharedAccess(sharedAccess: SharedAccess) = sharedAccess(JsonField.of(sharedAccess)) + + /** + * Sets [Builder.sharedAccess] to an arbitrary JSON value. + * + * You should usually call [Builder.sharedAccess] with a well-typed [SharedAccess] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sharedAccess(sharedAccess: JsonField) = apply { + this.sharedAccess = sharedAccess + } + + /** Auto-generated title derived from the first user message. */ + fun generatedTitle(generatedTitle: String?) = + generatedTitle(JsonField.ofNullable(generatedTitle)) + + /** Alias for calling [Builder.generatedTitle] with `generatedTitle.orElse(null)`. */ + fun generatedTitle(generatedTitle: Optional) = + generatedTitle(generatedTitle.getOrNull()) + + /** + * Sets [Builder.generatedTitle] to an arbitrary JSON value. + * + * You should usually call [Builder.generatedTitle] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun generatedTitle(generatedTitle: JsonField) = apply { + this.generatedTitle = generatedTitle + } + + /** Indexes this session is bound to. Null on unbound sessions. */ + fun indexIds(indexIds: List?) = indexIds(JsonField.ofNullable(indexIds)) + + /** Alias for calling [Builder.indexIds] with `indexIds.orElse(null)`. */ + fun indexIds(indexIds: Optional>) = indexIds(indexIds.getOrNull()) + + /** + * Sets [Builder.indexIds] to an arbitrary JSON value. + * + * You should usually call [Builder.indexIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun indexIds(indexIds: JsonField>) = apply { + this.indexIds = indexIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [indexIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addIndexId(indexId: String) = apply { + indexIds = + (indexIds ?: JsonField.of(mutableListOf())).also { + checkKnown("indexIds", it).add(indexId) + } + } + + /** + * Token usage and status from the most recent run. Null if the session has not been run + * yet. + */ + fun jobMetadata(jobMetadata: JobMetadata?) = jobMetadata(JsonField.ofNullable(jobMetadata)) + + /** Alias for calling [Builder.jobMetadata] with `jobMetadata.orElse(null)`. */ + fun jobMetadata(jobMetadata: Optional) = jobMetadata(jobMetadata.getOrNull()) + + /** + * Sets [Builder.jobMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.jobMetadata] with a well-typed [JobMetadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun jobMetadata(jobMetadata: JsonField) = apply { + this.jobMetadata = jobMetadata + } + + 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 [ChatListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .lastUpdatedAt() + * .sessionId() + * .sharedAccess() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatListResponse = + ChatListResponse( + checkRequired("lastUpdatedAt", lastUpdatedAt), + checkRequired("sessionId", sessionId), + checkRequired("sharedAccess", sharedAccess), + generatedTitle, + (indexIds ?: JsonMissing.of()).map { it.toImmutable() }, + jobMetadata, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ChatListResponse = apply { + if (validated) { + return@apply + } + + lastUpdatedAt() + sessionId() + sharedAccess().validate() + generatedTitle() + indexIds() + jobMetadata().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (lastUpdatedAt.asKnown().isPresent) 1 else 0) + + (if (sessionId.asKnown().isPresent) 1 else 0) + + (sharedAccess.asKnown().getOrNull()?.validity() ?: 0) + + (if (generatedTitle.asKnown().isPresent) 1 else 0) + + (indexIds.asKnown().getOrNull()?.size ?: 0) + + (jobMetadata.asKnown().getOrNull()?.validity() ?: 0) + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask new + * questions). + */ + class SharedAccess @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 QUERY = of("query") + + @JvmField val READ_ONLY = of("read_only") + + @JvmStatic fun of(value: String) = SharedAccess(JsonField.of(value)) + } + + /** An enum containing [SharedAccess]'s known values. */ + enum class Known { + QUERY, + READ_ONLY, + } + + /** + * An enum containing [SharedAccess]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [SharedAccess] 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 { + QUERY, + READ_ONLY, + /** + * An enum member indicating that [SharedAccess] 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) { + QUERY -> Value.QUERY + READ_ONLY -> Value.READ_ONLY + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + QUERY -> Known.QUERY + READ_ONLY -> Known.READ_ONLY + else -> throw LlamaCloudInvalidDataException("Unknown SharedAccess: $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 LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SharedAccess = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 SharedAccess && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * Token usage and status from the most recent run. Null if the session has not been run yet. + */ + class JobMetadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val durationMs: JsonField, + private val error: JsonField, + private val exportConfigIds: JsonField>, + private val isError: JsonField, + private val totalInputTokens: JsonField, + private val totalOutputTokens: JsonField, + private val turns: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("duration_ms") + @ExcludeMissing + durationMs: JsonField = JsonMissing.of(), + @JsonProperty("error") @ExcludeMissing error: JsonField = JsonMissing.of(), + @JsonProperty("export_config_ids") + @ExcludeMissing + exportConfigIds: JsonField> = JsonMissing.of(), + @JsonProperty("is_error") + @ExcludeMissing + isError: JsonField = JsonMissing.of(), + @JsonProperty("total_input_tokens") + @ExcludeMissing + totalInputTokens: JsonField = JsonMissing.of(), + @JsonProperty("total_output_tokens") + @ExcludeMissing + totalOutputTokens: JsonField = JsonMissing.of(), + @JsonProperty("turns") @ExcludeMissing turns: JsonField = JsonMissing.of(), + ) : this( + durationMs, + error, + exportConfigIds, + isError, + totalInputTokens, + totalOutputTokens, + turns, + mutableMapOf(), + ) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun durationMs(): Optional = durationMs.getOptional("duration_ms") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun error(): Optional = error.getOptional("error") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun exportConfigIds(): Optional> = + exportConfigIds.getOptional("export_config_ids") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun isError(): Optional = isError.getOptional("is_error") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun totalInputTokens(): Optional = totalInputTokens.getOptional("total_input_tokens") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun totalOutputTokens(): Optional = + totalOutputTokens.getOptional("total_output_tokens") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun turns(): Optional = turns.getOptional("turns") + + /** + * Returns the raw JSON value of [durationMs]. + * + * Unlike [durationMs], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("duration_ms") + @ExcludeMissing + fun _durationMs(): JsonField = durationMs + + /** + * Returns the raw JSON value of [error]. + * + * Unlike [error], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error") @ExcludeMissing fun _error(): JsonField = error + + /** + * Returns the raw JSON value of [exportConfigIds]. + * + * Unlike [exportConfigIds], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("export_config_ids") + @ExcludeMissing + fun _exportConfigIds(): JsonField> = exportConfigIds + + /** + * Returns the raw JSON value of [isError]. + * + * Unlike [isError], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("is_error") @ExcludeMissing fun _isError(): JsonField = isError + + /** + * Returns the raw JSON value of [totalInputTokens]. + * + * Unlike [totalInputTokens], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("total_input_tokens") + @ExcludeMissing + fun _totalInputTokens(): JsonField = totalInputTokens + + /** + * Returns the raw JSON value of [totalOutputTokens]. + * + * Unlike [totalOutputTokens], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("total_output_tokens") + @ExcludeMissing + fun _totalOutputTokens(): JsonField = totalOutputTokens + + /** + * Returns the raw JSON value of [turns]. + * + * Unlike [turns], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("turns") @ExcludeMissing fun _turns(): JsonField = turns + + @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 [JobMetadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JobMetadata]. */ + class Builder internal constructor() { + + private var durationMs: JsonField = JsonMissing.of() + private var error: JsonField = JsonMissing.of() + private var exportConfigIds: JsonField>? = null + private var isError: JsonField = JsonMissing.of() + private var totalInputTokens: JsonField = JsonMissing.of() + private var totalOutputTokens: JsonField = JsonMissing.of() + private var turns: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(jobMetadata: JobMetadata) = apply { + durationMs = jobMetadata.durationMs + error = jobMetadata.error + exportConfigIds = jobMetadata.exportConfigIds.map { it.toMutableList() } + isError = jobMetadata.isError + totalInputTokens = jobMetadata.totalInputTokens + totalOutputTokens = jobMetadata.totalOutputTokens + turns = jobMetadata.turns + additionalProperties = jobMetadata.additionalProperties.toMutableMap() + } + + fun durationMs(durationMs: Double) = durationMs(JsonField.of(durationMs)) + + /** + * Sets [Builder.durationMs] to an arbitrary JSON value. + * + * You should usually call [Builder.durationMs] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun durationMs(durationMs: JsonField) = apply { this.durationMs = durationMs } + + fun error(error: String?) = error(JsonField.ofNullable(error)) + + /** Alias for calling [Builder.error] with `error.orElse(null)`. */ + fun error(error: Optional) = error(error.getOrNull()) + + /** + * Sets [Builder.error] to an arbitrary JSON value. + * + * You should usually call [Builder.error] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun error(error: JsonField) = apply { this.error = error } + + fun exportConfigIds(exportConfigIds: List?) = + exportConfigIds(JsonField.ofNullable(exportConfigIds)) + + /** Alias for calling [Builder.exportConfigIds] with `exportConfigIds.orElse(null)`. */ + fun exportConfigIds(exportConfigIds: Optional>) = + exportConfigIds(exportConfigIds.getOrNull()) + + /** + * Sets [Builder.exportConfigIds] to an arbitrary JSON value. + * + * You should usually call [Builder.exportConfigIds] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun exportConfigIds(exportConfigIds: JsonField>) = apply { + this.exportConfigIds = exportConfigIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [exportConfigIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExportConfigId(exportConfigId: String) = apply { + exportConfigIds = + (exportConfigIds ?: JsonField.of(mutableListOf())).also { + checkKnown("exportConfigIds", it).add(exportConfigId) + } + } + + fun isError(isError: Boolean) = isError(JsonField.of(isError)) + + /** + * Sets [Builder.isError] to an arbitrary JSON value. + * + * You should usually call [Builder.isError] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isError(isError: JsonField) = apply { this.isError = isError } + + fun totalInputTokens(totalInputTokens: Long?) = + totalInputTokens(JsonField.ofNullable(totalInputTokens)) + + /** + * Alias for [Builder.totalInputTokens]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalInputTokens(totalInputTokens: Long) = + totalInputTokens(totalInputTokens as Long?) + + /** + * Alias for calling [Builder.totalInputTokens] with `totalInputTokens.orElse(null)`. + */ + fun totalInputTokens(totalInputTokens: Optional) = + totalInputTokens(totalInputTokens.getOrNull()) + + /** + * Sets [Builder.totalInputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.totalInputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun totalInputTokens(totalInputTokens: JsonField) = apply { + this.totalInputTokens = totalInputTokens + } + + fun totalOutputTokens(totalOutputTokens: Long?) = + totalOutputTokens(JsonField.ofNullable(totalOutputTokens)) + + /** + * Alias for [Builder.totalOutputTokens]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalOutputTokens(totalOutputTokens: Long) = + totalOutputTokens(totalOutputTokens as Long?) + + /** + * Alias for calling [Builder.totalOutputTokens] with `totalOutputTokens.orElse(null)`. + */ + fun totalOutputTokens(totalOutputTokens: Optional) = + totalOutputTokens(totalOutputTokens.getOrNull()) + + /** + * Sets [Builder.totalOutputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.totalOutputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun totalOutputTokens(totalOutputTokens: JsonField) = apply { + this.totalOutputTokens = totalOutputTokens + } + + fun turns(turns: Long) = turns(JsonField.of(turns)) + + /** + * Sets [Builder.turns] to an arbitrary JSON value. + * + * You should usually call [Builder.turns] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun turns(turns: JsonField) = apply { this.turns = turns } + + 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 [JobMetadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): JobMetadata = + JobMetadata( + durationMs, + error, + (exportConfigIds ?: JsonMissing.of()).map { it.toImmutable() }, + isError, + totalInputTokens, + totalOutputTokens, + turns, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): JobMetadata = apply { + if (validated) { + return@apply + } + + durationMs() + error() + exportConfigIds() + isError() + totalInputTokens() + totalOutputTokens() + turns() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (durationMs.asKnown().isPresent) 1 else 0) + + (if (error.asKnown().isPresent) 1 else 0) + + (exportConfigIds.asKnown().getOrNull()?.size ?: 0) + + (if (isError.asKnown().isPresent) 1 else 0) + + (if (totalInputTokens.asKnown().isPresent) 1 else 0) + + (if (totalOutputTokens.asKnown().isPresent) 1 else 0) + + (if (turns.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JobMetadata && + durationMs == other.durationMs && + error == other.error && + exportConfigIds == other.exportConfigIds && + isError == other.isError && + totalInputTokens == other.totalInputTokens && + totalOutputTokens == other.totalOutputTokens && + turns == other.turns && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + durationMs, + error, + exportConfigIds, + isError, + totalInputTokens, + totalOutputTokens, + turns, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JobMetadata{durationMs=$durationMs, error=$error, exportConfigIds=$exportConfigIds, isError=$isError, totalInputTokens=$totalInputTokens, totalOutputTokens=$totalOutputTokens, turns=$turns, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatListResponse && + lastUpdatedAt == other.lastUpdatedAt && + sessionId == other.sessionId && + sharedAccess == other.sharedAccess && + generatedTitle == other.generatedTitle && + indexIds == other.indexIds && + jobMetadata == other.jobMetadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + lastUpdatedAt, + sessionId, + sharedAccess, + generatedTitle, + indexIds, + jobMetadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatListResponse{lastUpdatedAt=$lastUpdatedAt, sessionId=$sessionId, sharedAccess=$sharedAccess, generatedTitle=$generatedTitle, indexIds=$indexIds, jobMetadata=$jobMetadata, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatRetrieveParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatRetrieveParams.kt new file mode 100644 index 0000000..1a57458 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatRetrieveParams.kt @@ -0,0 +1,226 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieve a full session by ID, including its event history. */ +class ChatRetrieveParams +private constructor( + private val sessionId: String?, + private val organizationId: String?, + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sessionId(): Optional = Optional.ofNullable(sessionId) + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): ChatRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ChatRetrieveParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatRetrieveParams]. */ + class Builder internal constructor() { + + private var sessionId: String? = null + private var organizationId: String? = null + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(chatRetrieveParams: ChatRetrieveParams) = apply { + sessionId = chatRetrieveParams.sessionId + organizationId = chatRetrieveParams.organizationId + projectId = chatRetrieveParams.projectId + additionalHeaders = chatRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = chatRetrieveParams.additionalQueryParams.toBuilder() + } + + fun sessionId(sessionId: String?) = apply { this.sessionId = sessionId } + + /** Alias for calling [Builder.sessionId] with `sessionId.orElse(null)`. */ + fun sessionId(sessionId: Optional) = sessionId(sessionId.getOrNull()) + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [ChatRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ChatRetrieveParams = + ChatRetrieveParams( + sessionId, + organizationId, + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sessionId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatRetrieveParams && + sessionId == other.sessionId && + organizationId == other.organizationId && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(sessionId, organizationId, projectId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ChatRetrieveParams{sessionId=$sessionId, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatRetrieveResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatRetrieveResponse.kt new file mode 100644 index 0000000..6890eae --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatRetrieveResponse.kt @@ -0,0 +1,5269 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.BaseDeserializer +import ai.llamaindex.llamacloud.core.BaseSerializer +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.getOrThrow +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Full chat session including its complete event history. */ +class ChatRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val events: JsonField>, + private val lastUpdatedAt: JsonField, + private val sessionId: JsonField, + private val sharedAccess: JsonField, + private val generatedTitle: JsonField, + private val indexIds: JsonField>, + private val jobMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("events") @ExcludeMissing events: JsonField> = JsonMissing.of(), + @JsonProperty("last_updated_at") + @ExcludeMissing + lastUpdatedAt: JsonField = JsonMissing.of(), + @JsonProperty("session_id") @ExcludeMissing sessionId: JsonField = JsonMissing.of(), + @JsonProperty("shared_access") + @ExcludeMissing + sharedAccess: JsonField = JsonMissing.of(), + @JsonProperty("generated_title") + @ExcludeMissing + generatedTitle: JsonField = JsonMissing.of(), + @JsonProperty("index_ids") + @ExcludeMissing + indexIds: JsonField> = JsonMissing.of(), + @JsonProperty("job_metadata") + @ExcludeMissing + jobMetadata: JsonField = JsonMissing.of(), + ) : this( + events, + lastUpdatedAt, + sessionId, + sharedAccess, + generatedTitle, + indexIds, + jobMetadata, + mutableMapOf(), + ) + + /** + * Ordered list of events that make up the conversation history. + * + * @throws LlamaCloudInvalidDataException 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 events(): List = events.getRequired("events") + + /** + * ISO-format timestamp showing when the session was last updated. + * + * @throws LlamaCloudInvalidDataException 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 lastUpdatedAt(): String = lastUpdatedAt.getRequired("last_updated_at") + + /** + * Unique session identifier. + * + * @throws LlamaCloudInvalidDataException 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 sessionId(): String = sessionId.getRequired("session_id") + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask new + * questions). + * + * @throws LlamaCloudInvalidDataException 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 sharedAccess(): SharedAccess = sharedAccess.getRequired("shared_access") + + /** + * Auto-generated title derived from the first user message. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun generatedTitle(): Optional = generatedTitle.getOptional("generated_title") + + /** + * Indexes this session is bound to. Null on unbound sessions. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun indexIds(): Optional> = indexIds.getOptional("index_ids") + + /** + * Token usage and status from the most recent run. Null if the session has not been run yet. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun jobMetadata(): Optional = jobMetadata.getOptional("job_metadata") + + /** + * Returns the raw JSON value of [events]. + * + * Unlike [events], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("events") @ExcludeMissing fun _events(): JsonField> = events + + /** + * Returns the raw JSON value of [lastUpdatedAt]. + * + * Unlike [lastUpdatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_updated_at") + @ExcludeMissing + fun _lastUpdatedAt(): JsonField = lastUpdatedAt + + /** + * Returns the raw JSON value of [sessionId]. + * + * Unlike [sessionId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_id") @ExcludeMissing fun _sessionId(): JsonField = sessionId + + /** + * Returns the raw JSON value of [sharedAccess]. + * + * Unlike [sharedAccess], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("shared_access") + @ExcludeMissing + fun _sharedAccess(): JsonField = sharedAccess + + /** + * Returns the raw JSON value of [generatedTitle]. + * + * Unlike [generatedTitle], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("generated_title") + @ExcludeMissing + fun _generatedTitle(): JsonField = generatedTitle + + /** + * Returns the raw JSON value of [indexIds]. + * + * Unlike [indexIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("index_ids") @ExcludeMissing fun _indexIds(): JsonField> = indexIds + + /** + * Returns the raw JSON value of [jobMetadata]. + * + * Unlike [jobMetadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("job_metadata") + @ExcludeMissing + fun _jobMetadata(): JsonField = jobMetadata + + @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 [ChatRetrieveResponse]. + * + * The following fields are required: + * ```java + * .events() + * .lastUpdatedAt() + * .sessionId() + * .sharedAccess() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatRetrieveResponse]. */ + class Builder internal constructor() { + + private var events: JsonField>? = null + private var lastUpdatedAt: JsonField? = null + private var sessionId: JsonField? = null + private var sharedAccess: JsonField? = null + private var generatedTitle: JsonField = JsonMissing.of() + private var indexIds: JsonField>? = null + private var jobMetadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatRetrieveResponse: ChatRetrieveResponse) = apply { + events = chatRetrieveResponse.events.map { it.toMutableList() } + lastUpdatedAt = chatRetrieveResponse.lastUpdatedAt + sessionId = chatRetrieveResponse.sessionId + sharedAccess = chatRetrieveResponse.sharedAccess + generatedTitle = chatRetrieveResponse.generatedTitle + indexIds = chatRetrieveResponse.indexIds.map { it.toMutableList() } + jobMetadata = chatRetrieveResponse.jobMetadata + additionalProperties = chatRetrieveResponse.additionalProperties.toMutableMap() + } + + /** Ordered list of events that make up the conversation history. */ + fun events(events: List) = events(JsonField.of(events)) + + /** + * Sets [Builder.events] to an arbitrary JSON value. + * + * You should usually call [Builder.events] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun events(events: JsonField>) = apply { + this.events = events.map { it.toMutableList() } + } + + /** + * Adds a single [Event] to [events]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEvent(event: Event) = apply { + events = + (events ?: JsonField.of(mutableListOf())).also { + checkKnown("events", it).add(event) + } + } + + /** Alias for calling [addEvent] with `Event.ofStop(stop)`. */ + fun addEvent(stop: Event.Stop) = addEvent(Event.ofStop(stop)) + + /** Alias for calling [addEvent] with `Event.ofTextDelta(textDelta)`. */ + fun addEvent(textDelta: Event.TextDelta) = addEvent(Event.ofTextDelta(textDelta)) + + /** + * Alias for calling [addEvent] with the following: + * ```java + * Event.TextDelta.builder() + * .type(ChatRetrieveResponse.Event.TextDelta.Type.TEXT_DELTA) + * .content(content) + * .build() + * ``` + */ + fun addTextDeltaEvent(content: String) = + addEvent( + Event.TextDelta.builder() + .type(ChatRetrieveResponse.Event.TextDelta.Type.TEXT_DELTA) + .content(content) + .build() + ) + + /** Alias for calling [addEvent] with `Event.ofText(text)`. */ + fun addEvent(text: Event.Text) = addEvent(Event.ofText(text)) + + /** + * Alias for calling [addEvent] with the following: + * ```java + * Event.Text.builder() + * .type(ChatRetrieveResponse.Event.Text.Type.TEXT) + * .content(content) + * .build() + * ``` + */ + fun addTextEvent(content: String) = + addEvent( + Event.Text.builder() + .type(ChatRetrieveResponse.Event.Text.Type.TEXT) + .content(content) + .build() + ) + + /** Alias for calling [addEvent] with `Event.ofThinkingDelta(thinkingDelta)`. */ + fun addEvent(thinkingDelta: Event.ThinkingDelta) = + addEvent(Event.ofThinkingDelta(thinkingDelta)) + + /** + * Alias for calling [addEvent] with the following: + * ```java + * Event.ThinkingDelta.builder() + * .type(ChatRetrieveResponse.Event.ThinkingDelta.Type.THINKING_DELTA) + * .content(content) + * .build() + * ``` + */ + fun addThinkingDeltaEvent(content: String) = + addEvent( + Event.ThinkingDelta.builder() + .type(ChatRetrieveResponse.Event.ThinkingDelta.Type.THINKING_DELTA) + .content(content) + .build() + ) + + /** Alias for calling [addEvent] with `Event.ofThinking(thinking)`. */ + fun addEvent(thinking: Event.Thinking) = addEvent(Event.ofThinking(thinking)) + + /** + * Alias for calling [addEvent] with the following: + * ```java + * Event.Thinking.builder() + * .type(ChatRetrieveResponse.Event.Thinking.Type.THINKING) + * .content(content) + * .build() + * ``` + */ + fun addThinkingEvent(content: String) = + addEvent( + Event.Thinking.builder() + .type(ChatRetrieveResponse.Event.Thinking.Type.THINKING) + .content(content) + .build() + ) + + /** Alias for calling [addEvent] with `Event.ofToolCall(toolCall)`. */ + fun addEvent(toolCall: Event.ToolCall) = addEvent(Event.ofToolCall(toolCall)) + + /** Alias for calling [addEvent] with `Event.ofToolResult(toolResult)`. */ + fun addEvent(toolResult: Event.ToolResult) = addEvent(Event.ofToolResult(toolResult)) + + /** Alias for calling [addEvent] with `Event.ofUserInput(userInput)`. */ + fun addEvent(userInput: Event.UserInput) = addEvent(Event.ofUserInput(userInput)) + + /** + * Alias for calling [addEvent] with the following: + * ```java + * Event.UserInput.builder() + * .type(ChatRetrieveResponse.Event.UserInput.Type.USER_INPUT) + * .content(content) + * .build() + * ``` + */ + fun addUserInputEvent(content: String) = + addEvent( + Event.UserInput.builder() + .type(ChatRetrieveResponse.Event.UserInput.Type.USER_INPUT) + .content(content) + .build() + ) + + /** ISO-format timestamp showing when the session was last updated. */ + fun lastUpdatedAt(lastUpdatedAt: String) = lastUpdatedAt(JsonField.of(lastUpdatedAt)) + + /** + * Sets [Builder.lastUpdatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.lastUpdatedAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun lastUpdatedAt(lastUpdatedAt: JsonField) = apply { + this.lastUpdatedAt = lastUpdatedAt + } + + /** Unique session identifier. */ + fun sessionId(sessionId: String) = sessionId(JsonField.of(sessionId)) + + /** + * Sets [Builder.sessionId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun sessionId(sessionId: JsonField) = apply { this.sessionId = sessionId } + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask + * new questions). + */ + fun sharedAccess(sharedAccess: SharedAccess) = sharedAccess(JsonField.of(sharedAccess)) + + /** + * Sets [Builder.sharedAccess] to an arbitrary JSON value. + * + * You should usually call [Builder.sharedAccess] with a well-typed [SharedAccess] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sharedAccess(sharedAccess: JsonField) = apply { + this.sharedAccess = sharedAccess + } + + /** Auto-generated title derived from the first user message. */ + fun generatedTitle(generatedTitle: String?) = + generatedTitle(JsonField.ofNullable(generatedTitle)) + + /** Alias for calling [Builder.generatedTitle] with `generatedTitle.orElse(null)`. */ + fun generatedTitle(generatedTitle: Optional) = + generatedTitle(generatedTitle.getOrNull()) + + /** + * Sets [Builder.generatedTitle] to an arbitrary JSON value. + * + * You should usually call [Builder.generatedTitle] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun generatedTitle(generatedTitle: JsonField) = apply { + this.generatedTitle = generatedTitle + } + + /** Indexes this session is bound to. Null on unbound sessions. */ + fun indexIds(indexIds: List?) = indexIds(JsonField.ofNullable(indexIds)) + + /** Alias for calling [Builder.indexIds] with `indexIds.orElse(null)`. */ + fun indexIds(indexIds: Optional>) = indexIds(indexIds.getOrNull()) + + /** + * Sets [Builder.indexIds] to an arbitrary JSON value. + * + * You should usually call [Builder.indexIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun indexIds(indexIds: JsonField>) = apply { + this.indexIds = indexIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [indexIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addIndexId(indexId: String) = apply { + indexIds = + (indexIds ?: JsonField.of(mutableListOf())).also { + checkKnown("indexIds", it).add(indexId) + } + } + + /** + * Token usage and status from the most recent run. Null if the session has not been run + * yet. + */ + fun jobMetadata(jobMetadata: JobMetadata?) = jobMetadata(JsonField.ofNullable(jobMetadata)) + + /** Alias for calling [Builder.jobMetadata] with `jobMetadata.orElse(null)`. */ + fun jobMetadata(jobMetadata: Optional) = jobMetadata(jobMetadata.getOrNull()) + + /** + * Sets [Builder.jobMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.jobMetadata] with a well-typed [JobMetadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun jobMetadata(jobMetadata: JsonField) = apply { + this.jobMetadata = jobMetadata + } + + 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 [ChatRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .events() + * .lastUpdatedAt() + * .sessionId() + * .sharedAccess() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatRetrieveResponse = + ChatRetrieveResponse( + checkRequired("events", events).map { it.toImmutable() }, + checkRequired("lastUpdatedAt", lastUpdatedAt), + checkRequired("sessionId", sessionId), + checkRequired("sharedAccess", sharedAccess), + generatedTitle, + (indexIds ?: JsonMissing.of()).map { it.toImmutable() }, + jobMetadata, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ChatRetrieveResponse = apply { + if (validated) { + return@apply + } + + events().forEach { it.validate() } + lastUpdatedAt() + sessionId() + sharedAccess().validate() + generatedTitle() + indexIds() + jobMetadata().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (events.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (lastUpdatedAt.asKnown().isPresent) 1 else 0) + + (if (sessionId.asKnown().isPresent) 1 else 0) + + (sharedAccess.asKnown().getOrNull()?.validity() ?: 0) + + (if (generatedTitle.asKnown().isPresent) 1 else 0) + + (indexIds.asKnown().getOrNull()?.size ?: 0) + + (jobMetadata.asKnown().getOrNull()?.validity() ?: 0) + + @JsonDeserialize(using = Event.Deserializer::class) + @JsonSerialize(using = Event.Serializer::class) + class Event + private constructor( + private val stop: Stop? = null, + private val textDelta: TextDelta? = null, + private val text: Text? = null, + private val thinkingDelta: ThinkingDelta? = null, + private val thinking: Thinking? = null, + private val toolCall: ToolCall? = null, + private val toolResult: ToolResult? = null, + private val userInput: UserInput? = null, + private val _json: JsonValue? = null, + ) { + + fun stop(): Optional = Optional.ofNullable(stop) + + fun textDelta(): Optional = Optional.ofNullable(textDelta) + + fun text(): Optional = Optional.ofNullable(text) + + fun thinkingDelta(): Optional = Optional.ofNullable(thinkingDelta) + + fun thinking(): Optional = Optional.ofNullable(thinking) + + fun toolCall(): Optional = Optional.ofNullable(toolCall) + + fun toolResult(): Optional = Optional.ofNullable(toolResult) + + fun userInput(): Optional = Optional.ofNullable(userInput) + + fun isStop(): Boolean = stop != null + + fun isTextDelta(): Boolean = textDelta != null + + fun isText(): Boolean = text != null + + fun isThinkingDelta(): Boolean = thinkingDelta != null + + fun isThinking(): Boolean = thinking != null + + fun isToolCall(): Boolean = toolCall != null + + fun isToolResult(): Boolean = toolResult != null + + fun isUserInput(): Boolean = userInput != null + + fun asStop(): Stop = stop.getOrThrow("stop") + + fun asTextDelta(): TextDelta = textDelta.getOrThrow("textDelta") + + fun asText(): Text = text.getOrThrow("text") + + fun asThinkingDelta(): ThinkingDelta = thinkingDelta.getOrThrow("thinkingDelta") + + fun asThinking(): Thinking = thinking.getOrThrow("thinking") + + fun asToolCall(): ToolCall = toolCall.getOrThrow("toolCall") + + fun asToolResult(): ToolResult = toolResult.getOrThrow("toolResult") + + fun asUserInput(): UserInput = userInput.getOrThrow("userInput") + + 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 ai.llamaindex.llamacloud.core.JsonValue; + * import java.util.Optional; + * + * Optional result = event.accept(new Event.Visitor>() { + * @Override + * public Optional visitStop(Stop stop) { + * return Optional.of(stop.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws LlamaCloudInvalidDataException if [Visitor.unknown] is not overridden in + * [visitor] and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + stop != null -> visitor.visitStop(stop) + textDelta != null -> visitor.visitTextDelta(textDelta) + text != null -> visitor.visitText(text) + thinkingDelta != null -> visitor.visitThinkingDelta(thinkingDelta) + thinking != null -> visitor.visitThinking(thinking) + toolCall != null -> visitor.visitToolCall(toolCall) + toolResult != null -> visitor.visitToolResult(toolResult) + userInput != null -> visitor.visitUserInput(userInput) + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Event = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitStop(stop: Stop) { + stop.validate() + } + + override fun visitTextDelta(textDelta: TextDelta) { + textDelta.validate() + } + + override fun visitText(text: Text) { + text.validate() + } + + override fun visitThinkingDelta(thinkingDelta: ThinkingDelta) { + thinkingDelta.validate() + } + + override fun visitThinking(thinking: Thinking) { + thinking.validate() + } + + override fun visitToolCall(toolCall: ToolCall) { + toolCall.validate() + } + + override fun visitToolResult(toolResult: ToolResult) { + toolResult.validate() + } + + override fun visitUserInput(userInput: UserInput) { + userInput.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 visitStop(stop: Stop) = stop.validity() + + override fun visitTextDelta(textDelta: TextDelta) = textDelta.validity() + + override fun visitText(text: Text) = text.validity() + + override fun visitThinkingDelta(thinkingDelta: ThinkingDelta) = + thinkingDelta.validity() + + override fun visitThinking(thinking: Thinking) = thinking.validity() + + override fun visitToolCall(toolCall: ToolCall) = toolCall.validity() + + override fun visitToolResult(toolResult: ToolResult) = toolResult.validity() + + override fun visitUserInput(userInput: UserInput) = userInput.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Event && + stop == other.stop && + textDelta == other.textDelta && + text == other.text && + thinkingDelta == other.thinkingDelta && + thinking == other.thinking && + toolCall == other.toolCall && + toolResult == other.toolResult && + userInput == other.userInput + } + + override fun hashCode(): Int = + Objects.hash( + stop, + textDelta, + text, + thinkingDelta, + thinking, + toolCall, + toolResult, + userInput, + ) + + override fun toString(): String = + when { + stop != null -> "Event{stop=$stop}" + textDelta != null -> "Event{textDelta=$textDelta}" + text != null -> "Event{text=$text}" + thinkingDelta != null -> "Event{thinkingDelta=$thinkingDelta}" + thinking != null -> "Event{thinking=$thinking}" + toolCall != null -> "Event{toolCall=$toolCall}" + toolResult != null -> "Event{toolResult=$toolResult}" + userInput != null -> "Event{userInput=$userInput}" + _json != null -> "Event{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Event") + } + + companion object { + + @JvmStatic fun ofStop(stop: Stop) = Event(stop = stop) + + @JvmStatic fun ofTextDelta(textDelta: TextDelta) = Event(textDelta = textDelta) + + @JvmStatic fun ofText(text: Text) = Event(text = text) + + @JvmStatic + fun ofThinkingDelta(thinkingDelta: ThinkingDelta) = Event(thinkingDelta = thinkingDelta) + + @JvmStatic fun ofThinking(thinking: Thinking) = Event(thinking = thinking) + + @JvmStatic fun ofToolCall(toolCall: ToolCall) = Event(toolCall = toolCall) + + @JvmStatic fun ofToolResult(toolResult: ToolResult) = Event(toolResult = toolResult) + + @JvmStatic fun ofUserInput(userInput: UserInput) = Event(userInput = userInput) + } + + /** An interface that defines how to map each variant of [Event] to a value of type [T]. */ + interface Visitor { + + fun visitStop(stop: Stop): T + + fun visitTextDelta(textDelta: TextDelta): T + + fun visitText(text: Text): T + + fun visitThinkingDelta(thinkingDelta: ThinkingDelta): T + + fun visitThinking(thinking: Thinking): T + + fun visitToolCall(toolCall: ToolCall): T + + fun visitToolResult(toolResult: ToolResult): T + + fun visitUserInput(userInput: UserInput): T + + /** + * Maps an unknown variant of [Event] to a value of type [T]. + * + * An instance of [Event] 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 LlamaCloudInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw LlamaCloudInvalidDataException("Unknown Event: $json") + } + } + + internal class Deserializer : BaseDeserializer(Event::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Event { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "stop" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Event(stop = it, _json = json) + } ?: Event(_json = json) + } + "text_delta" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Event(textDelta = it, _json = json) + } ?: Event(_json = json) + } + "text" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Event(text = it, _json = json) + } ?: Event(_json = json) + } + "thinking_delta" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Event(thinkingDelta = it, _json = json) + } ?: Event(_json = json) + } + "thinking" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Event(thinking = it, _json = json) + } ?: Event(_json = json) + } + "tool_call" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Event(toolCall = it, _json = json) + } ?: Event(_json = json) + } + "tool_result" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Event(toolResult = it, _json = json) + } ?: Event(_json = json) + } + "user_input" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Event(userInput = it, _json = json) + } ?: Event(_json = json) + } + } + + return Event(_json = json) + } + } + + internal class Serializer : BaseSerializer(Event::class) { + + override fun serialize( + value: Event, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.stop != null -> generator.writeObject(value.stop) + value.textDelta != null -> generator.writeObject(value.textDelta) + value.text != null -> generator.writeObject(value.text) + value.thinkingDelta != null -> generator.writeObject(value.thinkingDelta) + value.thinking != null -> generator.writeObject(value.thinking) + value.toolCall != null -> generator.writeObject(value.toolCall) + value.toolResult != null -> generator.writeObject(value.toolResult) + value.userInput != null -> generator.writeObject(value.userInput) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Event") + } + } + } + + class Stop + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val error: JsonField, + private val isError: JsonField, + private val usage: JsonField, + private val skippedIndexIds: JsonField>, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("error") @ExcludeMissing error: JsonField = JsonMissing.of(), + @JsonProperty("is_error") + @ExcludeMissing + isError: JsonField = JsonMissing.of(), + @JsonProperty("usage") @ExcludeMissing usage: JsonField = JsonMissing.of(), + @JsonProperty("skipped_index_ids") + @ExcludeMissing + skippedIndexIds: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(error, isError, usage, skippedIndexIds, type, mutableMapOf()) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun error(): Optional = error.getOptional("error") + + /** + * @throws LlamaCloudInvalidDataException 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 isError(): Boolean = isError.getRequired("is_error") + + /** + * @throws LlamaCloudInvalidDataException 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 usage(): Usage = usage.getRequired("usage") + + /** + * Requested indexes this turn could not query. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun skippedIndexIds(): Optional> = + skippedIndexIds.getOptional("skipped_index_ids") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [error]. + * + * Unlike [error], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error") @ExcludeMissing fun _error(): JsonField = error + + /** + * Returns the raw JSON value of [isError]. + * + * Unlike [isError], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("is_error") @ExcludeMissing fun _isError(): JsonField = isError + + /** + * Returns the raw JSON value of [usage]. + * + * Unlike [usage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("usage") @ExcludeMissing fun _usage(): JsonField = usage + + /** + * Returns the raw JSON value of [skippedIndexIds]. + * + * Unlike [skippedIndexIds], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("skipped_index_ids") + @ExcludeMissing + fun _skippedIndexIds(): JsonField> = skippedIndexIds + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Stop]. + * + * The following fields are required: + * ```java + * .error() + * .isError() + * .usage() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Stop]. */ + class Builder internal constructor() { + + private var error: JsonField? = null + private var isError: JsonField? = null + private var usage: JsonField? = null + private var skippedIndexIds: JsonField>? = null + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(stop: Stop) = apply { + error = stop.error + isError = stop.isError + usage = stop.usage + skippedIndexIds = stop.skippedIndexIds.map { it.toMutableList() } + type = stop.type + additionalProperties = stop.additionalProperties.toMutableMap() + } + + fun error(error: String?) = error(JsonField.ofNullable(error)) + + /** Alias for calling [Builder.error] with `error.orElse(null)`. */ + fun error(error: Optional) = error(error.getOrNull()) + + /** + * Sets [Builder.error] to an arbitrary JSON value. + * + * You should usually call [Builder.error] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun error(error: JsonField) = apply { this.error = error } + + fun isError(isError: Boolean) = isError(JsonField.of(isError)) + + /** + * Sets [Builder.isError] to an arbitrary JSON value. + * + * You should usually call [Builder.isError] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun isError(isError: JsonField) = apply { this.isError = isError } + + fun usage(usage: Usage) = usage(JsonField.of(usage)) + + /** + * Sets [Builder.usage] to an arbitrary JSON value. + * + * You should usually call [Builder.usage] with a well-typed [Usage] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun usage(usage: JsonField) = apply { this.usage = usage } + + /** Requested indexes this turn could not query. */ + fun skippedIndexIds(skippedIndexIds: List) = + skippedIndexIds(JsonField.of(skippedIndexIds)) + + /** + * Sets [Builder.skippedIndexIds] to an arbitrary JSON value. + * + * You should usually call [Builder.skippedIndexIds] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun skippedIndexIds(skippedIndexIds: JsonField>) = apply { + this.skippedIndexIds = skippedIndexIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [skippedIndexIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSkippedIndexId(skippedIndexId: String) = apply { + skippedIndexIds = + (skippedIndexIds ?: JsonField.of(mutableListOf())).also { + checkKnown("skippedIndexIds", it).add(skippedIndexId) + } + } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Stop]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .error() + * .isError() + * .usage() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Stop = + Stop( + checkRequired("error", error), + checkRequired("isError", isError), + checkRequired("usage", usage), + (skippedIndexIds ?: JsonMissing.of()).map { it.toImmutable() }, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Stop = apply { + if (validated) { + return@apply + } + + error() + isError() + usage().validate() + skippedIndexIds() + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (error.asKnown().isPresent) 1 else 0) + + (if (isError.asKnown().isPresent) 1 else 0) + + (usage.asKnown().getOrNull()?.validity() ?: 0) + + (skippedIndexIds.asKnown().getOrNull()?.size ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Usage + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val durationMs: JsonField, + private val totalInputTokens: JsonField, + private val totalOutputTokens: JsonField, + private val turns: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("duration_ms") + @ExcludeMissing + durationMs: JsonField = JsonMissing.of(), + @JsonProperty("total_input_tokens") + @ExcludeMissing + totalInputTokens: JsonField = JsonMissing.of(), + @JsonProperty("total_output_tokens") + @ExcludeMissing + totalOutputTokens: JsonField = JsonMissing.of(), + @JsonProperty("turns") @ExcludeMissing turns: JsonField = JsonMissing.of(), + ) : this(durationMs, totalInputTokens, totalOutputTokens, turns, mutableMapOf()) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun durationMs(): Optional = durationMs.getOptional("duration_ms") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun totalInputTokens(): Optional = + totalInputTokens.getOptional("total_input_tokens") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun totalOutputTokens(): Optional = + totalOutputTokens.getOptional("total_output_tokens") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun turns(): Optional = turns.getOptional("turns") + + /** + * Returns the raw JSON value of [durationMs]. + * + * Unlike [durationMs], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("duration_ms") + @ExcludeMissing + fun _durationMs(): JsonField = durationMs + + /** + * Returns the raw JSON value of [totalInputTokens]. + * + * Unlike [totalInputTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("total_input_tokens") + @ExcludeMissing + fun _totalInputTokens(): JsonField = totalInputTokens + + /** + * Returns the raw JSON value of [totalOutputTokens]. + * + * Unlike [totalOutputTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("total_output_tokens") + @ExcludeMissing + fun _totalOutputTokens(): JsonField = totalOutputTokens + + /** + * Returns the raw JSON value of [turns]. + * + * Unlike [turns], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("turns") @ExcludeMissing fun _turns(): JsonField = turns + + @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 [Usage]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Usage]. */ + class Builder internal constructor() { + + private var durationMs: JsonField = JsonMissing.of() + private var totalInputTokens: JsonField = JsonMissing.of() + private var totalOutputTokens: JsonField = JsonMissing.of() + private var turns: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(usage: Usage) = apply { + durationMs = usage.durationMs + totalInputTokens = usage.totalInputTokens + totalOutputTokens = usage.totalOutputTokens + turns = usage.turns + additionalProperties = usage.additionalProperties.toMutableMap() + } + + fun durationMs(durationMs: Double) = durationMs(JsonField.of(durationMs)) + + /** + * Sets [Builder.durationMs] to an arbitrary JSON value. + * + * You should usually call [Builder.durationMs] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun durationMs(durationMs: JsonField) = apply { + this.durationMs = durationMs + } + + fun totalInputTokens(totalInputTokens: Long?) = + totalInputTokens(JsonField.ofNullable(totalInputTokens)) + + /** + * Alias for [Builder.totalInputTokens]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalInputTokens(totalInputTokens: Long) = + totalInputTokens(totalInputTokens as Long?) + + /** + * Alias for calling [Builder.totalInputTokens] with + * `totalInputTokens.orElse(null)`. + */ + fun totalInputTokens(totalInputTokens: Optional) = + totalInputTokens(totalInputTokens.getOrNull()) + + /** + * Sets [Builder.totalInputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.totalInputTokens] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun totalInputTokens(totalInputTokens: JsonField) = apply { + this.totalInputTokens = totalInputTokens + } + + fun totalOutputTokens(totalOutputTokens: Long?) = + totalOutputTokens(JsonField.ofNullable(totalOutputTokens)) + + /** + * Alias for [Builder.totalOutputTokens]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalOutputTokens(totalOutputTokens: Long) = + totalOutputTokens(totalOutputTokens as Long?) + + /** + * Alias for calling [Builder.totalOutputTokens] with + * `totalOutputTokens.orElse(null)`. + */ + fun totalOutputTokens(totalOutputTokens: Optional) = + totalOutputTokens(totalOutputTokens.getOrNull()) + + /** + * Sets [Builder.totalOutputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.totalOutputTokens] with a well-typed [Long] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun totalOutputTokens(totalOutputTokens: JsonField) = apply { + this.totalOutputTokens = totalOutputTokens + } + + fun turns(turns: Long) = turns(JsonField.of(turns)) + + /** + * Sets [Builder.turns] to an arbitrary JSON value. + * + * You should usually call [Builder.turns] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun turns(turns: JsonField) = apply { this.turns = turns } + + 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 [Usage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Usage = + Usage( + durationMs, + totalInputTokens, + totalOutputTokens, + turns, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Usage = apply { + if (validated) { + return@apply + } + + durationMs() + totalInputTokens() + totalOutputTokens() + turns() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (durationMs.asKnown().isPresent) 1 else 0) + + (if (totalInputTokens.asKnown().isPresent) 1 else 0) + + (if (totalOutputTokens.asKnown().isPresent) 1 else 0) + + (if (turns.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Usage && + durationMs == other.durationMs && + totalInputTokens == other.totalInputTokens && + totalOutputTokens == other.totalOutputTokens && + turns == other.turns && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + durationMs, + totalInputTokens, + totalOutputTokens, + turns, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Usage{durationMs=$durationMs, totalInputTokens=$totalInputTokens, totalOutputTokens=$totalOutputTokens, turns=$turns, additionalProperties=$additionalProperties}" + } + + 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 STOP = of("stop") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + STOP + } + + /** + * 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 { + STOP, + /** + * 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) { + STOP -> Value.STOP + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + STOP -> Known.STOP + else -> throw LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException 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: LlamaCloudInvalidDataException) { + 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 Stop && + error == other.error && + isError == other.isError && + usage == other.usage && + skippedIndexIds == other.skippedIndexIds && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(error, isError, usage, skippedIndexIds, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Stop{error=$error, isError=$isError, usage=$usage, skippedIndexIds=$skippedIndexIds, type=$type, additionalProperties=$additionalProperties}" + } + + class TextDelta + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val content: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(content, type, mutableMapOf()) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun content(): String = content.getRequired("content") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [TextDelta]. + * + * The following fields are required: + * ```java + * .content() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TextDelta]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(textDelta: TextDelta) = apply { + content = textDelta.content + type = textDelta.type + additionalProperties = textDelta.additionalProperties.toMutableMap() + } + + fun content(content: String) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TextDelta]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TextDelta = + TextDelta( + checkRequired("content", content), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): TextDelta = apply { + if (validated) { + return@apply + } + + content() + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (content.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 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 TEXT_DELTA = of("text_delta") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TEXT_DELTA + } + + /** + * 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 { + TEXT_DELTA, + /** + * 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) { + TEXT_DELTA -> Value.TEXT_DELTA + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TEXT_DELTA -> Known.TEXT_DELTA + else -> throw LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException 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: LlamaCloudInvalidDataException) { + 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 TextDelta && + content == other.content && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(content, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TextDelta{content=$content, type=$type, additionalProperties=$additionalProperties}" + } + + class Text + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val content: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(content, type, mutableMapOf()) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun content(): String = content.getRequired("content") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Text]. + * + * The following fields are required: + * ```java + * .content() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Text]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(text: Text) = apply { + content = text.content + type = text.type + additionalProperties = text.additionalProperties.toMutableMap() + } + + fun content(content: String) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Text]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Text = + Text( + checkRequired("content", content), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Text = apply { + if (validated) { + return@apply + } + + content() + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (content.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 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 TEXT = of("text") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TEXT + } + + /** + * 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 { + TEXT, + /** + * 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) { + TEXT -> Value.TEXT + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TEXT -> Known.TEXT + else -> throw LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException 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: LlamaCloudInvalidDataException) { + 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 Text && + content == other.content && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(content, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Text{content=$content, type=$type, additionalProperties=$additionalProperties}" + } + + class ThinkingDelta + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val content: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(content, type, mutableMapOf()) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun content(): String = content.getRequired("content") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ThinkingDelta]. + * + * The following fields are required: + * ```java + * .content() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThinkingDelta]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(thinkingDelta: ThinkingDelta) = apply { + content = thinkingDelta.content + type = thinkingDelta.type + additionalProperties = thinkingDelta.additionalProperties.toMutableMap() + } + + fun content(content: String) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ThinkingDelta]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ThinkingDelta = + ThinkingDelta( + checkRequired("content", content), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ThinkingDelta = apply { + if (validated) { + return@apply + } + + content() + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (content.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 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 THINKING_DELTA = of("thinking_delta") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + THINKING_DELTA + } + + /** + * 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 { + THINKING_DELTA, + /** + * 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) { + THINKING_DELTA -> Value.THINKING_DELTA + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + THINKING_DELTA -> Known.THINKING_DELTA + else -> throw LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException 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: LlamaCloudInvalidDataException) { + 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 ThinkingDelta && + content == other.content && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(content, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThinkingDelta{content=$content, type=$type, additionalProperties=$additionalProperties}" + } + + class Thinking + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val content: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(content, type, mutableMapOf()) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun content(): String = content.getRequired("content") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Thinking]. + * + * The following fields are required: + * ```java + * .content() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Thinking]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(thinking: Thinking) = apply { + content = thinking.content + type = thinking.type + additionalProperties = thinking.additionalProperties.toMutableMap() + } + + fun content(content: String) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Thinking]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Thinking = + Thinking( + checkRequired("content", content), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Thinking = apply { + if (validated) { + return@apply + } + + content() + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (content.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 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 THINKING = of("thinking") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + THINKING + } + + /** + * 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 { + THINKING, + /** + * 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) { + THINKING -> Value.THINKING + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + THINKING -> Known.THINKING + else -> throw LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException 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: LlamaCloudInvalidDataException) { + 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 Thinking && + content == other.content && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(content, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Thinking{content=$content, type=$type, additionalProperties=$additionalProperties}" + } + + class ToolCall + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val arguments: JsonField, + private val callId: JsonField, + private val name: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("arguments") + @ExcludeMissing + arguments: JsonField = JsonMissing.of(), + @JsonProperty("call_id") + @ExcludeMissing + callId: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(arguments, callId, name, type, mutableMapOf()) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun arguments(): Arguments = arguments.getRequired("arguments") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun callId(): String = callId.getRequired("call_id") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun name(): String = name.getRequired("name") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [arguments]. + * + * Unlike [arguments], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("arguments") + @ExcludeMissing + fun _arguments(): JsonField = arguments + + /** + * Returns the raw JSON value of [callId]. + * + * Unlike [callId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("call_id") @ExcludeMissing fun _callId(): JsonField = callId + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ToolCall]. + * + * The following fields are required: + * ```java + * .arguments() + * .callId() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ToolCall]. */ + class Builder internal constructor() { + + private var arguments: JsonField? = null + private var callId: JsonField? = null + private var name: JsonField? = null + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(toolCall: ToolCall) = apply { + arguments = toolCall.arguments + callId = toolCall.callId + name = toolCall.name + type = toolCall.type + additionalProperties = toolCall.additionalProperties.toMutableMap() + } + + fun arguments(arguments: Arguments) = arguments(JsonField.of(arguments)) + + /** + * Sets [Builder.arguments] to an arbitrary JSON value. + * + * You should usually call [Builder.arguments] with a well-typed [Arguments] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun arguments(arguments: JsonField) = apply { + this.arguments = arguments + } + + fun callId(callId: String) = callId(JsonField.of(callId)) + + /** + * Sets [Builder.callId] to an arbitrary JSON value. + * + * You should usually call [Builder.callId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun callId(callId: JsonField) = apply { this.callId = callId } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ToolCall]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .arguments() + * .callId() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ToolCall = + ToolCall( + checkRequired("arguments", arguments), + checkRequired("callId", callId), + checkRequired("name", name), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ToolCall = apply { + if (validated) { + return@apply + } + + arguments().validate() + callId() + name() + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (arguments.asKnown().getOrNull()?.validity() ?: 0) + + (if (callId.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Arguments + @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 [Arguments]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Arguments]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(arguments: Arguments) = apply { + additionalProperties = arguments.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 [Arguments]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Arguments = Arguments(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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Arguments = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Arguments && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Arguments{additionalProperties=$additionalProperties}" + } + + 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 TOOL_CALL = of("tool_call") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TOOL_CALL + } + + /** + * 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 { + TOOL_CALL, + /** + * 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) { + TOOL_CALL -> Value.TOOL_CALL + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TOOL_CALL -> Known.TOOL_CALL + else -> throw LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException 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: LlamaCloudInvalidDataException) { + 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 ToolCall && + arguments == other.arguments && + callId == other.callId && + name == other.name && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(arguments, callId, name, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ToolCall{arguments=$arguments, callId=$callId, name=$name, type=$type, additionalProperties=$additionalProperties}" + } + + class ToolResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val callId: JsonField, + private val name: JsonField, + private val result: JsonValue, + private val imageAttachment: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("call_id") + @ExcludeMissing + callId: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("result") @ExcludeMissing result: JsonValue = JsonMissing.of(), + @JsonProperty("image_attachment") + @ExcludeMissing + imageAttachment: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(callId, name, result, imageAttachment, type, mutableMapOf()) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun callId(): String = callId.getRequired("call_id") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun name(): String = name.getRequired("name") + + /** + * This arbitrary value can be deserialized into a custom type using the `convert` + * method: + * ```java + * MyClass myObject = toolResult.result().convert(MyClass.class); + * ``` + */ + @JsonProperty("result") @ExcludeMissing fun _result(): JsonValue = result + + /** + * Coordinates for lazily resolving a page screenshot presigned URL. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun imageAttachment(): Optional = + imageAttachment.getOptional("image_attachment") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [callId]. + * + * Unlike [callId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("call_id") @ExcludeMissing fun _callId(): JsonField = callId + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [imageAttachment]. + * + * Unlike [imageAttachment], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("image_attachment") + @ExcludeMissing + fun _imageAttachment(): JsonField = imageAttachment + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ToolResult]. + * + * The following fields are required: + * ```java + * .callId() + * .name() + * .result() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ToolResult]. */ + class Builder internal constructor() { + + private var callId: JsonField? = null + private var name: JsonField? = null + private var result: JsonValue? = null + private var imageAttachment: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(toolResult: ToolResult) = apply { + callId = toolResult.callId + name = toolResult.name + result = toolResult.result + imageAttachment = toolResult.imageAttachment + type = toolResult.type + additionalProperties = toolResult.additionalProperties.toMutableMap() + } + + fun callId(callId: String) = callId(JsonField.of(callId)) + + /** + * Sets [Builder.callId] to an arbitrary JSON value. + * + * You should usually call [Builder.callId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun callId(callId: JsonField) = apply { this.callId = callId } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun result(result: JsonValue) = apply { this.result = result } + + /** Coordinates for lazily resolving a page screenshot presigned URL. */ + fun imageAttachment(imageAttachment: ImageAttachment?) = + imageAttachment(JsonField.ofNullable(imageAttachment)) + + /** + * Alias for calling [Builder.imageAttachment] with `imageAttachment.orElse(null)`. + */ + fun imageAttachment(imageAttachment: Optional) = + imageAttachment(imageAttachment.getOrNull()) + + /** + * Sets [Builder.imageAttachment] to an arbitrary JSON value. + * + * You should usually call [Builder.imageAttachment] with a well-typed + * [ImageAttachment] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun imageAttachment(imageAttachment: JsonField) = apply { + this.imageAttachment = imageAttachment + } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ToolResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .callId() + * .name() + * .result() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ToolResult = + ToolResult( + checkRequired("callId", callId), + checkRequired("name", name), + checkRequired("result", result), + imageAttachment, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ToolResult = apply { + if (validated) { + return@apply + } + + callId() + name() + imageAttachment().ifPresent { it.validate() } + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (callId.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (imageAttachment.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + /** Coordinates for lazily resolving a page screenshot presigned URL. */ + class ImageAttachment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val attachmentName: JsonField, + private val sourceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("attachment_name") + @ExcludeMissing + attachmentName: JsonField = JsonMissing.of(), + @JsonProperty("source_id") + @ExcludeMissing + sourceId: JsonField = JsonMissing.of(), + ) : this(attachmentName, sourceId, mutableMapOf()) + + /** + * @throws LlamaCloudInvalidDataException 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 attachmentName(): String = attachmentName.getRequired("attachment_name") + + /** + * @throws LlamaCloudInvalidDataException 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 sourceId(): String = sourceId.getRequired("source_id") + + /** + * Returns the raw JSON value of [attachmentName]. + * + * Unlike [attachmentName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("attachment_name") + @ExcludeMissing + fun _attachmentName(): JsonField = attachmentName + + /** + * Returns the raw JSON value of [sourceId]. + * + * Unlike [sourceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("source_id") + @ExcludeMissing + fun _sourceId(): JsonField = sourceId + + @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 [ImageAttachment]. + * + * The following fields are required: + * ```java + * .attachmentName() + * .sourceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ImageAttachment]. */ + class Builder internal constructor() { + + private var attachmentName: JsonField? = null + private var sourceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(imageAttachment: ImageAttachment) = apply { + attachmentName = imageAttachment.attachmentName + sourceId = imageAttachment.sourceId + additionalProperties = imageAttachment.additionalProperties.toMutableMap() + } + + fun attachmentName(attachmentName: String) = + attachmentName(JsonField.of(attachmentName)) + + /** + * Sets [Builder.attachmentName] to an arbitrary JSON value. + * + * You should usually call [Builder.attachmentName] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun attachmentName(attachmentName: JsonField) = apply { + this.attachmentName = attachmentName + } + + fun sourceId(sourceId: String) = sourceId(JsonField.of(sourceId)) + + /** + * Sets [Builder.sourceId] to an arbitrary JSON value. + * + * You should usually call [Builder.sourceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun sourceId(sourceId: JsonField) = apply { this.sourceId = sourceId } + + 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 [ImageAttachment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .attachmentName() + * .sourceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ImageAttachment = + ImageAttachment( + checkRequired("attachmentName", attachmentName), + checkRequired("sourceId", sourceId), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): ImageAttachment = apply { + if (validated) { + return@apply + } + + attachmentName() + sourceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (attachmentName.asKnown().isPresent) 1 else 0) + + (if (sourceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ImageAttachment && + attachmentName == other.attachmentName && + sourceId == other.sourceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(attachmentName, sourceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ImageAttachment{attachmentName=$attachmentName, sourceId=$sourceId, additionalProperties=$additionalProperties}" + } + + 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 TOOL_RESULT = of("tool_result") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TOOL_RESULT + } + + /** + * 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 { + TOOL_RESULT, + /** + * 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) { + TOOL_RESULT -> Value.TOOL_RESULT + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + TOOL_RESULT -> Known.TOOL_RESULT + else -> throw LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException 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: LlamaCloudInvalidDataException) { + 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 ToolResult && + callId == other.callId && + name == other.name && + result == other.result && + imageAttachment == other.imageAttachment && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(callId, name, result, imageAttachment, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ToolResult{callId=$callId, name=$name, result=$result, imageAttachment=$imageAttachment, type=$type, additionalProperties=$additionalProperties}" + } + + class UserInput + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val content: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(content, type, mutableMapOf()) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun content(): String = content.getRequired("content") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [UserInput]. + * + * The following fields are required: + * ```java + * .content() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UserInput]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(userInput: UserInput) = apply { + content = userInput.content + type = userInput.type + additionalProperties = userInput.additionalProperties.toMutableMap() + } + + fun content(content: String) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UserInput]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UserInput = + UserInput( + checkRequired("content", content), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): UserInput = apply { + if (validated) { + return@apply + } + + content() + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (content.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 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 USER_INPUT = of("user_input") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + USER_INPUT + } + + /** + * 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 { + USER_INPUT, + /** + * 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) { + USER_INPUT -> Value.USER_INPUT + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + USER_INPUT -> Known.USER_INPUT + else -> throw LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException 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: LlamaCloudInvalidDataException) { + 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 UserInput && + content == other.content && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(content, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UserInput{content=$content, type=$type, additionalProperties=$additionalProperties}" + } + } + + /** + * What this chat's share link grants: read_only (transcript only) or query (viewers may ask new + * questions). + */ + class SharedAccess @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 QUERY = of("query") + + @JvmField val READ_ONLY = of("read_only") + + @JvmStatic fun of(value: String) = SharedAccess(JsonField.of(value)) + } + + /** An enum containing [SharedAccess]'s known values. */ + enum class Known { + QUERY, + READ_ONLY, + } + + /** + * An enum containing [SharedAccess]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [SharedAccess] 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 { + QUERY, + READ_ONLY, + /** + * An enum member indicating that [SharedAccess] 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) { + QUERY -> Value.QUERY + READ_ONLY -> Value.READ_ONLY + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + QUERY -> Known.QUERY + READ_ONLY -> Known.READ_ONLY + else -> throw LlamaCloudInvalidDataException("Unknown SharedAccess: $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 LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): SharedAccess = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 SharedAccess && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * Token usage and status from the most recent run. Null if the session has not been run yet. + */ + class JobMetadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val durationMs: JsonField, + private val error: JsonField, + private val exportConfigIds: JsonField>, + private val isError: JsonField, + private val totalInputTokens: JsonField, + private val totalOutputTokens: JsonField, + private val turns: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("duration_ms") + @ExcludeMissing + durationMs: JsonField = JsonMissing.of(), + @JsonProperty("error") @ExcludeMissing error: JsonField = JsonMissing.of(), + @JsonProperty("export_config_ids") + @ExcludeMissing + exportConfigIds: JsonField> = JsonMissing.of(), + @JsonProperty("is_error") + @ExcludeMissing + isError: JsonField = JsonMissing.of(), + @JsonProperty("total_input_tokens") + @ExcludeMissing + totalInputTokens: JsonField = JsonMissing.of(), + @JsonProperty("total_output_tokens") + @ExcludeMissing + totalOutputTokens: JsonField = JsonMissing.of(), + @JsonProperty("turns") @ExcludeMissing turns: JsonField = JsonMissing.of(), + ) : this( + durationMs, + error, + exportConfigIds, + isError, + totalInputTokens, + totalOutputTokens, + turns, + mutableMapOf(), + ) + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun durationMs(): Optional = durationMs.getOptional("duration_ms") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun error(): Optional = error.getOptional("error") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun exportConfigIds(): Optional> = + exportConfigIds.getOptional("export_config_ids") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun isError(): Optional = isError.getOptional("is_error") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun totalInputTokens(): Optional = totalInputTokens.getOptional("total_input_tokens") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun totalOutputTokens(): Optional = + totalOutputTokens.getOptional("total_output_tokens") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun turns(): Optional = turns.getOptional("turns") + + /** + * Returns the raw JSON value of [durationMs]. + * + * Unlike [durationMs], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("duration_ms") + @ExcludeMissing + fun _durationMs(): JsonField = durationMs + + /** + * Returns the raw JSON value of [error]. + * + * Unlike [error], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error") @ExcludeMissing fun _error(): JsonField = error + + /** + * Returns the raw JSON value of [exportConfigIds]. + * + * Unlike [exportConfigIds], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("export_config_ids") + @ExcludeMissing + fun _exportConfigIds(): JsonField> = exportConfigIds + + /** + * Returns the raw JSON value of [isError]. + * + * Unlike [isError], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("is_error") @ExcludeMissing fun _isError(): JsonField = isError + + /** + * Returns the raw JSON value of [totalInputTokens]. + * + * Unlike [totalInputTokens], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("total_input_tokens") + @ExcludeMissing + fun _totalInputTokens(): JsonField = totalInputTokens + + /** + * Returns the raw JSON value of [totalOutputTokens]. + * + * Unlike [totalOutputTokens], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("total_output_tokens") + @ExcludeMissing + fun _totalOutputTokens(): JsonField = totalOutputTokens + + /** + * Returns the raw JSON value of [turns]. + * + * Unlike [turns], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("turns") @ExcludeMissing fun _turns(): JsonField = turns + + @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 [JobMetadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JobMetadata]. */ + class Builder internal constructor() { + + private var durationMs: JsonField = JsonMissing.of() + private var error: JsonField = JsonMissing.of() + private var exportConfigIds: JsonField>? = null + private var isError: JsonField = JsonMissing.of() + private var totalInputTokens: JsonField = JsonMissing.of() + private var totalOutputTokens: JsonField = JsonMissing.of() + private var turns: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(jobMetadata: JobMetadata) = apply { + durationMs = jobMetadata.durationMs + error = jobMetadata.error + exportConfigIds = jobMetadata.exportConfigIds.map { it.toMutableList() } + isError = jobMetadata.isError + totalInputTokens = jobMetadata.totalInputTokens + totalOutputTokens = jobMetadata.totalOutputTokens + turns = jobMetadata.turns + additionalProperties = jobMetadata.additionalProperties.toMutableMap() + } + + fun durationMs(durationMs: Double) = durationMs(JsonField.of(durationMs)) + + /** + * Sets [Builder.durationMs] to an arbitrary JSON value. + * + * You should usually call [Builder.durationMs] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun durationMs(durationMs: JsonField) = apply { this.durationMs = durationMs } + + fun error(error: String?) = error(JsonField.ofNullable(error)) + + /** Alias for calling [Builder.error] with `error.orElse(null)`. */ + fun error(error: Optional) = error(error.getOrNull()) + + /** + * Sets [Builder.error] to an arbitrary JSON value. + * + * You should usually call [Builder.error] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun error(error: JsonField) = apply { this.error = error } + + fun exportConfigIds(exportConfigIds: List?) = + exportConfigIds(JsonField.ofNullable(exportConfigIds)) + + /** Alias for calling [Builder.exportConfigIds] with `exportConfigIds.orElse(null)`. */ + fun exportConfigIds(exportConfigIds: Optional>) = + exportConfigIds(exportConfigIds.getOrNull()) + + /** + * Sets [Builder.exportConfigIds] to an arbitrary JSON value. + * + * You should usually call [Builder.exportConfigIds] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun exportConfigIds(exportConfigIds: JsonField>) = apply { + this.exportConfigIds = exportConfigIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [exportConfigIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExportConfigId(exportConfigId: String) = apply { + exportConfigIds = + (exportConfigIds ?: JsonField.of(mutableListOf())).also { + checkKnown("exportConfigIds", it).add(exportConfigId) + } + } + + fun isError(isError: Boolean) = isError(JsonField.of(isError)) + + /** + * Sets [Builder.isError] to an arbitrary JSON value. + * + * You should usually call [Builder.isError] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isError(isError: JsonField) = apply { this.isError = isError } + + fun totalInputTokens(totalInputTokens: Long?) = + totalInputTokens(JsonField.ofNullable(totalInputTokens)) + + /** + * Alias for [Builder.totalInputTokens]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalInputTokens(totalInputTokens: Long) = + totalInputTokens(totalInputTokens as Long?) + + /** + * Alias for calling [Builder.totalInputTokens] with `totalInputTokens.orElse(null)`. + */ + fun totalInputTokens(totalInputTokens: Optional) = + totalInputTokens(totalInputTokens.getOrNull()) + + /** + * Sets [Builder.totalInputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.totalInputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun totalInputTokens(totalInputTokens: JsonField) = apply { + this.totalInputTokens = totalInputTokens + } + + fun totalOutputTokens(totalOutputTokens: Long?) = + totalOutputTokens(JsonField.ofNullable(totalOutputTokens)) + + /** + * Alias for [Builder.totalOutputTokens]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalOutputTokens(totalOutputTokens: Long) = + totalOutputTokens(totalOutputTokens as Long?) + + /** + * Alias for calling [Builder.totalOutputTokens] with `totalOutputTokens.orElse(null)`. + */ + fun totalOutputTokens(totalOutputTokens: Optional) = + totalOutputTokens(totalOutputTokens.getOrNull()) + + /** + * Sets [Builder.totalOutputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.totalOutputTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun totalOutputTokens(totalOutputTokens: JsonField) = apply { + this.totalOutputTokens = totalOutputTokens + } + + fun turns(turns: Long) = turns(JsonField.of(turns)) + + /** + * Sets [Builder.turns] to an arbitrary JSON value. + * + * You should usually call [Builder.turns] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun turns(turns: JsonField) = apply { this.turns = turns } + + 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 [JobMetadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): JobMetadata = + JobMetadata( + durationMs, + error, + (exportConfigIds ?: JsonMissing.of()).map { it.toImmutable() }, + isError, + totalInputTokens, + totalOutputTokens, + turns, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): JobMetadata = apply { + if (validated) { + return@apply + } + + durationMs() + error() + exportConfigIds() + isError() + totalInputTokens() + totalOutputTokens() + turns() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (durationMs.asKnown().isPresent) 1 else 0) + + (if (error.asKnown().isPresent) 1 else 0) + + (exportConfigIds.asKnown().getOrNull()?.size ?: 0) + + (if (isError.asKnown().isPresent) 1 else 0) + + (if (totalInputTokens.asKnown().isPresent) 1 else 0) + + (if (totalOutputTokens.asKnown().isPresent) 1 else 0) + + (if (turns.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JobMetadata && + durationMs == other.durationMs && + error == other.error && + exportConfigIds == other.exportConfigIds && + isError == other.isError && + totalInputTokens == other.totalInputTokens && + totalOutputTokens == other.totalOutputTokens && + turns == other.turns && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + durationMs, + error, + exportConfigIds, + isError, + totalInputTokens, + totalOutputTokens, + turns, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JobMetadata{durationMs=$durationMs, error=$error, exportConfigIds=$exportConfigIds, isError=$isError, totalInputTokens=$totalInputTokens, totalOutputTokens=$totalOutputTokens, turns=$turns, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatRetrieveResponse && + events == other.events && + lastUpdatedAt == other.lastUpdatedAt && + sessionId == other.sessionId && + sharedAccess == other.sharedAccess && + generatedTitle == other.generatedTitle && + indexIds == other.indexIds && + jobMetadata == other.jobMetadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + events, + lastUpdatedAt, + sessionId, + sharedAccess, + generatedTitle, + indexIds, + jobMetadata, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatRetrieveResponse{events=$events, lastUpdatedAt=$lastUpdatedAt, sessionId=$sessionId, sharedAccess=$sharedAccess, generatedTitle=$generatedTitle, indexIds=$indexIds, jobMetadata=$jobMetadata, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatStreamParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatStreamParams.kt new file mode 100644 index 0000000..387ac40 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatStreamParams.kt @@ -0,0 +1,663 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Stream agent events for a chat turn as Server-Sent Events. */ +class ChatStreamParams +private constructor( + private val sessionId: String?, + private val organizationId: String?, + private val projectId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sessionId(): Optional = Optional.ofNullable(sessionId) + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * Indexes to retrieve data from. + * + * @throws LlamaCloudInvalidDataException 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 indexIds(): List = body.indexIds() + + /** + * User message for this chat turn. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun prompt(): String = body.prompt() + + /** + * Fail the turn if any requested index cannot be queried. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun requireAllIndexes(): Optional = body.requireAllIndexes() + + /** + * Returns the raw JSON value of [indexIds]. + * + * Unlike [indexIds], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _indexIds(): JsonField> = body._indexIds() + + /** + * Returns the raw JSON value of [prompt]. + * + * Unlike [prompt], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _prompt(): JsonField = body._prompt() + + /** + * Returns the raw JSON value of [requireAllIndexes]. + * + * Unlike [requireAllIndexes], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _requireAllIndexes(): JsonField = body._requireAllIndexes() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ChatStreamParams]. + * + * The following fields are required: + * ```java + * .indexIds() + * .prompt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatStreamParams]. */ + class Builder internal constructor() { + + private var sessionId: String? = null + private var organizationId: String? = null + private var projectId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(chatStreamParams: ChatStreamParams) = apply { + sessionId = chatStreamParams.sessionId + organizationId = chatStreamParams.organizationId + projectId = chatStreamParams.projectId + body = chatStreamParams.body.toBuilder() + additionalHeaders = chatStreamParams.additionalHeaders.toBuilder() + additionalQueryParams = chatStreamParams.additionalQueryParams.toBuilder() + } + + fun sessionId(sessionId: String?) = apply { this.sessionId = sessionId } + + /** Alias for calling [Builder.sessionId] with `sessionId.orElse(null)`. */ + fun sessionId(sessionId: Optional) = sessionId(sessionId.getOrNull()) + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [indexIds] + * - [prompt] + * - [requireAllIndexes] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** Indexes to retrieve data from. */ + fun indexIds(indexIds: List) = apply { body.indexIds(indexIds) } + + /** + * Sets [Builder.indexIds] to an arbitrary JSON value. + * + * You should usually call [Builder.indexIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun indexIds(indexIds: JsonField>) = apply { body.indexIds(indexIds) } + + /** + * Adds a single [String] to [indexIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addIndexId(indexId: String) = apply { body.addIndexId(indexId) } + + /** User message for this chat turn. */ + fun prompt(prompt: String) = apply { body.prompt(prompt) } + + /** + * Sets [Builder.prompt] to an arbitrary JSON value. + * + * You should usually call [Builder.prompt] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun prompt(prompt: JsonField) = apply { body.prompt(prompt) } + + /** Fail the turn if any requested index cannot be queried. */ + fun requireAllIndexes(requireAllIndexes: Boolean) = apply { + body.requireAllIndexes(requireAllIndexes) + } + + /** + * Sets [Builder.requireAllIndexes] to an arbitrary JSON value. + * + * You should usually call [Builder.requireAllIndexes] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun requireAllIndexes(requireAllIndexes: JsonField) = apply { + body.requireAllIndexes(requireAllIndexes) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [ChatStreamParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .indexIds() + * .prompt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatStreamParams = + ChatStreamParams( + sessionId, + organizationId, + projectId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sessionId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + /** Request body for running a chat turn against one or more indexes. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val indexIds: JsonField>, + private val prompt: JsonField, + private val requireAllIndexes: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("index_ids") + @ExcludeMissing + indexIds: JsonField> = JsonMissing.of(), + @JsonProperty("prompt") @ExcludeMissing prompt: JsonField = JsonMissing.of(), + @JsonProperty("require_all_indexes") + @ExcludeMissing + requireAllIndexes: JsonField = JsonMissing.of(), + ) : this(indexIds, prompt, requireAllIndexes, mutableMapOf()) + + /** + * Indexes to retrieve data from. + * + * @throws LlamaCloudInvalidDataException 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 indexIds(): List = indexIds.getRequired("index_ids") + + /** + * User message for this chat turn. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun prompt(): String = prompt.getRequired("prompt") + + /** + * Fail the turn if any requested index cannot be queried. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun requireAllIndexes(): Optional = + requireAllIndexes.getOptional("require_all_indexes") + + /** + * Returns the raw JSON value of [indexIds]. + * + * Unlike [indexIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("index_ids") + @ExcludeMissing + fun _indexIds(): JsonField> = indexIds + + /** + * Returns the raw JSON value of [prompt]. + * + * Unlike [prompt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prompt") @ExcludeMissing fun _prompt(): JsonField = prompt + + /** + * Returns the raw JSON value of [requireAllIndexes]. + * + * Unlike [requireAllIndexes], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("require_all_indexes") + @ExcludeMissing + fun _requireAllIndexes(): JsonField = requireAllIndexes + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .indexIds() + * .prompt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var indexIds: JsonField>? = null + private var prompt: JsonField? = null + private var requireAllIndexes: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + indexIds = body.indexIds.map { it.toMutableList() } + prompt = body.prompt + requireAllIndexes = body.requireAllIndexes + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Indexes to retrieve data from. */ + fun indexIds(indexIds: List) = indexIds(JsonField.of(indexIds)) + + /** + * Sets [Builder.indexIds] to an arbitrary JSON value. + * + * You should usually call [Builder.indexIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun indexIds(indexIds: JsonField>) = apply { + this.indexIds = indexIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [indexIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addIndexId(indexId: String) = apply { + indexIds = + (indexIds ?: JsonField.of(mutableListOf())).also { + checkKnown("indexIds", it).add(indexId) + } + } + + /** User message for this chat turn. */ + fun prompt(prompt: String) = prompt(JsonField.of(prompt)) + + /** + * Sets [Builder.prompt] to an arbitrary JSON value. + * + * You should usually call [Builder.prompt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun prompt(prompt: JsonField) = apply { this.prompt = prompt } + + /** Fail the turn if any requested index cannot be queried. */ + fun requireAllIndexes(requireAllIndexes: Boolean) = + requireAllIndexes(JsonField.of(requireAllIndexes)) + + /** + * Sets [Builder.requireAllIndexes] to an arbitrary JSON value. + * + * You should usually call [Builder.requireAllIndexes] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun requireAllIndexes(requireAllIndexes: JsonField) = apply { + this.requireAllIndexes = requireAllIndexes + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .indexIds() + * .prompt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("indexIds", indexIds).map { it.toImmutable() }, + checkRequired("prompt", prompt), + requireAllIndexes, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + indexIds() + prompt() + requireAllIndexes() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (indexIds.asKnown().getOrNull()?.size ?: 0) + + (if (prompt.asKnown().isPresent) 1 else 0) + + (if (requireAllIndexes.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + indexIds == other.indexIds && + prompt == other.prompt && + requireAllIndexes == other.requireAllIndexes && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(indexIds, prompt, requireAllIndexes, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{indexIds=$indexIds, prompt=$prompt, requireAllIndexes=$requireAllIndexes, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatStreamParams && + sessionId == other.sessionId && + organizationId == other.organizationId && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + sessionId, + organizationId, + projectId, + body, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "ChatStreamParams{sessionId=$sessionId, organizationId=$organizationId, projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatStreamResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatStreamResponse.kt new file mode 100644 index 0000000..aa611b9 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/chat/ChatStreamResponse.kt @@ -0,0 +1,121 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import java.util.Collections +import java.util.Objects + +class ChatStreamResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + + @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 [ChatStreamResponse]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatStreamResponse]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatStreamResponse: ChatStreamResponse) = apply { + additionalProperties = chatStreamResponse.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 [ChatStreamResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ChatStreamResponse = ChatStreamResponse(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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ChatStreamResponse = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = 0 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ChatStreamResponse && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "ChatStreamResponse{additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyCreateRequest.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyCreateRequest.kt index 9c90604..ffaabd9 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyCreateRequest.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/classify/ClassifyCreateRequest.kt @@ -974,6 +974,16 @@ private constructor( @JvmField val UNMAPPED_EVENT = of("unmapped_event") + @JvmField val VERIFY_CANCELLED = of("verify.cancelled") + + @JvmField val VERIFY_ERROR = of("verify.error") + + @JvmField val VERIFY_PENDING = of("verify.pending") + + @JvmField val VERIFY_RUNNING = of("verify.running") + + @JvmField val VERIFY_SUCCESS = of("verify.success") + @JvmStatic fun of(value: String) = WebhookEvent(JsonField.of(value)) } @@ -1012,6 +1022,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, } /** @@ -1057,6 +1072,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, /** * An enum member indicating that [WebhookEvent] was instantiated with an unknown * value. @@ -1106,6 +1126,11 @@ private constructor( SPLIT_PROCESSING -> Value.SPLIT_PROCESSING SPLIT_SUCCESS -> Value.SPLIT_SUCCESS UNMAPPED_EVENT -> Value.UNMAPPED_EVENT + VERIFY_CANCELLED -> Value.VERIFY_CANCELLED + VERIFY_ERROR -> Value.VERIFY_ERROR + VERIFY_PENDING -> Value.VERIFY_PENDING + VERIFY_RUNNING -> Value.VERIFY_RUNNING + VERIFY_SUCCESS -> Value.VERIFY_SUCCESS else -> Value._UNKNOWN } @@ -1153,6 +1178,11 @@ private constructor( SPLIT_PROCESSING -> Known.SPLIT_PROCESSING SPLIT_SUCCESS -> Known.SPLIT_SUCCESS UNMAPPED_EVENT -> Known.UNMAPPED_EVENT + VERIFY_CANCELLED -> Known.VERIFY_CANCELLED + VERIFY_ERROR -> Known.VERIFY_ERROR + VERIFY_PENDING -> Known.VERIFY_PENDING + VERIFY_RUNNING -> Known.VERIFY_RUNNING + VERIFY_SUCCESS -> Known.VERIFY_SUCCESS else -> throw LlamaCloudInvalidDataException("Unknown WebhookEvent: $value") } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/extract/ExtractV2JobCreate.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/extract/ExtractV2JobCreate.kt index e589149..d2eab21 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/extract/ExtractV2JobCreate.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/extract/ExtractV2JobCreate.kt @@ -847,6 +847,16 @@ private constructor( @JvmField val UNMAPPED_EVENT = of("unmapped_event") + @JvmField val VERIFY_CANCELLED = of("verify.cancelled") + + @JvmField val VERIFY_ERROR = of("verify.error") + + @JvmField val VERIFY_PENDING = of("verify.pending") + + @JvmField val VERIFY_RUNNING = of("verify.running") + + @JvmField val VERIFY_SUCCESS = of("verify.success") + @JvmStatic fun of(value: String) = WebhookEvent(JsonField.of(value)) } @@ -885,6 +895,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, } /** @@ -930,6 +945,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, /** * An enum member indicating that [WebhookEvent] was instantiated with an unknown * value. @@ -979,6 +999,11 @@ private constructor( SPLIT_PROCESSING -> Value.SPLIT_PROCESSING SPLIT_SUCCESS -> Value.SPLIT_SUCCESS UNMAPPED_EVENT -> Value.UNMAPPED_EVENT + VERIFY_CANCELLED -> Value.VERIFY_CANCELLED + VERIFY_ERROR -> Value.VERIFY_ERROR + VERIFY_PENDING -> Value.VERIFY_PENDING + VERIFY_RUNNING -> Value.VERIFY_RUNNING + VERIFY_SUCCESS -> Value.VERIFY_SUCCESS else -> Value._UNKNOWN } @@ -1026,6 +1051,11 @@ private constructor( SPLIT_PROCESSING -> Known.SPLIT_PROCESSING SPLIT_SUCCESS -> Known.SPLIT_SUCCESS UNMAPPED_EVENT -> Known.UNMAPPED_EVENT + VERIFY_CANCELLED -> Known.VERIFY_CANCELLED + VERIFY_ERROR -> Known.VERIFY_ERROR + VERIFY_PENDING -> Known.VERIFY_PENDING + VERIFY_RUNNING -> Known.VERIFY_RUNNING + VERIFY_SUCCESS -> Known.VERIFY_SUCCESS else -> throw LlamaCloudInvalidDataException("Unknown WebhookEvent: $value") } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCancelSyncParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCancelSyncParams.kt new file mode 100644 index 0000000..9064f6e --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCancelSyncParams.kt @@ -0,0 +1,268 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Cancel the running sync for an index. Returns 409 if no sync is running. */ +class IndexCancelSyncParams +private constructor( + private val indexId: String?, + private val organizationId: String?, + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun indexId(): Optional = Optional.ofNullable(indexId) + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): IndexCancelSyncParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [IndexCancelSyncParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexCancelSyncParams]. */ + class Builder internal constructor() { + + private var indexId: String? = null + private var organizationId: String? = null + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(indexCancelSyncParams: IndexCancelSyncParams) = apply { + indexId = indexCancelSyncParams.indexId + organizationId = indexCancelSyncParams.organizationId + projectId = indexCancelSyncParams.projectId + additionalHeaders = indexCancelSyncParams.additionalHeaders.toBuilder() + additionalQueryParams = indexCancelSyncParams.additionalQueryParams.toBuilder() + additionalBodyProperties = indexCancelSyncParams.additionalBodyProperties.toMutableMap() + } + + fun indexId(indexId: String?) = apply { this.indexId = indexId } + + /** Alias for calling [Builder.indexId] with `indexId.orElse(null)`. */ + fun indexId(indexId: Optional) = indexId(indexId.getOrNull()) + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [IndexCancelSyncParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): IndexCancelSyncParams = + IndexCancelSyncParams( + indexId, + organizationId, + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> indexId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IndexCancelSyncParams && + indexId == other.indexId && + organizationId == other.organizationId && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + indexId, + organizationId, + projectId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "IndexCancelSyncParams{indexId=$indexId, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCancelSyncResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCancelSyncResponse.kt new file mode 100644 index 0000000..2b1ce67 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCancelSyncResponse.kt @@ -0,0 +1,123 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import java.util.Collections +import java.util.Objects + +class IndexCancelSyncResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + + @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 [IndexCancelSyncResponse]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexCancelSyncResponse]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(indexCancelSyncResponse: IndexCancelSyncResponse) = apply { + additionalProperties = indexCancelSyncResponse.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 [IndexCancelSyncResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): IndexCancelSyncResponse = + IndexCancelSyncResponse(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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): IndexCancelSyncResponse = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = 0 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IndexCancelSyncResponse && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "IndexCancelSyncResponse{additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCreateParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCreateParams.kt new file mode 100644 index 0000000..4d87784 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCreateParams.kt @@ -0,0 +1,1423 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Create a searchable index over a source directory. */ +class IndexCreateParams +private constructor( + private val organizationId: String?, + private val projectId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * ID of the source directory containing your documents. + * + * @throws LlamaCloudInvalidDataException 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 sourceDirectoryId(): String = body.sourceDirectoryId() + + /** + * Optional description of the index. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = body.description() + + /** + * Optional display name for the index. If omitted, the index is named after the source + * directory. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = body.name() + + /** + * Product configurations for syncing. Omit to use a default parse configuration. Include an + * explicit entry per product type (e.g. parse, extract) to override the default. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun products(): Optional> = body.products() + + /** + * Attachment kinds to store alongside parsed output. Each entry must be one of: screenshots, + * items. For example, ['screenshots'] renders and stores per-page screenshots; ['items'] stores + * structured items with bounding boxes. Omit or pass an empty list to skip attachments. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun storeAttachments(): Optional> = body.storeAttachments() + + /** + * How often to re-run the sync. One of: manual, daily, on_source_change. Defaults to manual. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun syncFrequency(): Optional = body.syncFrequency() + + /** + * Vector export destination for the index. 'DEFAULT' exports to the managed vector DB + * destination resolved from configuration. 'DISABLED' skips vector export — the export + * destination falls back to 'Download'. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun vectorTarget(): Optional = body.vectorTarget() + + /** + * Returns the raw JSON value of [sourceDirectoryId]. + * + * Unlike [sourceDirectoryId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _sourceDirectoryId(): JsonField = body._sourceDirectoryId() + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _description(): JsonField = body._description() + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _name(): JsonField = body._name() + + /** + * Returns the raw JSON value of [products]. + * + * Unlike [products], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _products(): JsonField> = body._products() + + /** + * Returns the raw JSON value of [storeAttachments]. + * + * Unlike [storeAttachments], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _storeAttachments(): JsonField> = body._storeAttachments() + + /** + * Returns the raw JSON value of [syncFrequency]. + * + * Unlike [syncFrequency], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _syncFrequency(): JsonField = body._syncFrequency() + + /** + * Returns the raw JSON value of [vectorTarget]. + * + * Unlike [vectorTarget], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _vectorTarget(): JsonField = body._vectorTarget() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [IndexCreateParams]. + * + * The following fields are required: + * ```java + * .sourceDirectoryId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexCreateParams]. */ + class Builder internal constructor() { + + private var organizationId: String? = null + private var projectId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(indexCreateParams: IndexCreateParams) = apply { + organizationId = indexCreateParams.organizationId + projectId = indexCreateParams.projectId + body = indexCreateParams.body.toBuilder() + additionalHeaders = indexCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = indexCreateParams.additionalQueryParams.toBuilder() + } + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [sourceDirectoryId] + * - [description] + * - [name] + * - [products] + * - [storeAttachments] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** ID of the source directory containing your documents. */ + fun sourceDirectoryId(sourceDirectoryId: String) = apply { + body.sourceDirectoryId(sourceDirectoryId) + } + + /** + * Sets [Builder.sourceDirectoryId] to an arbitrary JSON value. + * + * You should usually call [Builder.sourceDirectoryId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sourceDirectoryId(sourceDirectoryId: JsonField) = apply { + body.sourceDirectoryId(sourceDirectoryId) + } + + /** Optional description of the index. */ + fun description(description: String?) = apply { body.description(description) } + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { body.description(description) } + + /** + * Optional display name for the index. If omitted, the index is named after the source + * directory. + */ + fun name(name: String?) = apply { body.name(name) } + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { body.name(name) } + + /** + * Product configurations for syncing. Omit to use a default parse configuration. Include an + * explicit entry per product type (e.g. parse, extract) to override the default. + */ + fun products(products: List?) = apply { body.products(products) } + + /** Alias for calling [Builder.products] with `products.orElse(null)`. */ + fun products(products: Optional>) = products(products.getOrNull()) + + /** + * Sets [Builder.products] to an arbitrary JSON value. + * + * You should usually call [Builder.products] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun products(products: JsonField>) = apply { body.products(products) } + + /** + * Adds a single [Product] to [products]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addProduct(product: Product) = apply { body.addProduct(product) } + + /** + * Attachment kinds to store alongside parsed output. Each entry must be one of: + * screenshots, items. For example, ['screenshots'] renders and stores per-page screenshots; + * ['items'] stores structured items with bounding boxes. Omit or pass an empty list to skip + * attachments. + */ + fun storeAttachments(storeAttachments: List?) = apply { + body.storeAttachments(storeAttachments) + } + + /** Alias for calling [Builder.storeAttachments] with `storeAttachments.orElse(null)`. */ + fun storeAttachments(storeAttachments: Optional>) = + storeAttachments(storeAttachments.getOrNull()) + + /** + * Sets [Builder.storeAttachments] to an arbitrary JSON value. + * + * You should usually call [Builder.storeAttachments] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun storeAttachments(storeAttachments: JsonField>) = apply { + body.storeAttachments(storeAttachments) + } + + /** + * Adds a single [String] to [storeAttachments]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addStoreAttachment(storeAttachment: String) = apply { + body.addStoreAttachment(storeAttachment) + } + + /** + * How often to re-run the sync. One of: manual, daily, on_source_change. Defaults to + * manual. + */ + fun syncFrequency(syncFrequency: String) = apply { body.syncFrequency(syncFrequency) } + + /** + * Sets [Builder.syncFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.syncFrequency] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun syncFrequency(syncFrequency: JsonField) = apply { + body.syncFrequency(syncFrequency) + } + + /** + * Vector export destination for the index. 'DEFAULT' exports to the managed vector DB + * destination resolved from configuration. 'DISABLED' skips vector export — the export + * destination falls back to 'Download'. + */ + fun vectorTarget(vectorTarget: VectorTarget) = apply { body.vectorTarget(vectorTarget) } + + /** + * Sets [Builder.vectorTarget] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorTarget] with a well-typed [VectorTarget] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun vectorTarget(vectorTarget: JsonField) = apply { + body.vectorTarget(vectorTarget) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [IndexCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sourceDirectoryId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): IndexCreateParams = + IndexCreateParams( + organizationId, + projectId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + /** + * Create a searchable index over a source directory. + * + * Sets up the full pipeline — parsing, chunking, embedding, and vector store indexing — in a + * single call. An initial sync is triggered automatically. + * + * Omit ``products`` to use a default parse configuration (cost-effective tier). Pass it + * explicitly to control parsing or to include extraction. + */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val sourceDirectoryId: JsonField, + private val description: JsonField, + private val name: JsonField, + private val products: JsonField>, + private val storeAttachments: JsonField>, + private val syncFrequency: JsonField, + private val vectorTarget: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("source_directory_id") + @ExcludeMissing + sourceDirectoryId: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("products") + @ExcludeMissing + products: JsonField> = JsonMissing.of(), + @JsonProperty("store_attachments") + @ExcludeMissing + storeAttachments: JsonField> = JsonMissing.of(), + @JsonProperty("sync_frequency") + @ExcludeMissing + syncFrequency: JsonField = JsonMissing.of(), + @JsonProperty("vector_target") + @ExcludeMissing + vectorTarget: JsonField = JsonMissing.of(), + ) : this( + sourceDirectoryId, + description, + name, + products, + storeAttachments, + syncFrequency, + vectorTarget, + mutableMapOf(), + ) + + /** + * ID of the source directory containing your documents. + * + * @throws LlamaCloudInvalidDataException 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 sourceDirectoryId(): String = sourceDirectoryId.getRequired("source_directory_id") + + /** + * Optional description of the index. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Optional display name for the index. If omitted, the index is named after the source + * directory. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * Product configurations for syncing. Omit to use a default parse configuration. Include an + * explicit entry per product type (e.g. parse, extract) to override the default. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun products(): Optional> = products.getOptional("products") + + /** + * Attachment kinds to store alongside parsed output. Each entry must be one of: + * screenshots, items. For example, ['screenshots'] renders and stores per-page screenshots; + * ['items'] stores structured items with bounding boxes. Omit or pass an empty list to skip + * attachments. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun storeAttachments(): Optional> = + storeAttachments.getOptional("store_attachments") + + /** + * How often to re-run the sync. One of: manual, daily, on_source_change. Defaults to + * manual. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun syncFrequency(): Optional = syncFrequency.getOptional("sync_frequency") + + /** + * Vector export destination for the index. 'DEFAULT' exports to the managed vector DB + * destination resolved from configuration. 'DISABLED' skips vector export — the export + * destination falls back to 'Download'. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun vectorTarget(): Optional = vectorTarget.getOptional("vector_target") + + /** + * Returns the raw JSON value of [sourceDirectoryId]. + * + * Unlike [sourceDirectoryId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("source_directory_id") + @ExcludeMissing + fun _sourceDirectoryId(): JsonField = sourceDirectoryId + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [products]. + * + * Unlike [products], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("products") + @ExcludeMissing + fun _products(): JsonField> = products + + /** + * Returns the raw JSON value of [storeAttachments]. + * + * Unlike [storeAttachments], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("store_attachments") + @ExcludeMissing + fun _storeAttachments(): JsonField> = storeAttachments + + /** + * Returns the raw JSON value of [syncFrequency]. + * + * Unlike [syncFrequency], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("sync_frequency") + @ExcludeMissing + fun _syncFrequency(): JsonField = syncFrequency + + /** + * Returns the raw JSON value of [vectorTarget]. + * + * Unlike [vectorTarget], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("vector_target") + @ExcludeMissing + fun _vectorTarget(): JsonField = vectorTarget + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .sourceDirectoryId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var sourceDirectoryId: JsonField? = null + private var description: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var products: JsonField>? = null + private var storeAttachments: JsonField>? = null + private var syncFrequency: JsonField = JsonMissing.of() + private var vectorTarget: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + sourceDirectoryId = body.sourceDirectoryId + description = body.description + name = body.name + products = body.products.map { it.toMutableList() } + storeAttachments = body.storeAttachments.map { it.toMutableList() } + syncFrequency = body.syncFrequency + vectorTarget = body.vectorTarget + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** ID of the source directory containing your documents. */ + fun sourceDirectoryId(sourceDirectoryId: String) = + sourceDirectoryId(JsonField.of(sourceDirectoryId)) + + /** + * Sets [Builder.sourceDirectoryId] to an arbitrary JSON value. + * + * You should usually call [Builder.sourceDirectoryId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sourceDirectoryId(sourceDirectoryId: JsonField) = apply { + this.sourceDirectoryId = sourceDirectoryId + } + + /** Optional description of the index. */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun description(description: JsonField) = apply { + this.description = description + } + + /** + * Optional display name for the index. If omitted, the index is named after the source + * directory. + */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * Product configurations for syncing. Omit to use a default parse configuration. + * Include an explicit entry per product type (e.g. parse, extract) to override the + * default. + */ + fun products(products: List?) = products(JsonField.ofNullable(products)) + + /** Alias for calling [Builder.products] with `products.orElse(null)`. */ + fun products(products: Optional>) = products(products.getOrNull()) + + /** + * Sets [Builder.products] to an arbitrary JSON value. + * + * You should usually call [Builder.products] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun products(products: JsonField>) = apply { + this.products = products.map { it.toMutableList() } + } + + /** + * Adds a single [Product] to [products]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addProduct(product: Product) = apply { + products = + (products ?: JsonField.of(mutableListOf())).also { + checkKnown("products", it).add(product) + } + } + + /** + * Attachment kinds to store alongside parsed output. Each entry must be one of: + * screenshots, items. For example, ['screenshots'] renders and stores per-page + * screenshots; ['items'] stores structured items with bounding boxes. Omit or pass an + * empty list to skip attachments. + */ + fun storeAttachments(storeAttachments: List?) = + storeAttachments(JsonField.ofNullable(storeAttachments)) + + /** + * Alias for calling [Builder.storeAttachments] with `storeAttachments.orElse(null)`. + */ + fun storeAttachments(storeAttachments: Optional>) = + storeAttachments(storeAttachments.getOrNull()) + + /** + * Sets [Builder.storeAttachments] to an arbitrary JSON value. + * + * You should usually call [Builder.storeAttachments] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun storeAttachments(storeAttachments: JsonField>) = apply { + this.storeAttachments = storeAttachments.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [storeAttachments]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addStoreAttachment(storeAttachment: String) = apply { + storeAttachments = + (storeAttachments ?: JsonField.of(mutableListOf())).also { + checkKnown("storeAttachments", it).add(storeAttachment) + } + } + + /** + * How often to re-run the sync. One of: manual, daily, on_source_change. Defaults to + * manual. + */ + fun syncFrequency(syncFrequency: String) = syncFrequency(JsonField.of(syncFrequency)) + + /** + * Sets [Builder.syncFrequency] to an arbitrary JSON value. + * + * You should usually call [Builder.syncFrequency] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun syncFrequency(syncFrequency: JsonField) = apply { + this.syncFrequency = syncFrequency + } + + /** + * Vector export destination for the index. 'DEFAULT' exports to the managed vector DB + * destination resolved from configuration. 'DISABLED' skips vector export — the export + * destination falls back to 'Download'. + */ + fun vectorTarget(vectorTarget: VectorTarget) = vectorTarget(JsonField.of(vectorTarget)) + + /** + * Sets [Builder.vectorTarget] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorTarget] with a well-typed [VectorTarget] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun vectorTarget(vectorTarget: JsonField) = apply { + this.vectorTarget = vectorTarget + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sourceDirectoryId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("sourceDirectoryId", sourceDirectoryId), + description, + name, + (products ?: JsonMissing.of()).map { it.toImmutable() }, + (storeAttachments ?: JsonMissing.of()).map { it.toImmutable() }, + syncFrequency, + vectorTarget, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + sourceDirectoryId() + description() + name() + products().ifPresent { it.forEach { it.validate() } } + storeAttachments() + syncFrequency() + vectorTarget().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (sourceDirectoryId.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (products.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (storeAttachments.asKnown().getOrNull()?.size ?: 0) + + (if (syncFrequency.asKnown().isPresent) 1 else 0) + + (vectorTarget.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + sourceDirectoryId == other.sourceDirectoryId && + description == other.description && + name == other.name && + products == other.products && + storeAttachments == other.storeAttachments && + syncFrequency == other.syncFrequency && + vectorTarget == other.vectorTarget && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + sourceDirectoryId, + description, + name, + products, + storeAttachments, + syncFrequency, + vectorTarget, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{sourceDirectoryId=$sourceDirectoryId, description=$description, name=$name, products=$products, storeAttachments=$storeAttachments, syncFrequency=$syncFrequency, vectorTarget=$vectorTarget, additionalProperties=$additionalProperties}" + } + + /** + * A product configuration to include in an index's sync. + * + * Structurally mirrors ``directory_sync.SyncProductEntryRequest`` but is a distinct class so + * the Index API surface stays SDK-gen-isolated from directory-sync internals. Translation + * between the two happens in ``index/api_utils.py``. + */ + class Product + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val productConfigId: JsonField, + private val productType: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("product_config_id") + @ExcludeMissing + productConfigId: JsonField = JsonMissing.of(), + @JsonProperty("product_type") + @ExcludeMissing + productType: JsonField = JsonMissing.of(), + ) : this(productConfigId, productType, mutableMapOf()) + + /** + * ID of the product configuration. + * + * @throws LlamaCloudInvalidDataException 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 productConfigId(): String = productConfigId.getRequired("product_config_id") + + /** + * Product type. One of: parse, extract. + * + * @throws LlamaCloudInvalidDataException 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 productType(): String = productType.getRequired("product_type") + + /** + * Returns the raw JSON value of [productConfigId]. + * + * Unlike [productConfigId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("product_config_id") + @ExcludeMissing + fun _productConfigId(): JsonField = productConfigId + + /** + * Returns the raw JSON value of [productType]. + * + * Unlike [productType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("product_type") + @ExcludeMissing + fun _productType(): JsonField = productType + + @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 [Product]. + * + * The following fields are required: + * ```java + * .productConfigId() + * .productType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Product]. */ + class Builder internal constructor() { + + private var productConfigId: JsonField? = null + private var productType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(product: Product) = apply { + productConfigId = product.productConfigId + productType = product.productType + additionalProperties = product.additionalProperties.toMutableMap() + } + + /** ID of the product configuration. */ + fun productConfigId(productConfigId: String) = + productConfigId(JsonField.of(productConfigId)) + + /** + * Sets [Builder.productConfigId] to an arbitrary JSON value. + * + * You should usually call [Builder.productConfigId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun productConfigId(productConfigId: JsonField) = apply { + this.productConfigId = productConfigId + } + + /** Product type. One of: parse, extract. */ + fun productType(productType: String) = productType(JsonField.of(productType)) + + /** + * Sets [Builder.productType] to an arbitrary JSON value. + * + * You should usually call [Builder.productType] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun productType(productType: JsonField) = apply { + this.productType = productType + } + + 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 [Product]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .productConfigId() + * .productType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Product = + Product( + checkRequired("productConfigId", productConfigId), + checkRequired("productType", productType), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Product = apply { + if (validated) { + return@apply + } + + productConfigId() + productType() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (productConfigId.asKnown().isPresent) 1 else 0) + + (if (productType.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Product && + productConfigId == other.productConfigId && + productType == other.productType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(productConfigId, productType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Product{productConfigId=$productConfigId, productType=$productType, additionalProperties=$additionalProperties}" + } + + /** + * Vector export destination for the index. 'DEFAULT' exports to the managed vector DB + * destination resolved from configuration. 'DISABLED' skips vector export — the export + * destination falls back to 'Download'. + */ + class VectorTarget @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 DEFAULT = of("DEFAULT") + + @JvmField val DISABLED = of("DISABLED") + + @JvmStatic fun of(value: String) = VectorTarget(JsonField.of(value)) + } + + /** An enum containing [VectorTarget]'s known values. */ + enum class Known { + DEFAULT, + DISABLED, + } + + /** + * An enum containing [VectorTarget]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [VectorTarget] 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 { + DEFAULT, + DISABLED, + /** + * An enum member indicating that [VectorTarget] 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) { + DEFAULT -> Value.DEFAULT + DISABLED -> Value.DISABLED + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + DEFAULT -> Known.DEFAULT + DISABLED -> Known.DISABLED + else -> throw LlamaCloudInvalidDataException("Unknown VectorTarget: $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 LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): VectorTarget = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 VectorTarget && 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 IndexCreateParams && + organizationId == other.organizationId && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(organizationId, projectId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "IndexCreateParams{organizationId=$organizationId, projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCreateResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCreateResponse.kt new file mode 100644 index 0000000..ee9e380 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCreateResponse.kt @@ -0,0 +1,888 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A searchable index over a directory of documents. */ +class IndexCreateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val exportConfigId: JsonField, + private val name: JsonField, + private val outputDirectoryId: JsonField, + private val projectId: JsonField, + private val sourceDirectoryId: JsonField, + private val syncConfigId: JsonField, + private val createdAt: JsonField, + private val description: JsonField, + private val lastExportedAt: JsonField, + private val lastSyncedAt: JsonField, + private val metadata: JsonField, + private val syncInProgress: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("export_config_id") + @ExcludeMissing + exportConfigId: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("output_directory_id") + @ExcludeMissing + outputDirectoryId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("source_directory_id") + @ExcludeMissing + sourceDirectoryId: JsonField = JsonMissing.of(), + @JsonProperty("sync_config_id") + @ExcludeMissing + syncConfigId: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("last_exported_at") + @ExcludeMissing + lastExportedAt: JsonField = JsonMissing.of(), + @JsonProperty("last_synced_at") + @ExcludeMissing + lastSyncedAt: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("sync_in_progress") + @ExcludeMissing + syncInProgress: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + ) : this( + id, + exportConfigId, + name, + outputDirectoryId, + projectId, + sourceDirectoryId, + syncConfigId, + createdAt, + description, + lastExportedAt, + lastSyncedAt, + metadata, + syncInProgress, + updatedAt, + mutableMapOf(), + ) + + /** + * Unique identifier + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * ID of the export configuration. + * + * @throws LlamaCloudInvalidDataException 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 exportConfigId(): String = exportConfigId.getRequired("export_config_id") + + /** + * Index name. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * ID of the output directory holding the indexed files. + * + * @throws LlamaCloudInvalidDataException 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 outputDirectoryId(): String = outputDirectoryId.getRequired("output_directory_id") + + /** + * Project this index belongs to. + * + * @throws LlamaCloudInvalidDataException 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 projectId(): String = projectId.getRequired("project_id") + + /** + * ID of the source directory. + * + * @throws LlamaCloudInvalidDataException 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 sourceDirectoryId(): String = sourceDirectoryId.getRequired("source_directory_id") + + /** + * ID of the sync configuration. + * + * @throws LlamaCloudInvalidDataException 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 syncConfigId(): String = syncConfigId.getRequired("sync_config_id") + + /** + * Creation datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * Index description. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Last export time. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastExportedAt(): Optional = lastExportedAt.getOptional("last_exported_at") + + /** + * Last sync time. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastSyncedAt(): Optional = lastSyncedAt.getOptional("last_synced_at") + + /** + * Build state and diagnostic info. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Whether the index is syncing its source or exporting the result. Requires + * `expand=sync_in_progress`. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun syncInProgress(): Optional = syncInProgress.getOptional("sync_in_progress") + + /** + * Update datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [exportConfigId]. + * + * Unlike [exportConfigId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("export_config_id") + @ExcludeMissing + fun _exportConfigId(): JsonField = exportConfigId + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [outputDirectoryId]. + * + * Unlike [outputDirectoryId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("output_directory_id") + @ExcludeMissing + fun _outputDirectoryId(): JsonField = outputDirectoryId + + /** + * 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 [sourceDirectoryId]. + * + * Unlike [sourceDirectoryId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("source_directory_id") + @ExcludeMissing + fun _sourceDirectoryId(): JsonField = sourceDirectoryId + + /** + * Returns the raw JSON value of [syncConfigId]. + * + * Unlike [syncConfigId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sync_config_id") + @ExcludeMissing + fun _syncConfigId(): JsonField = syncConfigId + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [lastExportedAt]. + * + * Unlike [lastExportedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_exported_at") + @ExcludeMissing + fun _lastExportedAt(): JsonField = lastExportedAt + + /** + * Returns the raw JSON value of [lastSyncedAt]. + * + * Unlike [lastSyncedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_synced_at") + @ExcludeMissing + fun _lastSyncedAt(): JsonField = lastSyncedAt + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [syncInProgress]. + * + * Unlike [syncInProgress], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sync_in_progress") + @ExcludeMissing + fun _syncInProgress(): JsonField = syncInProgress + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") + @ExcludeMissing + fun _updatedAt(): JsonField = updatedAt + + @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 [IndexCreateResponse]. + * + * The following fields are required: + * ```java + * .id() + * .exportConfigId() + * .name() + * .outputDirectoryId() + * .projectId() + * .sourceDirectoryId() + * .syncConfigId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexCreateResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var exportConfigId: JsonField? = null + private var name: JsonField? = null + private var outputDirectoryId: JsonField? = null + private var projectId: JsonField? = null + private var sourceDirectoryId: JsonField? = null + private var syncConfigId: JsonField? = null + private var createdAt: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var lastExportedAt: JsonField = JsonMissing.of() + private var lastSyncedAt: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var syncInProgress: JsonField = JsonMissing.of() + private var updatedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(indexCreateResponse: IndexCreateResponse) = apply { + id = indexCreateResponse.id + exportConfigId = indexCreateResponse.exportConfigId + name = indexCreateResponse.name + outputDirectoryId = indexCreateResponse.outputDirectoryId + projectId = indexCreateResponse.projectId + sourceDirectoryId = indexCreateResponse.sourceDirectoryId + syncConfigId = indexCreateResponse.syncConfigId + createdAt = indexCreateResponse.createdAt + description = indexCreateResponse.description + lastExportedAt = indexCreateResponse.lastExportedAt + lastSyncedAt = indexCreateResponse.lastSyncedAt + metadata = indexCreateResponse.metadata + syncInProgress = indexCreateResponse.syncInProgress + updatedAt = indexCreateResponse.updatedAt + additionalProperties = indexCreateResponse.additionalProperties.toMutableMap() + } + + /** Unique identifier */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** ID of the export configuration. */ + fun exportConfigId(exportConfigId: String) = exportConfigId(JsonField.of(exportConfigId)) + + /** + * Sets [Builder.exportConfigId] to an arbitrary JSON value. + * + * You should usually call [Builder.exportConfigId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun exportConfigId(exportConfigId: JsonField) = apply { + this.exportConfigId = exportConfigId + } + + /** Index name. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** ID of the output directory holding the indexed files. */ + fun outputDirectoryId(outputDirectoryId: String) = + outputDirectoryId(JsonField.of(outputDirectoryId)) + + /** + * Sets [Builder.outputDirectoryId] to an arbitrary JSON value. + * + * You should usually call [Builder.outputDirectoryId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun outputDirectoryId(outputDirectoryId: JsonField) = apply { + this.outputDirectoryId = outputDirectoryId + } + + /** Project this index belongs to. */ + 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 } + + /** ID of the source directory. */ + fun sourceDirectoryId(sourceDirectoryId: String) = + sourceDirectoryId(JsonField.of(sourceDirectoryId)) + + /** + * Sets [Builder.sourceDirectoryId] to an arbitrary JSON value. + * + * You should usually call [Builder.sourceDirectoryId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sourceDirectoryId(sourceDirectoryId: JsonField) = apply { + this.sourceDirectoryId = sourceDirectoryId + } + + /** ID of the sync configuration. */ + fun syncConfigId(syncConfigId: String) = syncConfigId(JsonField.of(syncConfigId)) + + /** + * Sets [Builder.syncConfigId] to an arbitrary JSON value. + * + * You should usually call [Builder.syncConfigId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun syncConfigId(syncConfigId: JsonField) = apply { + this.syncConfigId = syncConfigId + } + + /** Creation datetime */ + fun createdAt(createdAt: OffsetDateTime?) = createdAt(JsonField.ofNullable(createdAt)) + + /** Alias for calling [Builder.createdAt] with `createdAt.orElse(null)`. */ + fun createdAt(createdAt: Optional) = createdAt(createdAt.getOrNull()) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Index description. */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** Last export time. */ + fun lastExportedAt(lastExportedAt: OffsetDateTime?) = + lastExportedAt(JsonField.ofNullable(lastExportedAt)) + + /** Alias for calling [Builder.lastExportedAt] with `lastExportedAt.orElse(null)`. */ + fun lastExportedAt(lastExportedAt: Optional) = + lastExportedAt(lastExportedAt.getOrNull()) + + /** + * Sets [Builder.lastExportedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.lastExportedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastExportedAt(lastExportedAt: JsonField) = apply { + this.lastExportedAt = lastExportedAt + } + + /** Last sync time. */ + fun lastSyncedAt(lastSyncedAt: OffsetDateTime?) = + lastSyncedAt(JsonField.ofNullable(lastSyncedAt)) + + /** Alias for calling [Builder.lastSyncedAt] with `lastSyncedAt.orElse(null)`. */ + fun lastSyncedAt(lastSyncedAt: Optional) = + lastSyncedAt(lastSyncedAt.getOrNull()) + + /** + * Sets [Builder.lastSyncedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.lastSyncedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastSyncedAt(lastSyncedAt: JsonField) = apply { + this.lastSyncedAt = lastSyncedAt + } + + /** Build state and diagnostic info. */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * Whether the index is syncing its source or exporting the result. Requires + * `expand=sync_in_progress`. + */ + fun syncInProgress(syncInProgress: Boolean?) = + syncInProgress(JsonField.ofNullable(syncInProgress)) + + /** + * Alias for [Builder.syncInProgress]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun syncInProgress(syncInProgress: Boolean) = syncInProgress(syncInProgress as Boolean?) + + /** Alias for calling [Builder.syncInProgress] with `syncInProgress.orElse(null)`. */ + fun syncInProgress(syncInProgress: Optional) = + syncInProgress(syncInProgress.getOrNull()) + + /** + * Sets [Builder.syncInProgress] to an arbitrary JSON value. + * + * You should usually call [Builder.syncInProgress] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun syncInProgress(syncInProgress: JsonField) = apply { + this.syncInProgress = syncInProgress + } + + /** Update datetime */ + fun updatedAt(updatedAt: OffsetDateTime?) = updatedAt(JsonField.ofNullable(updatedAt)) + + /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ + fun updatedAt(updatedAt: Optional) = updatedAt(updatedAt.getOrNull()) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + 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 [IndexCreateResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .exportConfigId() + * .name() + * .outputDirectoryId() + * .projectId() + * .sourceDirectoryId() + * .syncConfigId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): IndexCreateResponse = + IndexCreateResponse( + checkRequired("id", id), + checkRequired("exportConfigId", exportConfigId), + checkRequired("name", name), + checkRequired("outputDirectoryId", outputDirectoryId), + checkRequired("projectId", projectId), + checkRequired("sourceDirectoryId", sourceDirectoryId), + checkRequired("syncConfigId", syncConfigId), + createdAt, + description, + lastExportedAt, + lastSyncedAt, + metadata, + syncInProgress, + updatedAt, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): IndexCreateResponse = apply { + if (validated) { + return@apply + } + + id() + exportConfigId() + name() + outputDirectoryId() + projectId() + sourceDirectoryId() + syncConfigId() + createdAt() + description() + lastExportedAt() + lastSyncedAt() + metadata().ifPresent { it.validate() } + syncInProgress() + updatedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (exportConfigId.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (outputDirectoryId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (sourceDirectoryId.asKnown().isPresent) 1 else 0) + + (if (syncConfigId.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (lastExportedAt.asKnown().isPresent) 1 else 0) + + (if (lastSyncedAt.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (syncInProgress.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + /** Build state and diagnostic info. */ + class Metadata + @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 [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IndexCreateResponse && + id == other.id && + exportConfigId == other.exportConfigId && + name == other.name && + outputDirectoryId == other.outputDirectoryId && + projectId == other.projectId && + sourceDirectoryId == other.sourceDirectoryId && + syncConfigId == other.syncConfigId && + createdAt == other.createdAt && + description == other.description && + lastExportedAt == other.lastExportedAt && + lastSyncedAt == other.lastSyncedAt && + metadata == other.metadata && + syncInProgress == other.syncInProgress && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + exportConfigId, + name, + outputDirectoryId, + projectId, + sourceDirectoryId, + syncConfigId, + createdAt, + description, + lastExportedAt, + lastSyncedAt, + metadata, + syncInProgress, + updatedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "IndexCreateResponse{id=$id, exportConfigId=$exportConfigId, name=$name, outputDirectoryId=$outputDirectoryId, projectId=$projectId, sourceDirectoryId=$sourceDirectoryId, syncConfigId=$syncConfigId, createdAt=$createdAt, description=$description, lastExportedAt=$lastExportedAt, lastSyncedAt=$lastSyncedAt, metadata=$metadata, syncInProgress=$syncInProgress, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexDeleteParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexDeleteParams.kt new file mode 100644 index 0000000..0385258 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexDeleteParams.kt @@ -0,0 +1,268 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Delete an index. */ +class IndexDeleteParams +private constructor( + private val indexId: String?, + private val organizationId: String?, + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun indexId(): Optional = Optional.ofNullable(indexId) + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): IndexDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [IndexDeleteParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexDeleteParams]. */ + class Builder internal constructor() { + + private var indexId: String? = null + private var organizationId: String? = null + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(indexDeleteParams: IndexDeleteParams) = apply { + indexId = indexDeleteParams.indexId + organizationId = indexDeleteParams.organizationId + projectId = indexDeleteParams.projectId + additionalHeaders = indexDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = indexDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = indexDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun indexId(indexId: String?) = apply { this.indexId = indexId } + + /** Alias for calling [Builder.indexId] with `indexId.orElse(null)`. */ + fun indexId(indexId: Optional) = indexId(indexId.getOrNull()) + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [IndexDeleteParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): IndexDeleteParams = + IndexDeleteParams( + indexId, + organizationId, + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> indexId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IndexDeleteParams && + indexId == other.indexId && + organizationId == other.organizationId && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + indexId, + organizationId, + projectId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "IndexDeleteParams{indexId=$indexId, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexGetParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexGetParams.kt new file mode 100644 index 0000000..75eb891 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexGetParams.kt @@ -0,0 +1,392 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Get an index by ID. */ +class IndexGetParams +private constructor( + private val indexId: String?, + private val expand: List?, + private val organizationId: String?, + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun indexId(): Optional = Optional.ofNullable(indexId) + + /** Fields to expand. Supported value: sync_in_progress. */ + fun expand(): Optional> = Optional.ofNullable(expand) + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): IndexGetParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [IndexGetParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexGetParams]. */ + class Builder internal constructor() { + + private var indexId: String? = null + private var expand: MutableList? = null + private var organizationId: String? = null + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(indexGetParams: IndexGetParams) = apply { + indexId = indexGetParams.indexId + expand = indexGetParams.expand?.toMutableList() + organizationId = indexGetParams.organizationId + projectId = indexGetParams.projectId + additionalHeaders = indexGetParams.additionalHeaders.toBuilder() + additionalQueryParams = indexGetParams.additionalQueryParams.toBuilder() + } + + fun indexId(indexId: String?) = apply { this.indexId = indexId } + + /** Alias for calling [Builder.indexId] with `indexId.orElse(null)`. */ + fun indexId(indexId: Optional) = indexId(indexId.getOrNull()) + + /** Fields to expand. Supported value: sync_in_progress. */ + fun expand(expand: List?) = apply { this.expand = expand?.toMutableList() } + + /** Alias for calling [Builder.expand] with `expand.orElse(null)`. */ + fun expand(expand: Optional>) = expand(expand.getOrNull()) + + /** + * Adds a single [Expand] to [Builder.expand]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExpand(expand: Expand) = apply { + this.expand = (this.expand ?: mutableListOf()).apply { add(expand) } + } + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [IndexGetParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): IndexGetParams = + IndexGetParams( + indexId, + expand?.toImmutable(), + organizationId, + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> indexId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + expand?.forEach { put("expand", it.toString()) } + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + class Expand @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 SYNC_IN_PROGRESS = of("sync_in_progress") + + @JvmStatic fun of(value: String) = Expand(JsonField.of(value)) + } + + /** An enum containing [Expand]'s known values. */ + enum class Known { + SYNC_IN_PROGRESS + } + + /** + * An enum containing [Expand]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Expand] 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 { + SYNC_IN_PROGRESS, + /** An enum member indicating that [Expand] 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) { + SYNC_IN_PROGRESS -> Value.SYNC_IN_PROGRESS + 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 LlamaCloudInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SYNC_IN_PROGRESS -> Known.SYNC_IN_PROGRESS + else -> throw LlamaCloudInvalidDataException("Unknown Expand: $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 LlamaCloudInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Expand = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Expand && 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 IndexGetParams && + indexId == other.indexId && + expand == other.expand && + organizationId == other.organizationId && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + indexId, + expand, + organizationId, + projectId, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "IndexGetParams{indexId=$indexId, expand=$expand, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexGetResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexGetResponse.kt new file mode 100644 index 0000000..e25f138 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexGetResponse.kt @@ -0,0 +1,888 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A searchable index over a directory of documents. */ +class IndexGetResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val exportConfigId: JsonField, + private val name: JsonField, + private val outputDirectoryId: JsonField, + private val projectId: JsonField, + private val sourceDirectoryId: JsonField, + private val syncConfigId: JsonField, + private val createdAt: JsonField, + private val description: JsonField, + private val lastExportedAt: JsonField, + private val lastSyncedAt: JsonField, + private val metadata: JsonField, + private val syncInProgress: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("export_config_id") + @ExcludeMissing + exportConfigId: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("output_directory_id") + @ExcludeMissing + outputDirectoryId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("source_directory_id") + @ExcludeMissing + sourceDirectoryId: JsonField = JsonMissing.of(), + @JsonProperty("sync_config_id") + @ExcludeMissing + syncConfigId: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("last_exported_at") + @ExcludeMissing + lastExportedAt: JsonField = JsonMissing.of(), + @JsonProperty("last_synced_at") + @ExcludeMissing + lastSyncedAt: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("sync_in_progress") + @ExcludeMissing + syncInProgress: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + ) : this( + id, + exportConfigId, + name, + outputDirectoryId, + projectId, + sourceDirectoryId, + syncConfigId, + createdAt, + description, + lastExportedAt, + lastSyncedAt, + metadata, + syncInProgress, + updatedAt, + mutableMapOf(), + ) + + /** + * Unique identifier + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * ID of the export configuration. + * + * @throws LlamaCloudInvalidDataException 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 exportConfigId(): String = exportConfigId.getRequired("export_config_id") + + /** + * Index name. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * ID of the output directory holding the indexed files. + * + * @throws LlamaCloudInvalidDataException 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 outputDirectoryId(): String = outputDirectoryId.getRequired("output_directory_id") + + /** + * Project this index belongs to. + * + * @throws LlamaCloudInvalidDataException 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 projectId(): String = projectId.getRequired("project_id") + + /** + * ID of the source directory. + * + * @throws LlamaCloudInvalidDataException 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 sourceDirectoryId(): String = sourceDirectoryId.getRequired("source_directory_id") + + /** + * ID of the sync configuration. + * + * @throws LlamaCloudInvalidDataException 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 syncConfigId(): String = syncConfigId.getRequired("sync_config_id") + + /** + * Creation datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * Index description. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Last export time. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastExportedAt(): Optional = lastExportedAt.getOptional("last_exported_at") + + /** + * Last sync time. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastSyncedAt(): Optional = lastSyncedAt.getOptional("last_synced_at") + + /** + * Build state and diagnostic info. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Whether the index is syncing its source or exporting the result. Requires + * `expand=sync_in_progress`. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun syncInProgress(): Optional = syncInProgress.getOptional("sync_in_progress") + + /** + * Update datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [exportConfigId]. + * + * Unlike [exportConfigId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("export_config_id") + @ExcludeMissing + fun _exportConfigId(): JsonField = exportConfigId + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [outputDirectoryId]. + * + * Unlike [outputDirectoryId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("output_directory_id") + @ExcludeMissing + fun _outputDirectoryId(): JsonField = outputDirectoryId + + /** + * 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 [sourceDirectoryId]. + * + * Unlike [sourceDirectoryId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("source_directory_id") + @ExcludeMissing + fun _sourceDirectoryId(): JsonField = sourceDirectoryId + + /** + * Returns the raw JSON value of [syncConfigId]. + * + * Unlike [syncConfigId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sync_config_id") + @ExcludeMissing + fun _syncConfigId(): JsonField = syncConfigId + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [lastExportedAt]. + * + * Unlike [lastExportedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_exported_at") + @ExcludeMissing + fun _lastExportedAt(): JsonField = lastExportedAt + + /** + * Returns the raw JSON value of [lastSyncedAt]. + * + * Unlike [lastSyncedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_synced_at") + @ExcludeMissing + fun _lastSyncedAt(): JsonField = lastSyncedAt + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [syncInProgress]. + * + * Unlike [syncInProgress], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sync_in_progress") + @ExcludeMissing + fun _syncInProgress(): JsonField = syncInProgress + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") + @ExcludeMissing + fun _updatedAt(): JsonField = updatedAt + + @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 [IndexGetResponse]. + * + * The following fields are required: + * ```java + * .id() + * .exportConfigId() + * .name() + * .outputDirectoryId() + * .projectId() + * .sourceDirectoryId() + * .syncConfigId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexGetResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var exportConfigId: JsonField? = null + private var name: JsonField? = null + private var outputDirectoryId: JsonField? = null + private var projectId: JsonField? = null + private var sourceDirectoryId: JsonField? = null + private var syncConfigId: JsonField? = null + private var createdAt: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var lastExportedAt: JsonField = JsonMissing.of() + private var lastSyncedAt: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var syncInProgress: JsonField = JsonMissing.of() + private var updatedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(indexGetResponse: IndexGetResponse) = apply { + id = indexGetResponse.id + exportConfigId = indexGetResponse.exportConfigId + name = indexGetResponse.name + outputDirectoryId = indexGetResponse.outputDirectoryId + projectId = indexGetResponse.projectId + sourceDirectoryId = indexGetResponse.sourceDirectoryId + syncConfigId = indexGetResponse.syncConfigId + createdAt = indexGetResponse.createdAt + description = indexGetResponse.description + lastExportedAt = indexGetResponse.lastExportedAt + lastSyncedAt = indexGetResponse.lastSyncedAt + metadata = indexGetResponse.metadata + syncInProgress = indexGetResponse.syncInProgress + updatedAt = indexGetResponse.updatedAt + additionalProperties = indexGetResponse.additionalProperties.toMutableMap() + } + + /** Unique identifier */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** ID of the export configuration. */ + fun exportConfigId(exportConfigId: String) = exportConfigId(JsonField.of(exportConfigId)) + + /** + * Sets [Builder.exportConfigId] to an arbitrary JSON value. + * + * You should usually call [Builder.exportConfigId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun exportConfigId(exportConfigId: JsonField) = apply { + this.exportConfigId = exportConfigId + } + + /** Index name. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** ID of the output directory holding the indexed files. */ + fun outputDirectoryId(outputDirectoryId: String) = + outputDirectoryId(JsonField.of(outputDirectoryId)) + + /** + * Sets [Builder.outputDirectoryId] to an arbitrary JSON value. + * + * You should usually call [Builder.outputDirectoryId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun outputDirectoryId(outputDirectoryId: JsonField) = apply { + this.outputDirectoryId = outputDirectoryId + } + + /** Project this index belongs to. */ + 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 } + + /** ID of the source directory. */ + fun sourceDirectoryId(sourceDirectoryId: String) = + sourceDirectoryId(JsonField.of(sourceDirectoryId)) + + /** + * Sets [Builder.sourceDirectoryId] to an arbitrary JSON value. + * + * You should usually call [Builder.sourceDirectoryId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sourceDirectoryId(sourceDirectoryId: JsonField) = apply { + this.sourceDirectoryId = sourceDirectoryId + } + + /** ID of the sync configuration. */ + fun syncConfigId(syncConfigId: String) = syncConfigId(JsonField.of(syncConfigId)) + + /** + * Sets [Builder.syncConfigId] to an arbitrary JSON value. + * + * You should usually call [Builder.syncConfigId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun syncConfigId(syncConfigId: JsonField) = apply { + this.syncConfigId = syncConfigId + } + + /** Creation datetime */ + fun createdAt(createdAt: OffsetDateTime?) = createdAt(JsonField.ofNullable(createdAt)) + + /** Alias for calling [Builder.createdAt] with `createdAt.orElse(null)`. */ + fun createdAt(createdAt: Optional) = createdAt(createdAt.getOrNull()) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Index description. */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** Last export time. */ + fun lastExportedAt(lastExportedAt: OffsetDateTime?) = + lastExportedAt(JsonField.ofNullable(lastExportedAt)) + + /** Alias for calling [Builder.lastExportedAt] with `lastExportedAt.orElse(null)`. */ + fun lastExportedAt(lastExportedAt: Optional) = + lastExportedAt(lastExportedAt.getOrNull()) + + /** + * Sets [Builder.lastExportedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.lastExportedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastExportedAt(lastExportedAt: JsonField) = apply { + this.lastExportedAt = lastExportedAt + } + + /** Last sync time. */ + fun lastSyncedAt(lastSyncedAt: OffsetDateTime?) = + lastSyncedAt(JsonField.ofNullable(lastSyncedAt)) + + /** Alias for calling [Builder.lastSyncedAt] with `lastSyncedAt.orElse(null)`. */ + fun lastSyncedAt(lastSyncedAt: Optional) = + lastSyncedAt(lastSyncedAt.getOrNull()) + + /** + * Sets [Builder.lastSyncedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.lastSyncedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastSyncedAt(lastSyncedAt: JsonField) = apply { + this.lastSyncedAt = lastSyncedAt + } + + /** Build state and diagnostic info. */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * Whether the index is syncing its source or exporting the result. Requires + * `expand=sync_in_progress`. + */ + fun syncInProgress(syncInProgress: Boolean?) = + syncInProgress(JsonField.ofNullable(syncInProgress)) + + /** + * Alias for [Builder.syncInProgress]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun syncInProgress(syncInProgress: Boolean) = syncInProgress(syncInProgress as Boolean?) + + /** Alias for calling [Builder.syncInProgress] with `syncInProgress.orElse(null)`. */ + fun syncInProgress(syncInProgress: Optional) = + syncInProgress(syncInProgress.getOrNull()) + + /** + * Sets [Builder.syncInProgress] to an arbitrary JSON value. + * + * You should usually call [Builder.syncInProgress] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun syncInProgress(syncInProgress: JsonField) = apply { + this.syncInProgress = syncInProgress + } + + /** Update datetime */ + fun updatedAt(updatedAt: OffsetDateTime?) = updatedAt(JsonField.ofNullable(updatedAt)) + + /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ + fun updatedAt(updatedAt: Optional) = updatedAt(updatedAt.getOrNull()) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + 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 [IndexGetResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .exportConfigId() + * .name() + * .outputDirectoryId() + * .projectId() + * .sourceDirectoryId() + * .syncConfigId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): IndexGetResponse = + IndexGetResponse( + checkRequired("id", id), + checkRequired("exportConfigId", exportConfigId), + checkRequired("name", name), + checkRequired("outputDirectoryId", outputDirectoryId), + checkRequired("projectId", projectId), + checkRequired("sourceDirectoryId", sourceDirectoryId), + checkRequired("syncConfigId", syncConfigId), + createdAt, + description, + lastExportedAt, + lastSyncedAt, + metadata, + syncInProgress, + updatedAt, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): IndexGetResponse = apply { + if (validated) { + return@apply + } + + id() + exportConfigId() + name() + outputDirectoryId() + projectId() + sourceDirectoryId() + syncConfigId() + createdAt() + description() + lastExportedAt() + lastSyncedAt() + metadata().ifPresent { it.validate() } + syncInProgress() + updatedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (exportConfigId.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (outputDirectoryId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (sourceDirectoryId.asKnown().isPresent) 1 else 0) + + (if (syncConfigId.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (lastExportedAt.asKnown().isPresent) 1 else 0) + + (if (lastSyncedAt.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (syncInProgress.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + /** Build state and diagnostic info. */ + class Metadata + @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 [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IndexGetResponse && + id == other.id && + exportConfigId == other.exportConfigId && + name == other.name && + outputDirectoryId == other.outputDirectoryId && + projectId == other.projectId && + sourceDirectoryId == other.sourceDirectoryId && + syncConfigId == other.syncConfigId && + createdAt == other.createdAt && + description == other.description && + lastExportedAt == other.lastExportedAt && + lastSyncedAt == other.lastSyncedAt && + metadata == other.metadata && + syncInProgress == other.syncInProgress && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + exportConfigId, + name, + outputDirectoryId, + projectId, + sourceDirectoryId, + syncConfigId, + createdAt, + description, + lastExportedAt, + lastSyncedAt, + metadata, + syncInProgress, + updatedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "IndexGetResponse{id=$id, exportConfigId=$exportConfigId, name=$name, outputDirectoryId=$outputDirectoryId, projectId=$projectId, sourceDirectoryId=$sourceDirectoryId, syncConfigId=$syncConfigId, createdAt=$createdAt, description=$description, lastExportedAt=$lastExportedAt, lastSyncedAt=$lastSyncedAt, metadata=$metadata, syncInProgress=$syncInProgress, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListPage.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListPage.kt new file mode 100644 index 0000000..c180196 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListPage.kt @@ -0,0 +1,130 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.AutoPager +import ai.llamaindex.llamacloud.core.Page +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.services.blocking.IndexService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see IndexService.list */ +class IndexListPage +private constructor( + private val service: IndexService, + private val params: IndexListParams, + private val response: IndexListPageResponse, +) : Page { + + /** + * Delegates to [IndexListPageResponse], but gracefully handles missing data. + * + * @see IndexListPageResponse.items + */ + override fun items(): List = + response._items().getOptional("items").getOrNull() ?: emptyList() + + /** + * Delegates to [IndexListPageResponse], but gracefully handles missing data. + * + * @see IndexListPageResponse.nextPageToken + */ + fun nextPageToken(): Optional = response._nextPageToken().getOptional("next_page_token") + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageToken().isPresent + + fun nextPageParams(): IndexListParams { + val nextCursor = + nextPageToken().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().pageToken(nextCursor).build() + } + + override fun nextPage(): IndexListPage = service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): IndexListParams = params + + /** The response that this page was parsed from. */ + fun response(): IndexListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [IndexListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexListPage]. */ + class Builder internal constructor() { + + private var service: IndexService? = null + private var params: IndexListParams? = null + private var response: IndexListPageResponse? = null + + @JvmSynthetic + internal fun from(indexListPage: IndexListPage) = apply { + service = indexListPage.service + params = indexListPage.params + response = indexListPage.response + } + + fun service(service: IndexService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: IndexListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: IndexListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [IndexListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): IndexListPage = + IndexListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IndexListPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = "IndexListPage{service=$service, params=$params, response=$response}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListPageAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListPageAsync.kt new file mode 100644 index 0000000..af2e909 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListPageAsync.kt @@ -0,0 +1,145 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.AutoPagerAsync +import ai.llamaindex.llamacloud.core.PageAsync +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.services.async.IndexServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see IndexServiceAsync.list */ +class IndexListPageAsync +private constructor( + private val service: IndexServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: IndexListParams, + private val response: IndexListPageResponse, +) : PageAsync { + + /** + * Delegates to [IndexListPageResponse], but gracefully handles missing data. + * + * @see IndexListPageResponse.items + */ + override fun items(): List = + response._items().getOptional("items").getOrNull() ?: emptyList() + + /** + * Delegates to [IndexListPageResponse], but gracefully handles missing data. + * + * @see IndexListPageResponse.nextPageToken + */ + fun nextPageToken(): Optional = response._nextPageToken().getOptional("next_page_token") + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageToken().isPresent + + fun nextPageParams(): IndexListParams { + val nextCursor = + nextPageToken().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().pageToken(nextCursor).build() + } + + override fun nextPage(): CompletableFuture = service.list(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) + + /** The parameters that were used to request this page. */ + fun params(): IndexListParams = params + + /** The response that this page was parsed from. */ + fun response(): IndexListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [IndexListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexListPageAsync]. */ + class Builder internal constructor() { + + private var service: IndexServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: IndexListParams? = null + private var response: IndexListPageResponse? = null + + @JvmSynthetic + internal fun from(indexListPageAsync: IndexListPageAsync) = apply { + service = indexListPageAsync.service + streamHandlerExecutor = indexListPageAsync.streamHandlerExecutor + params = indexListPageAsync.params + response = indexListPageAsync.response + } + + fun service(service: IndexServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: IndexListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: IndexListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [IndexListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): IndexListPageAsync = + IndexListPageAsync( + checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IndexListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) + + override fun toString() = + "IndexListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListPageResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListPageResponse.kt new file mode 100644 index 0000000..c4dc1ec --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListPageResponse.kt @@ -0,0 +1,303 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Paginated list of indexes. */ +class IndexListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val items: JsonField>, + private val nextPageToken: JsonField, + private val totalSize: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("items") + @ExcludeMissing + items: JsonField> = JsonMissing.of(), + @JsonProperty("next_page_token") + @ExcludeMissing + nextPageToken: JsonField = JsonMissing.of(), + @JsonProperty("total_size") @ExcludeMissing totalSize: JsonField = JsonMissing.of(), + ) : this(items, nextPageToken, totalSize, mutableMapOf()) + + /** + * The list of items. + * + * @throws LlamaCloudInvalidDataException 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 items(): List = items.getRequired("items") + + /** + * A token, which can be sent as page_token to retrieve the next page. If this field is omitted, + * there are no subsequent pages. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextPageToken(): Optional = nextPageToken.getOptional("next_page_token") + + /** + * The total number of items available. This is only populated when specifically requested. The + * value may be an estimate and can be used for display purposes only. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun totalSize(): Optional = totalSize.getOptional("total_size") + + /** + * Returns the raw JSON value of [items]. + * + * Unlike [items], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("items") @ExcludeMissing fun _items(): JsonField> = items + + /** + * Returns the raw JSON value of [nextPageToken]. + * + * Unlike [nextPageToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_page_token") + @ExcludeMissing + fun _nextPageToken(): JsonField = nextPageToken + + /** + * Returns the raw JSON value of [totalSize]. + * + * Unlike [totalSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("total_size") @ExcludeMissing fun _totalSize(): JsonField = totalSize + + @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 [IndexListPageResponse]. + * + * The following fields are required: + * ```java + * .items() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexListPageResponse]. */ + class Builder internal constructor() { + + private var items: JsonField>? = null + private var nextPageToken: JsonField = JsonMissing.of() + private var totalSize: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(indexListPageResponse: IndexListPageResponse) = apply { + items = indexListPageResponse.items.map { it.toMutableList() } + nextPageToken = indexListPageResponse.nextPageToken + totalSize = indexListPageResponse.totalSize + additionalProperties = indexListPageResponse.additionalProperties.toMutableMap() + } + + /** The list of items. */ + fun items(items: List) = items(JsonField.of(items)) + + /** + * Sets [Builder.items] to an arbitrary JSON value. + * + * You should usually call [Builder.items] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun items(items: JsonField>) = apply { + this.items = items.map { it.toMutableList() } + } + + /** + * Adds a single [IndexListResponse] to [items]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addItem(item: IndexListResponse) = apply { + items = + (items ?: JsonField.of(mutableListOf())).also { checkKnown("items", it).add(item) } + } + + /** + * A token, which can be sent as page_token to retrieve the next page. If this field is + * omitted, there are no subsequent pages. + */ + fun nextPageToken(nextPageToken: String?) = + nextPageToken(JsonField.ofNullable(nextPageToken)) + + /** Alias for calling [Builder.nextPageToken] with `nextPageToken.orElse(null)`. */ + fun nextPageToken(nextPageToken: Optional) = + nextPageToken(nextPageToken.getOrNull()) + + /** + * Sets [Builder.nextPageToken] to an arbitrary JSON value. + * + * You should usually call [Builder.nextPageToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun nextPageToken(nextPageToken: JsonField) = apply { + this.nextPageToken = nextPageToken + } + + /** + * The total number of items available. This is only populated when specifically requested. + * The value may be an estimate and can be used for display purposes only. + */ + fun totalSize(totalSize: Long?) = totalSize(JsonField.ofNullable(totalSize)) + + /** + * Alias for [Builder.totalSize]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalSize(totalSize: Long) = totalSize(totalSize as Long?) + + /** Alias for calling [Builder.totalSize] with `totalSize.orElse(null)`. */ + fun totalSize(totalSize: Optional) = totalSize(totalSize.getOrNull()) + + /** + * Sets [Builder.totalSize] to an arbitrary JSON value. + * + * You should usually call [Builder.totalSize] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun totalSize(totalSize: JsonField) = apply { this.totalSize = totalSize } + + 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 [IndexListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .items() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): IndexListPageResponse = + IndexListPageResponse( + checkRequired("items", items).map { it.toImmutable() }, + nextPageToken, + totalSize, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): IndexListPageResponse = apply { + if (validated) { + return@apply + } + + items().forEach { it.validate() } + nextPageToken() + totalSize() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (items.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (nextPageToken.asKnown().isPresent) 1 else 0) + + (if (totalSize.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IndexListPageResponse && + items == other.items && + nextPageToken == other.nextPageToken && + totalSize == other.totalSize && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(items, nextPageToken, totalSize, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "IndexListPageResponse{items=$items, nextPageToken=$nextPageToken, totalSize=$totalSize, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListParams.kt new file mode 100644 index 0000000..3889e0a --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListParams.kt @@ -0,0 +1,265 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** List indexes for the current project. */ +class IndexListParams +private constructor( + private val organizationId: String?, + private val pageSize: Long?, + private val pageToken: String?, + private val projectId: String?, + private val sourceDirectoryId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun pageSize(): Optional = Optional.ofNullable(pageSize) + + fun pageToken(): Optional = Optional.ofNullable(pageToken) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + fun sourceDirectoryId(): Optional = Optional.ofNullable(sourceDirectoryId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): IndexListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [IndexListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexListParams]. */ + class Builder internal constructor() { + + private var organizationId: String? = null + private var pageSize: Long? = null + private var pageToken: String? = null + private var projectId: String? = null + private var sourceDirectoryId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(indexListParams: IndexListParams) = apply { + organizationId = indexListParams.organizationId + pageSize = indexListParams.pageSize + pageToken = indexListParams.pageToken + projectId = indexListParams.projectId + sourceDirectoryId = indexListParams.sourceDirectoryId + additionalHeaders = indexListParams.additionalHeaders.toBuilder() + additionalQueryParams = indexListParams.additionalQueryParams.toBuilder() + } + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun pageSize(pageSize: Long?) = apply { this.pageSize = pageSize } + + /** + * Alias for [Builder.pageSize]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun pageSize(pageSize: Long) = pageSize(pageSize as Long?) + + /** Alias for calling [Builder.pageSize] with `pageSize.orElse(null)`. */ + fun pageSize(pageSize: Optional) = pageSize(pageSize.getOrNull()) + + fun pageToken(pageToken: String?) = apply { this.pageToken = pageToken } + + /** Alias for calling [Builder.pageToken] with `pageToken.orElse(null)`. */ + fun pageToken(pageToken: Optional) = pageToken(pageToken.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + fun sourceDirectoryId(sourceDirectoryId: String?) = apply { + this.sourceDirectoryId = sourceDirectoryId + } + + /** Alias for calling [Builder.sourceDirectoryId] with `sourceDirectoryId.orElse(null)`. */ + fun sourceDirectoryId(sourceDirectoryId: Optional) = + sourceDirectoryId(sourceDirectoryId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [IndexListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): IndexListParams = + IndexListParams( + organizationId, + pageSize, + pageToken, + projectId, + sourceDirectoryId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + pageSize?.let { put("page_size", it.toString()) } + pageToken?.let { put("page_token", it) } + projectId?.let { put("project_id", it) } + sourceDirectoryId?.let { put("source_directory_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IndexListParams && + organizationId == other.organizationId && + pageSize == other.pageSize && + pageToken == other.pageToken && + projectId == other.projectId && + sourceDirectoryId == other.sourceDirectoryId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + organizationId, + pageSize, + pageToken, + projectId, + sourceDirectoryId, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "IndexListParams{organizationId=$organizationId, pageSize=$pageSize, pageToken=$pageToken, projectId=$projectId, sourceDirectoryId=$sourceDirectoryId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListResponse.kt new file mode 100644 index 0000000..56234d7 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListResponse.kt @@ -0,0 +1,888 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A searchable index over a directory of documents. */ +class IndexListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val exportConfigId: JsonField, + private val name: JsonField, + private val outputDirectoryId: JsonField, + private val projectId: JsonField, + private val sourceDirectoryId: JsonField, + private val syncConfigId: JsonField, + private val createdAt: JsonField, + private val description: JsonField, + private val lastExportedAt: JsonField, + private val lastSyncedAt: JsonField, + private val metadata: JsonField, + private val syncInProgress: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("export_config_id") + @ExcludeMissing + exportConfigId: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("output_directory_id") + @ExcludeMissing + outputDirectoryId: JsonField = JsonMissing.of(), + @JsonProperty("project_id") @ExcludeMissing projectId: JsonField = JsonMissing.of(), + @JsonProperty("source_directory_id") + @ExcludeMissing + sourceDirectoryId: JsonField = JsonMissing.of(), + @JsonProperty("sync_config_id") + @ExcludeMissing + syncConfigId: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("last_exported_at") + @ExcludeMissing + lastExportedAt: JsonField = JsonMissing.of(), + @JsonProperty("last_synced_at") + @ExcludeMissing + lastSyncedAt: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("sync_in_progress") + @ExcludeMissing + syncInProgress: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + ) : this( + id, + exportConfigId, + name, + outputDirectoryId, + projectId, + sourceDirectoryId, + syncConfigId, + createdAt, + description, + lastExportedAt, + lastSyncedAt, + metadata, + syncInProgress, + updatedAt, + mutableMapOf(), + ) + + /** + * Unique identifier + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * ID of the export configuration. + * + * @throws LlamaCloudInvalidDataException 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 exportConfigId(): String = exportConfigId.getRequired("export_config_id") + + /** + * Index name. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * ID of the output directory holding the indexed files. + * + * @throws LlamaCloudInvalidDataException 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 outputDirectoryId(): String = outputDirectoryId.getRequired("output_directory_id") + + /** + * Project this index belongs to. + * + * @throws LlamaCloudInvalidDataException 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 projectId(): String = projectId.getRequired("project_id") + + /** + * ID of the source directory. + * + * @throws LlamaCloudInvalidDataException 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 sourceDirectoryId(): String = sourceDirectoryId.getRequired("source_directory_id") + + /** + * ID of the sync configuration. + * + * @throws LlamaCloudInvalidDataException 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 syncConfigId(): String = syncConfigId.getRequired("sync_config_id") + + /** + * Creation datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * Index description. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * Last export time. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastExportedAt(): Optional = lastExportedAt.getOptional("last_exported_at") + + /** + * Last sync time. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastSyncedAt(): Optional = lastSyncedAt.getOptional("last_synced_at") + + /** + * Build state and diagnostic info. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Whether the index is syncing its source or exporting the result. Requires + * `expand=sync_in_progress`. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun syncInProgress(): Optional = syncInProgress.getOptional("sync_in_progress") + + /** + * Update datetime + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [exportConfigId]. + * + * Unlike [exportConfigId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("export_config_id") + @ExcludeMissing + fun _exportConfigId(): JsonField = exportConfigId + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [outputDirectoryId]. + * + * Unlike [outputDirectoryId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("output_directory_id") + @ExcludeMissing + fun _outputDirectoryId(): JsonField = outputDirectoryId + + /** + * 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 [sourceDirectoryId]. + * + * Unlike [sourceDirectoryId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("source_directory_id") + @ExcludeMissing + fun _sourceDirectoryId(): JsonField = sourceDirectoryId + + /** + * Returns the raw JSON value of [syncConfigId]. + * + * Unlike [syncConfigId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sync_config_id") + @ExcludeMissing + fun _syncConfigId(): JsonField = syncConfigId + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [description]. + * + * Unlike [description], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + + /** + * Returns the raw JSON value of [lastExportedAt]. + * + * Unlike [lastExportedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_exported_at") + @ExcludeMissing + fun _lastExportedAt(): JsonField = lastExportedAt + + /** + * Returns the raw JSON value of [lastSyncedAt]. + * + * Unlike [lastSyncedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_synced_at") + @ExcludeMissing + fun _lastSyncedAt(): JsonField = lastSyncedAt + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [syncInProgress]. + * + * Unlike [syncInProgress], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sync_in_progress") + @ExcludeMissing + fun _syncInProgress(): JsonField = syncInProgress + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") + @ExcludeMissing + fun _updatedAt(): JsonField = updatedAt + + @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 [IndexListResponse]. + * + * The following fields are required: + * ```java + * .id() + * .exportConfigId() + * .name() + * .outputDirectoryId() + * .projectId() + * .sourceDirectoryId() + * .syncConfigId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexListResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var exportConfigId: JsonField? = null + private var name: JsonField? = null + private var outputDirectoryId: JsonField? = null + private var projectId: JsonField? = null + private var sourceDirectoryId: JsonField? = null + private var syncConfigId: JsonField? = null + private var createdAt: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var lastExportedAt: JsonField = JsonMissing.of() + private var lastSyncedAt: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var syncInProgress: JsonField = JsonMissing.of() + private var updatedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(indexListResponse: IndexListResponse) = apply { + id = indexListResponse.id + exportConfigId = indexListResponse.exportConfigId + name = indexListResponse.name + outputDirectoryId = indexListResponse.outputDirectoryId + projectId = indexListResponse.projectId + sourceDirectoryId = indexListResponse.sourceDirectoryId + syncConfigId = indexListResponse.syncConfigId + createdAt = indexListResponse.createdAt + description = indexListResponse.description + lastExportedAt = indexListResponse.lastExportedAt + lastSyncedAt = indexListResponse.lastSyncedAt + metadata = indexListResponse.metadata + syncInProgress = indexListResponse.syncInProgress + updatedAt = indexListResponse.updatedAt + additionalProperties = indexListResponse.additionalProperties.toMutableMap() + } + + /** Unique identifier */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** ID of the export configuration. */ + fun exportConfigId(exportConfigId: String) = exportConfigId(JsonField.of(exportConfigId)) + + /** + * Sets [Builder.exportConfigId] to an arbitrary JSON value. + * + * You should usually call [Builder.exportConfigId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun exportConfigId(exportConfigId: JsonField) = apply { + this.exportConfigId = exportConfigId + } + + /** Index name. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** ID of the output directory holding the indexed files. */ + fun outputDirectoryId(outputDirectoryId: String) = + outputDirectoryId(JsonField.of(outputDirectoryId)) + + /** + * Sets [Builder.outputDirectoryId] to an arbitrary JSON value. + * + * You should usually call [Builder.outputDirectoryId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun outputDirectoryId(outputDirectoryId: JsonField) = apply { + this.outputDirectoryId = outputDirectoryId + } + + /** Project this index belongs to. */ + 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 } + + /** ID of the source directory. */ + fun sourceDirectoryId(sourceDirectoryId: String) = + sourceDirectoryId(JsonField.of(sourceDirectoryId)) + + /** + * Sets [Builder.sourceDirectoryId] to an arbitrary JSON value. + * + * You should usually call [Builder.sourceDirectoryId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sourceDirectoryId(sourceDirectoryId: JsonField) = apply { + this.sourceDirectoryId = sourceDirectoryId + } + + /** ID of the sync configuration. */ + fun syncConfigId(syncConfigId: String) = syncConfigId(JsonField.of(syncConfigId)) + + /** + * Sets [Builder.syncConfigId] to an arbitrary JSON value. + * + * You should usually call [Builder.syncConfigId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun syncConfigId(syncConfigId: JsonField) = apply { + this.syncConfigId = syncConfigId + } + + /** Creation datetime */ + fun createdAt(createdAt: OffsetDateTime?) = createdAt(JsonField.ofNullable(createdAt)) + + /** Alias for calling [Builder.createdAt] with `createdAt.orElse(null)`. */ + fun createdAt(createdAt: Optional) = createdAt(createdAt.getOrNull()) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Index description. */ + fun description(description: String?) = description(JsonField.ofNullable(description)) + + /** Alias for calling [Builder.description] with `description.orElse(null)`. */ + fun description(description: Optional) = description(description.getOrNull()) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** Last export time. */ + fun lastExportedAt(lastExportedAt: OffsetDateTime?) = + lastExportedAt(JsonField.ofNullable(lastExportedAt)) + + /** Alias for calling [Builder.lastExportedAt] with `lastExportedAt.orElse(null)`. */ + fun lastExportedAt(lastExportedAt: Optional) = + lastExportedAt(lastExportedAt.getOrNull()) + + /** + * Sets [Builder.lastExportedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.lastExportedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastExportedAt(lastExportedAt: JsonField) = apply { + this.lastExportedAt = lastExportedAt + } + + /** Last sync time. */ + fun lastSyncedAt(lastSyncedAt: OffsetDateTime?) = + lastSyncedAt(JsonField.ofNullable(lastSyncedAt)) + + /** Alias for calling [Builder.lastSyncedAt] with `lastSyncedAt.orElse(null)`. */ + fun lastSyncedAt(lastSyncedAt: Optional) = + lastSyncedAt(lastSyncedAt.getOrNull()) + + /** + * Sets [Builder.lastSyncedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.lastSyncedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastSyncedAt(lastSyncedAt: JsonField) = apply { + this.lastSyncedAt = lastSyncedAt + } + + /** Build state and diagnostic info. */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** + * Whether the index is syncing its source or exporting the result. Requires + * `expand=sync_in_progress`. + */ + fun syncInProgress(syncInProgress: Boolean?) = + syncInProgress(JsonField.ofNullable(syncInProgress)) + + /** + * Alias for [Builder.syncInProgress]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun syncInProgress(syncInProgress: Boolean) = syncInProgress(syncInProgress as Boolean?) + + /** Alias for calling [Builder.syncInProgress] with `syncInProgress.orElse(null)`. */ + fun syncInProgress(syncInProgress: Optional) = + syncInProgress(syncInProgress.getOrNull()) + + /** + * Sets [Builder.syncInProgress] to an arbitrary JSON value. + * + * You should usually call [Builder.syncInProgress] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun syncInProgress(syncInProgress: JsonField) = apply { + this.syncInProgress = syncInProgress + } + + /** Update datetime */ + fun updatedAt(updatedAt: OffsetDateTime?) = updatedAt(JsonField.ofNullable(updatedAt)) + + /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ + fun updatedAt(updatedAt: Optional) = updatedAt(updatedAt.getOrNull()) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + 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 [IndexListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .exportConfigId() + * .name() + * .outputDirectoryId() + * .projectId() + * .sourceDirectoryId() + * .syncConfigId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): IndexListResponse = + IndexListResponse( + checkRequired("id", id), + checkRequired("exportConfigId", exportConfigId), + checkRequired("name", name), + checkRequired("outputDirectoryId", outputDirectoryId), + checkRequired("projectId", projectId), + checkRequired("sourceDirectoryId", sourceDirectoryId), + checkRequired("syncConfigId", syncConfigId), + createdAt, + description, + lastExportedAt, + lastSyncedAt, + metadata, + syncInProgress, + updatedAt, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): IndexListResponse = apply { + if (validated) { + return@apply + } + + id() + exportConfigId() + name() + outputDirectoryId() + projectId() + sourceDirectoryId() + syncConfigId() + createdAt() + description() + lastExportedAt() + lastSyncedAt() + metadata().ifPresent { it.validate() } + syncInProgress() + updatedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (exportConfigId.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (outputDirectoryId.asKnown().isPresent) 1 else 0) + + (if (projectId.asKnown().isPresent) 1 else 0) + + (if (sourceDirectoryId.asKnown().isPresent) 1 else 0) + + (if (syncConfigId.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (lastExportedAt.asKnown().isPresent) 1 else 0) + + (if (lastSyncedAt.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (syncInProgress.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + /** Build state and diagnostic info. */ + class Metadata + @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 [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IndexListResponse && + id == other.id && + exportConfigId == other.exportConfigId && + name == other.name && + outputDirectoryId == other.outputDirectoryId && + projectId == other.projectId && + sourceDirectoryId == other.sourceDirectoryId && + syncConfigId == other.syncConfigId && + createdAt == other.createdAt && + description == other.description && + lastExportedAt == other.lastExportedAt && + lastSyncedAt == other.lastSyncedAt && + metadata == other.metadata && + syncInProgress == other.syncInProgress && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + exportConfigId, + name, + outputDirectoryId, + projectId, + sourceDirectoryId, + syncConfigId, + createdAt, + description, + lastExportedAt, + lastSyncedAt, + metadata, + syncInProgress, + updatedAt, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "IndexListResponse{id=$id, exportConfigId=$exportConfigId, name=$name, outputDirectoryId=$outputDirectoryId, projectId=$projectId, sourceDirectoryId=$sourceDirectoryId, syncConfigId=$syncConfigId, createdAt=$createdAt, description=$description, lastExportedAt=$lastExportedAt, lastSyncedAt=$lastSyncedAt, metadata=$metadata, syncInProgress=$syncInProgress, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexSyncParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexSyncParams.kt new file mode 100644 index 0000000..2d3309b --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexSyncParams.kt @@ -0,0 +1,271 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Trigger a sync and export for an existing index, re-parsing changed files and exporting updated + * chunks. + */ +class IndexSyncParams +private constructor( + private val indexId: String?, + private val organizationId: String?, + private val projectId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun indexId(): Optional = Optional.ofNullable(indexId) + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): IndexSyncParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [IndexSyncParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexSyncParams]. */ + class Builder internal constructor() { + + private var indexId: String? = null + private var organizationId: String? = null + private var projectId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(indexSyncParams: IndexSyncParams) = apply { + indexId = indexSyncParams.indexId + organizationId = indexSyncParams.organizationId + projectId = indexSyncParams.projectId + additionalHeaders = indexSyncParams.additionalHeaders.toBuilder() + additionalQueryParams = indexSyncParams.additionalQueryParams.toBuilder() + additionalBodyProperties = indexSyncParams.additionalBodyProperties.toMutableMap() + } + + fun indexId(indexId: String?) = apply { this.indexId = indexId } + + /** Alias for calling [Builder.indexId] with `indexId.orElse(null)`. */ + fun indexId(indexId: Optional) = indexId(indexId.getOrNull()) + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [IndexSyncParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): IndexSyncParams = + IndexSyncParams( + indexId, + organizationId, + projectId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> indexId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IndexSyncParams && + indexId == other.indexId && + organizationId == other.organizationId && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + indexId, + organizationId, + projectId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "IndexSyncParams{indexId=$indexId, organizationId=$organizationId, projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexSyncResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexSyncResponse.kt new file mode 100644 index 0000000..f3b9573 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexSyncResponse.kt @@ -0,0 +1,121 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import java.util.Collections +import java.util.Objects + +class IndexSyncResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor(private val additionalProperties: MutableMap) { + + @JsonCreator private constructor() : this(mutableMapOf()) + + @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 [IndexSyncResponse]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [IndexSyncResponse]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(indexSyncResponse: IndexSyncResponse) = apply { + additionalProperties = indexSyncResponse.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 [IndexSyncResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): IndexSyncResponse = IndexSyncResponse(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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): IndexSyncResponse = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = 0 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is IndexSyncResponse && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "IndexSyncResponse{additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/pipelines/LlamaParseParameters.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/pipelines/LlamaParseParameters.kt index ae46367..6247100 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/pipelines/LlamaParseParameters.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/pipelines/LlamaParseParameters.kt @@ -6916,6 +6916,16 @@ private constructor( @JvmField val UNMAPPED_EVENT = of("unmapped_event") + @JvmField val VERIFY_CANCELLED = of("verify.cancelled") + + @JvmField val VERIFY_ERROR = of("verify.error") + + @JvmField val VERIFY_PENDING = of("verify.pending") + + @JvmField val VERIFY_RUNNING = of("verify.running") + + @JvmField val VERIFY_SUCCESS = of("verify.success") + @JvmStatic fun of(value: String) = WebhookEvent(JsonField.of(value)) } @@ -6954,6 +6964,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, } /** @@ -6999,6 +7014,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, /** * An enum member indicating that [WebhookEvent] was instantiated with an unknown * value. @@ -7048,6 +7068,11 @@ private constructor( SPLIT_PROCESSING -> Value.SPLIT_PROCESSING SPLIT_SUCCESS -> Value.SPLIT_SUCCESS UNMAPPED_EVENT -> Value.UNMAPPED_EVENT + VERIFY_CANCELLED -> Value.VERIFY_CANCELLED + VERIFY_ERROR -> Value.VERIFY_ERROR + VERIFY_PENDING -> Value.VERIFY_PENDING + VERIFY_RUNNING -> Value.VERIFY_RUNNING + VERIFY_SUCCESS -> Value.VERIFY_SUCCESS else -> Value._UNKNOWN } @@ -7095,6 +7120,11 @@ private constructor( SPLIT_PROCESSING -> Known.SPLIT_PROCESSING SPLIT_SUCCESS -> Known.SPLIT_SUCCESS UNMAPPED_EVENT -> Known.UNMAPPED_EVENT + VERIFY_CANCELLED -> Known.VERIFY_CANCELLED + VERIFY_ERROR -> Known.VERIFY_ERROR + VERIFY_PENDING -> Known.VERIFY_PENDING + VERIFY_RUNNING -> Known.VERIFY_RUNNING + VERIFY_SUCCESS -> Known.VERIFY_SUCCESS else -> throw LlamaCloudInvalidDataException("Unknown WebhookEvent: $value") } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindPage.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindPage.kt new file mode 100644 index 0000000..3faf154 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindPage.kt @@ -0,0 +1,131 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.AutoPager +import ai.llamaindex.llamacloud.core.Page +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.services.blocking.RetrievalService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see RetrievalService.find */ +class RetrievalFindPage +private constructor( + private val service: RetrievalService, + private val params: RetrievalFindParams, + private val response: RetrievalFindPageResponse, +) : Page { + + /** + * Delegates to [RetrievalFindPageResponse], but gracefully handles missing data. + * + * @see RetrievalFindPageResponse.items + */ + override fun items(): List = + response._items().getOptional("items").getOrNull() ?: emptyList() + + /** + * Delegates to [RetrievalFindPageResponse], but gracefully handles missing data. + * + * @see RetrievalFindPageResponse.nextPageToken + */ + fun nextPageToken(): Optional = response._nextPageToken().getOptional("next_page_token") + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageToken().isPresent + + fun nextPageParams(): RetrievalFindParams { + val nextCursor = + nextPageToken().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().pageToken(nextCursor).build() + } + + override fun nextPage(): RetrievalFindPage = service.find(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): RetrievalFindParams = params + + /** The response that this page was parsed from. */ + fun response(): RetrievalFindPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RetrievalFindPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalFindPage]. */ + class Builder internal constructor() { + + private var service: RetrievalService? = null + private var params: RetrievalFindParams? = null + private var response: RetrievalFindPageResponse? = null + + @JvmSynthetic + internal fun from(retrievalFindPage: RetrievalFindPage) = apply { + service = retrievalFindPage.service + params = retrievalFindPage.params + response = retrievalFindPage.response + } + + fun service(service: RetrievalService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: RetrievalFindParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: RetrievalFindPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [RetrievalFindPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalFindPage = + RetrievalFindPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalFindPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = + "RetrievalFindPage{service=$service, params=$params, response=$response}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindPageAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindPageAsync.kt new file mode 100644 index 0000000..e5c205f --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindPageAsync.kt @@ -0,0 +1,146 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.AutoPagerAsync +import ai.llamaindex.llamacloud.core.PageAsync +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.services.async.RetrievalServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see RetrievalServiceAsync.find */ +class RetrievalFindPageAsync +private constructor( + private val service: RetrievalServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: RetrievalFindParams, + private val response: RetrievalFindPageResponse, +) : PageAsync { + + /** + * Delegates to [RetrievalFindPageResponse], but gracefully handles missing data. + * + * @see RetrievalFindPageResponse.items + */ + override fun items(): List = + response._items().getOptional("items").getOrNull() ?: emptyList() + + /** + * Delegates to [RetrievalFindPageResponse], but gracefully handles missing data. + * + * @see RetrievalFindPageResponse.nextPageToken + */ + fun nextPageToken(): Optional = response._nextPageToken().getOptional("next_page_token") + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageToken().isPresent + + fun nextPageParams(): RetrievalFindParams { + val nextCursor = + nextPageToken().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().pageToken(nextCursor).build() + } + + override fun nextPage(): CompletableFuture = + service.find(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) + + /** The parameters that were used to request this page. */ + fun params(): RetrievalFindParams = params + + /** The response that this page was parsed from. */ + fun response(): RetrievalFindPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RetrievalFindPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalFindPageAsync]. */ + class Builder internal constructor() { + + private var service: RetrievalServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: RetrievalFindParams? = null + private var response: RetrievalFindPageResponse? = null + + @JvmSynthetic + internal fun from(retrievalFindPageAsync: RetrievalFindPageAsync) = apply { + service = retrievalFindPageAsync.service + streamHandlerExecutor = retrievalFindPageAsync.streamHandlerExecutor + params = retrievalFindPageAsync.params + response = retrievalFindPageAsync.response + } + + fun service(service: RetrievalServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: RetrievalFindParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: RetrievalFindPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [RetrievalFindPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalFindPageAsync = + RetrievalFindPageAsync( + checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalFindPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) + + override fun toString() = + "RetrievalFindPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindPageResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindPageResponse.kt new file mode 100644 index 0000000..0ce4fdf --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindPageResponse.kt @@ -0,0 +1,305 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Paginated file find results. */ +class RetrievalFindPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val items: JsonField>, + private val nextPageToken: JsonField, + private val totalSize: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("items") + @ExcludeMissing + items: JsonField> = JsonMissing.of(), + @JsonProperty("next_page_token") + @ExcludeMissing + nextPageToken: JsonField = JsonMissing.of(), + @JsonProperty("total_size") @ExcludeMissing totalSize: JsonField = JsonMissing.of(), + ) : this(items, nextPageToken, totalSize, mutableMapOf()) + + /** + * The list of items. + * + * @throws LlamaCloudInvalidDataException 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 items(): List = items.getRequired("items") + + /** + * A token, which can be sent as page_token to retrieve the next page. If this field is omitted, + * there are no subsequent pages. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextPageToken(): Optional = nextPageToken.getOptional("next_page_token") + + /** + * The total number of items available. This is only populated when specifically requested. The + * value may be an estimate and can be used for display purposes only. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun totalSize(): Optional = totalSize.getOptional("total_size") + + /** + * Returns the raw JSON value of [items]. + * + * Unlike [items], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("items") + @ExcludeMissing + fun _items(): JsonField> = items + + /** + * Returns the raw JSON value of [nextPageToken]. + * + * Unlike [nextPageToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_page_token") + @ExcludeMissing + fun _nextPageToken(): JsonField = nextPageToken + + /** + * Returns the raw JSON value of [totalSize]. + * + * Unlike [totalSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("total_size") @ExcludeMissing fun _totalSize(): JsonField = totalSize + + @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 [RetrievalFindPageResponse]. + * + * The following fields are required: + * ```java + * .items() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalFindPageResponse]. */ + class Builder internal constructor() { + + private var items: JsonField>? = null + private var nextPageToken: JsonField = JsonMissing.of() + private var totalSize: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(retrievalFindPageResponse: RetrievalFindPageResponse) = apply { + items = retrievalFindPageResponse.items.map { it.toMutableList() } + nextPageToken = retrievalFindPageResponse.nextPageToken + totalSize = retrievalFindPageResponse.totalSize + additionalProperties = retrievalFindPageResponse.additionalProperties.toMutableMap() + } + + /** The list of items. */ + fun items(items: List) = items(JsonField.of(items)) + + /** + * Sets [Builder.items] to an arbitrary JSON value. + * + * You should usually call [Builder.items] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun items(items: JsonField>) = apply { + this.items = items.map { it.toMutableList() } + } + + /** + * Adds a single [RetrievalFindResponse] to [items]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addItem(item: RetrievalFindResponse) = apply { + items = + (items ?: JsonField.of(mutableListOf())).also { checkKnown("items", it).add(item) } + } + + /** + * A token, which can be sent as page_token to retrieve the next page. If this field is + * omitted, there are no subsequent pages. + */ + fun nextPageToken(nextPageToken: String?) = + nextPageToken(JsonField.ofNullable(nextPageToken)) + + /** Alias for calling [Builder.nextPageToken] with `nextPageToken.orElse(null)`. */ + fun nextPageToken(nextPageToken: Optional) = + nextPageToken(nextPageToken.getOrNull()) + + /** + * Sets [Builder.nextPageToken] to an arbitrary JSON value. + * + * You should usually call [Builder.nextPageToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun nextPageToken(nextPageToken: JsonField) = apply { + this.nextPageToken = nextPageToken + } + + /** + * The total number of items available. This is only populated when specifically requested. + * The value may be an estimate and can be used for display purposes only. + */ + fun totalSize(totalSize: Long?) = totalSize(JsonField.ofNullable(totalSize)) + + /** + * Alias for [Builder.totalSize]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalSize(totalSize: Long) = totalSize(totalSize as Long?) + + /** Alias for calling [Builder.totalSize] with `totalSize.orElse(null)`. */ + fun totalSize(totalSize: Optional) = totalSize(totalSize.getOrNull()) + + /** + * Sets [Builder.totalSize] to an arbitrary JSON value. + * + * You should usually call [Builder.totalSize] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun totalSize(totalSize: JsonField) = apply { this.totalSize = totalSize } + + 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 [RetrievalFindPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .items() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalFindPageResponse = + RetrievalFindPageResponse( + checkRequired("items", items).map { it.toImmutable() }, + nextPageToken, + totalSize, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RetrievalFindPageResponse = apply { + if (validated) { + return@apply + } + + items().forEach { it.validate() } + nextPageToken() + totalSize() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (items.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (nextPageToken.asKnown().isPresent) 1 else 0) + + (if (totalSize.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalFindPageResponse && + items == other.items && + nextPageToken == other.nextPageToken && + totalSize == other.totalSize && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(items, nextPageToken, totalSize, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RetrievalFindPageResponse{items=$items, nextPageToken=$nextPageToken, totalSize=$totalSize, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindParams.kt new file mode 100644 index 0000000..e462ddd --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindParams.kt @@ -0,0 +1,805 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Search for files by name. */ +class RetrievalFindParams +private constructor( + private val organizationId: String?, + private val projectId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * ID of the index to search within. + * + * @throws LlamaCloudInvalidDataException 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 indexId(): String = body.indexId() + + /** + * Exact file name to match. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fileName(): Optional = body.fileName() + + /** + * Substring match on file name (case-insensitive). + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fileNameContains(): Optional = body.fileNameContains() + + /** + * The maximum number of items to return. The service may return fewer than this value. If + * unspecified, a default page size will be used. The maximum value is typically 1000; values + * above this will be coerced to the maximum. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun pageSize(): Optional = body.pageSize() + + /** + * A page token, received from a previous list call. Provide this to retrieve the subsequent + * page. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun pageToken(): Optional = body.pageToken() + + /** + * Returns the raw JSON value of [indexId]. + * + * Unlike [indexId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _indexId(): JsonField = body._indexId() + + /** + * Returns the raw JSON value of [fileName]. + * + * Unlike [fileName], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _fileName(): JsonField = body._fileName() + + /** + * Returns the raw JSON value of [fileNameContains]. + * + * Unlike [fileNameContains], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _fileNameContains(): JsonField = body._fileNameContains() + + /** + * Returns the raw JSON value of [pageSize]. + * + * Unlike [pageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _pageSize(): JsonField = body._pageSize() + + /** + * Returns the raw JSON value of [pageToken]. + * + * Unlike [pageToken], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _pageToken(): JsonField = body._pageToken() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RetrievalFindParams]. + * + * The following fields are required: + * ```java + * .indexId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalFindParams]. */ + class Builder internal constructor() { + + private var organizationId: String? = null + private var projectId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(retrievalFindParams: RetrievalFindParams) = apply { + organizationId = retrievalFindParams.organizationId + projectId = retrievalFindParams.projectId + body = retrievalFindParams.body.toBuilder() + additionalHeaders = retrievalFindParams.additionalHeaders.toBuilder() + additionalQueryParams = retrievalFindParams.additionalQueryParams.toBuilder() + } + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [indexId] + * - [fileName] + * - [fileNameContains] + * - [pageSize] + * - [pageToken] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** ID of the index to search within. */ + fun indexId(indexId: String) = apply { body.indexId(indexId) } + + /** + * Sets [Builder.indexId] to an arbitrary JSON value. + * + * You should usually call [Builder.indexId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun indexId(indexId: JsonField) = apply { body.indexId(indexId) } + + /** Exact file name to match. */ + fun fileName(fileName: String?) = apply { body.fileName(fileName) } + + /** Alias for calling [Builder.fileName] with `fileName.orElse(null)`. */ + fun fileName(fileName: Optional) = fileName(fileName.getOrNull()) + + /** + * Sets [Builder.fileName] to an arbitrary JSON value. + * + * You should usually call [Builder.fileName] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun fileName(fileName: JsonField) = apply { body.fileName(fileName) } + + /** Substring match on file name (case-insensitive). */ + fun fileNameContains(fileNameContains: String?) = apply { + body.fileNameContains(fileNameContains) + } + + /** Alias for calling [Builder.fileNameContains] with `fileNameContains.orElse(null)`. */ + fun fileNameContains(fileNameContains: Optional) = + fileNameContains(fileNameContains.getOrNull()) + + /** + * Sets [Builder.fileNameContains] to an arbitrary JSON value. + * + * You should usually call [Builder.fileNameContains] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileNameContains(fileNameContains: JsonField) = apply { + body.fileNameContains(fileNameContains) + } + + /** + * The maximum number of items to return. The service may return fewer than this value. If + * unspecified, a default page size will be used. The maximum value is typically 1000; + * values above this will be coerced to the maximum. + */ + fun pageSize(pageSize: Long?) = apply { body.pageSize(pageSize) } + + /** + * Alias for [Builder.pageSize]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun pageSize(pageSize: Long) = pageSize(pageSize as Long?) + + /** Alias for calling [Builder.pageSize] with `pageSize.orElse(null)`. */ + fun pageSize(pageSize: Optional) = pageSize(pageSize.getOrNull()) + + /** + * Sets [Builder.pageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.pageSize] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun pageSize(pageSize: JsonField) = apply { body.pageSize(pageSize) } + + /** + * A page token, received from a previous list call. Provide this to retrieve the subsequent + * page. + */ + fun pageToken(pageToken: String?) = apply { body.pageToken(pageToken) } + + /** Alias for calling [Builder.pageToken] with `pageToken.orElse(null)`. */ + fun pageToken(pageToken: Optional) = pageToken(pageToken.getOrNull()) + + /** + * Sets [Builder.pageToken] to an arbitrary JSON value. + * + * You should usually call [Builder.pageToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun pageToken(pageToken: JsonField) = apply { body.pageToken(pageToken) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [RetrievalFindParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .indexId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalFindParams = + RetrievalFindParams( + organizationId, + projectId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + /** Search for files by name. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val indexId: JsonField, + private val fileName: JsonField, + private val fileNameContains: JsonField, + private val pageSize: JsonField, + private val pageToken: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("index_id") @ExcludeMissing indexId: JsonField = JsonMissing.of(), + @JsonProperty("file_name") + @ExcludeMissing + fileName: JsonField = JsonMissing.of(), + @JsonProperty("file_name_contains") + @ExcludeMissing + fileNameContains: JsonField = JsonMissing.of(), + @JsonProperty("page_size") @ExcludeMissing pageSize: JsonField = JsonMissing.of(), + @JsonProperty("page_token") + @ExcludeMissing + pageToken: JsonField = JsonMissing.of(), + ) : this(indexId, fileName, fileNameContains, pageSize, pageToken, mutableMapOf()) + + /** + * ID of the index to search within. + * + * @throws LlamaCloudInvalidDataException 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 indexId(): String = indexId.getRequired("index_id") + + /** + * Exact file name to match. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fileName(): Optional = fileName.getOptional("file_name") + + /** + * Substring match on file name (case-insensitive). + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fileNameContains(): Optional = + fileNameContains.getOptional("file_name_contains") + + /** + * The maximum number of items to return. The service may return fewer than this value. If + * unspecified, a default page size will be used. The maximum value is typically 1000; + * values above this will be coerced to the maximum. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun pageSize(): Optional = pageSize.getOptional("page_size") + + /** + * A page token, received from a previous list call. Provide this to retrieve the subsequent + * page. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun pageToken(): Optional = pageToken.getOptional("page_token") + + /** + * Returns the raw JSON value of [indexId]. + * + * Unlike [indexId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("index_id") @ExcludeMissing fun _indexId(): JsonField = indexId + + /** + * Returns the raw JSON value of [fileName]. + * + * Unlike [fileName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_name") @ExcludeMissing fun _fileName(): JsonField = fileName + + /** + * Returns the raw JSON value of [fileNameContains]. + * + * Unlike [fileNameContains], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("file_name_contains") + @ExcludeMissing + fun _fileNameContains(): JsonField = fileNameContains + + /** + * Returns the raw JSON value of [pageSize]. + * + * Unlike [pageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page_size") @ExcludeMissing fun _pageSize(): JsonField = pageSize + + /** + * Returns the raw JSON value of [pageToken]. + * + * Unlike [pageToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page_token") @ExcludeMissing fun _pageToken(): JsonField = pageToken + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .indexId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var indexId: JsonField? = null + private var fileName: JsonField = JsonMissing.of() + private var fileNameContains: JsonField = JsonMissing.of() + private var pageSize: JsonField = JsonMissing.of() + private var pageToken: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + indexId = body.indexId + fileName = body.fileName + fileNameContains = body.fileNameContains + pageSize = body.pageSize + pageToken = body.pageToken + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** ID of the index to search within. */ + fun indexId(indexId: String) = indexId(JsonField.of(indexId)) + + /** + * Sets [Builder.indexId] to an arbitrary JSON value. + * + * You should usually call [Builder.indexId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun indexId(indexId: JsonField) = apply { this.indexId = indexId } + + /** Exact file name to match. */ + fun fileName(fileName: String?) = fileName(JsonField.ofNullable(fileName)) + + /** Alias for calling [Builder.fileName] with `fileName.orElse(null)`. */ + fun fileName(fileName: Optional) = fileName(fileName.getOrNull()) + + /** + * Sets [Builder.fileName] to an arbitrary JSON value. + * + * You should usually call [Builder.fileName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileName(fileName: JsonField) = apply { this.fileName = fileName } + + /** Substring match on file name (case-insensitive). */ + fun fileNameContains(fileNameContains: String?) = + fileNameContains(JsonField.ofNullable(fileNameContains)) + + /** + * Alias for calling [Builder.fileNameContains] with `fileNameContains.orElse(null)`. + */ + fun fileNameContains(fileNameContains: Optional) = + fileNameContains(fileNameContains.getOrNull()) + + /** + * Sets [Builder.fileNameContains] to an arbitrary JSON value. + * + * You should usually call [Builder.fileNameContains] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileNameContains(fileNameContains: JsonField) = apply { + this.fileNameContains = fileNameContains + } + + /** + * The maximum number of items to return. The service may return fewer than this value. + * If unspecified, a default page size will be used. The maximum value is typically + * 1000; values above this will be coerced to the maximum. + */ + fun pageSize(pageSize: Long?) = pageSize(JsonField.ofNullable(pageSize)) + + /** + * Alias for [Builder.pageSize]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun pageSize(pageSize: Long) = pageSize(pageSize as Long?) + + /** Alias for calling [Builder.pageSize] with `pageSize.orElse(null)`. */ + fun pageSize(pageSize: Optional) = pageSize(pageSize.getOrNull()) + + /** + * Sets [Builder.pageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.pageSize] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pageSize(pageSize: JsonField) = apply { this.pageSize = pageSize } + + /** + * A page token, received from a previous list call. Provide this to retrieve the + * subsequent page. + */ + fun pageToken(pageToken: String?) = pageToken(JsonField.ofNullable(pageToken)) + + /** Alias for calling [Builder.pageToken] with `pageToken.orElse(null)`. */ + fun pageToken(pageToken: Optional) = pageToken(pageToken.getOrNull()) + + /** + * Sets [Builder.pageToken] to an arbitrary JSON value. + * + * You should usually call [Builder.pageToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pageToken(pageToken: JsonField) = apply { this.pageToken = pageToken } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .indexId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("indexId", indexId), + fileName, + fileNameContains, + pageSize, + pageToken, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + indexId() + fileName() + fileNameContains() + pageSize() + pageToken() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (indexId.asKnown().isPresent) 1 else 0) + + (if (fileName.asKnown().isPresent) 1 else 0) + + (if (fileNameContains.asKnown().isPresent) 1 else 0) + + (if (pageSize.asKnown().isPresent) 1 else 0) + + (if (pageToken.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + indexId == other.indexId && + fileName == other.fileName && + fileNameContains == other.fileNameContains && + pageSize == other.pageSize && + pageToken == other.pageToken && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + indexId, + fileName, + fileNameContains, + pageSize, + pageToken, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{indexId=$indexId, fileName=$fileName, fileNameContains=$fileNameContains, pageSize=$pageSize, pageToken=$pageToken, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalFindParams && + organizationId == other.organizationId && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(organizationId, projectId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RetrievalFindParams{organizationId=$organizationId, projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindResponse.kt new file mode 100644 index 0000000..46dbf4f --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindResponse.kt @@ -0,0 +1,219 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects + +/** A file returned by find. */ +class RetrievalFindResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val fileId: JsonField, + private val fileName: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("file_id") @ExcludeMissing fileId: JsonField = JsonMissing.of(), + @JsonProperty("file_name") @ExcludeMissing fileName: JsonField = JsonMissing.of(), + ) : this(fileId, fileName, mutableMapOf()) + + /** + * ID of the file. + * + * @throws LlamaCloudInvalidDataException 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 fileId(): String = fileId.getRequired("file_id") + + /** + * Display name of the file. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun fileName(): String = fileName.getRequired("file_name") + + /** + * Returns the raw JSON value of [fileId]. + * + * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_id") @ExcludeMissing fun _fileId(): JsonField = fileId + + /** + * Returns the raw JSON value of [fileName]. + * + * Unlike [fileName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_name") @ExcludeMissing fun _fileName(): JsonField = fileName + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RetrievalFindResponse]. + * + * The following fields are required: + * ```java + * .fileId() + * .fileName() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalFindResponse]. */ + class Builder internal constructor() { + + private var fileId: JsonField? = null + private var fileName: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(retrievalFindResponse: RetrievalFindResponse) = apply { + fileId = retrievalFindResponse.fileId + fileName = retrievalFindResponse.fileName + additionalProperties = retrievalFindResponse.additionalProperties.toMutableMap() + } + + /** ID of the file. */ + fun fileId(fileId: String) = fileId(JsonField.of(fileId)) + + /** + * Sets [Builder.fileId] to an arbitrary JSON value. + * + * You should usually call [Builder.fileId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun fileId(fileId: JsonField) = apply { this.fileId = fileId } + + /** Display name of the file. */ + fun fileName(fileName: String) = fileName(JsonField.of(fileName)) + + /** + * Sets [Builder.fileName] to an arbitrary JSON value. + * + * You should usually call [Builder.fileName] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun fileName(fileName: JsonField) = apply { this.fileName = fileName } + + 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 [RetrievalFindResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fileId() + * .fileName() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalFindResponse = + RetrievalFindResponse( + checkRequired("fileId", fileId), + checkRequired("fileName", fileName), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RetrievalFindResponse = apply { + if (validated) { + return@apply + } + + fileId() + fileName() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (fileId.asKnown().isPresent) 1 else 0) + (if (fileName.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalFindResponse && + fileId == other.fileId && + fileName == other.fileName && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(fileId, fileName, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RetrievalFindResponse{fileId=$fileId, fileName=$fileName, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepPage.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepPage.kt new file mode 100644 index 0000000..f927228 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepPage.kt @@ -0,0 +1,131 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.AutoPager +import ai.llamaindex.llamacloud.core.Page +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.services.blocking.RetrievalService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see RetrievalService.grep */ +class RetrievalGrepPage +private constructor( + private val service: RetrievalService, + private val params: RetrievalGrepParams, + private val response: RetrievalGrepPageResponse, +) : Page { + + /** + * Delegates to [RetrievalGrepPageResponse], but gracefully handles missing data. + * + * @see RetrievalGrepPageResponse.items + */ + override fun items(): List = + response._items().getOptional("items").getOrNull() ?: emptyList() + + /** + * Delegates to [RetrievalGrepPageResponse], but gracefully handles missing data. + * + * @see RetrievalGrepPageResponse.nextPageToken + */ + fun nextPageToken(): Optional = response._nextPageToken().getOptional("next_page_token") + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageToken().isPresent + + fun nextPageParams(): RetrievalGrepParams { + val nextCursor = + nextPageToken().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().pageToken(nextCursor).build() + } + + override fun nextPage(): RetrievalGrepPage = service.grep(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): RetrievalGrepParams = params + + /** The response that this page was parsed from. */ + fun response(): RetrievalGrepPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RetrievalGrepPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalGrepPage]. */ + class Builder internal constructor() { + + private var service: RetrievalService? = null + private var params: RetrievalGrepParams? = null + private var response: RetrievalGrepPageResponse? = null + + @JvmSynthetic + internal fun from(retrievalGrepPage: RetrievalGrepPage) = apply { + service = retrievalGrepPage.service + params = retrievalGrepPage.params + response = retrievalGrepPage.response + } + + fun service(service: RetrievalService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: RetrievalGrepParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: RetrievalGrepPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [RetrievalGrepPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalGrepPage = + RetrievalGrepPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalGrepPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = + "RetrievalGrepPage{service=$service, params=$params, response=$response}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepPageAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepPageAsync.kt new file mode 100644 index 0000000..07b8792 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepPageAsync.kt @@ -0,0 +1,146 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.AutoPagerAsync +import ai.llamaindex.llamacloud.core.PageAsync +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.services.async.RetrievalServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see RetrievalServiceAsync.grep */ +class RetrievalGrepPageAsync +private constructor( + private val service: RetrievalServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: RetrievalGrepParams, + private val response: RetrievalGrepPageResponse, +) : PageAsync { + + /** + * Delegates to [RetrievalGrepPageResponse], but gracefully handles missing data. + * + * @see RetrievalGrepPageResponse.items + */ + override fun items(): List = + response._items().getOptional("items").getOrNull() ?: emptyList() + + /** + * Delegates to [RetrievalGrepPageResponse], but gracefully handles missing data. + * + * @see RetrievalGrepPageResponse.nextPageToken + */ + fun nextPageToken(): Optional = response._nextPageToken().getOptional("next_page_token") + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageToken().isPresent + + fun nextPageParams(): RetrievalGrepParams { + val nextCursor = + nextPageToken().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().pageToken(nextCursor).build() + } + + override fun nextPage(): CompletableFuture = + service.grep(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) + + /** The parameters that were used to request this page. */ + fun params(): RetrievalGrepParams = params + + /** The response that this page was parsed from. */ + fun response(): RetrievalGrepPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RetrievalGrepPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalGrepPageAsync]. */ + class Builder internal constructor() { + + private var service: RetrievalServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: RetrievalGrepParams? = null + private var response: RetrievalGrepPageResponse? = null + + @JvmSynthetic + internal fun from(retrievalGrepPageAsync: RetrievalGrepPageAsync) = apply { + service = retrievalGrepPageAsync.service + streamHandlerExecutor = retrievalGrepPageAsync.streamHandlerExecutor + params = retrievalGrepPageAsync.params + response = retrievalGrepPageAsync.response + } + + fun service(service: RetrievalServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: RetrievalGrepParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: RetrievalGrepPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [RetrievalGrepPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalGrepPageAsync = + RetrievalGrepPageAsync( + checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalGrepPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) + + override fun toString() = + "RetrievalGrepPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepPageResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepPageResponse.kt new file mode 100644 index 0000000..11d23e1 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepPageResponse.kt @@ -0,0 +1,305 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Paginated grep results for a file. */ +class RetrievalGrepPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val items: JsonField>, + private val nextPageToken: JsonField, + private val totalSize: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("items") + @ExcludeMissing + items: JsonField> = JsonMissing.of(), + @JsonProperty("next_page_token") + @ExcludeMissing + nextPageToken: JsonField = JsonMissing.of(), + @JsonProperty("total_size") @ExcludeMissing totalSize: JsonField = JsonMissing.of(), + ) : this(items, nextPageToken, totalSize, mutableMapOf()) + + /** + * The list of items. + * + * @throws LlamaCloudInvalidDataException 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 items(): List = items.getRequired("items") + + /** + * A token, which can be sent as page_token to retrieve the next page. If this field is omitted, + * there are no subsequent pages. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextPageToken(): Optional = nextPageToken.getOptional("next_page_token") + + /** + * The total number of items available. This is only populated when specifically requested. The + * value may be an estimate and can be used for display purposes only. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun totalSize(): Optional = totalSize.getOptional("total_size") + + /** + * Returns the raw JSON value of [items]. + * + * Unlike [items], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("items") + @ExcludeMissing + fun _items(): JsonField> = items + + /** + * Returns the raw JSON value of [nextPageToken]. + * + * Unlike [nextPageToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_page_token") + @ExcludeMissing + fun _nextPageToken(): JsonField = nextPageToken + + /** + * Returns the raw JSON value of [totalSize]. + * + * Unlike [totalSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("total_size") @ExcludeMissing fun _totalSize(): JsonField = totalSize + + @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 [RetrievalGrepPageResponse]. + * + * The following fields are required: + * ```java + * .items() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalGrepPageResponse]. */ + class Builder internal constructor() { + + private var items: JsonField>? = null + private var nextPageToken: JsonField = JsonMissing.of() + private var totalSize: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(retrievalGrepPageResponse: RetrievalGrepPageResponse) = apply { + items = retrievalGrepPageResponse.items.map { it.toMutableList() } + nextPageToken = retrievalGrepPageResponse.nextPageToken + totalSize = retrievalGrepPageResponse.totalSize + additionalProperties = retrievalGrepPageResponse.additionalProperties.toMutableMap() + } + + /** The list of items. */ + fun items(items: List) = items(JsonField.of(items)) + + /** + * Sets [Builder.items] to an arbitrary JSON value. + * + * You should usually call [Builder.items] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun items(items: JsonField>) = apply { + this.items = items.map { it.toMutableList() } + } + + /** + * Adds a single [RetrievalGrepResponse] to [items]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addItem(item: RetrievalGrepResponse) = apply { + items = + (items ?: JsonField.of(mutableListOf())).also { checkKnown("items", it).add(item) } + } + + /** + * A token, which can be sent as page_token to retrieve the next page. If this field is + * omitted, there are no subsequent pages. + */ + fun nextPageToken(nextPageToken: String?) = + nextPageToken(JsonField.ofNullable(nextPageToken)) + + /** Alias for calling [Builder.nextPageToken] with `nextPageToken.orElse(null)`. */ + fun nextPageToken(nextPageToken: Optional) = + nextPageToken(nextPageToken.getOrNull()) + + /** + * Sets [Builder.nextPageToken] to an arbitrary JSON value. + * + * You should usually call [Builder.nextPageToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun nextPageToken(nextPageToken: JsonField) = apply { + this.nextPageToken = nextPageToken + } + + /** + * The total number of items available. This is only populated when specifically requested. + * The value may be an estimate and can be used for display purposes only. + */ + fun totalSize(totalSize: Long?) = totalSize(JsonField.ofNullable(totalSize)) + + /** + * Alias for [Builder.totalSize]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun totalSize(totalSize: Long) = totalSize(totalSize as Long?) + + /** Alias for calling [Builder.totalSize] with `totalSize.orElse(null)`. */ + fun totalSize(totalSize: Optional) = totalSize(totalSize.getOrNull()) + + /** + * Sets [Builder.totalSize] to an arbitrary JSON value. + * + * You should usually call [Builder.totalSize] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun totalSize(totalSize: JsonField) = apply { this.totalSize = totalSize } + + 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 [RetrievalGrepPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .items() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalGrepPageResponse = + RetrievalGrepPageResponse( + checkRequired("items", items).map { it.toImmutable() }, + nextPageToken, + totalSize, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RetrievalGrepPageResponse = apply { + if (validated) { + return@apply + } + + items().forEach { it.validate() } + nextPageToken() + totalSize() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (items.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (nextPageToken.asKnown().isPresent) 1 else 0) + + (if (totalSize.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalGrepPageResponse && + items == other.items && + nextPageToken == other.nextPageToken && + totalSize == other.totalSize && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(items, nextPageToken, totalSize, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RetrievalGrepPageResponse{items=$items, nextPageToken=$nextPageToken, totalSize=$totalSize, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepParams.kt new file mode 100644 index 0000000..bd194ac --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepParams.kt @@ -0,0 +1,878 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Grep within a file's parsed content using a regex pattern. */ +class RetrievalGrepParams +private constructor( + private val organizationId: String?, + private val projectId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * ID of the file to grep. + * + * @throws LlamaCloudInvalidDataException 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 fileId(): String = body.fileId() + + /** + * ID of the index the file belongs to. + * + * @throws LlamaCloudInvalidDataException 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 indexId(): String = body.indexId() + + /** + * Regex pattern to search for. + * + * @throws LlamaCloudInvalidDataException 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 pattern(): String = body.pattern() + + /** + * Number of characters of context to include before and after the matched pattern in the + * content field of the response + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun contextChars(): Optional = body.contextChars() + + /** + * The maximum number of items to return. The service may return fewer than this value. If + * unspecified, a default page size will be used. The maximum value is typically 1000; values + * above this will be coerced to the maximum. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun pageSize(): Optional = body.pageSize() + + /** + * A page token, received from a previous list call. Provide this to retrieve the subsequent + * page. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun pageToken(): Optional = body.pageToken() + + /** + * Returns the raw JSON value of [fileId]. + * + * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _fileId(): JsonField = body._fileId() + + /** + * Returns the raw JSON value of [indexId]. + * + * Unlike [indexId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _indexId(): JsonField = body._indexId() + + /** + * Returns the raw JSON value of [pattern]. + * + * Unlike [pattern], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _pattern(): JsonField = body._pattern() + + /** + * Returns the raw JSON value of [contextChars]. + * + * Unlike [contextChars], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _contextChars(): JsonField = body._contextChars() + + /** + * Returns the raw JSON value of [pageSize]. + * + * Unlike [pageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _pageSize(): JsonField = body._pageSize() + + /** + * Returns the raw JSON value of [pageToken]. + * + * Unlike [pageToken], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _pageToken(): JsonField = body._pageToken() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RetrievalGrepParams]. + * + * The following fields are required: + * ```java + * .fileId() + * .indexId() + * .pattern() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalGrepParams]. */ + class Builder internal constructor() { + + private var organizationId: String? = null + private var projectId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(retrievalGrepParams: RetrievalGrepParams) = apply { + organizationId = retrievalGrepParams.organizationId + projectId = retrievalGrepParams.projectId + body = retrievalGrepParams.body.toBuilder() + additionalHeaders = retrievalGrepParams.additionalHeaders.toBuilder() + additionalQueryParams = retrievalGrepParams.additionalQueryParams.toBuilder() + } + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [fileId] + * - [indexId] + * - [pattern] + * - [contextChars] + * - [pageSize] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** ID of the file to grep. */ + fun fileId(fileId: String) = apply { body.fileId(fileId) } + + /** + * Sets [Builder.fileId] to an arbitrary JSON value. + * + * You should usually call [Builder.fileId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun fileId(fileId: JsonField) = apply { body.fileId(fileId) } + + /** ID of the index the file belongs to. */ + fun indexId(indexId: String) = apply { body.indexId(indexId) } + + /** + * Sets [Builder.indexId] to an arbitrary JSON value. + * + * You should usually call [Builder.indexId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun indexId(indexId: JsonField) = apply { body.indexId(indexId) } + + /** Regex pattern to search for. */ + fun pattern(pattern: String) = apply { body.pattern(pattern) } + + /** + * Sets [Builder.pattern] to an arbitrary JSON value. + * + * You should usually call [Builder.pattern] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun pattern(pattern: JsonField) = apply { body.pattern(pattern) } + + /** + * Number of characters of context to include before and after the matched pattern in the + * content field of the response + */ + fun contextChars(contextChars: Long?) = apply { body.contextChars(contextChars) } + + /** + * Alias for [Builder.contextChars]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun contextChars(contextChars: Long) = contextChars(contextChars as Long?) + + /** Alias for calling [Builder.contextChars] with `contextChars.orElse(null)`. */ + fun contextChars(contextChars: Optional) = contextChars(contextChars.getOrNull()) + + /** + * Sets [Builder.contextChars] to an arbitrary JSON value. + * + * You should usually call [Builder.contextChars] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun contextChars(contextChars: JsonField) = apply { body.contextChars(contextChars) } + + /** + * The maximum number of items to return. The service may return fewer than this value. If + * unspecified, a default page size will be used. The maximum value is typically 1000; + * values above this will be coerced to the maximum. + */ + fun pageSize(pageSize: Long?) = apply { body.pageSize(pageSize) } + + /** + * Alias for [Builder.pageSize]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun pageSize(pageSize: Long) = pageSize(pageSize as Long?) + + /** Alias for calling [Builder.pageSize] with `pageSize.orElse(null)`. */ + fun pageSize(pageSize: Optional) = pageSize(pageSize.getOrNull()) + + /** + * Sets [Builder.pageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.pageSize] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun pageSize(pageSize: JsonField) = apply { body.pageSize(pageSize) } + + /** + * A page token, received from a previous list call. Provide this to retrieve the subsequent + * page. + */ + fun pageToken(pageToken: String?) = apply { body.pageToken(pageToken) } + + /** Alias for calling [Builder.pageToken] with `pageToken.orElse(null)`. */ + fun pageToken(pageToken: Optional) = pageToken(pageToken.getOrNull()) + + /** + * Sets [Builder.pageToken] to an arbitrary JSON value. + * + * You should usually call [Builder.pageToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun pageToken(pageToken: JsonField) = apply { body.pageToken(pageToken) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [RetrievalGrepParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fileId() + * .indexId() + * .pattern() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalGrepParams = + RetrievalGrepParams( + organizationId, + projectId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + /** Grep within a specific file's parsed content. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val fileId: JsonField, + private val indexId: JsonField, + private val pattern: JsonField, + private val contextChars: JsonField, + private val pageSize: JsonField, + private val pageToken: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("file_id") @ExcludeMissing fileId: JsonField = JsonMissing.of(), + @JsonProperty("index_id") @ExcludeMissing indexId: JsonField = JsonMissing.of(), + @JsonProperty("pattern") @ExcludeMissing pattern: JsonField = JsonMissing.of(), + @JsonProperty("context_chars") + @ExcludeMissing + contextChars: JsonField = JsonMissing.of(), + @JsonProperty("page_size") @ExcludeMissing pageSize: JsonField = JsonMissing.of(), + @JsonProperty("page_token") + @ExcludeMissing + pageToken: JsonField = JsonMissing.of(), + ) : this(fileId, indexId, pattern, contextChars, pageSize, pageToken, mutableMapOf()) + + /** + * ID of the file to grep. + * + * @throws LlamaCloudInvalidDataException 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 fileId(): String = fileId.getRequired("file_id") + + /** + * ID of the index the file belongs to. + * + * @throws LlamaCloudInvalidDataException 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 indexId(): String = indexId.getRequired("index_id") + + /** + * Regex pattern to search for. + * + * @throws LlamaCloudInvalidDataException 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 pattern(): String = pattern.getRequired("pattern") + + /** + * Number of characters of context to include before and after the matched pattern in the + * content field of the response + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun contextChars(): Optional = contextChars.getOptional("context_chars") + + /** + * The maximum number of items to return. The service may return fewer than this value. If + * unspecified, a default page size will be used. The maximum value is typically 1000; + * values above this will be coerced to the maximum. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun pageSize(): Optional = pageSize.getOptional("page_size") + + /** + * A page token, received from a previous list call. Provide this to retrieve the subsequent + * page. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun pageToken(): Optional = pageToken.getOptional("page_token") + + /** + * Returns the raw JSON value of [fileId]. + * + * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_id") @ExcludeMissing fun _fileId(): JsonField = fileId + + /** + * Returns the raw JSON value of [indexId]. + * + * Unlike [indexId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("index_id") @ExcludeMissing fun _indexId(): JsonField = indexId + + /** + * Returns the raw JSON value of [pattern]. + * + * Unlike [pattern], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("pattern") @ExcludeMissing fun _pattern(): JsonField = pattern + + /** + * Returns the raw JSON value of [contextChars]. + * + * Unlike [contextChars], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("context_chars") + @ExcludeMissing + fun _contextChars(): JsonField = contextChars + + /** + * Returns the raw JSON value of [pageSize]. + * + * Unlike [pageSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page_size") @ExcludeMissing fun _pageSize(): JsonField = pageSize + + /** + * Returns the raw JSON value of [pageToken]. + * + * Unlike [pageToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page_token") @ExcludeMissing fun _pageToken(): JsonField = pageToken + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .fileId() + * .indexId() + * .pattern() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var fileId: JsonField? = null + private var indexId: JsonField? = null + private var pattern: JsonField? = null + private var contextChars: JsonField = JsonMissing.of() + private var pageSize: JsonField = JsonMissing.of() + private var pageToken: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + fileId = body.fileId + indexId = body.indexId + pattern = body.pattern + contextChars = body.contextChars + pageSize = body.pageSize + pageToken = body.pageToken + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** ID of the file to grep. */ + fun fileId(fileId: String) = fileId(JsonField.of(fileId)) + + /** + * Sets [Builder.fileId] to an arbitrary JSON value. + * + * You should usually call [Builder.fileId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileId(fileId: JsonField) = apply { this.fileId = fileId } + + /** ID of the index the file belongs to. */ + fun indexId(indexId: String) = indexId(JsonField.of(indexId)) + + /** + * Sets [Builder.indexId] to an arbitrary JSON value. + * + * You should usually call [Builder.indexId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun indexId(indexId: JsonField) = apply { this.indexId = indexId } + + /** Regex pattern to search for. */ + fun pattern(pattern: String) = pattern(JsonField.of(pattern)) + + /** + * Sets [Builder.pattern] to an arbitrary JSON value. + * + * You should usually call [Builder.pattern] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pattern(pattern: JsonField) = apply { this.pattern = pattern } + + /** + * Number of characters of context to include before and after the matched pattern in + * the content field of the response + */ + fun contextChars(contextChars: Long?) = contextChars(JsonField.ofNullable(contextChars)) + + /** + * Alias for [Builder.contextChars]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun contextChars(contextChars: Long) = contextChars(contextChars as Long?) + + /** Alias for calling [Builder.contextChars] with `contextChars.orElse(null)`. */ + fun contextChars(contextChars: Optional) = contextChars(contextChars.getOrNull()) + + /** + * Sets [Builder.contextChars] to an arbitrary JSON value. + * + * You should usually call [Builder.contextChars] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun contextChars(contextChars: JsonField) = apply { + this.contextChars = contextChars + } + + /** + * The maximum number of items to return. The service may return fewer than this value. + * If unspecified, a default page size will be used. The maximum value is typically + * 1000; values above this will be coerced to the maximum. + */ + fun pageSize(pageSize: Long?) = pageSize(JsonField.ofNullable(pageSize)) + + /** + * Alias for [Builder.pageSize]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun pageSize(pageSize: Long) = pageSize(pageSize as Long?) + + /** Alias for calling [Builder.pageSize] with `pageSize.orElse(null)`. */ + fun pageSize(pageSize: Optional) = pageSize(pageSize.getOrNull()) + + /** + * Sets [Builder.pageSize] to an arbitrary JSON value. + * + * You should usually call [Builder.pageSize] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pageSize(pageSize: JsonField) = apply { this.pageSize = pageSize } + + /** + * A page token, received from a previous list call. Provide this to retrieve the + * subsequent page. + */ + fun pageToken(pageToken: String?) = pageToken(JsonField.ofNullable(pageToken)) + + /** Alias for calling [Builder.pageToken] with `pageToken.orElse(null)`. */ + fun pageToken(pageToken: Optional) = pageToken(pageToken.getOrNull()) + + /** + * Sets [Builder.pageToken] to an arbitrary JSON value. + * + * You should usually call [Builder.pageToken] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pageToken(pageToken: JsonField) = apply { this.pageToken = pageToken } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fileId() + * .indexId() + * .pattern() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("fileId", fileId), + checkRequired("indexId", indexId), + checkRequired("pattern", pattern), + contextChars, + pageSize, + pageToken, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + fileId() + indexId() + pattern() + contextChars() + pageSize() + pageToken() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (fileId.asKnown().isPresent) 1 else 0) + + (if (indexId.asKnown().isPresent) 1 else 0) + + (if (pattern.asKnown().isPresent) 1 else 0) + + (if (contextChars.asKnown().isPresent) 1 else 0) + + (if (pageSize.asKnown().isPresent) 1 else 0) + + (if (pageToken.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + fileId == other.fileId && + indexId == other.indexId && + pattern == other.pattern && + contextChars == other.contextChars && + pageSize == other.pageSize && + pageToken == other.pageToken && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + fileId, + indexId, + pattern, + contextChars, + pageSize, + pageToken, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{fileId=$fileId, indexId=$indexId, pattern=$pattern, contextChars=$contextChars, pageSize=$pageSize, pageToken=$pageToken, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalGrepParams && + organizationId == other.organizationId && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(organizationId, projectId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RetrievalGrepParams{organizationId=$organizationId, projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepResponse.kt new file mode 100644 index 0000000..c4b40a3 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepResponse.kt @@ -0,0 +1,258 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects + +/** A single grep match within a file. */ +class RetrievalGrepResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val content: JsonField, + private val endChar: JsonField, + private val startChar: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of(), + @JsonProperty("end_char") @ExcludeMissing endChar: JsonField = JsonMissing.of(), + @JsonProperty("start_char") @ExcludeMissing startChar: JsonField = JsonMissing.of(), + ) : this(content, endChar, startChar, mutableMapOf()) + + /** + * Matched text content. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun content(): String = content.getRequired("content") + + /** + * End character offset of the match. + * + * @throws LlamaCloudInvalidDataException 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 endChar(): Long = endChar.getRequired("end_char") + + /** + * Start character offset of the match. + * + * @throws LlamaCloudInvalidDataException 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 startChar(): Long = startChar.getRequired("start_char") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [endChar]. + * + * Unlike [endChar], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("end_char") @ExcludeMissing fun _endChar(): JsonField = endChar + + /** + * Returns the raw JSON value of [startChar]. + * + * Unlike [startChar], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("start_char") @ExcludeMissing fun _startChar(): JsonField = startChar + + @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 [RetrievalGrepResponse]. + * + * The following fields are required: + * ```java + * .content() + * .endChar() + * .startChar() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalGrepResponse]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var endChar: JsonField? = null + private var startChar: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(retrievalGrepResponse: RetrievalGrepResponse) = apply { + content = retrievalGrepResponse.content + endChar = retrievalGrepResponse.endChar + startChar = retrievalGrepResponse.startChar + additionalProperties = retrievalGrepResponse.additionalProperties.toMutableMap() + } + + /** Matched text content. */ + fun content(content: String) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + /** End character offset of the match. */ + fun endChar(endChar: Long) = endChar(JsonField.of(endChar)) + + /** + * Sets [Builder.endChar] to an arbitrary JSON value. + * + * You should usually call [Builder.endChar] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun endChar(endChar: JsonField) = apply { this.endChar = endChar } + + /** Start character offset of the match. */ + fun startChar(startChar: Long) = startChar(JsonField.of(startChar)) + + /** + * Sets [Builder.startChar] to an arbitrary JSON value. + * + * You should usually call [Builder.startChar] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun startChar(startChar: JsonField) = apply { this.startChar = startChar } + + 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 [RetrievalGrepResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * .endChar() + * .startChar() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalGrepResponse = + RetrievalGrepResponse( + checkRequired("content", content), + checkRequired("endChar", endChar), + checkRequired("startChar", startChar), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RetrievalGrepResponse = apply { + if (validated) { + return@apply + } + + content() + endChar() + startChar() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (content.asKnown().isPresent) 1 else 0) + + (if (endChar.asKnown().isPresent) 1 else 0) + + (if (startChar.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalGrepResponse && + content == other.content && + endChar == other.endChar && + startChar == other.startChar && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(content, endChar, startChar, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RetrievalGrepResponse{content=$content, endChar=$endChar, startChar=$startChar, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalReadParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalReadParams.kt new file mode 100644 index 0000000..e50eda5 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalReadParams.kt @@ -0,0 +1,679 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Read the parsed text content of a specific file. */ +class RetrievalReadParams +private constructor( + private val organizationId: String?, + private val projectId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * ID of the file to read. + * + * @throws LlamaCloudInvalidDataException 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 fileId(): String = body.fileId() + + /** + * ID of the index the file belongs to. + * + * @throws LlamaCloudInvalidDataException 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 indexId(): String = body.indexId() + + /** + * Maximum number of characters to read from the offset. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun maxLength(): Optional = body.maxLength() + + /** + * Starting character offset. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun offset(): Optional = body.offset() + + /** + * Returns the raw JSON value of [fileId]. + * + * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _fileId(): JsonField = body._fileId() + + /** + * Returns the raw JSON value of [indexId]. + * + * Unlike [indexId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _indexId(): JsonField = body._indexId() + + /** + * Returns the raw JSON value of [maxLength]. + * + * Unlike [maxLength], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _maxLength(): JsonField = body._maxLength() + + /** + * Returns the raw JSON value of [offset]. + * + * Unlike [offset], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _offset(): JsonField = body._offset() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RetrievalReadParams]. + * + * The following fields are required: + * ```java + * .fileId() + * .indexId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalReadParams]. */ + class Builder internal constructor() { + + private var organizationId: String? = null + private var projectId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(retrievalReadParams: RetrievalReadParams) = apply { + organizationId = retrievalReadParams.organizationId + projectId = retrievalReadParams.projectId + body = retrievalReadParams.body.toBuilder() + additionalHeaders = retrievalReadParams.additionalHeaders.toBuilder() + additionalQueryParams = retrievalReadParams.additionalQueryParams.toBuilder() + } + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [fileId] + * - [indexId] + * - [maxLength] + * - [offset] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** ID of the file to read. */ + fun fileId(fileId: String) = apply { body.fileId(fileId) } + + /** + * Sets [Builder.fileId] to an arbitrary JSON value. + * + * You should usually call [Builder.fileId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun fileId(fileId: JsonField) = apply { body.fileId(fileId) } + + /** ID of the index the file belongs to. */ + fun indexId(indexId: String) = apply { body.indexId(indexId) } + + /** + * Sets [Builder.indexId] to an arbitrary JSON value. + * + * You should usually call [Builder.indexId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun indexId(indexId: JsonField) = apply { body.indexId(indexId) } + + /** Maximum number of characters to read from the offset. */ + fun maxLength(maxLength: Long?) = apply { body.maxLength(maxLength) } + + /** + * Alias for [Builder.maxLength]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun maxLength(maxLength: Long) = maxLength(maxLength as Long?) + + /** Alias for calling [Builder.maxLength] with `maxLength.orElse(null)`. */ + fun maxLength(maxLength: Optional) = maxLength(maxLength.getOrNull()) + + /** + * Sets [Builder.maxLength] to an arbitrary JSON value. + * + * You should usually call [Builder.maxLength] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun maxLength(maxLength: JsonField) = apply { body.maxLength(maxLength) } + + /** Starting character offset. */ + fun offset(offset: Long) = apply { body.offset(offset) } + + /** + * Sets [Builder.offset] to an arbitrary JSON value. + * + * You should usually call [Builder.offset] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun offset(offset: JsonField) = apply { body.offset(offset) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [RetrievalReadParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fileId() + * .indexId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalReadParams = + RetrievalReadParams( + organizationId, + projectId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + /** Read parsed content of a specific file. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val fileId: JsonField, + private val indexId: JsonField, + private val maxLength: JsonField, + private val offset: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("file_id") @ExcludeMissing fileId: JsonField = JsonMissing.of(), + @JsonProperty("index_id") @ExcludeMissing indexId: JsonField = JsonMissing.of(), + @JsonProperty("max_length") + @ExcludeMissing + maxLength: JsonField = JsonMissing.of(), + @JsonProperty("offset") @ExcludeMissing offset: JsonField = JsonMissing.of(), + ) : this(fileId, indexId, maxLength, offset, mutableMapOf()) + + /** + * ID of the file to read. + * + * @throws LlamaCloudInvalidDataException 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 fileId(): String = fileId.getRequired("file_id") + + /** + * ID of the index the file belongs to. + * + * @throws LlamaCloudInvalidDataException 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 indexId(): String = indexId.getRequired("index_id") + + /** + * Maximum number of characters to read from the offset. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun maxLength(): Optional = maxLength.getOptional("max_length") + + /** + * Starting character offset. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun offset(): Optional = offset.getOptional("offset") + + /** + * Returns the raw JSON value of [fileId]. + * + * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("file_id") @ExcludeMissing fun _fileId(): JsonField = fileId + + /** + * Returns the raw JSON value of [indexId]. + * + * Unlike [indexId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("index_id") @ExcludeMissing fun _indexId(): JsonField = indexId + + /** + * Returns the raw JSON value of [maxLength]. + * + * Unlike [maxLength], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("max_length") @ExcludeMissing fun _maxLength(): JsonField = maxLength + + /** + * Returns the raw JSON value of [offset]. + * + * Unlike [offset], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("offset") @ExcludeMissing fun _offset(): JsonField = offset + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .fileId() + * .indexId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var fileId: JsonField? = null + private var indexId: JsonField? = null + private var maxLength: JsonField = JsonMissing.of() + private var offset: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + fileId = body.fileId + indexId = body.indexId + maxLength = body.maxLength + offset = body.offset + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** ID of the file to read. */ + fun fileId(fileId: String) = fileId(JsonField.of(fileId)) + + /** + * Sets [Builder.fileId] to an arbitrary JSON value. + * + * You should usually call [Builder.fileId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileId(fileId: JsonField) = apply { this.fileId = fileId } + + /** ID of the index the file belongs to. */ + fun indexId(indexId: String) = indexId(JsonField.of(indexId)) + + /** + * Sets [Builder.indexId] to an arbitrary JSON value. + * + * You should usually call [Builder.indexId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun indexId(indexId: JsonField) = apply { this.indexId = indexId } + + /** Maximum number of characters to read from the offset. */ + fun maxLength(maxLength: Long?) = maxLength(JsonField.ofNullable(maxLength)) + + /** + * Alias for [Builder.maxLength]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun maxLength(maxLength: Long) = maxLength(maxLength as Long?) + + /** Alias for calling [Builder.maxLength] with `maxLength.orElse(null)`. */ + fun maxLength(maxLength: Optional) = maxLength(maxLength.getOrNull()) + + /** + * Sets [Builder.maxLength] to an arbitrary JSON value. + * + * You should usually call [Builder.maxLength] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxLength(maxLength: JsonField) = apply { this.maxLength = maxLength } + + /** Starting character offset. */ + fun offset(offset: Long) = offset(JsonField.of(offset)) + + /** + * Sets [Builder.offset] to an arbitrary JSON value. + * + * You should usually call [Builder.offset] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun offset(offset: JsonField) = apply { this.offset = offset } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fileId() + * .indexId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("fileId", fileId), + checkRequired("indexId", indexId), + maxLength, + offset, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + fileId() + indexId() + maxLength() + offset() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (fileId.asKnown().isPresent) 1 else 0) + + (if (indexId.asKnown().isPresent) 1 else 0) + + (if (maxLength.asKnown().isPresent) 1 else 0) + + (if (offset.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + fileId == other.fileId && + indexId == other.indexId && + maxLength == other.maxLength && + offset == other.offset && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(fileId, indexId, maxLength, offset, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{fileId=$fileId, indexId=$indexId, maxLength=$maxLength, offset=$offset, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalReadParams && + organizationId == other.organizationId && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(organizationId, projectId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RetrievalReadParams{organizationId=$organizationId, projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalReadResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalReadResponse.kt new file mode 100644 index 0000000..c5e233e --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalReadResponse.kt @@ -0,0 +1,182 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects + +/** File read result. */ +class RetrievalReadResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val content: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of() + ) : this(content, mutableMapOf()) + + /** + * Parsed text content of the file. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun content(): String = content.getRequired("content") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + @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 [RetrievalReadResponse]. + * + * The following fields are required: + * ```java + * .content() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalReadResponse]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(retrievalReadResponse: RetrievalReadResponse) = apply { + content = retrievalReadResponse.content + additionalProperties = retrievalReadResponse.additionalProperties.toMutableMap() + } + + /** Parsed text content of the file. */ + fun content(content: String) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + 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 [RetrievalReadResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalReadResponse = + RetrievalReadResponse( + checkRequired("content", content), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RetrievalReadResponse = apply { + if (validated) { + return@apply + } + + content() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (content.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalReadResponse && + content == other.content && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(content, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RetrievalReadResponse{content=$content, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalRetrieveParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalRetrieveParams.kt new file mode 100644 index 0000000..80358ec --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalRetrieveParams.kt @@ -0,0 +1,2371 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.BaseDeserializer +import ai.llamaindex.llamacloud.core.BaseSerializer +import ai.llamaindex.llamacloud.core.Enum +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.Params +import ai.llamaindex.llamacloud.core.allMaxBy +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.getOrThrow +import ai.llamaindex.llamacloud.core.http.Headers +import ai.llamaindex.llamacloud.core.http.QueryParams +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Retrieve relevant chunks via hybrid search (vector + full-text), with filtering on built-in or + * user-defined metadata. + */ +class RetrievalRetrieveParams +private constructor( + private val organizationId: String?, + private val projectId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun organizationId(): Optional = Optional.ofNullable(organizationId) + + fun projectId(): Optional = Optional.ofNullable(projectId) + + /** + * ID of the index to retrieve against. + * + * @throws LlamaCloudInvalidDataException 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 indexId(): String = body.indexId() + + /** + * Natural-language query to retrieve relevant chunks. + * + * @throws LlamaCloudInvalidDataException 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 query(): String = body.query() + + /** + * Filters on user-defined metadata fields. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun customFilters(): Optional = body.customFilters() + + /** + * Weight of the full-text search pipeline (0-1). + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fullTextPipelineWeight(): Optional = body.fullTextPipelineWeight() + + /** + * Number of candidates for approximate nearest neighbor search. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun numCandidates(): Optional = body.numCandidates() + + /** + * Reranking configuration applied after hybrid search. Enabled by default. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun rerank(): Optional = body.rerank() + + /** + * Minimum score threshold for returned results. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun scoreThreshold(): Optional = body.scoreThreshold() + + /** + * Filters on built-in document fields (page range, chunk index, etc.). + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun staticFilters(): Optional = body.staticFilters() + + /** + * Maximum number of results to return. Values above 500 are capped at 500. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun topK(): Optional = body.topK() + + /** + * Weight of the vector search pipeline (0-1). + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun vectorPipelineWeight(): Optional = body.vectorPipelineWeight() + + /** + * Returns the raw JSON value of [indexId]. + * + * Unlike [indexId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _indexId(): JsonField = body._indexId() + + /** + * Returns the raw JSON value of [query]. + * + * Unlike [query], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _query(): JsonField = body._query() + + /** + * Returns the raw JSON value of [customFilters]. + * + * Unlike [customFilters], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _customFilters(): JsonField = body._customFilters() + + /** + * Returns the raw JSON value of [fullTextPipelineWeight]. + * + * Unlike [fullTextPipelineWeight], this method doesn't throw if the JSON field has an + * unexpected type. + */ + fun _fullTextPipelineWeight(): JsonField = body._fullTextPipelineWeight() + + /** + * Returns the raw JSON value of [numCandidates]. + * + * Unlike [numCandidates], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _numCandidates(): JsonField = body._numCandidates() + + /** + * Returns the raw JSON value of [rerank]. + * + * Unlike [rerank], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _rerank(): JsonField = body._rerank() + + /** + * Returns the raw JSON value of [scoreThreshold]. + * + * Unlike [scoreThreshold], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _scoreThreshold(): JsonField = body._scoreThreshold() + + /** + * Returns the raw JSON value of [staticFilters]. + * + * Unlike [staticFilters], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _staticFilters(): JsonField = body._staticFilters() + + /** + * Returns the raw JSON value of [topK]. + * + * Unlike [topK], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _topK(): JsonField = body._topK() + + /** + * Returns the raw JSON value of [vectorPipelineWeight]. + * + * Unlike [vectorPipelineWeight], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _vectorPipelineWeight(): JsonField = body._vectorPipelineWeight() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RetrievalRetrieveParams]. + * + * The following fields are required: + * ```java + * .indexId() + * .query() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalRetrieveParams]. */ + class Builder internal constructor() { + + private var organizationId: String? = null + private var projectId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(retrievalRetrieveParams: RetrievalRetrieveParams) = apply { + organizationId = retrievalRetrieveParams.organizationId + projectId = retrievalRetrieveParams.projectId + body = retrievalRetrieveParams.body.toBuilder() + additionalHeaders = retrievalRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = retrievalRetrieveParams.additionalQueryParams.toBuilder() + } + + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) + + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [indexId] + * - [query] + * - [customFilters] + * - [fullTextPipelineWeight] + * - [numCandidates] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** ID of the index to retrieve against. */ + fun indexId(indexId: String) = apply { body.indexId(indexId) } + + /** + * Sets [Builder.indexId] to an arbitrary JSON value. + * + * You should usually call [Builder.indexId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun indexId(indexId: JsonField) = apply { body.indexId(indexId) } + + /** Natural-language query to retrieve relevant chunks. */ + fun query(query: String) = apply { body.query(query) } + + /** + * Sets [Builder.query] to an arbitrary JSON value. + * + * You should usually call [Builder.query] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun query(query: JsonField) = apply { body.query(query) } + + /** Filters on user-defined metadata fields. */ + fun customFilters(customFilters: CustomFilters?) = apply { + body.customFilters(customFilters) + } + + /** Alias for calling [Builder.customFilters] with `customFilters.orElse(null)`. */ + fun customFilters(customFilters: Optional) = + customFilters(customFilters.getOrNull()) + + /** + * Sets [Builder.customFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.customFilters] with a well-typed [CustomFilters] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun customFilters(customFilters: JsonField) = apply { + body.customFilters(customFilters) + } + + /** Weight of the full-text search pipeline (0-1). */ + fun fullTextPipelineWeight(fullTextPipelineWeight: Double?) = apply { + body.fullTextPipelineWeight(fullTextPipelineWeight) + } + + /** + * Alias for [Builder.fullTextPipelineWeight]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fullTextPipelineWeight(fullTextPipelineWeight: Double) = + fullTextPipelineWeight(fullTextPipelineWeight as Double?) + + /** + * Alias for calling [Builder.fullTextPipelineWeight] with + * `fullTextPipelineWeight.orElse(null)`. + */ + fun fullTextPipelineWeight(fullTextPipelineWeight: Optional) = + fullTextPipelineWeight(fullTextPipelineWeight.getOrNull()) + + /** + * Sets [Builder.fullTextPipelineWeight] to an arbitrary JSON value. + * + * You should usually call [Builder.fullTextPipelineWeight] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fullTextPipelineWeight(fullTextPipelineWeight: JsonField) = apply { + body.fullTextPipelineWeight(fullTextPipelineWeight) + } + + /** Number of candidates for approximate nearest neighbor search. */ + fun numCandidates(numCandidates: Long?) = apply { body.numCandidates(numCandidates) } + + /** + * Alias for [Builder.numCandidates]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun numCandidates(numCandidates: Long) = numCandidates(numCandidates as Long?) + + /** Alias for calling [Builder.numCandidates] with `numCandidates.orElse(null)`. */ + fun numCandidates(numCandidates: Optional) = numCandidates(numCandidates.getOrNull()) + + /** + * Sets [Builder.numCandidates] to an arbitrary JSON value. + * + * You should usually call [Builder.numCandidates] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun numCandidates(numCandidates: JsonField) = apply { + body.numCandidates(numCandidates) + } + + /** Reranking configuration applied after hybrid search. Enabled by default. */ + fun rerank(rerank: Rerank) = apply { body.rerank(rerank) } + + /** + * Sets [Builder.rerank] to an arbitrary JSON value. + * + * You should usually call [Builder.rerank] with a well-typed [Rerank] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun rerank(rerank: JsonField) = apply { body.rerank(rerank) } + + /** Minimum score threshold for returned results. */ + fun scoreThreshold(scoreThreshold: Double?) = apply { body.scoreThreshold(scoreThreshold) } + + /** + * Alias for [Builder.scoreThreshold]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun scoreThreshold(scoreThreshold: Double) = scoreThreshold(scoreThreshold as Double?) + + /** Alias for calling [Builder.scoreThreshold] with `scoreThreshold.orElse(null)`. */ + fun scoreThreshold(scoreThreshold: Optional) = + scoreThreshold(scoreThreshold.getOrNull()) + + /** + * Sets [Builder.scoreThreshold] to an arbitrary JSON value. + * + * You should usually call [Builder.scoreThreshold] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun scoreThreshold(scoreThreshold: JsonField) = apply { + body.scoreThreshold(scoreThreshold) + } + + /** Filters on built-in document fields (page range, chunk index, etc.). */ + fun staticFilters(staticFilters: StaticFilters?) = apply { + body.staticFilters(staticFilters) + } + + /** Alias for calling [Builder.staticFilters] with `staticFilters.orElse(null)`. */ + fun staticFilters(staticFilters: Optional) = + staticFilters(staticFilters.getOrNull()) + + /** + * Sets [Builder.staticFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.staticFilters] with a well-typed [StaticFilters] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun staticFilters(staticFilters: JsonField) = apply { + body.staticFilters(staticFilters) + } + + /** Maximum number of results to return. Values above 500 are capped at 500. */ + fun topK(topK: Long?) = apply { body.topK(topK) } + + /** + * Alias for [Builder.topK]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun topK(topK: Long) = topK(topK as Long?) + + /** Alias for calling [Builder.topK] with `topK.orElse(null)`. */ + fun topK(topK: Optional) = topK(topK.getOrNull()) + + /** + * Sets [Builder.topK] to an arbitrary JSON value. + * + * You should usually call [Builder.topK] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun topK(topK: JsonField) = apply { body.topK(topK) } + + /** Weight of the vector search pipeline (0-1). */ + fun vectorPipelineWeight(vectorPipelineWeight: Double?) = apply { + body.vectorPipelineWeight(vectorPipelineWeight) + } + + /** + * Alias for [Builder.vectorPipelineWeight]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun vectorPipelineWeight(vectorPipelineWeight: Double) = + vectorPipelineWeight(vectorPipelineWeight as Double?) + + /** + * Alias for calling [Builder.vectorPipelineWeight] with + * `vectorPipelineWeight.orElse(null)`. + */ + fun vectorPipelineWeight(vectorPipelineWeight: Optional) = + vectorPipelineWeight(vectorPipelineWeight.getOrNull()) + + /** + * Sets [Builder.vectorPipelineWeight] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorPipelineWeight] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun vectorPipelineWeight(vectorPipelineWeight: JsonField) = apply { + body.vectorPipelineWeight(vectorPipelineWeight) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [RetrievalRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .indexId() + * .query() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalRetrieveParams = + RetrievalRetrieveParams( + organizationId, + projectId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + organizationId?.let { put("organization_id", it) } + projectId?.let { put("project_id", it) } + putAll(additionalQueryParams) + } + .build() + + /** Hybrid retrieval request combining vector and full-text search. */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val indexId: JsonField, + private val query: JsonField, + private val customFilters: JsonField, + private val fullTextPipelineWeight: JsonField, + private val numCandidates: JsonField, + private val rerank: JsonField, + private val scoreThreshold: JsonField, + private val staticFilters: JsonField, + private val topK: JsonField, + private val vectorPipelineWeight: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("index_id") @ExcludeMissing indexId: JsonField = JsonMissing.of(), + @JsonProperty("query") @ExcludeMissing query: JsonField = JsonMissing.of(), + @JsonProperty("custom_filters") + @ExcludeMissing + customFilters: JsonField = JsonMissing.of(), + @JsonProperty("full_text_pipeline_weight") + @ExcludeMissing + fullTextPipelineWeight: JsonField = JsonMissing.of(), + @JsonProperty("num_candidates") + @ExcludeMissing + numCandidates: JsonField = JsonMissing.of(), + @JsonProperty("rerank") @ExcludeMissing rerank: JsonField = JsonMissing.of(), + @JsonProperty("score_threshold") + @ExcludeMissing + scoreThreshold: JsonField = JsonMissing.of(), + @JsonProperty("static_filters") + @ExcludeMissing + staticFilters: JsonField = JsonMissing.of(), + @JsonProperty("top_k") @ExcludeMissing topK: JsonField = JsonMissing.of(), + @JsonProperty("vector_pipeline_weight") + @ExcludeMissing + vectorPipelineWeight: JsonField = JsonMissing.of(), + ) : this( + indexId, + query, + customFilters, + fullTextPipelineWeight, + numCandidates, + rerank, + scoreThreshold, + staticFilters, + topK, + vectorPipelineWeight, + mutableMapOf(), + ) + + /** + * ID of the index to retrieve against. + * + * @throws LlamaCloudInvalidDataException 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 indexId(): String = indexId.getRequired("index_id") + + /** + * Natural-language query to retrieve relevant chunks. + * + * @throws LlamaCloudInvalidDataException 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 query(): String = query.getRequired("query") + + /** + * Filters on user-defined metadata fields. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun customFilters(): Optional = customFilters.getOptional("custom_filters") + + /** + * Weight of the full-text search pipeline (0-1). + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fullTextPipelineWeight(): Optional = + fullTextPipelineWeight.getOptional("full_text_pipeline_weight") + + /** + * Number of candidates for approximate nearest neighbor search. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun numCandidates(): Optional = numCandidates.getOptional("num_candidates") + + /** + * Reranking configuration applied after hybrid search. Enabled by default. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rerank(): Optional = rerank.getOptional("rerank") + + /** + * Minimum score threshold for returned results. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun scoreThreshold(): Optional = scoreThreshold.getOptional("score_threshold") + + /** + * Filters on built-in document fields (page range, chunk index, etc.). + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun staticFilters(): Optional = staticFilters.getOptional("static_filters") + + /** + * Maximum number of results to return. Values above 500 are capped at 500. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun topK(): Optional = topK.getOptional("top_k") + + /** + * Weight of the vector search pipeline (0-1). + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun vectorPipelineWeight(): Optional = + vectorPipelineWeight.getOptional("vector_pipeline_weight") + + /** + * Returns the raw JSON value of [indexId]. + * + * Unlike [indexId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("index_id") @ExcludeMissing fun _indexId(): JsonField = indexId + + /** + * Returns the raw JSON value of [query]. + * + * Unlike [query], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("query") @ExcludeMissing fun _query(): JsonField = query + + /** + * Returns the raw JSON value of [customFilters]. + * + * Unlike [customFilters], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("custom_filters") + @ExcludeMissing + fun _customFilters(): JsonField = customFilters + + /** + * Returns the raw JSON value of [fullTextPipelineWeight]. + * + * Unlike [fullTextPipelineWeight], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("full_text_pipeline_weight") + @ExcludeMissing + fun _fullTextPipelineWeight(): JsonField = fullTextPipelineWeight + + /** + * Returns the raw JSON value of [numCandidates]. + * + * Unlike [numCandidates], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("num_candidates") + @ExcludeMissing + fun _numCandidates(): JsonField = numCandidates + + /** + * Returns the raw JSON value of [rerank]. + * + * Unlike [rerank], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rerank") @ExcludeMissing fun _rerank(): JsonField = rerank + + /** + * Returns the raw JSON value of [scoreThreshold]. + * + * Unlike [scoreThreshold], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("score_threshold") + @ExcludeMissing + fun _scoreThreshold(): JsonField = scoreThreshold + + /** + * Returns the raw JSON value of [staticFilters]. + * + * Unlike [staticFilters], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("static_filters") + @ExcludeMissing + fun _staticFilters(): JsonField = staticFilters + + /** + * Returns the raw JSON value of [topK]. + * + * Unlike [topK], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("top_k") @ExcludeMissing fun _topK(): JsonField = topK + + /** + * Returns the raw JSON value of [vectorPipelineWeight]. + * + * Unlike [vectorPipelineWeight], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("vector_pipeline_weight") + @ExcludeMissing + fun _vectorPipelineWeight(): JsonField = vectorPipelineWeight + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .indexId() + * .query() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var indexId: JsonField? = null + private var query: JsonField? = null + private var customFilters: JsonField = JsonMissing.of() + private var fullTextPipelineWeight: JsonField = JsonMissing.of() + private var numCandidates: JsonField = JsonMissing.of() + private var rerank: JsonField = JsonMissing.of() + private var scoreThreshold: JsonField = JsonMissing.of() + private var staticFilters: JsonField = JsonMissing.of() + private var topK: JsonField = JsonMissing.of() + private var vectorPipelineWeight: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + indexId = body.indexId + query = body.query + customFilters = body.customFilters + fullTextPipelineWeight = body.fullTextPipelineWeight + numCandidates = body.numCandidates + rerank = body.rerank + scoreThreshold = body.scoreThreshold + staticFilters = body.staticFilters + topK = body.topK + vectorPipelineWeight = body.vectorPipelineWeight + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** ID of the index to retrieve against. */ + fun indexId(indexId: String) = indexId(JsonField.of(indexId)) + + /** + * Sets [Builder.indexId] to an arbitrary JSON value. + * + * You should usually call [Builder.indexId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun indexId(indexId: JsonField) = apply { this.indexId = indexId } + + /** Natural-language query to retrieve relevant chunks. */ + fun query(query: String) = query(JsonField.of(query)) + + /** + * Sets [Builder.query] to an arbitrary JSON value. + * + * You should usually call [Builder.query] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun query(query: JsonField) = apply { this.query = query } + + /** Filters on user-defined metadata fields. */ + fun customFilters(customFilters: CustomFilters?) = + customFilters(JsonField.ofNullable(customFilters)) + + /** Alias for calling [Builder.customFilters] with `customFilters.orElse(null)`. */ + fun customFilters(customFilters: Optional) = + customFilters(customFilters.getOrNull()) + + /** + * Sets [Builder.customFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.customFilters] with a well-typed [CustomFilters] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun customFilters(customFilters: JsonField) = apply { + this.customFilters = customFilters + } + + /** Weight of the full-text search pipeline (0-1). */ + fun fullTextPipelineWeight(fullTextPipelineWeight: Double?) = + fullTextPipelineWeight(JsonField.ofNullable(fullTextPipelineWeight)) + + /** + * Alias for [Builder.fullTextPipelineWeight]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun fullTextPipelineWeight(fullTextPipelineWeight: Double) = + fullTextPipelineWeight(fullTextPipelineWeight as Double?) + + /** + * Alias for calling [Builder.fullTextPipelineWeight] with + * `fullTextPipelineWeight.orElse(null)`. + */ + fun fullTextPipelineWeight(fullTextPipelineWeight: Optional) = + fullTextPipelineWeight(fullTextPipelineWeight.getOrNull()) + + /** + * Sets [Builder.fullTextPipelineWeight] to an arbitrary JSON value. + * + * You should usually call [Builder.fullTextPipelineWeight] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun fullTextPipelineWeight(fullTextPipelineWeight: JsonField) = apply { + this.fullTextPipelineWeight = fullTextPipelineWeight + } + + /** Number of candidates for approximate nearest neighbor search. */ + fun numCandidates(numCandidates: Long?) = + numCandidates(JsonField.ofNullable(numCandidates)) + + /** + * Alias for [Builder.numCandidates]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun numCandidates(numCandidates: Long) = numCandidates(numCandidates as Long?) + + /** Alias for calling [Builder.numCandidates] with `numCandidates.orElse(null)`. */ + fun numCandidates(numCandidates: Optional) = + numCandidates(numCandidates.getOrNull()) + + /** + * Sets [Builder.numCandidates] to an arbitrary JSON value. + * + * You should usually call [Builder.numCandidates] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun numCandidates(numCandidates: JsonField) = apply { + this.numCandidates = numCandidates + } + + /** Reranking configuration applied after hybrid search. Enabled by default. */ + fun rerank(rerank: Rerank) = rerank(JsonField.of(rerank)) + + /** + * Sets [Builder.rerank] to an arbitrary JSON value. + * + * You should usually call [Builder.rerank] with a well-typed [Rerank] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun rerank(rerank: JsonField) = apply { this.rerank = rerank } + + /** Minimum score threshold for returned results. */ + fun scoreThreshold(scoreThreshold: Double?) = + scoreThreshold(JsonField.ofNullable(scoreThreshold)) + + /** + * Alias for [Builder.scoreThreshold]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun scoreThreshold(scoreThreshold: Double) = scoreThreshold(scoreThreshold as Double?) + + /** Alias for calling [Builder.scoreThreshold] with `scoreThreshold.orElse(null)`. */ + fun scoreThreshold(scoreThreshold: Optional) = + scoreThreshold(scoreThreshold.getOrNull()) + + /** + * Sets [Builder.scoreThreshold] to an arbitrary JSON value. + * + * You should usually call [Builder.scoreThreshold] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun scoreThreshold(scoreThreshold: JsonField) = apply { + this.scoreThreshold = scoreThreshold + } + + /** Filters on built-in document fields (page range, chunk index, etc.). */ + fun staticFilters(staticFilters: StaticFilters?) = + staticFilters(JsonField.ofNullable(staticFilters)) + + /** Alias for calling [Builder.staticFilters] with `staticFilters.orElse(null)`. */ + fun staticFilters(staticFilters: Optional) = + staticFilters(staticFilters.getOrNull()) + + /** + * Sets [Builder.staticFilters] to an arbitrary JSON value. + * + * You should usually call [Builder.staticFilters] with a well-typed [StaticFilters] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun staticFilters(staticFilters: JsonField) = apply { + this.staticFilters = staticFilters + } + + /** Maximum number of results to return. Values above 500 are capped at 500. */ + fun topK(topK: Long?) = topK(JsonField.ofNullable(topK)) + + /** + * Alias for [Builder.topK]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun topK(topK: Long) = topK(topK as Long?) + + /** Alias for calling [Builder.topK] with `topK.orElse(null)`. */ + fun topK(topK: Optional) = topK(topK.getOrNull()) + + /** + * Sets [Builder.topK] to an arbitrary JSON value. + * + * You should usually call [Builder.topK] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun topK(topK: JsonField) = apply { this.topK = topK } + + /** Weight of the vector search pipeline (0-1). */ + fun vectorPipelineWeight(vectorPipelineWeight: Double?) = + vectorPipelineWeight(JsonField.ofNullable(vectorPipelineWeight)) + + /** + * Alias for [Builder.vectorPipelineWeight]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun vectorPipelineWeight(vectorPipelineWeight: Double) = + vectorPipelineWeight(vectorPipelineWeight as Double?) + + /** + * Alias for calling [Builder.vectorPipelineWeight] with + * `vectorPipelineWeight.orElse(null)`. + */ + fun vectorPipelineWeight(vectorPipelineWeight: Optional) = + vectorPipelineWeight(vectorPipelineWeight.getOrNull()) + + /** + * Sets [Builder.vectorPipelineWeight] to an arbitrary JSON value. + * + * You should usually call [Builder.vectorPipelineWeight] with a well-typed [Double] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun vectorPipelineWeight(vectorPipelineWeight: JsonField) = apply { + this.vectorPipelineWeight = vectorPipelineWeight + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .indexId() + * .query() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("indexId", indexId), + checkRequired("query", query), + customFilters, + fullTextPipelineWeight, + numCandidates, + rerank, + scoreThreshold, + staticFilters, + topK, + vectorPipelineWeight, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + indexId() + query() + customFilters().ifPresent { it.validate() } + fullTextPipelineWeight() + numCandidates() + rerank().ifPresent { it.validate() } + scoreThreshold() + staticFilters().ifPresent { it.validate() } + topK() + vectorPipelineWeight() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (indexId.asKnown().isPresent) 1 else 0) + + (if (query.asKnown().isPresent) 1 else 0) + + (customFilters.asKnown().getOrNull()?.validity() ?: 0) + + (if (fullTextPipelineWeight.asKnown().isPresent) 1 else 0) + + (if (numCandidates.asKnown().isPresent) 1 else 0) + + (rerank.asKnown().getOrNull()?.validity() ?: 0) + + (if (scoreThreshold.asKnown().isPresent) 1 else 0) + + (staticFilters.asKnown().getOrNull()?.validity() ?: 0) + + (if (topK.asKnown().isPresent) 1 else 0) + + (if (vectorPipelineWeight.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + indexId == other.indexId && + query == other.query && + customFilters == other.customFilters && + fullTextPipelineWeight == other.fullTextPipelineWeight && + numCandidates == other.numCandidates && + rerank == other.rerank && + scoreThreshold == other.scoreThreshold && + staticFilters == other.staticFilters && + topK == other.topK && + vectorPipelineWeight == other.vectorPipelineWeight && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + indexId, + query, + customFilters, + fullTextPipelineWeight, + numCandidates, + rerank, + scoreThreshold, + staticFilters, + topK, + vectorPipelineWeight, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{indexId=$indexId, query=$query, customFilters=$customFilters, fullTextPipelineWeight=$fullTextPipelineWeight, numCandidates=$numCandidates, rerank=$rerank, scoreThreshold=$scoreThreshold, staticFilters=$staticFilters, topK=$topK, vectorPipelineWeight=$vectorPipelineWeight, additionalProperties=$additionalProperties}" + } + + /** Filters on user-defined metadata fields. */ + class CustomFilters + @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 [CustomFilters]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomFilters]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(customFilters: CustomFilters) = apply { + additionalProperties = customFilters.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 [CustomFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CustomFilters = CustomFilters(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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): CustomFilters = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 CustomFilters && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "CustomFilters{additionalProperties=$additionalProperties}" + } + + /** Reranking configuration applied after hybrid search. Enabled by default. */ + class Rerank + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val enabled: JsonField, + private val topN: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of(), + @JsonProperty("top_n") @ExcludeMissing topN: JsonField = JsonMissing.of(), + ) : this(enabled, topN, mutableMapOf()) + + /** + * Set to false to disable reranking. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun enabled(): Optional = enabled.getOptional("enabled") + + /** + * Number of results to return after reranking. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun topN(): Optional = topN.getOptional("top_n") + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + /** + * Returns the raw JSON value of [topN]. + * + * Unlike [topN], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("top_n") @ExcludeMissing fun _topN(): JsonField = topN + + @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 [Rerank]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Rerank]. */ + class Builder internal constructor() { + + private var enabled: JsonField = JsonMissing.of() + private var topN: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(rerank: Rerank) = apply { + enabled = rerank.enabled + topN = rerank.topN + additionalProperties = rerank.additionalProperties.toMutableMap() + } + + /** Set to false to disable reranking. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + /** Number of results to return after reranking. */ + fun topN(topN: Long?) = topN(JsonField.ofNullable(topN)) + + /** + * Alias for [Builder.topN]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun topN(topN: Long) = topN(topN as Long?) + + /** Alias for calling [Builder.topN] with `topN.orElse(null)`. */ + fun topN(topN: Optional) = topN(topN.getOrNull()) + + /** + * Sets [Builder.topN] to an arbitrary JSON value. + * + * You should usually call [Builder.topN] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun topN(topN: JsonField) = apply { this.topN = topN } + + 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 [Rerank]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Rerank = Rerank(enabled, topN, 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Rerank = apply { + if (validated) { + return@apply + } + + enabled() + topN() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (enabled.asKnown().isPresent) 1 else 0) + (if (topN.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Rerank && + enabled == other.enabled && + topN == other.topN && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(enabled, topN, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Rerank{enabled=$enabled, topN=$topN, additionalProperties=$additionalProperties}" + } + + /** Filters on built-in document fields (page range, chunk index, etc.). */ + class StaticFilters + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val parsedDirectoryFileId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("parsed_directory_file_id") + @ExcludeMissing + parsedDirectoryFileId: JsonField = JsonMissing.of() + ) : this(parsedDirectoryFileId, mutableMapOf()) + + /** + * Filter on a string field. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun parsedDirectoryFileId(): Optional = + parsedDirectoryFileId.getOptional("parsed_directory_file_id") + + /** + * Returns the raw JSON value of [parsedDirectoryFileId]. + * + * Unlike [parsedDirectoryFileId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("parsed_directory_file_id") + @ExcludeMissing + fun _parsedDirectoryFileId(): JsonField = parsedDirectoryFileId + + @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 [StaticFilters]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StaticFilters]. */ + class Builder internal constructor() { + + private var parsedDirectoryFileId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(staticFilters: StaticFilters) = apply { + parsedDirectoryFileId = staticFilters.parsedDirectoryFileId + additionalProperties = staticFilters.additionalProperties.toMutableMap() + } + + /** Filter on a string field. */ + fun parsedDirectoryFileId(parsedDirectoryFileId: ParsedDirectoryFileId?) = + parsedDirectoryFileId(JsonField.ofNullable(parsedDirectoryFileId)) + + /** + * Alias for calling [Builder.parsedDirectoryFileId] with + * `parsedDirectoryFileId.orElse(null)`. + */ + fun parsedDirectoryFileId(parsedDirectoryFileId: Optional) = + parsedDirectoryFileId(parsedDirectoryFileId.getOrNull()) + + /** + * Sets [Builder.parsedDirectoryFileId] to an arbitrary JSON value. + * + * You should usually call [Builder.parsedDirectoryFileId] with a well-typed + * [ParsedDirectoryFileId] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun parsedDirectoryFileId(parsedDirectoryFileId: JsonField) = + apply { + this.parsedDirectoryFileId = parsedDirectoryFileId + } + + 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 [StaticFilters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): StaticFilters = + StaticFilters(parsedDirectoryFileId, 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): StaticFilters = apply { + if (validated) { + return@apply + } + + parsedDirectoryFileId().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (parsedDirectoryFileId.asKnown().getOrNull()?.validity() ?: 0) + + /** Filter on a string field. */ + class ParsedDirectoryFileId + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val operator: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("operator") + @ExcludeMissing + operator: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), + ) : this(operator, value, mutableMapOf()) + + /** + * @throws LlamaCloudInvalidDataException 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 operator(): Operator = operator.getRequired("operator") + + /** + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun value(): Value = value.getRequired("value") + + /** + * Returns the raw JSON value of [operator]. + * + * Unlike [operator], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("operator") + @ExcludeMissing + fun _operator(): JsonField = operator + + /** + * Returns the raw JSON value of [value]. + * + * Unlike [value], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [ParsedDirectoryFileId]. + * + * The following fields are required: + * ```java + * .operator() + * .value() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ParsedDirectoryFileId]. */ + class Builder internal constructor() { + + private var operator: JsonField? = null + private var value: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(parsedDirectoryFileId: ParsedDirectoryFileId) = apply { + operator = parsedDirectoryFileId.operator + value = parsedDirectoryFileId.value + additionalProperties = parsedDirectoryFileId.additionalProperties.toMutableMap() + } + + fun operator(operator: Operator) = operator(JsonField.of(operator)) + + /** + * Sets [Builder.operator] to an arbitrary JSON value. + * + * You should usually call [Builder.operator] with a well-typed [Operator] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun operator(operator: JsonField) = apply { this.operator = operator } + + fun value(value: Value) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Value] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun value(value: JsonField) = apply { this.value = value } + + /** Alias for calling [value] with `Value.ofString(string)`. */ + fun value(string: String) = value(Value.ofString(string)) + + /** Alias for calling [value] with `Value.ofStrings(strings)`. */ + fun valueOfStrings(strings: List) = value(Value.ofStrings(strings)) + + 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 [ParsedDirectoryFileId]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .operator() + * .value() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ParsedDirectoryFileId = + ParsedDirectoryFileId( + checkRequired("operator", operator), + checkRequired("value", value), + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): ParsedDirectoryFileId = apply { + if (validated) { + return@apply + } + + operator().validate() + value().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (operator.asKnown().getOrNull()?.validity() ?: 0) + + (value.asKnown().getOrNull()?.validity() ?: 0) + + class Operator @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 EQ = of("eq") + + @JvmField val GT = of("gt") + + @JvmField val GTE = of("gte") + + @JvmField val IN = of("in") + + @JvmField val LT = of("lt") + + @JvmField val LTE = of("lte") + + @JvmField val NE = of("ne") + + @JvmField val NIN = of("nin") + + @JvmStatic fun of(value: String) = Operator(JsonField.of(value)) + } + + /** An enum containing [Operator]'s known values. */ + enum class Known { + EQ, + GT, + GTE, + IN, + LT, + LTE, + NE, + NIN, + } + + /** + * An enum containing [Operator]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operator] 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 { + EQ, + GT, + GTE, + IN, + LT, + LTE, + NE, + NIN, + /** + * An enum member indicating that [Operator] 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) { + EQ -> Value.EQ + GT -> Value.GT + GTE -> Value.GTE + IN -> Value.IN + LT -> Value.LT + LTE -> Value.LTE + NE -> Value.NE + NIN -> Value.NIN + 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 LlamaCloudInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + EQ -> Known.EQ + GT -> Known.GT + GTE -> Known.GTE + IN -> Known.IN + LT -> Known.LT + LTE -> Known.LTE + NE -> Known.NE + NIN -> Known.NIN + else -> throw LlamaCloudInvalidDataException("Unknown Operator: $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 LlamaCloudInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LlamaCloudInvalidDataException("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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Operator = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Operator && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + 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 ai.llamaindex.llamacloud.core.JsonValue; + * import java.util.Optional; + * + * Optional result = value.accept(new Value.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 LlamaCloudInvalidDataException 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Value = 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: LlamaCloudInvalidDataException) { + 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 Value && string == other.string && strings == other.strings + } + + override fun hashCode(): Int = Objects.hash(string, strings) + + override fun toString(): String = + when { + string != null -> "Value{string=$string}" + strings != null -> "Value{strings=$strings}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofString(string: String) = Value(string = string) + + @JvmStatic + fun ofStrings(strings: List) = Value(strings = strings.toImmutable()) + } + + /** + * An interface that defines how to map each variant of [Value] to a value of type + * [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + fun visitStrings(strings: List): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] 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 LlamaCloudInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw LlamaCloudInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef>())?.let { + Value(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 -> Value(_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(Value::class) { + + override fun serialize( + value: Value, + 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 Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ParsedDirectoryFileId && + operator == other.operator && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(operator, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ParsedDirectoryFileId{operator=$operator, value=$value, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StaticFilters && + parsedDirectoryFileId == other.parsedDirectoryFileId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(parsedDirectoryFileId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "StaticFilters{parsedDirectoryFileId=$parsedDirectoryFileId, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalRetrieveParams && + organizationId == other.organizationId && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(organizationId, projectId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RetrievalRetrieveParams{organizationId=$organizationId, projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalRetrieveResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalRetrieveResponse.kt new file mode 100644 index 0000000..7465644 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalRetrieveResponse.kt @@ -0,0 +1,1519 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.ExcludeMissing +import ai.llamaindex.llamacloud.core.JsonField +import ai.llamaindex.llamacloud.core.JsonMissing +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.checkKnown +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.toImmutable +import ai.llamaindex.llamacloud.errors.LlamaCloudInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Response containing retrieval results. */ +class RetrievalRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val results: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("results") @ExcludeMissing results: JsonField> = JsonMissing.of() + ) : this(results, mutableMapOf()) + + /** + * Ordered list of retrieved chunks. + * + * @throws LlamaCloudInvalidDataException 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 results(): List = results.getRequired("results") + + /** + * Returns the raw JSON value of [results]. + * + * Unlike [results], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("results") @ExcludeMissing fun _results(): JsonField> = results + + @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 [RetrievalRetrieveResponse]. + * + * The following fields are required: + * ```java + * .results() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RetrievalRetrieveResponse]. */ + class Builder internal constructor() { + + private var results: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(retrievalRetrieveResponse: RetrievalRetrieveResponse) = apply { + results = retrievalRetrieveResponse.results.map { it.toMutableList() } + additionalProperties = retrievalRetrieveResponse.additionalProperties.toMutableMap() + } + + /** Ordered list of retrieved chunks. */ + fun results(results: List) = results(JsonField.of(results)) + + /** + * Sets [Builder.results] to an arbitrary JSON value. + * + * You should usually call [Builder.results] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun results(results: JsonField>) = apply { + this.results = results.map { it.toMutableList() } + } + + /** + * Adds a single [Result] to [results]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addResult(result: Result) = apply { + results = + (results ?: JsonField.of(mutableListOf())).also { + checkKnown("results", it).add(result) + } + } + + 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 [RetrievalRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .results() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RetrievalRetrieveResponse = + RetrievalRetrieveResponse( + checkRequired("results", results).map { it.toImmutable() }, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): RetrievalRetrieveResponse = apply { + if (validated) { + return@apply + } + + results().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (results.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + /** A single retrieval result. */ + class Result + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val content: JsonField, + private val metadata: JsonField, + private val rerankScore: JsonField, + private val score: JsonField, + private val staticFields: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("rerank_score") + @ExcludeMissing + rerankScore: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + @JsonProperty("static_fields") + @ExcludeMissing + staticFields: JsonField = JsonMissing.of(), + ) : this(content, metadata, rerankScore, score, staticFields, mutableMapOf()) + + /** + * Text content of the retrieved chunk. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun content(): String = content.getRequired("content") + + /** + * User-defined metadata associated with the chunk. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Relevance score from the reranker, if reranking was applied. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun rerankScore(): Optional = rerankScore.getOptional("rerank_score") + + /** + * Hybrid search relevance score. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun score(): Optional = score.getOptional("score") + + /** + * Built-in fields stored for every exported chunk. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun staticFields(): Optional = staticFields.getOptional("static_fields") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [rerankScore]. + * + * Unlike [rerankScore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rerank_score") + @ExcludeMissing + fun _rerankScore(): JsonField = rerankScore + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + /** + * Returns the raw JSON value of [staticFields]. + * + * Unlike [staticFields], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("static_fields") + @ExcludeMissing + fun _staticFields(): JsonField = staticFields + + @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 [Result]. + * + * The following fields are required: + * ```java + * .content() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Result]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var metadata: JsonField = JsonMissing.of() + private var rerankScore: JsonField = JsonMissing.of() + private var score: JsonField = JsonMissing.of() + private var staticFields: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(result: Result) = apply { + content = result.content + metadata = result.metadata + rerankScore = result.rerankScore + score = result.score + staticFields = result.staticFields + additionalProperties = result.additionalProperties.toMutableMap() + } + + /** Text content of the retrieved chunk. */ + fun content(content: String) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + /** User-defined metadata associated with the chunk. */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** Relevance score from the reranker, if reranking was applied. */ + fun rerankScore(rerankScore: Double?) = rerankScore(JsonField.ofNullable(rerankScore)) + + /** + * Alias for [Builder.rerankScore]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun rerankScore(rerankScore: Double) = rerankScore(rerankScore as Double?) + + /** Alias for calling [Builder.rerankScore] with `rerankScore.orElse(null)`. */ + fun rerankScore(rerankScore: Optional) = rerankScore(rerankScore.getOrNull()) + + /** + * Sets [Builder.rerankScore] to an arbitrary JSON value. + * + * You should usually call [Builder.rerankScore] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun rerankScore(rerankScore: JsonField) = apply { + this.rerankScore = rerankScore + } + + /** Hybrid search relevance score. */ + fun score(score: Double?) = score(JsonField.ofNullable(score)) + + /** + * Alias for [Builder.score]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun score(score: Double) = score(score as Double?) + + /** Alias for calling [Builder.score] with `score.orElse(null)`. */ + fun score(score: Optional) = score(score.getOrNull()) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + /** Built-in fields stored for every exported chunk. */ + fun staticFields(staticFields: StaticFields) = staticFields(JsonField.of(staticFields)) + + /** + * Sets [Builder.staticFields] to an arbitrary JSON value. + * + * You should usually call [Builder.staticFields] with a well-typed [StaticFields] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun staticFields(staticFields: JsonField) = apply { + this.staticFields = staticFields + } + + 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 [Result]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Result = + Result( + checkRequired("content", content), + metadata, + rerankScore, + score, + staticFields, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Result = apply { + if (validated) { + return@apply + } + + content() + metadata().ifPresent { it.validate() } + rerankScore() + score() + staticFields().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (content.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (rerankScore.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + (staticFields.asKnown().getOrNull()?.validity() ?: 0) + + /** User-defined metadata associated with the chunk. */ + class Metadata + @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 [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.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 [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + /** Built-in fields stored for every exported chunk. */ + class StaticFields + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val attachments: JsonField>, + private val chunkEndChar: JsonField, + private val chunkIndex: JsonField, + private val chunkStartChar: JsonField, + private val chunkTokenCount: JsonField, + private val pageRangeEnd: JsonField, + private val pageRangeStart: JsonField, + private val parsedDirectoryFileId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("attachments") + @ExcludeMissing + attachments: JsonField> = JsonMissing.of(), + @JsonProperty("chunk_end_char") + @ExcludeMissing + chunkEndChar: JsonField = JsonMissing.of(), + @JsonProperty("chunk_index") + @ExcludeMissing + chunkIndex: JsonField = JsonMissing.of(), + @JsonProperty("chunk_start_char") + @ExcludeMissing + chunkStartChar: JsonField = JsonMissing.of(), + @JsonProperty("chunk_token_count") + @ExcludeMissing + chunkTokenCount: JsonField = JsonMissing.of(), + @JsonProperty("page_range_end") + @ExcludeMissing + pageRangeEnd: JsonField = JsonMissing.of(), + @JsonProperty("page_range_start") + @ExcludeMissing + pageRangeStart: JsonField = JsonMissing.of(), + @JsonProperty("parsed_directory_file_id") + @ExcludeMissing + parsedDirectoryFileId: JsonField = JsonMissing.of(), + ) : this( + attachments, + chunkEndChar, + chunkIndex, + chunkStartChar, + chunkTokenCount, + pageRangeEnd, + pageRangeStart, + parsedDirectoryFileId, + mutableMapOf(), + ) + + /** + * Attachments associated with the chunk + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun attachments(): Optional> = attachments.getOptional("attachments") + + /** + * End character offset of the chunk. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun chunkEndChar(): Optional = chunkEndChar.getOptional("chunk_end_char") + + /** + * Index of the chunk within the file. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun chunkIndex(): Optional = chunkIndex.getOptional("chunk_index") + + /** + * Start character offset of the chunk. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun chunkStartChar(): Optional = chunkStartChar.getOptional("chunk_start_char") + + /** + * Token count of the chunk. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun chunkTokenCount(): Optional = chunkTokenCount.getOptional("chunk_token_count") + + /** + * Last page number covered by this chunk. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun pageRangeEnd(): Optional = pageRangeEnd.getOptional("page_range_end") + + /** + * First page number covered by this chunk. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun pageRangeStart(): Optional = pageRangeStart.getOptional("page_range_start") + + /** + * ID of the parsed file. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun parsedDirectoryFileId(): Optional = + parsedDirectoryFileId.getOptional("parsed_directory_file_id") + + /** + * Returns the raw JSON value of [attachments]. + * + * Unlike [attachments], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("attachments") + @ExcludeMissing + fun _attachments(): JsonField> = attachments + + /** + * Returns the raw JSON value of [chunkEndChar]. + * + * Unlike [chunkEndChar], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("chunk_end_char") + @ExcludeMissing + fun _chunkEndChar(): JsonField = chunkEndChar + + /** + * Returns the raw JSON value of [chunkIndex]. + * + * Unlike [chunkIndex], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("chunk_index") + @ExcludeMissing + fun _chunkIndex(): JsonField = chunkIndex + + /** + * Returns the raw JSON value of [chunkStartChar]. + * + * Unlike [chunkStartChar], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("chunk_start_char") + @ExcludeMissing + fun _chunkStartChar(): JsonField = chunkStartChar + + /** + * Returns the raw JSON value of [chunkTokenCount]. + * + * Unlike [chunkTokenCount], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("chunk_token_count") + @ExcludeMissing + fun _chunkTokenCount(): JsonField = chunkTokenCount + + /** + * Returns the raw JSON value of [pageRangeEnd]. + * + * Unlike [pageRangeEnd], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("page_range_end") + @ExcludeMissing + fun _pageRangeEnd(): JsonField = pageRangeEnd + + /** + * Returns the raw JSON value of [pageRangeStart]. + * + * Unlike [pageRangeStart], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("page_range_start") + @ExcludeMissing + fun _pageRangeStart(): JsonField = pageRangeStart + + /** + * Returns the raw JSON value of [parsedDirectoryFileId]. + * + * Unlike [parsedDirectoryFileId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("parsed_directory_file_id") + @ExcludeMissing + fun _parsedDirectoryFileId(): JsonField = parsedDirectoryFileId + + @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 [StaticFields]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StaticFields]. */ + class Builder internal constructor() { + + private var attachments: JsonField>? = null + private var chunkEndChar: JsonField = JsonMissing.of() + private var chunkIndex: JsonField = JsonMissing.of() + private var chunkStartChar: JsonField = JsonMissing.of() + private var chunkTokenCount: JsonField = JsonMissing.of() + private var pageRangeEnd: JsonField = JsonMissing.of() + private var pageRangeStart: JsonField = JsonMissing.of() + private var parsedDirectoryFileId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(staticFields: StaticFields) = apply { + attachments = staticFields.attachments.map { it.toMutableList() } + chunkEndChar = staticFields.chunkEndChar + chunkIndex = staticFields.chunkIndex + chunkStartChar = staticFields.chunkStartChar + chunkTokenCount = staticFields.chunkTokenCount + pageRangeEnd = staticFields.pageRangeEnd + pageRangeStart = staticFields.pageRangeStart + parsedDirectoryFileId = staticFields.parsedDirectoryFileId + additionalProperties = staticFields.additionalProperties.toMutableMap() + } + + /** Attachments associated with the chunk */ + fun attachments(attachments: List) = + attachments(JsonField.of(attachments)) + + /** + * Sets [Builder.attachments] to an arbitrary JSON value. + * + * You should usually call [Builder.attachments] with a well-typed + * `List` value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun attachments(attachments: JsonField>) = apply { + this.attachments = attachments.map { it.toMutableList() } + } + + /** + * Adds a single [Attachment] to [attachments]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAttachment(attachment: Attachment) = apply { + attachments = + (attachments ?: JsonField.of(mutableListOf())).also { + checkKnown("attachments", it).add(attachment) + } + } + + /** End character offset of the chunk. */ + fun chunkEndChar(chunkEndChar: Long?) = + chunkEndChar(JsonField.ofNullable(chunkEndChar)) + + /** + * Alias for [Builder.chunkEndChar]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun chunkEndChar(chunkEndChar: Long) = chunkEndChar(chunkEndChar as Long?) + + /** Alias for calling [Builder.chunkEndChar] with `chunkEndChar.orElse(null)`. */ + fun chunkEndChar(chunkEndChar: Optional) = + chunkEndChar(chunkEndChar.getOrNull()) + + /** + * Sets [Builder.chunkEndChar] to an arbitrary JSON value. + * + * You should usually call [Builder.chunkEndChar] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun chunkEndChar(chunkEndChar: JsonField) = apply { + this.chunkEndChar = chunkEndChar + } + + /** Index of the chunk within the file. */ + fun chunkIndex(chunkIndex: Long?) = chunkIndex(JsonField.ofNullable(chunkIndex)) + + /** + * Alias for [Builder.chunkIndex]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun chunkIndex(chunkIndex: Long) = chunkIndex(chunkIndex as Long?) + + /** Alias for calling [Builder.chunkIndex] with `chunkIndex.orElse(null)`. */ + fun chunkIndex(chunkIndex: Optional) = chunkIndex(chunkIndex.getOrNull()) + + /** + * Sets [Builder.chunkIndex] to an arbitrary JSON value. + * + * You should usually call [Builder.chunkIndex] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun chunkIndex(chunkIndex: JsonField) = apply { this.chunkIndex = chunkIndex } + + /** Start character offset of the chunk. */ + fun chunkStartChar(chunkStartChar: Long?) = + chunkStartChar(JsonField.ofNullable(chunkStartChar)) + + /** + * Alias for [Builder.chunkStartChar]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun chunkStartChar(chunkStartChar: Long) = chunkStartChar(chunkStartChar as Long?) + + /** + * Alias for calling [Builder.chunkStartChar] with `chunkStartChar.orElse(null)`. + */ + fun chunkStartChar(chunkStartChar: Optional) = + chunkStartChar(chunkStartChar.getOrNull()) + + /** + * Sets [Builder.chunkStartChar] to an arbitrary JSON value. + * + * You should usually call [Builder.chunkStartChar] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun chunkStartChar(chunkStartChar: JsonField) = apply { + this.chunkStartChar = chunkStartChar + } + + /** Token count of the chunk. */ + fun chunkTokenCount(chunkTokenCount: Long?) = + chunkTokenCount(JsonField.ofNullable(chunkTokenCount)) + + /** + * Alias for [Builder.chunkTokenCount]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun chunkTokenCount(chunkTokenCount: Long) = + chunkTokenCount(chunkTokenCount as Long?) + + /** + * Alias for calling [Builder.chunkTokenCount] with `chunkTokenCount.orElse(null)`. + */ + fun chunkTokenCount(chunkTokenCount: Optional) = + chunkTokenCount(chunkTokenCount.getOrNull()) + + /** + * Sets [Builder.chunkTokenCount] to an arbitrary JSON value. + * + * You should usually call [Builder.chunkTokenCount] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun chunkTokenCount(chunkTokenCount: JsonField) = apply { + this.chunkTokenCount = chunkTokenCount + } + + /** Last page number covered by this chunk. */ + fun pageRangeEnd(pageRangeEnd: Long?) = + pageRangeEnd(JsonField.ofNullable(pageRangeEnd)) + + /** + * Alias for [Builder.pageRangeEnd]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun pageRangeEnd(pageRangeEnd: Long) = pageRangeEnd(pageRangeEnd as Long?) + + /** Alias for calling [Builder.pageRangeEnd] with `pageRangeEnd.orElse(null)`. */ + fun pageRangeEnd(pageRangeEnd: Optional) = + pageRangeEnd(pageRangeEnd.getOrNull()) + + /** + * Sets [Builder.pageRangeEnd] to an arbitrary JSON value. + * + * You should usually call [Builder.pageRangeEnd] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun pageRangeEnd(pageRangeEnd: JsonField) = apply { + this.pageRangeEnd = pageRangeEnd + } + + /** First page number covered by this chunk. */ + fun pageRangeStart(pageRangeStart: Long?) = + pageRangeStart(JsonField.ofNullable(pageRangeStart)) + + /** + * Alias for [Builder.pageRangeStart]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun pageRangeStart(pageRangeStart: Long) = pageRangeStart(pageRangeStart as Long?) + + /** + * Alias for calling [Builder.pageRangeStart] with `pageRangeStart.orElse(null)`. + */ + fun pageRangeStart(pageRangeStart: Optional) = + pageRangeStart(pageRangeStart.getOrNull()) + + /** + * Sets [Builder.pageRangeStart] to an arbitrary JSON value. + * + * You should usually call [Builder.pageRangeStart] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun pageRangeStart(pageRangeStart: JsonField) = apply { + this.pageRangeStart = pageRangeStart + } + + /** ID of the parsed file. */ + fun parsedDirectoryFileId(parsedDirectoryFileId: String?) = + parsedDirectoryFileId(JsonField.ofNullable(parsedDirectoryFileId)) + + /** + * Alias for calling [Builder.parsedDirectoryFileId] with + * `parsedDirectoryFileId.orElse(null)`. + */ + fun parsedDirectoryFileId(parsedDirectoryFileId: Optional) = + parsedDirectoryFileId(parsedDirectoryFileId.getOrNull()) + + /** + * Sets [Builder.parsedDirectoryFileId] to an arbitrary JSON value. + * + * You should usually call [Builder.parsedDirectoryFileId] with a well-typed + * [String] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun parsedDirectoryFileId(parsedDirectoryFileId: JsonField) = apply { + this.parsedDirectoryFileId = parsedDirectoryFileId + } + + 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 [StaticFields]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): StaticFields = + StaticFields( + (attachments ?: JsonMissing.of()).map { it.toImmutable() }, + chunkEndChar, + chunkIndex, + chunkStartChar, + chunkTokenCount, + pageRangeEnd, + pageRangeStart, + parsedDirectoryFileId, + 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 LlamaCloudInvalidDataException if any value type in this object doesn't match + * its expected type. + */ + fun validate(): StaticFields = apply { + if (validated) { + return@apply + } + + attachments().ifPresent { it.forEach { it.validate() } } + chunkEndChar() + chunkIndex() + chunkStartChar() + chunkTokenCount() + pageRangeEnd() + pageRangeStart() + parsedDirectoryFileId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 = + (attachments.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (chunkEndChar.asKnown().isPresent) 1 else 0) + + (if (chunkIndex.asKnown().isPresent) 1 else 0) + + (if (chunkStartChar.asKnown().isPresent) 1 else 0) + + (if (chunkTokenCount.asKnown().isPresent) 1 else 0) + + (if (pageRangeEnd.asKnown().isPresent) 1 else 0) + + (if (pageRangeStart.asKnown().isPresent) 1 else 0) + + (if (parsedDirectoryFileId.asKnown().isPresent) 1 else 0) + + /** + * Reference to a file attachment, retrievable via ``GET + * /api/v1/beta/attachments/{attachment_name}?source_id=...``. + */ + class Attachment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val attachmentName: JsonField, + private val sourceId: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("attachment_name") + @ExcludeMissing + attachmentName: JsonField = JsonMissing.of(), + @JsonProperty("source_id") + @ExcludeMissing + sourceId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(attachmentName, sourceId, type, mutableMapOf()) + + /** + * Attachment-relative path, e.g. 'screenshots/page_7.jpg'. + * + * @throws LlamaCloudInvalidDataException 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 attachmentName(): String = attachmentName.getRequired("attachment_name") + + /** + * File ID to pass as source_id when fetching the attachment. + * + * @throws LlamaCloudInvalidDataException 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 sourceId(): String = sourceId.getRequired("source_id") + + /** + * Attachment kind, e.g. 'screenshot', 'items'. + * + * @throws LlamaCloudInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun type(): String = type.getRequired("type") + + /** + * Returns the raw JSON value of [attachmentName]. + * + * Unlike [attachmentName], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("attachment_name") + @ExcludeMissing + fun _attachmentName(): JsonField = attachmentName + + /** + * Returns the raw JSON value of [sourceId]. + * + * Unlike [sourceId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("source_id") + @ExcludeMissing + fun _sourceId(): JsonField = sourceId + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Attachment]. + * + * The following fields are required: + * ```java + * .attachmentName() + * .sourceId() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Attachment]. */ + class Builder internal constructor() { + + private var attachmentName: JsonField? = null + private var sourceId: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(attachment: Attachment) = apply { + attachmentName = attachment.attachmentName + sourceId = attachment.sourceId + type = attachment.type + additionalProperties = attachment.additionalProperties.toMutableMap() + } + + /** Attachment-relative path, e.g. 'screenshots/page_7.jpg'. */ + fun attachmentName(attachmentName: String) = + attachmentName(JsonField.of(attachmentName)) + + /** + * Sets [Builder.attachmentName] to an arbitrary JSON value. + * + * You should usually call [Builder.attachmentName] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun attachmentName(attachmentName: JsonField) = apply { + this.attachmentName = attachmentName + } + + /** File ID to pass as source_id when fetching the attachment. */ + fun sourceId(sourceId: String) = sourceId(JsonField.of(sourceId)) + + /** + * Sets [Builder.sourceId] to an arbitrary JSON value. + * + * You should usually call [Builder.sourceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun sourceId(sourceId: JsonField) = apply { this.sourceId = sourceId } + + /** Attachment kind, e.g. 'screenshot', 'items'. */ + fun type(type: String) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Attachment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .attachmentName() + * .sourceId() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Attachment = + Attachment( + checkRequired("attachmentName", attachmentName), + checkRequired("sourceId", sourceId), + checkRequired("type", 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 LlamaCloudInvalidDataException if any value type in this object doesn't + * match its expected type. + */ + fun validate(): Attachment = apply { + if (validated) { + return@apply + } + + attachmentName() + sourceId() + type() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LlamaCloudInvalidDataException) { + 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 (attachmentName.asKnown().isPresent) 1 else 0) + + (if (sourceId.asKnown().isPresent) 1 else 0) + + (if (type.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Attachment && + attachmentName == other.attachmentName && + sourceId == other.sourceId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(attachmentName, sourceId, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Attachment{attachmentName=$attachmentName, sourceId=$sourceId, type=$type, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StaticFields && + attachments == other.attachments && + chunkEndChar == other.chunkEndChar && + chunkIndex == other.chunkIndex && + chunkStartChar == other.chunkStartChar && + chunkTokenCount == other.chunkTokenCount && + pageRangeEnd == other.pageRangeEnd && + pageRangeStart == other.pageRangeStart && + parsedDirectoryFileId == other.parsedDirectoryFileId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + attachments, + chunkEndChar, + chunkIndex, + chunkStartChar, + chunkTokenCount, + pageRangeEnd, + pageRangeStart, + parsedDirectoryFileId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "StaticFields{attachments=$attachments, chunkEndChar=$chunkEndChar, chunkIndex=$chunkIndex, chunkStartChar=$chunkStartChar, chunkTokenCount=$chunkTokenCount, pageRangeEnd=$pageRangeEnd, pageRangeStart=$pageRangeStart, parsedDirectoryFileId=$parsedDirectoryFileId, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Result && + content == other.content && + metadata == other.metadata && + rerankScore == other.rerankScore && + score == other.score && + staticFields == other.staticFields && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(content, metadata, rerankScore, score, staticFields, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Result{content=$content, metadata=$metadata, rerankScore=$rerankScore, score=$score, staticFields=$staticFields, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RetrievalRetrieveResponse && + results == other.results && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(results, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RetrievalRetrieveResponse{results=$results, additionalProperties=$additionalProperties}" +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/split/SplitCreateParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/split/SplitCreateParams.kt index 2f9e1f7..2e74a90 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/split/SplitCreateParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/split/SplitCreateParams.kt @@ -2473,6 +2473,16 @@ private constructor( @JvmField val UNMAPPED_EVENT = of("unmapped_event") + @JvmField val VERIFY_CANCELLED = of("verify.cancelled") + + @JvmField val VERIFY_ERROR = of("verify.error") + + @JvmField val VERIFY_PENDING = of("verify.pending") + + @JvmField val VERIFY_RUNNING = of("verify.running") + + @JvmField val VERIFY_SUCCESS = of("verify.success") + @JvmStatic fun of(value: String) = WebhookEvent(JsonField.of(value)) } @@ -2511,6 +2521,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, } /** @@ -2556,6 +2571,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, /** * An enum member indicating that [WebhookEvent] was instantiated with an unknown * value. @@ -2605,6 +2625,11 @@ private constructor( SPLIT_PROCESSING -> Value.SPLIT_PROCESSING SPLIT_SUCCESS -> Value.SPLIT_SUCCESS UNMAPPED_EVENT -> Value.UNMAPPED_EVENT + VERIFY_CANCELLED -> Value.VERIFY_CANCELLED + VERIFY_ERROR -> Value.VERIFY_ERROR + VERIFY_PENDING -> Value.VERIFY_PENDING + VERIFY_RUNNING -> Value.VERIFY_RUNNING + VERIFY_SUCCESS -> Value.VERIFY_SUCCESS else -> Value._UNKNOWN } @@ -2652,6 +2677,11 @@ private constructor( SPLIT_PROCESSING -> Known.SPLIT_PROCESSING SPLIT_SUCCESS -> Known.SPLIT_SUCCESS UNMAPPED_EVENT -> Known.UNMAPPED_EVENT + VERIFY_CANCELLED -> Known.VERIFY_CANCELLED + VERIFY_ERROR -> Known.VERIFY_ERROR + VERIFY_PENDING -> Known.VERIFY_PENDING + VERIFY_RUNNING -> Known.VERIFY_RUNNING + VERIFY_SUCCESS -> Known.VERIFY_SUCCESS else -> throw LlamaCloudInvalidDataException("Unknown WebhookEvent: $value") } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/webhookconfigs/WebhookConfigCreate.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/webhookconfigs/WebhookConfigCreate.kt index 6f2537d..dbfe91b 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/webhookconfigs/WebhookConfigCreate.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/webhookconfigs/WebhookConfigCreate.kt @@ -474,6 +474,16 @@ private constructor( @JvmField val UNMAPPED_EVENT = of("unmapped_event") + @JvmField val VERIFY_CANCELLED = of("verify.cancelled") + + @JvmField val VERIFY_ERROR = of("verify.error") + + @JvmField val VERIFY_PENDING = of("verify.pending") + + @JvmField val VERIFY_RUNNING = of("verify.running") + + @JvmField val VERIFY_SUCCESS = of("verify.success") + @JvmStatic fun of(value: String) = WebhookEvent(JsonField.of(value)) } @@ -512,6 +522,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, } /** @@ -557,6 +572,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, /** * An enum member indicating that [WebhookEvent] was instantiated with an unknown value. */ @@ -605,6 +625,11 @@ private constructor( SPLIT_PROCESSING -> Value.SPLIT_PROCESSING SPLIT_SUCCESS -> Value.SPLIT_SUCCESS UNMAPPED_EVENT -> Value.UNMAPPED_EVENT + VERIFY_CANCELLED -> Value.VERIFY_CANCELLED + VERIFY_ERROR -> Value.VERIFY_ERROR + VERIFY_PENDING -> Value.VERIFY_PENDING + VERIFY_RUNNING -> Value.VERIFY_RUNNING + VERIFY_SUCCESS -> Value.VERIFY_SUCCESS else -> Value._UNKNOWN } @@ -652,6 +677,11 @@ private constructor( SPLIT_PROCESSING -> Known.SPLIT_PROCESSING SPLIT_SUCCESS -> Known.SPLIT_SUCCESS UNMAPPED_EVENT -> Known.UNMAPPED_EVENT + VERIFY_CANCELLED -> Known.VERIFY_CANCELLED + VERIFY_ERROR -> Known.VERIFY_ERROR + VERIFY_PENDING -> Known.VERIFY_PENDING + VERIFY_RUNNING -> Known.VERIFY_RUNNING + VERIFY_SUCCESS -> Known.VERIFY_SUCCESS else -> throw LlamaCloudInvalidDataException("Unknown WebhookEvent: $value") } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/webhookconfigs/WebhookConfigResponse.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/webhookconfigs/WebhookConfigResponse.kt index 3201b1a..ace0539 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/webhookconfigs/WebhookConfigResponse.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/webhookconfigs/WebhookConfigResponse.kt @@ -646,6 +646,16 @@ private constructor( @JvmField val UNMAPPED_EVENT = of("unmapped_event") + @JvmField val VERIFY_CANCELLED = of("verify.cancelled") + + @JvmField val VERIFY_ERROR = of("verify.error") + + @JvmField val VERIFY_PENDING = of("verify.pending") + + @JvmField val VERIFY_RUNNING = of("verify.running") + + @JvmField val VERIFY_SUCCESS = of("verify.success") + @JvmStatic fun of(value: String) = WebhookEvent(JsonField.of(value)) } @@ -684,6 +694,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, } /** @@ -729,6 +744,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, /** * An enum member indicating that [WebhookEvent] was instantiated with an unknown value. */ @@ -777,6 +797,11 @@ private constructor( SPLIT_PROCESSING -> Value.SPLIT_PROCESSING SPLIT_SUCCESS -> Value.SPLIT_SUCCESS UNMAPPED_EVENT -> Value.UNMAPPED_EVENT + VERIFY_CANCELLED -> Value.VERIFY_CANCELLED + VERIFY_ERROR -> Value.VERIFY_ERROR + VERIFY_PENDING -> Value.VERIFY_PENDING + VERIFY_RUNNING -> Value.VERIFY_RUNNING + VERIFY_SUCCESS -> Value.VERIFY_SUCCESS else -> Value._UNKNOWN } @@ -824,6 +849,11 @@ private constructor( SPLIT_PROCESSING -> Known.SPLIT_PROCESSING SPLIT_SUCCESS -> Known.SPLIT_SUCCESS UNMAPPED_EVENT -> Known.UNMAPPED_EVENT + VERIFY_CANCELLED -> Known.VERIFY_CANCELLED + VERIFY_ERROR -> Known.VERIFY_ERROR + VERIFY_PENDING -> Known.VERIFY_PENDING + VERIFY_RUNNING -> Known.VERIFY_RUNNING + VERIFY_SUCCESS -> Known.VERIFY_SUCCESS else -> throw LlamaCloudInvalidDataException("Unknown WebhookEvent: $value") } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/webhookconfigs/WebhookConfigUpdateParams.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/webhookconfigs/WebhookConfigUpdateParams.kt index db797af..2cd97d1 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/webhookconfigs/WebhookConfigUpdateParams.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/models/webhookconfigs/WebhookConfigUpdateParams.kt @@ -918,6 +918,16 @@ private constructor( @JvmField val UNMAPPED_EVENT = of("unmapped_event") + @JvmField val VERIFY_CANCELLED = of("verify.cancelled") + + @JvmField val VERIFY_ERROR = of("verify.error") + + @JvmField val VERIFY_PENDING = of("verify.pending") + + @JvmField val VERIFY_RUNNING = of("verify.running") + + @JvmField val VERIFY_SUCCESS = of("verify.success") + @JvmStatic fun of(value: String) = WebhookEvent(JsonField.of(value)) } @@ -956,6 +966,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, } /** @@ -1001,6 +1016,11 @@ private constructor( SPLIT_PROCESSING, SPLIT_SUCCESS, UNMAPPED_EVENT, + VERIFY_CANCELLED, + VERIFY_ERROR, + VERIFY_PENDING, + VERIFY_RUNNING, + VERIFY_SUCCESS, /** * An enum member indicating that [WebhookEvent] was instantiated with an unknown value. */ @@ -1049,6 +1069,11 @@ private constructor( SPLIT_PROCESSING -> Value.SPLIT_PROCESSING SPLIT_SUCCESS -> Value.SPLIT_SUCCESS UNMAPPED_EVENT -> Value.UNMAPPED_EVENT + VERIFY_CANCELLED -> Value.VERIFY_CANCELLED + VERIFY_ERROR -> Value.VERIFY_ERROR + VERIFY_PENDING -> Value.VERIFY_PENDING + VERIFY_RUNNING -> Value.VERIFY_RUNNING + VERIFY_SUCCESS -> Value.VERIFY_SUCCESS else -> Value._UNKNOWN } @@ -1096,6 +1121,11 @@ private constructor( SPLIT_PROCESSING -> Known.SPLIT_PROCESSING SPLIT_SUCCESS -> Known.SPLIT_SUCCESS UNMAPPED_EVENT -> Known.UNMAPPED_EVENT + VERIFY_CANCELLED -> Known.VERIFY_CANCELLED + VERIFY_ERROR -> Known.VERIFY_ERROR + VERIFY_PENDING -> Known.VERIFY_PENDING + VERIFY_RUNNING -> Known.VERIFY_RUNNING + VERIFY_SUCCESS -> Known.VERIFY_SUCCESS else -> throw LlamaCloudInvalidDataException("Unknown WebhookEvent: $value") } diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/AlphaServiceAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/AlphaServiceAsync.kt new file mode 100644 index 0000000..9f3189f --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/AlphaServiceAsync.kt @@ -0,0 +1,39 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.services.async.alpha.VerifyServiceAsync +import java.util.function.Consumer + +interface AlphaServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AlphaServiceAsync + + fun verify(): VerifyServiceAsync + + /** A view of [AlphaServiceAsync] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): AlphaServiceAsync.WithRawResponse + + fun verify(): VerifyServiceAsync.WithRawResponse + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/AlphaServiceAsyncImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/AlphaServiceAsyncImpl.kt new file mode 100644 index 0000000..175dc20 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/AlphaServiceAsyncImpl.kt @@ -0,0 +1,42 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.services.async.alpha.VerifyServiceAsync +import ai.llamaindex.llamacloud.services.async.alpha.VerifyServiceAsyncImpl +import java.util.function.Consumer + +class AlphaServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + AlphaServiceAsync { + + private val withRawResponse: AlphaServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val verify: VerifyServiceAsync by lazy { VerifyServiceAsyncImpl(clientOptions) } + + override fun withRawResponse(): AlphaServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): AlphaServiceAsync = + AlphaServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun verify(): VerifyServiceAsync = verify + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + AlphaServiceAsync.WithRawResponse { + + private val verify: VerifyServiceAsync.WithRawResponse by lazy { + VerifyServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): AlphaServiceAsync.WithRawResponse = + AlphaServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun verify(): VerifyServiceAsync.WithRawResponse = verify + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/ChatServiceAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/ChatServiceAsync.kt new file mode 100644 index 0000000..77cc448 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/ChatServiceAsync.kt @@ -0,0 +1,409 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.http.HttpResponse +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.models.chat.ChatCreateParams +import ai.llamaindex.llamacloud.models.chat.ChatCreateResponse +import ai.llamaindex.llamacloud.models.chat.ChatDeleteParams +import ai.llamaindex.llamacloud.models.chat.ChatGetSummaryParams +import ai.llamaindex.llamacloud.models.chat.ChatGetSummaryResponse +import ai.llamaindex.llamacloud.models.chat.ChatListPageAsync +import ai.llamaindex.llamacloud.models.chat.ChatListParams +import ai.llamaindex.llamacloud.models.chat.ChatRetrieveParams +import ai.llamaindex.llamacloud.models.chat.ChatRetrieveResponse +import ai.llamaindex.llamacloud.models.chat.ChatStreamParams +import ai.llamaindex.llamacloud.models.chat.ChatStreamResponse +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface ChatServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ChatServiceAsync + + /** Create a chat session, optionally bound to indexes (locked after the first message). */ + fun create(): CompletableFuture = create(ChatCreateParams.none()) + + /** @see create */ + fun create( + params: ChatCreateParams = ChatCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see create */ + fun create( + params: ChatCreateParams = ChatCreateParams.none() + ): CompletableFuture = create(params, RequestOptions.none()) + + /** @see create */ + fun create(requestOptions: RequestOptions): CompletableFuture = + create(ChatCreateParams.none(), requestOptions) + + /** Retrieve a full session by ID, including its event history. */ + fun retrieve(sessionId: String): CompletableFuture = + retrieve(sessionId, ChatRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + sessionId: String, + params: ChatRetrieveParams = ChatRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + sessionId: String, + params: ChatRetrieveParams = ChatRetrieveParams.none(), + ): CompletableFuture = retrieve(sessionId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ChatRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve(params: ChatRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + sessionId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(sessionId, ChatRetrieveParams.none(), requestOptions) + + /** List all chat sessions for the current project. */ + fun list(): CompletableFuture = list(ChatListParams.none()) + + /** @see list */ + fun list( + params: ChatListParams = ChatListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list(params: ChatListParams = ChatListParams.none()): CompletableFuture = + list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): CompletableFuture = + list(ChatListParams.none(), requestOptions) + + /** Delete a session. */ + fun delete(sessionId: String): CompletableFuture = + delete(sessionId, ChatDeleteParams.none()) + + /** @see delete */ + fun delete( + sessionId: String, + params: ChatDeleteParams = ChatDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see delete */ + fun delete( + sessionId: String, + params: ChatDeleteParams = ChatDeleteParams.none(), + ): CompletableFuture = delete(sessionId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: ChatDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see delete */ + fun delete(params: ChatDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(sessionId: String, requestOptions: RequestOptions): CompletableFuture = + delete(sessionId, ChatDeleteParams.none(), requestOptions) + + /** Retrieve a session summary by ID. */ + fun getSummary(sessionId: String): CompletableFuture = + getSummary(sessionId, ChatGetSummaryParams.none()) + + /** @see getSummary */ + fun getSummary( + sessionId: String, + params: ChatGetSummaryParams = ChatGetSummaryParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + getSummary(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see getSummary */ + fun getSummary( + sessionId: String, + params: ChatGetSummaryParams = ChatGetSummaryParams.none(), + ): CompletableFuture = + getSummary(sessionId, params, RequestOptions.none()) + + /** @see getSummary */ + fun getSummary( + params: ChatGetSummaryParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see getSummary */ + fun getSummary(params: ChatGetSummaryParams): CompletableFuture = + getSummary(params, RequestOptions.none()) + + /** @see getSummary */ + fun getSummary( + sessionId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + getSummary(sessionId, ChatGetSummaryParams.none(), requestOptions) + + /** Stream agent events for a chat turn as Server-Sent Events. */ + fun stream(sessionId: String, params: ChatStreamParams): CompletableFuture = + stream(sessionId, params, RequestOptions.none()) + + /** @see stream */ + fun stream( + sessionId: String, + params: ChatStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + stream(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see stream */ + fun stream(params: ChatStreamParams): CompletableFuture = + stream(params, RequestOptions.none()) + + /** @see stream */ + fun stream( + params: ChatStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** A view of [ChatServiceAsync] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ChatServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /api/v1/chat`, but is otherwise the same as + * [ChatServiceAsync.create]. + */ + fun create(): CompletableFuture> = + create(ChatCreateParams.none()) + + /** @see create */ + fun create( + params: ChatCreateParams = ChatCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see create */ + fun create( + params: ChatCreateParams = ChatCreateParams.none() + ): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + requestOptions: RequestOptions + ): CompletableFuture> = + create(ChatCreateParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/v1/chat/{session_id}`, but is otherwise the + * same as [ChatServiceAsync.retrieve]. + */ + fun retrieve(sessionId: String): CompletableFuture> = + retrieve(sessionId, ChatRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + sessionId: String, + params: ChatRetrieveParams = ChatRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + sessionId: String, + params: ChatRetrieveParams = ChatRetrieveParams.none(), + ): CompletableFuture> = + retrieve(sessionId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ChatRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve( + params: ChatRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + sessionId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(sessionId, ChatRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/v1/chat`, but is otherwise the same as + * [ChatServiceAsync.list]. + */ + fun list(): CompletableFuture> = + list(ChatListParams.none()) + + /** @see list */ + fun list( + params: ChatListParams = ChatListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: ChatListParams = ChatListParams.none() + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + requestOptions: RequestOptions + ): CompletableFuture> = + list(ChatListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /api/v1/chat/{session_id}`, but is otherwise the + * same as [ChatServiceAsync.delete]. + */ + fun delete(sessionId: String): CompletableFuture = + delete(sessionId, ChatDeleteParams.none()) + + /** @see delete */ + fun delete( + sessionId: String, + params: ChatDeleteParams = ChatDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see delete */ + fun delete( + sessionId: String, + params: ChatDeleteParams = ChatDeleteParams.none(), + ): CompletableFuture = delete(sessionId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: ChatDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see delete */ + fun delete(params: ChatDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + sessionId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + delete(sessionId, ChatDeleteParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/v1/chat/{session_id}/summary`, but is otherwise + * the same as [ChatServiceAsync.getSummary]. + */ + fun getSummary( + sessionId: String + ): CompletableFuture> = + getSummary(sessionId, ChatGetSummaryParams.none()) + + /** @see getSummary */ + fun getSummary( + sessionId: String, + params: ChatGetSummaryParams = ChatGetSummaryParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + getSummary(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see getSummary */ + fun getSummary( + sessionId: String, + params: ChatGetSummaryParams = ChatGetSummaryParams.none(), + ): CompletableFuture> = + getSummary(sessionId, params, RequestOptions.none()) + + /** @see getSummary */ + fun getSummary( + params: ChatGetSummaryParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see getSummary */ + fun getSummary( + params: ChatGetSummaryParams + ): CompletableFuture> = + getSummary(params, RequestOptions.none()) + + /** @see getSummary */ + fun getSummary( + sessionId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + getSummary(sessionId, ChatGetSummaryParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /api/v1/chat/{session_id}/messages/stream`, but is + * otherwise the same as [ChatServiceAsync.stream]. + */ + fun stream( + sessionId: String, + params: ChatStreamParams, + ): CompletableFuture> = + stream(sessionId, params, RequestOptions.none()) + + /** @see stream */ + fun stream( + sessionId: String, + params: ChatStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + stream(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see stream */ + fun stream( + params: ChatStreamParams + ): CompletableFuture> = + stream(params, RequestOptions.none()) + + /** @see stream */ + fun stream( + params: ChatStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/ChatServiceAsyncImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/ChatServiceAsyncImpl.kt new file mode 100644 index 0000000..bed427e --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/ChatServiceAsyncImpl.kt @@ -0,0 +1,306 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.handlers.emptyHandler +import ai.llamaindex.llamacloud.core.handlers.errorBodyHandler +import ai.llamaindex.llamacloud.core.handlers.errorHandler +import ai.llamaindex.llamacloud.core.handlers.jsonHandler +import ai.llamaindex.llamacloud.core.http.HttpMethod +import ai.llamaindex.llamacloud.core.http.HttpRequest +import ai.llamaindex.llamacloud.core.http.HttpResponse +import ai.llamaindex.llamacloud.core.http.HttpResponse.Handler +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.core.http.json +import ai.llamaindex.llamacloud.core.http.parseable +import ai.llamaindex.llamacloud.core.prepareAsync +import ai.llamaindex.llamacloud.models.chat.ChatCreateParams +import ai.llamaindex.llamacloud.models.chat.ChatCreateResponse +import ai.llamaindex.llamacloud.models.chat.ChatDeleteParams +import ai.llamaindex.llamacloud.models.chat.ChatGetSummaryParams +import ai.llamaindex.llamacloud.models.chat.ChatGetSummaryResponse +import ai.llamaindex.llamacloud.models.chat.ChatListPageAsync +import ai.llamaindex.llamacloud.models.chat.ChatListPageResponse +import ai.llamaindex.llamacloud.models.chat.ChatListParams +import ai.llamaindex.llamacloud.models.chat.ChatRetrieveParams +import ai.llamaindex.llamacloud.models.chat.ChatRetrieveResponse +import ai.llamaindex.llamacloud.models.chat.ChatStreamParams +import ai.llamaindex.llamacloud.models.chat.ChatStreamResponse +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class ChatServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + ChatServiceAsync { + + private val withRawResponse: ChatServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): ChatServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): ChatServiceAsync = + ChatServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: ChatCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/v1/chat + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun retrieve( + params: ChatRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /api/v1/chat/{session_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: ChatListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /api/v1/chat + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun delete( + params: ChatDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /api/v1/chat/{session_id} + withRawResponse().delete(params, requestOptions).thenAccept {} + + override fun getSummary( + params: ChatGetSummaryParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /api/v1/chat/{session_id}/summary + withRawResponse().getSummary(params, requestOptions).thenApply { it.parse() } + + override fun stream( + params: ChatStreamParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/v1/chat/{session_id}/messages/stream + withRawResponse().stream(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + ChatServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ChatServiceAsync.WithRawResponse = + ChatServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: ChatCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "chat") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: ChatRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sessionId", params.sessionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "chat", params._pathParam(0)) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: ChatListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "chat") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + ChatListPageAsync.builder() + .service(ChatServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) + .params(params) + .response(it) + .build() + } + } + } + } + + private val deleteHandler: Handler = emptyHandler() + + override fun delete( + params: ChatDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sessionId", params.sessionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "chat", params._pathParam(0)) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response.use { deleteHandler.handle(it) } + } + } + } + + private val getSummaryHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun getSummary( + params: ChatGetSummaryParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sessionId", params.sessionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "chat", params._pathParam(0), "summary") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { getSummaryHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val streamHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun stream( + params: ChatStreamParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sessionId", params.sessionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "api", + "v1", + "chat", + params._pathParam(0), + "messages", + "stream", + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { streamHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/IndexServiceAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/IndexServiceAsync.kt new file mode 100644 index 0000000..96b7db0 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/IndexServiceAsync.kt @@ -0,0 +1,413 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.http.HttpResponse +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.models.indexes.IndexCancelSyncParams +import ai.llamaindex.llamacloud.models.indexes.IndexCancelSyncResponse +import ai.llamaindex.llamacloud.models.indexes.IndexCreateParams +import ai.llamaindex.llamacloud.models.indexes.IndexCreateResponse +import ai.llamaindex.llamacloud.models.indexes.IndexDeleteParams +import ai.llamaindex.llamacloud.models.indexes.IndexGetParams +import ai.llamaindex.llamacloud.models.indexes.IndexGetResponse +import ai.llamaindex.llamacloud.models.indexes.IndexListPageAsync +import ai.llamaindex.llamacloud.models.indexes.IndexListParams +import ai.llamaindex.llamacloud.models.indexes.IndexSyncParams +import ai.llamaindex.llamacloud.models.indexes.IndexSyncResponse +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface IndexServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): IndexServiceAsync + + /** Create a searchable index over a source directory. */ + fun create(params: IndexCreateParams): CompletableFuture = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: IndexCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** List indexes for the current project. */ + fun list(): CompletableFuture = list(IndexListParams.none()) + + /** @see list */ + fun list( + params: IndexListParams = IndexListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list( + params: IndexListParams = IndexListParams.none() + ): CompletableFuture = list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): CompletableFuture = + list(IndexListParams.none(), requestOptions) + + /** Delete an index. */ + fun delete(indexId: String): CompletableFuture = + delete(indexId, IndexDeleteParams.none()) + + /** @see delete */ + fun delete( + indexId: String, + params: IndexDeleteParams = IndexDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see delete */ + fun delete( + indexId: String, + params: IndexDeleteParams = IndexDeleteParams.none(), + ): CompletableFuture = delete(indexId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: IndexDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see delete */ + fun delete(params: IndexDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(indexId: String, requestOptions: RequestOptions): CompletableFuture = + delete(indexId, IndexDeleteParams.none(), requestOptions) + + /** Cancel the running sync for an index. Returns 409 if no sync is running. */ + fun cancelSync(indexId: String): CompletableFuture = + cancelSync(indexId, IndexCancelSyncParams.none()) + + /** @see cancelSync */ + fun cancelSync( + indexId: String, + params: IndexCancelSyncParams = IndexCancelSyncParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + cancelSync(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see cancelSync */ + fun cancelSync( + indexId: String, + params: IndexCancelSyncParams = IndexCancelSyncParams.none(), + ): CompletableFuture = + cancelSync(indexId, params, RequestOptions.none()) + + /** @see cancelSync */ + fun cancelSync( + params: IndexCancelSyncParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see cancelSync */ + fun cancelSync(params: IndexCancelSyncParams): CompletableFuture = + cancelSync(params, RequestOptions.none()) + + /** @see cancelSync */ + fun cancelSync( + indexId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + cancelSync(indexId, IndexCancelSyncParams.none(), requestOptions) + + /** Get an index by ID. */ + fun get(indexId: String): CompletableFuture = + get(indexId, IndexGetParams.none()) + + /** @see get */ + fun get( + indexId: String, + params: IndexGetParams = IndexGetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + get(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see get */ + fun get( + indexId: String, + params: IndexGetParams = IndexGetParams.none(), + ): CompletableFuture = get(indexId, params, RequestOptions.none()) + + /** @see get */ + fun get( + params: IndexGetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see get */ + fun get(params: IndexGetParams): CompletableFuture = + get(params, RequestOptions.none()) + + /** @see get */ + fun get(indexId: String, requestOptions: RequestOptions): CompletableFuture = + get(indexId, IndexGetParams.none(), requestOptions) + + /** + * Trigger a sync and export for an existing index, re-parsing changed files and exporting + * updated chunks. + */ + fun sync(indexId: String): CompletableFuture = + sync(indexId, IndexSyncParams.none()) + + /** @see sync */ + fun sync( + indexId: String, + params: IndexSyncParams = IndexSyncParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + sync(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see sync */ + fun sync( + indexId: String, + params: IndexSyncParams = IndexSyncParams.none(), + ): CompletableFuture = sync(indexId, params, RequestOptions.none()) + + /** @see sync */ + fun sync( + params: IndexSyncParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see sync */ + fun sync(params: IndexSyncParams): CompletableFuture = + sync(params, RequestOptions.none()) + + /** @see sync */ + fun sync( + indexId: String, + requestOptions: RequestOptions, + ): CompletableFuture = sync(indexId, IndexSyncParams.none(), requestOptions) + + /** A view of [IndexServiceAsync] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): IndexServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /api/v1/indexes`, but is otherwise the same as + * [IndexServiceAsync.create]. + */ + fun create( + params: IndexCreateParams + ): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: IndexCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /api/v1/indexes`, but is otherwise the same as + * [IndexServiceAsync.list]. + */ + fun list(): CompletableFuture> = + list(IndexListParams.none()) + + /** @see list */ + fun list( + params: IndexListParams = IndexListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: IndexListParams = IndexListParams.none() + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + requestOptions: RequestOptions + ): CompletableFuture> = + list(IndexListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /api/v1/indexes/{index_id}`, but is otherwise the + * same as [IndexServiceAsync.delete]. + */ + fun delete(indexId: String): CompletableFuture = + delete(indexId, IndexDeleteParams.none()) + + /** @see delete */ + fun delete( + indexId: String, + params: IndexDeleteParams = IndexDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see delete */ + fun delete( + indexId: String, + params: IndexDeleteParams = IndexDeleteParams.none(), + ): CompletableFuture = delete(indexId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + params: IndexDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see delete */ + fun delete(params: IndexDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + indexId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + delete(indexId, IndexDeleteParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /api/v1/indexes/{index_id}/sync/cancel`, but is + * otherwise the same as [IndexServiceAsync.cancelSync]. + */ + fun cancelSync( + indexId: String + ): CompletableFuture> = + cancelSync(indexId, IndexCancelSyncParams.none()) + + /** @see cancelSync */ + fun cancelSync( + indexId: String, + params: IndexCancelSyncParams = IndexCancelSyncParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + cancelSync(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see cancelSync */ + fun cancelSync( + indexId: String, + params: IndexCancelSyncParams = IndexCancelSyncParams.none(), + ): CompletableFuture> = + cancelSync(indexId, params, RequestOptions.none()) + + /** @see cancelSync */ + fun cancelSync( + params: IndexCancelSyncParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see cancelSync */ + fun cancelSync( + params: IndexCancelSyncParams + ): CompletableFuture> = + cancelSync(params, RequestOptions.none()) + + /** @see cancelSync */ + fun cancelSync( + indexId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + cancelSync(indexId, IndexCancelSyncParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/v1/indexes/{index_id}`, but is otherwise the + * same as [IndexServiceAsync.get]. + */ + fun get(indexId: String): CompletableFuture> = + get(indexId, IndexGetParams.none()) + + /** @see get */ + fun get( + indexId: String, + params: IndexGetParams = IndexGetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + get(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see get */ + fun get( + indexId: String, + params: IndexGetParams = IndexGetParams.none(), + ): CompletableFuture> = + get(indexId, params, RequestOptions.none()) + + /** @see get */ + fun get( + params: IndexGetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see get */ + fun get(params: IndexGetParams): CompletableFuture> = + get(params, RequestOptions.none()) + + /** @see get */ + fun get( + indexId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + get(indexId, IndexGetParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /api/v1/indexes/{index_id}/sync`, but is otherwise + * the same as [IndexServiceAsync.sync]. + */ + fun sync(indexId: String): CompletableFuture> = + sync(indexId, IndexSyncParams.none()) + + /** @see sync */ + fun sync( + indexId: String, + params: IndexSyncParams = IndexSyncParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + sync(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see sync */ + fun sync( + indexId: String, + params: IndexSyncParams = IndexSyncParams.none(), + ): CompletableFuture> = + sync(indexId, params, RequestOptions.none()) + + /** @see sync */ + fun sync( + params: IndexSyncParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see sync */ + fun sync(params: IndexSyncParams): CompletableFuture> = + sync(params, RequestOptions.none()) + + /** @see sync */ + fun sync( + indexId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + sync(indexId, IndexSyncParams.none(), requestOptions) + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/IndexServiceAsyncImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/IndexServiceAsyncImpl.kt new file mode 100644 index 0000000..941afcf --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/IndexServiceAsyncImpl.kt @@ -0,0 +1,300 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.handlers.emptyHandler +import ai.llamaindex.llamacloud.core.handlers.errorBodyHandler +import ai.llamaindex.llamacloud.core.handlers.errorHandler +import ai.llamaindex.llamacloud.core.handlers.jsonHandler +import ai.llamaindex.llamacloud.core.http.HttpMethod +import ai.llamaindex.llamacloud.core.http.HttpRequest +import ai.llamaindex.llamacloud.core.http.HttpResponse +import ai.llamaindex.llamacloud.core.http.HttpResponse.Handler +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.core.http.json +import ai.llamaindex.llamacloud.core.http.parseable +import ai.llamaindex.llamacloud.core.prepareAsync +import ai.llamaindex.llamacloud.models.indexes.IndexCancelSyncParams +import ai.llamaindex.llamacloud.models.indexes.IndexCancelSyncResponse +import ai.llamaindex.llamacloud.models.indexes.IndexCreateParams +import ai.llamaindex.llamacloud.models.indexes.IndexCreateResponse +import ai.llamaindex.llamacloud.models.indexes.IndexDeleteParams +import ai.llamaindex.llamacloud.models.indexes.IndexGetParams +import ai.llamaindex.llamacloud.models.indexes.IndexGetResponse +import ai.llamaindex.llamacloud.models.indexes.IndexListPageAsync +import ai.llamaindex.llamacloud.models.indexes.IndexListPageResponse +import ai.llamaindex.llamacloud.models.indexes.IndexListParams +import ai.llamaindex.llamacloud.models.indexes.IndexSyncParams +import ai.llamaindex.llamacloud.models.indexes.IndexSyncResponse +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class IndexServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + IndexServiceAsync { + + private val withRawResponse: IndexServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): IndexServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): IndexServiceAsync = + IndexServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: IndexCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/v1/indexes + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: IndexListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /api/v1/indexes + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun delete( + params: IndexDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /api/v1/indexes/{index_id} + withRawResponse().delete(params, requestOptions).thenAccept {} + + override fun cancelSync( + params: IndexCancelSyncParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/v1/indexes/{index_id}/sync/cancel + withRawResponse().cancelSync(params, requestOptions).thenApply { it.parse() } + + override fun get( + params: IndexGetParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /api/v1/indexes/{index_id} + withRawResponse().get(params, requestOptions).thenApply { it.parse() } + + override fun sync( + params: IndexSyncParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/v1/indexes/{index_id}/sync + withRawResponse().sync(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + IndexServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): IndexServiceAsync.WithRawResponse = + IndexServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: IndexCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "indexes") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: IndexListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "indexes") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + IndexListPageAsync.builder() + .service(IndexServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) + .params(params) + .response(it) + .build() + } + } + } + } + + private val deleteHandler: Handler = emptyHandler() + + override fun delete( + params: IndexDeleteParams, + requestOptions: RequestOptions, + ): CompletableFuture { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("indexId", params.indexId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "indexes", params._pathParam(0)) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response.use { deleteHandler.handle(it) } + } + } + } + + private val cancelSyncHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun cancelSync( + params: IndexCancelSyncParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("indexId", params.indexId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "indexes", params._pathParam(0), "sync", "cancel") + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { cancelSyncHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val getHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun get( + params: IndexGetParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("indexId", params.indexId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "indexes", params._pathParam(0)) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { getHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val syncHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun sync( + params: IndexSyncParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("indexId", params.indexId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "indexes", params._pathParam(0), "sync") + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { syncHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/RetrievalServiceAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/RetrievalServiceAsync.kt new file mode 100644 index 0000000..4368989 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/RetrievalServiceAsync.kt @@ -0,0 +1,150 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.models.retrieval.RetrievalFindPageAsync +import ai.llamaindex.llamacloud.models.retrieval.RetrievalFindParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalGrepPageAsync +import ai.llamaindex.llamacloud.models.retrieval.RetrievalGrepParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalReadParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalReadResponse +import ai.llamaindex.llamacloud.models.retrieval.RetrievalRetrieveParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalRetrieveResponse +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface RetrievalServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RetrievalServiceAsync + + /** + * Retrieve relevant chunks via hybrid search (vector + full-text), with filtering on built-in + * or user-defined metadata. + */ + fun retrieve(params: RetrievalRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RetrievalRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** Search for files by name. */ + fun find(params: RetrievalFindParams): CompletableFuture = + find(params, RequestOptions.none()) + + /** @see find */ + fun find( + params: RetrievalFindParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** Grep within a file's parsed content using a regex pattern. */ + fun grep(params: RetrievalGrepParams): CompletableFuture = + grep(params, RequestOptions.none()) + + /** @see grep */ + fun grep( + params: RetrievalGrepParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** Read the parsed text content of a specific file. */ + fun read(params: RetrievalReadParams): CompletableFuture = + read(params, RequestOptions.none()) + + /** @see read */ + fun read( + params: RetrievalReadParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * A view of [RetrievalServiceAsync] that provides access to raw HTTP responses for each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): RetrievalServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /api/v1/retrieval/retrieve`, but is otherwise the + * same as [RetrievalServiceAsync.retrieve]. + */ + fun retrieve( + params: RetrievalRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RetrievalRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `post /api/v1/retrieval/files/find`, but is otherwise the + * same as [RetrievalServiceAsync.find]. + */ + fun find( + params: RetrievalFindParams + ): CompletableFuture> = + find(params, RequestOptions.none()) + + /** @see find */ + fun find( + params: RetrievalFindParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `post /api/v1/retrieval/files/grep`, but is otherwise the + * same as [RetrievalServiceAsync.grep]. + */ + fun grep( + params: RetrievalGrepParams + ): CompletableFuture> = + grep(params, RequestOptions.none()) + + /** @see grep */ + fun grep( + params: RetrievalGrepParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `post /api/v1/retrieval/files/read`, but is otherwise the + * same as [RetrievalServiceAsync.read]. + */ + fun read( + params: RetrievalReadParams + ): CompletableFuture> = + read(params, RequestOptions.none()) + + /** @see read */ + fun read( + params: RetrievalReadParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/RetrievalServiceAsyncImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/RetrievalServiceAsyncImpl.kt new file mode 100644 index 0000000..9ec6e24 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/RetrievalServiceAsyncImpl.kt @@ -0,0 +1,224 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.handlers.errorBodyHandler +import ai.llamaindex.llamacloud.core.handlers.errorHandler +import ai.llamaindex.llamacloud.core.handlers.jsonHandler +import ai.llamaindex.llamacloud.core.http.HttpMethod +import ai.llamaindex.llamacloud.core.http.HttpRequest +import ai.llamaindex.llamacloud.core.http.HttpResponse +import ai.llamaindex.llamacloud.core.http.HttpResponse.Handler +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.core.http.json +import ai.llamaindex.llamacloud.core.http.parseable +import ai.llamaindex.llamacloud.core.prepareAsync +import ai.llamaindex.llamacloud.models.retrieval.RetrievalFindPageAsync +import ai.llamaindex.llamacloud.models.retrieval.RetrievalFindPageResponse +import ai.llamaindex.llamacloud.models.retrieval.RetrievalFindParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalGrepPageAsync +import ai.llamaindex.llamacloud.models.retrieval.RetrievalGrepPageResponse +import ai.llamaindex.llamacloud.models.retrieval.RetrievalGrepParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalReadParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalReadResponse +import ai.llamaindex.llamacloud.models.retrieval.RetrievalRetrieveParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalRetrieveResponse +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +class RetrievalServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + RetrievalServiceAsync { + + private val withRawResponse: RetrievalServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): RetrievalServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): RetrievalServiceAsync = + RetrievalServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: RetrievalRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/v1/retrieval/retrieve + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun find( + params: RetrievalFindParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/v1/retrieval/files/find + withRawResponse().find(params, requestOptions).thenApply { it.parse() } + + override fun grep( + params: RetrievalGrepParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/v1/retrieval/files/grep + withRawResponse().grep(params, requestOptions).thenApply { it.parse() } + + override fun read( + params: RetrievalReadParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/v1/retrieval/files/read + withRawResponse().read(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + RetrievalServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): RetrievalServiceAsync.WithRawResponse = + RetrievalServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RetrievalRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "retrieval", "retrieve") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val findHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun find( + params: RetrievalFindParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "retrieval", "files", "find") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { findHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + RetrievalFindPageAsync.builder() + .service(RetrievalServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) + .params(params) + .response(it) + .build() + } + } + } + } + + private val grepHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun grep( + params: RetrievalGrepParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "retrieval", "files", "grep") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { grepHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + RetrievalGrepPageAsync.builder() + .service(RetrievalServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) + .params(params) + .response(it) + .build() + } + } + } + } + + private val readHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun read( + params: RetrievalReadParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "retrieval", "files", "read") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { readHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/alpha/VerifyServiceAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/alpha/VerifyServiceAsync.kt new file mode 100644 index 0000000..da87a03 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/alpha/VerifyServiceAsync.kt @@ -0,0 +1,393 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async.alpha + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCancelParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCancelResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCreateParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCreateResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetDetailsParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetDetailsResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyListPageAsync +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyListParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface VerifyServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): VerifyServiceAsync + + /** + * Create a Verify job. + * + * Analyzes a document for signs of doctoring (splicing, copy-move, AI generation, metadata + * tampering, ...). Set `file_input` to a file ID (`dfl-...`). Optionally provide a + * `configuration` object to control the semantic agent. + * + * The job runs asynchronously. Poll `GET /verify/{job_id}` with `expand=result` to check status + * and retrieve results. + */ + fun create(): CompletableFuture = create(VerifyCreateParams.none()) + + /** @see create */ + fun create( + params: VerifyCreateParams = VerifyCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see create */ + fun create( + params: VerifyCreateParams = VerifyCreateParams.none() + ): CompletableFuture = create(params, RequestOptions.none()) + + /** @see create */ + fun create(requestOptions: RequestOptions): CompletableFuture = + create(VerifyCreateParams.none(), requestOptions) + + /** + * List Verify jobs with optional filtering and pagination. + * + * Filter by `status`, specific `job_ids`, or creation date range. + */ + fun list(): CompletableFuture = list(VerifyListParams.none()) + + /** @see list */ + fun list( + params: VerifyListParams = VerifyListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list( + params: VerifyListParams = VerifyListParams.none() + ): CompletableFuture = list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): CompletableFuture = + list(VerifyListParams.none(), requestOptions) + + /** + * Cancel a running Verify job. + * + * Stops processing and marks the job as CANCELLED. Returns the updated job. Jobs already in a + * terminal state (COMPLETED, FAILED, CANCELLED) cannot be cancelled. + */ + fun cancel(jobId: String): CompletableFuture = + cancel(jobId, VerifyCancelParams.none()) + + /** @see cancel */ + fun cancel( + jobId: String, + params: VerifyCancelParams = VerifyCancelParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + cancel(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see cancel */ + fun cancel( + jobId: String, + params: VerifyCancelParams = VerifyCancelParams.none(), + ): CompletableFuture = cancel(jobId, params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + params: VerifyCancelParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see cancel */ + fun cancel(params: VerifyCancelParams): CompletableFuture = + cancel(params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + jobId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + cancel(jobId, VerifyCancelParams.none(), requestOptions) + + /** + * Get a Verify job by ID. + * + * Returns the job status and configuration. Pass `expand=result` to include the Verify result + * (overall score, verdict, confidence, composite scores, and suspect regions) when the job is + * complete. + * + * Raw per-signal detail is available via `GET /verify/{job_id}/details`. + */ + fun get(jobId: String): CompletableFuture = + get(jobId, VerifyGetParams.none()) + + /** @see get */ + fun get( + jobId: String, + params: VerifyGetParams = VerifyGetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + get(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see get */ + fun get( + jobId: String, + params: VerifyGetParams = VerifyGetParams.none(), + ): CompletableFuture = get(jobId, params, RequestOptions.none()) + + /** @see get */ + fun get( + params: VerifyGetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see get */ + fun get(params: VerifyGetParams): CompletableFuture = + get(params, RequestOptions.none()) + + /** @see get */ + fun get(jobId: String, requestOptions: RequestOptions): CompletableFuture = + get(jobId, VerifyGetParams.none(), requestOptions) + + /** + * Get the raw per-signal detail for a completed Verify job. + * + * Forensic drill-down behind the simplified result: the full evidence list, per-family + * sub-scores, raw localized regions, and per-page forensic heatmap overlays (presigned image + * URLs). + */ + fun getDetails(jobId: String): CompletableFuture = + getDetails(jobId, VerifyGetDetailsParams.none()) + + /** @see getDetails */ + fun getDetails( + jobId: String, + params: VerifyGetDetailsParams = VerifyGetDetailsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + getDetails(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see getDetails */ + fun getDetails( + jobId: String, + params: VerifyGetDetailsParams = VerifyGetDetailsParams.none(), + ): CompletableFuture = + getDetails(jobId, params, RequestOptions.none()) + + /** @see getDetails */ + fun getDetails( + params: VerifyGetDetailsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see getDetails */ + fun getDetails(params: VerifyGetDetailsParams): CompletableFuture = + getDetails(params, RequestOptions.none()) + + /** @see getDetails */ + fun getDetails( + jobId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + getDetails(jobId, VerifyGetDetailsParams.none(), requestOptions) + + /** + * A view of [VerifyServiceAsync] that provides access to raw HTTP responses for each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): VerifyServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /api/alpha/verify`, but is otherwise the same as + * [VerifyServiceAsync.create]. + */ + fun create(): CompletableFuture> = + create(VerifyCreateParams.none()) + + /** @see create */ + fun create( + params: VerifyCreateParams = VerifyCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see create */ + fun create( + params: VerifyCreateParams = VerifyCreateParams.none() + ): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + requestOptions: RequestOptions + ): CompletableFuture> = + create(VerifyCreateParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/alpha/verify`, but is otherwise the same as + * [VerifyServiceAsync.list]. + */ + fun list(): CompletableFuture> = + list(VerifyListParams.none()) + + /** @see list */ + fun list( + params: VerifyListParams = VerifyListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: VerifyListParams = VerifyListParams.none() + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + requestOptions: RequestOptions + ): CompletableFuture> = + list(VerifyListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /api/alpha/verify/{job_id}/cancel`, but is + * otherwise the same as [VerifyServiceAsync.cancel]. + */ + fun cancel(jobId: String): CompletableFuture> = + cancel(jobId, VerifyCancelParams.none()) + + /** @see cancel */ + fun cancel( + jobId: String, + params: VerifyCancelParams = VerifyCancelParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + cancel(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see cancel */ + fun cancel( + jobId: String, + params: VerifyCancelParams = VerifyCancelParams.none(), + ): CompletableFuture> = + cancel(jobId, params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + params: VerifyCancelParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see cancel */ + fun cancel( + params: VerifyCancelParams + ): CompletableFuture> = + cancel(params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + jobId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + cancel(jobId, VerifyCancelParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/alpha/verify/{job_id}`, but is otherwise the + * same as [VerifyServiceAsync.get]. + */ + fun get(jobId: String): CompletableFuture> = + get(jobId, VerifyGetParams.none()) + + /** @see get */ + fun get( + jobId: String, + params: VerifyGetParams = VerifyGetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + get(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see get */ + fun get( + jobId: String, + params: VerifyGetParams = VerifyGetParams.none(), + ): CompletableFuture> = + get(jobId, params, RequestOptions.none()) + + /** @see get */ + fun get( + params: VerifyGetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see get */ + fun get(params: VerifyGetParams): CompletableFuture> = + get(params, RequestOptions.none()) + + /** @see get */ + fun get( + jobId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + get(jobId, VerifyGetParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/alpha/verify/{job_id}/details`, but is + * otherwise the same as [VerifyServiceAsync.getDetails]. + */ + fun getDetails( + jobId: String + ): CompletableFuture> = + getDetails(jobId, VerifyGetDetailsParams.none()) + + /** @see getDetails */ + fun getDetails( + jobId: String, + params: VerifyGetDetailsParams = VerifyGetDetailsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + getDetails(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see getDetails */ + fun getDetails( + jobId: String, + params: VerifyGetDetailsParams = VerifyGetDetailsParams.none(), + ): CompletableFuture> = + getDetails(jobId, params, RequestOptions.none()) + + /** @see getDetails */ + fun getDetails( + params: VerifyGetDetailsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see getDetails */ + fun getDetails( + params: VerifyGetDetailsParams + ): CompletableFuture> = + getDetails(params, RequestOptions.none()) + + /** @see getDetails */ + fun getDetails( + jobId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + getDetails(jobId, VerifyGetDetailsParams.none(), requestOptions) + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/alpha/VerifyServiceAsyncImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/alpha/VerifyServiceAsyncImpl.kt new file mode 100644 index 0000000..d3945a7 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/alpha/VerifyServiceAsyncImpl.kt @@ -0,0 +1,263 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async.alpha + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.handlers.errorBodyHandler +import ai.llamaindex.llamacloud.core.handlers.errorHandler +import ai.llamaindex.llamacloud.core.handlers.jsonHandler +import ai.llamaindex.llamacloud.core.http.HttpMethod +import ai.llamaindex.llamacloud.core.http.HttpRequest +import ai.llamaindex.llamacloud.core.http.HttpResponse +import ai.llamaindex.llamacloud.core.http.HttpResponse.Handler +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.core.http.json +import ai.llamaindex.llamacloud.core.http.parseable +import ai.llamaindex.llamacloud.core.prepareAsync +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCancelParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCancelResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCreateParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCreateResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetDetailsParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetDetailsResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyListPageAsync +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyListPageResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyListParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class VerifyServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + VerifyServiceAsync { + + private val withRawResponse: VerifyServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): VerifyServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): VerifyServiceAsync = + VerifyServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: VerifyCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/alpha/verify + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: VerifyListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /api/alpha/verify + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun cancel( + params: VerifyCancelParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/alpha/verify/{job_id}/cancel + withRawResponse().cancel(params, requestOptions).thenApply { it.parse() } + + override fun get( + params: VerifyGetParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /api/alpha/verify/{job_id} + withRawResponse().get(params, requestOptions).thenApply { it.parse() } + + override fun getDetails( + params: VerifyGetDetailsParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /api/alpha/verify/{job_id}/details + withRawResponse().getDetails(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + VerifyServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): VerifyServiceAsync.WithRawResponse = + VerifyServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: VerifyCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "alpha", "verify") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: VerifyListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "alpha", "verify") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + VerifyListPageAsync.builder() + .service(VerifyServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) + .params(params) + .response(it) + .build() + } + } + } + } + + private val cancelHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun cancel( + params: VerifyCancelParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "alpha", "verify", params._pathParam(0), "cancel") + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { cancelHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val getHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun get( + params: VerifyGetParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "alpha", "verify", params._pathParam(0)) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { getHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val getDetailsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun getDetails( + params: VerifyGetDetailsParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "alpha", "verify", params._pathParam(0), "details") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { getDetailsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/ChatServiceAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/ChatServiceAsync.kt index 0c9a7b6..b15350e 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/ChatServiceAsync.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/ChatServiceAsync.kt @@ -35,28 +35,34 @@ interface ChatServiceAsync { fun withOptions(modifier: Consumer): ChatServiceAsync /** Create a chat session, optionally bound to indexes (locked after the first message). */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun create(): CompletableFuture = create(ChatCreateParams.none()) /** @see create */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun create( params: ChatCreateParams = ChatCreateParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** @see create */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun create( params: ChatCreateParams = ChatCreateParams.none() ): CompletableFuture = create(params, RequestOptions.none()) /** @see create */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun create(requestOptions: RequestOptions): CompletableFuture = create(ChatCreateParams.none(), requestOptions) /** Retrieve a full session by ID, including its event history. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve(sessionId: String): CompletableFuture = retrieve(sessionId, ChatRetrieveParams.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve( sessionId: String, params: ChatRetrieveParams = ChatRetrieveParams.none(), @@ -65,22 +71,26 @@ interface ChatServiceAsync { retrieve(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve( sessionId: String, params: ChatRetrieveParams = ChatRetrieveParams.none(), ): CompletableFuture = retrieve(sessionId, params, RequestOptions.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve( params: ChatRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve(params: ChatRetrieveParams): CompletableFuture = retrieve(params, RequestOptions.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve( sessionId: String, requestOptions: RequestOptions, @@ -88,27 +98,33 @@ interface ChatServiceAsync { retrieve(sessionId, ChatRetrieveParams.none(), requestOptions) /** List all chat sessions for the current project. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun list(): CompletableFuture = list(ChatListParams.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun list( params: ChatListParams = ChatListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** @see list */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun list(params: ChatListParams = ChatListParams.none()): CompletableFuture = list(params, RequestOptions.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun list(requestOptions: RequestOptions): CompletableFuture = list(ChatListParams.none(), requestOptions) /** Delete a session. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete(sessionId: String): CompletableFuture = delete(sessionId, ChatDeleteParams.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete( sessionId: String, params: ChatDeleteParams = ChatDeleteParams.none(), @@ -117,30 +133,36 @@ interface ChatServiceAsync { delete(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete( sessionId: String, params: ChatDeleteParams = ChatDeleteParams.none(), ): CompletableFuture = delete(sessionId, params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete( params: ChatDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete(params: ChatDeleteParams): CompletableFuture = delete(params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete(sessionId: String, requestOptions: RequestOptions): CompletableFuture = delete(sessionId, ChatDeleteParams.none(), requestOptions) /** Retrieve a session summary by ID. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary(sessionId: String): CompletableFuture = getSummary(sessionId, ChatGetSummaryParams.none()) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( sessionId: String, params: ChatGetSummaryParams = ChatGetSummaryParams.none(), @@ -149,6 +171,7 @@ interface ChatServiceAsync { getSummary(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( sessionId: String, params: ChatGetSummaryParams = ChatGetSummaryParams.none(), @@ -156,16 +179,19 @@ interface ChatServiceAsync { getSummary(sessionId, params, RequestOptions.none()) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( params: ChatGetSummaryParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary(params: ChatGetSummaryParams): CompletableFuture = getSummary(params, RequestOptions.none()) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( sessionId: String, requestOptions: RequestOptions, @@ -173,10 +199,12 @@ interface ChatServiceAsync { getSummary(sessionId, ChatGetSummaryParams.none(), requestOptions) /** Stream agent events for a chat turn as Server-Sent Events. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun stream(sessionId: String, params: ChatStreamParams): CompletableFuture = stream(sessionId, params, RequestOptions.none()) /** @see stream */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun stream( sessionId: String, params: ChatStreamParams, @@ -185,10 +213,12 @@ interface ChatServiceAsync { stream(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see stream */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun stream(params: ChatStreamParams): CompletableFuture = stream(params, RequestOptions.none()) /** @see stream */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun stream( params: ChatStreamParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -208,22 +238,26 @@ interface ChatServiceAsync { * Returns a raw HTTP response for `post /api/v1/chat`, but is otherwise the same as * [ChatServiceAsync.create]. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun create(): CompletableFuture> = create(ChatCreateParams.none()) /** @see create */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun create( params: ChatCreateParams = ChatCreateParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> /** @see create */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun create( params: ChatCreateParams = ChatCreateParams.none() ): CompletableFuture> = create(params, RequestOptions.none()) /** @see create */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun create( requestOptions: RequestOptions ): CompletableFuture> = @@ -233,10 +267,12 @@ interface ChatServiceAsync { * Returns a raw HTTP response for `get /api/v1/chat/{session_id}`, but is otherwise the * same as [ChatServiceAsync.retrieve]. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve(sessionId: String): CompletableFuture> = retrieve(sessionId, ChatRetrieveParams.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve( sessionId: String, params: ChatRetrieveParams = ChatRetrieveParams.none(), @@ -245,6 +281,7 @@ interface ChatServiceAsync { retrieve(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve( sessionId: String, params: ChatRetrieveParams = ChatRetrieveParams.none(), @@ -252,18 +289,21 @@ interface ChatServiceAsync { retrieve(sessionId, params, RequestOptions.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve( params: ChatRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve( params: ChatRetrieveParams ): CompletableFuture> = retrieve(params, RequestOptions.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve( sessionId: String, requestOptions: RequestOptions, @@ -274,22 +314,26 @@ interface ChatServiceAsync { * Returns a raw HTTP response for `get /api/v1/chat`, but is otherwise the same as * [ChatServiceAsync.list]. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun list(): CompletableFuture> = list(ChatListParams.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun list( params: ChatListParams = ChatListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> /** @see list */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun list( params: ChatListParams = ChatListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -299,10 +343,12 @@ interface ChatServiceAsync { * Returns a raw HTTP response for `delete /api/v1/chat/{session_id}`, but is otherwise the * same as [ChatServiceAsync.delete]. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete(sessionId: String): CompletableFuture = delete(sessionId, ChatDeleteParams.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete( sessionId: String, params: ChatDeleteParams = ChatDeleteParams.none(), @@ -311,22 +357,26 @@ interface ChatServiceAsync { delete(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete( sessionId: String, params: ChatDeleteParams = ChatDeleteParams.none(), ): CompletableFuture = delete(sessionId, params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete( params: ChatDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete(params: ChatDeleteParams): CompletableFuture = delete(params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete( sessionId: String, requestOptions: RequestOptions, @@ -337,12 +387,14 @@ interface ChatServiceAsync { * Returns a raw HTTP response for `get /api/v1/chat/{session_id}/summary`, but is otherwise * the same as [ChatServiceAsync.getSummary]. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( sessionId: String ): CompletableFuture> = getSummary(sessionId, ChatGetSummaryParams.none()) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( sessionId: String, params: ChatGetSummaryParams = ChatGetSummaryParams.none(), @@ -351,6 +403,7 @@ interface ChatServiceAsync { getSummary(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( sessionId: String, params: ChatGetSummaryParams = ChatGetSummaryParams.none(), @@ -358,18 +411,21 @@ interface ChatServiceAsync { getSummary(sessionId, params, RequestOptions.none()) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( params: ChatGetSummaryParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( params: ChatGetSummaryParams ): CompletableFuture> = getSummary(params, RequestOptions.none()) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( sessionId: String, requestOptions: RequestOptions, @@ -380,6 +436,7 @@ interface ChatServiceAsync { * Returns a raw HTTP response for `post /api/v1/chat/{session_id}/messages/stream`, but is * otherwise the same as [ChatServiceAsync.stream]. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun stream( sessionId: String, params: ChatStreamParams, @@ -387,6 +444,7 @@ interface ChatServiceAsync { stream(sessionId, params, RequestOptions.none()) /** @see stream */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun stream( sessionId: String, params: ChatStreamParams, @@ -395,12 +453,14 @@ interface ChatServiceAsync { stream(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see stream */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun stream( params: ChatStreamParams ): CompletableFuture> = stream(params, RequestOptions.none()) /** @see stream */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun stream( params: ChatStreamParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/ChatServiceAsyncImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/ChatServiceAsyncImpl.kt index dc0bff9..af28fce 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/ChatServiceAsyncImpl.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/ChatServiceAsyncImpl.kt @@ -45,6 +45,7 @@ class ChatServiceAsyncImpl internal constructor(private val clientOptions: Clien override fun withOptions(modifier: Consumer): ChatServiceAsync = ChatServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun create( params: ChatCreateParams, requestOptions: RequestOptions, @@ -52,6 +53,7 @@ class ChatServiceAsyncImpl internal constructor(private val clientOptions: Clien // post /api/v1/chat withRawResponse().create(params, requestOptions).thenApply { it.parse() } + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun retrieve( params: ChatRetrieveParams, requestOptions: RequestOptions, @@ -59,6 +61,7 @@ class ChatServiceAsyncImpl internal constructor(private val clientOptions: Clien // get /api/v1/chat/{session_id} withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun list( params: ChatListParams, requestOptions: RequestOptions, @@ -66,6 +69,7 @@ class ChatServiceAsyncImpl internal constructor(private val clientOptions: Clien // get /api/v1/chat withRawResponse().list(params, requestOptions).thenApply { it.parse() } + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun delete( params: ChatDeleteParams, requestOptions: RequestOptions, @@ -73,6 +77,7 @@ class ChatServiceAsyncImpl internal constructor(private val clientOptions: Clien // delete /api/v1/chat/{session_id} withRawResponse().delete(params, requestOptions).thenAccept {} + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun getSummary( params: ChatGetSummaryParams, requestOptions: RequestOptions, @@ -80,6 +85,7 @@ class ChatServiceAsyncImpl internal constructor(private val clientOptions: Clien // get /api/v1/chat/{session_id}/summary withRawResponse().getSummary(params, requestOptions).thenApply { it.parse() } + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun stream( params: ChatStreamParams, requestOptions: RequestOptions, @@ -103,6 +109,7 @@ class ChatServiceAsyncImpl internal constructor(private val clientOptions: Clien private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun create( params: ChatCreateParams, requestOptions: RequestOptions, @@ -134,6 +141,7 @@ class ChatServiceAsyncImpl internal constructor(private val clientOptions: Clien private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun retrieve( params: ChatRetrieveParams, requestOptions: RequestOptions, @@ -167,6 +175,7 @@ class ChatServiceAsyncImpl internal constructor(private val clientOptions: Clien private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun list( params: ChatListParams, requestOptions: RequestOptions, @@ -204,6 +213,7 @@ class ChatServiceAsyncImpl internal constructor(private val clientOptions: Clien private val deleteHandler: Handler = emptyHandler() + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun delete( params: ChatDeleteParams, requestOptions: RequestOptions, @@ -232,6 +242,7 @@ class ChatServiceAsyncImpl internal constructor(private val clientOptions: Clien private val getSummaryHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun getSummary( params: ChatGetSummaryParams, requestOptions: RequestOptions, @@ -265,6 +276,7 @@ class ChatServiceAsyncImpl internal constructor(private val clientOptions: Clien private val streamHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun stream( params: ChatStreamParams, requestOptions: RequestOptions, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/IndexServiceAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/IndexServiceAsync.kt index 3bd837e..9dec862 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/IndexServiceAsync.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/IndexServiceAsync.kt @@ -33,38 +33,46 @@ interface IndexServiceAsync { fun withOptions(modifier: Consumer): IndexServiceAsync /** Create a searchable index over a source directory. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun create(params: IndexCreateParams): CompletableFuture = create(params, RequestOptions.none()) /** @see create */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun create( params: IndexCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** List indexes for the current project. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun list(): CompletableFuture = list(IndexListParams.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun list( params: IndexListParams = IndexListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** @see list */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun list( params: IndexListParams = IndexListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun list(requestOptions: RequestOptions): CompletableFuture = list(IndexListParams.none(), requestOptions) /** Delete an index. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete(indexId: String): CompletableFuture = delete(indexId, IndexDeleteParams.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete( indexId: String, params: IndexDeleteParams = IndexDeleteParams.none(), @@ -73,30 +81,36 @@ interface IndexServiceAsync { delete(params.toBuilder().indexId(indexId).build(), requestOptions) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete( indexId: String, params: IndexDeleteParams = IndexDeleteParams.none(), ): CompletableFuture = delete(indexId, params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete( params: IndexDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete(params: IndexDeleteParams): CompletableFuture = delete(params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete(indexId: String, requestOptions: RequestOptions): CompletableFuture = delete(indexId, IndexDeleteParams.none(), requestOptions) /** Get an index by ID. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get(indexId: String): CompletableFuture = get(indexId, IndexGetParams.none()) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get( indexId: String, params: IndexGetParams = IndexGetParams.none(), @@ -105,22 +119,26 @@ interface IndexServiceAsync { get(params.toBuilder().indexId(indexId).build(), requestOptions) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get( indexId: String, params: IndexGetParams = IndexGetParams.none(), ): CompletableFuture = get(indexId, params, RequestOptions.none()) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get( params: IndexGetParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get(params: IndexGetParams): CompletableFuture = get(params, RequestOptions.none()) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get(indexId: String, requestOptions: RequestOptions): CompletableFuture = get(indexId, IndexGetParams.none(), requestOptions) @@ -128,10 +146,12 @@ interface IndexServiceAsync { * Trigger a sync and export for an existing index, re-parsing changed files and exporting * updated chunks. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync(indexId: String): CompletableFuture = sync(indexId, IndexSyncParams.none()) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync( indexId: String, params: IndexSyncParams = IndexSyncParams.none(), @@ -140,22 +160,26 @@ interface IndexServiceAsync { sync(params.toBuilder().indexId(indexId).build(), requestOptions) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync( indexId: String, params: IndexSyncParams = IndexSyncParams.none(), ): CompletableFuture = sync(indexId, params, RequestOptions.none()) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync( params: IndexSyncParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync(params: IndexSyncParams): CompletableFuture = sync(params, RequestOptions.none()) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync( indexId: String, requestOptions: RequestOptions, @@ -177,12 +201,14 @@ interface IndexServiceAsync { * Returns a raw HTTP response for `post /api/v1/indexes`, but is otherwise the same as * [IndexServiceAsync.create]. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun create( params: IndexCreateParams ): CompletableFuture> = create(params, RequestOptions.none()) /** @see create */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun create( params: IndexCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -192,22 +218,26 @@ interface IndexServiceAsync { * Returns a raw HTTP response for `get /api/v1/indexes`, but is otherwise the same as * [IndexServiceAsync.list]. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun list(): CompletableFuture> = list(IndexListParams.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun list( params: IndexListParams = IndexListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> /** @see list */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun list( params: IndexListParams = IndexListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -217,10 +247,12 @@ interface IndexServiceAsync { * Returns a raw HTTP response for `delete /api/v1/indexes/{index_id}`, but is otherwise the * same as [IndexServiceAsync.delete]. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete(indexId: String): CompletableFuture = delete(indexId, IndexDeleteParams.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete( indexId: String, params: IndexDeleteParams = IndexDeleteParams.none(), @@ -229,22 +261,26 @@ interface IndexServiceAsync { delete(params.toBuilder().indexId(indexId).build(), requestOptions) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete( indexId: String, params: IndexDeleteParams = IndexDeleteParams.none(), ): CompletableFuture = delete(indexId, params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete( params: IndexDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete(params: IndexDeleteParams): CompletableFuture = delete(params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete( indexId: String, requestOptions: RequestOptions, @@ -255,10 +291,12 @@ interface IndexServiceAsync { * Returns a raw HTTP response for `get /api/v1/indexes/{index_id}`, but is otherwise the * same as [IndexServiceAsync.get]. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get(indexId: String): CompletableFuture> = get(indexId, IndexGetParams.none()) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get( indexId: String, params: IndexGetParams = IndexGetParams.none(), @@ -267,6 +305,7 @@ interface IndexServiceAsync { get(params.toBuilder().indexId(indexId).build(), requestOptions) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get( indexId: String, params: IndexGetParams = IndexGetParams.none(), @@ -274,16 +313,19 @@ interface IndexServiceAsync { get(indexId, params, RequestOptions.none()) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get( params: IndexGetParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get(params: IndexGetParams): CompletableFuture> = get(params, RequestOptions.none()) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get( indexId: String, requestOptions: RequestOptions, @@ -294,10 +336,12 @@ interface IndexServiceAsync { * Returns a raw HTTP response for `post /api/v1/indexes/{index_id}/sync`, but is otherwise * the same as [IndexServiceAsync.sync]. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync(indexId: String): CompletableFuture> = sync(indexId, IndexSyncParams.none()) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync( indexId: String, params: IndexSyncParams = IndexSyncParams.none(), @@ -306,6 +350,7 @@ interface IndexServiceAsync { sync(params.toBuilder().indexId(indexId).build(), requestOptions) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync( indexId: String, params: IndexSyncParams = IndexSyncParams.none(), @@ -313,16 +358,19 @@ interface IndexServiceAsync { sync(indexId, params, RequestOptions.none()) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync( params: IndexSyncParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync(params: IndexSyncParams): CompletableFuture> = sync(params, RequestOptions.none()) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync( indexId: String, requestOptions: RequestOptions, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/IndexServiceAsyncImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/IndexServiceAsyncImpl.kt index 8932667..a4bab3a 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/IndexServiceAsyncImpl.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/IndexServiceAsyncImpl.kt @@ -43,6 +43,7 @@ class IndexServiceAsyncImpl internal constructor(private val clientOptions: Clie override fun withOptions(modifier: Consumer): IndexServiceAsync = IndexServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun create( params: IndexCreateParams, requestOptions: RequestOptions, @@ -50,6 +51,7 @@ class IndexServiceAsyncImpl internal constructor(private val clientOptions: Clie // post /api/v1/indexes withRawResponse().create(params, requestOptions).thenApply { it.parse() } + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun list( params: IndexListParams, requestOptions: RequestOptions, @@ -57,6 +59,7 @@ class IndexServiceAsyncImpl internal constructor(private val clientOptions: Clie // get /api/v1/indexes withRawResponse().list(params, requestOptions).thenApply { it.parse() } + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun delete( params: IndexDeleteParams, requestOptions: RequestOptions, @@ -64,6 +67,7 @@ class IndexServiceAsyncImpl internal constructor(private val clientOptions: Clie // delete /api/v1/indexes/{index_id} withRawResponse().delete(params, requestOptions).thenAccept {} + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun get( params: IndexGetParams, requestOptions: RequestOptions, @@ -71,6 +75,7 @@ class IndexServiceAsyncImpl internal constructor(private val clientOptions: Clie // get /api/v1/indexes/{index_id} withRawResponse().get(params, requestOptions).thenApply { it.parse() } + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun sync( params: IndexSyncParams, requestOptions: RequestOptions, @@ -94,6 +99,7 @@ class IndexServiceAsyncImpl internal constructor(private val clientOptions: Clie private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun create( params: IndexCreateParams, requestOptions: RequestOptions, @@ -125,6 +131,7 @@ class IndexServiceAsyncImpl internal constructor(private val clientOptions: Clie private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun list( params: IndexListParams, requestOptions: RequestOptions, @@ -162,6 +169,7 @@ class IndexServiceAsyncImpl internal constructor(private val clientOptions: Clie private val deleteHandler: Handler = emptyHandler() + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun delete( params: IndexDeleteParams, requestOptions: RequestOptions, @@ -190,6 +198,7 @@ class IndexServiceAsyncImpl internal constructor(private val clientOptions: Clie private val getHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun get( params: IndexGetParams, requestOptions: RequestOptions, @@ -223,6 +232,7 @@ class IndexServiceAsyncImpl internal constructor(private val clientOptions: Clie private val syncHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun sync( params: IndexSyncParams, requestOptions: RequestOptions, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/RetrievalServiceAsync.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/RetrievalServiceAsync.kt index f56ffdd..49dfd86 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/RetrievalServiceAsync.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/RetrievalServiceAsync.kt @@ -34,40 +34,48 @@ interface RetrievalServiceAsync { * Retrieve relevant chunks via hybrid search (vector + full-text), with filtering on built-in * or user-defined metadata. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun retrieve(params: RetrievalRetrieveParams): CompletableFuture = retrieve(params, RequestOptions.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun retrieve( params: RetrievalRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Search for files by name. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun find(params: RetrievalFindParams): CompletableFuture = find(params, RequestOptions.none()) /** @see find */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun find( params: RetrievalFindParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Grep within a file's parsed content using a regex pattern. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun grep(params: RetrievalGrepParams): CompletableFuture = grep(params, RequestOptions.none()) /** @see grep */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun grep( params: RetrievalGrepParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Read the parsed text content of a specific file. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun read(params: RetrievalReadParams): CompletableFuture = read(params, RequestOptions.none()) /** @see read */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun read( params: RetrievalReadParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -91,12 +99,14 @@ interface RetrievalServiceAsync { * Returns a raw HTTP response for `post /api/v1/retrieval/retrieve`, but is otherwise the * same as [RetrievalServiceAsync.retrieve]. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun retrieve( params: RetrievalRetrieveParams ): CompletableFuture> = retrieve(params, RequestOptions.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun retrieve( params: RetrievalRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -106,12 +116,14 @@ interface RetrievalServiceAsync { * Returns a raw HTTP response for `post /api/v1/retrieval/files/find`, but is otherwise the * same as [RetrievalServiceAsync.find]. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun find( params: RetrievalFindParams ): CompletableFuture> = find(params, RequestOptions.none()) /** @see find */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun find( params: RetrievalFindParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -121,12 +133,14 @@ interface RetrievalServiceAsync { * Returns a raw HTTP response for `post /api/v1/retrieval/files/grep`, but is otherwise the * same as [RetrievalServiceAsync.grep]. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun grep( params: RetrievalGrepParams ): CompletableFuture> = grep(params, RequestOptions.none()) /** @see grep */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun grep( params: RetrievalGrepParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -136,12 +150,14 @@ interface RetrievalServiceAsync { * Returns a raw HTTP response for `post /api/v1/retrieval/files/read`, but is otherwise the * same as [RetrievalServiceAsync.read]. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun read( params: RetrievalReadParams ): CompletableFuture> = read(params, RequestOptions.none()) /** @see read */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun read( params: RetrievalReadParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/RetrievalServiceAsyncImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/RetrievalServiceAsyncImpl.kt index 36b49cf..27bd1ab 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/RetrievalServiceAsyncImpl.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/async/beta/RetrievalServiceAsyncImpl.kt @@ -40,6 +40,7 @@ class RetrievalServiceAsyncImpl internal constructor(private val clientOptions: override fun withOptions(modifier: Consumer): RetrievalServiceAsync = RetrievalServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun retrieve( params: RetrievalRetrieveParams, requestOptions: RequestOptions, @@ -47,6 +48,7 @@ class RetrievalServiceAsyncImpl internal constructor(private val clientOptions: // post /api/v1/retrieval/retrieve withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun find( params: RetrievalFindParams, requestOptions: RequestOptions, @@ -54,6 +56,7 @@ class RetrievalServiceAsyncImpl internal constructor(private val clientOptions: // post /api/v1/retrieval/files/find withRawResponse().find(params, requestOptions).thenApply { it.parse() } + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun grep( params: RetrievalGrepParams, requestOptions: RequestOptions, @@ -61,6 +64,7 @@ class RetrievalServiceAsyncImpl internal constructor(private val clientOptions: // post /api/v1/retrieval/files/grep withRawResponse().grep(params, requestOptions).thenApply { it.parse() } + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun read( params: RetrievalReadParams, requestOptions: RequestOptions, @@ -84,6 +88,7 @@ class RetrievalServiceAsyncImpl internal constructor(private val clientOptions: private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun retrieve( params: RetrievalRetrieveParams, requestOptions: RequestOptions, @@ -115,6 +120,7 @@ class RetrievalServiceAsyncImpl internal constructor(private val clientOptions: private val findHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun find( params: RetrievalFindParams, requestOptions: RequestOptions, @@ -154,6 +160,7 @@ class RetrievalServiceAsyncImpl internal constructor(private val clientOptions: private val grepHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun grep( params: RetrievalGrepParams, requestOptions: RequestOptions, @@ -193,6 +200,7 @@ class RetrievalServiceAsyncImpl internal constructor(private val clientOptions: private val readHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun read( params: RetrievalReadParams, requestOptions: RequestOptions, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/AlphaService.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/AlphaService.kt new file mode 100644 index 0000000..8585af6 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/AlphaService.kt @@ -0,0 +1,37 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.services.blocking.alpha.VerifyService +import java.util.function.Consumer + +interface AlphaService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AlphaService + + fun verify(): VerifyService + + /** A view of [AlphaService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AlphaService.WithRawResponse + + fun verify(): VerifyService.WithRawResponse + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/AlphaServiceImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/AlphaServiceImpl.kt new file mode 100644 index 0000000..d763b26 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/AlphaServiceImpl.kt @@ -0,0 +1,42 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.services.blocking.alpha.VerifyService +import ai.llamaindex.llamacloud.services.blocking.alpha.VerifyServiceImpl +import java.util.function.Consumer + +class AlphaServiceImpl internal constructor(private val clientOptions: ClientOptions) : + AlphaService { + + private val withRawResponse: AlphaService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val verify: VerifyService by lazy { VerifyServiceImpl(clientOptions) } + + override fun withRawResponse(): AlphaService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): AlphaService = + AlphaServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun verify(): VerifyService = verify + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + AlphaService.WithRawResponse { + + private val verify: VerifyService.WithRawResponse by lazy { + VerifyServiceImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): AlphaService.WithRawResponse = + AlphaServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun verify(): VerifyService.WithRawResponse = verify + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/ChatService.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/ChatService.kt new file mode 100644 index 0000000..d534c53 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/ChatService.kt @@ -0,0 +1,396 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.http.HttpResponse +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.models.chat.ChatCreateParams +import ai.llamaindex.llamacloud.models.chat.ChatCreateResponse +import ai.llamaindex.llamacloud.models.chat.ChatDeleteParams +import ai.llamaindex.llamacloud.models.chat.ChatGetSummaryParams +import ai.llamaindex.llamacloud.models.chat.ChatGetSummaryResponse +import ai.llamaindex.llamacloud.models.chat.ChatListPage +import ai.llamaindex.llamacloud.models.chat.ChatListParams +import ai.llamaindex.llamacloud.models.chat.ChatRetrieveParams +import ai.llamaindex.llamacloud.models.chat.ChatRetrieveResponse +import ai.llamaindex.llamacloud.models.chat.ChatStreamParams +import ai.llamaindex.llamacloud.models.chat.ChatStreamResponse +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +interface ChatService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ChatService + + /** Create a chat session, optionally bound to indexes (locked after the first message). */ + fun create(): ChatCreateResponse = create(ChatCreateParams.none()) + + /** @see create */ + fun create( + params: ChatCreateParams = ChatCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ChatCreateResponse + + /** @see create */ + fun create(params: ChatCreateParams = ChatCreateParams.none()): ChatCreateResponse = + create(params, RequestOptions.none()) + + /** @see create */ + fun create(requestOptions: RequestOptions): ChatCreateResponse = + create(ChatCreateParams.none(), requestOptions) + + /** Retrieve a full session by ID, including its event history. */ + fun retrieve(sessionId: String): ChatRetrieveResponse = + retrieve(sessionId, ChatRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + sessionId: String, + params: ChatRetrieveParams = ChatRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ChatRetrieveResponse = + retrieve(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + sessionId: String, + params: ChatRetrieveParams = ChatRetrieveParams.none(), + ): ChatRetrieveResponse = retrieve(sessionId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ChatRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ChatRetrieveResponse + + /** @see retrieve */ + fun retrieve(params: ChatRetrieveParams): ChatRetrieveResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(sessionId: String, requestOptions: RequestOptions): ChatRetrieveResponse = + retrieve(sessionId, ChatRetrieveParams.none(), requestOptions) + + /** List all chat sessions for the current project. */ + fun list(): ChatListPage = list(ChatListParams.none()) + + /** @see list */ + fun list( + params: ChatListParams = ChatListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ChatListPage + + /** @see list */ + fun list(params: ChatListParams = ChatListParams.none()): ChatListPage = + list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): ChatListPage = + list(ChatListParams.none(), requestOptions) + + /** Delete a session. */ + fun delete(sessionId: String) = delete(sessionId, ChatDeleteParams.none()) + + /** @see delete */ + fun delete( + sessionId: String, + params: ChatDeleteParams = ChatDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ) = delete(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see delete */ + fun delete(sessionId: String, params: ChatDeleteParams = ChatDeleteParams.none()) = + delete(sessionId, params, RequestOptions.none()) + + /** @see delete */ + fun delete(params: ChatDeleteParams, requestOptions: RequestOptions = RequestOptions.none()) + + /** @see delete */ + fun delete(params: ChatDeleteParams) = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(sessionId: String, requestOptions: RequestOptions) = + delete(sessionId, ChatDeleteParams.none(), requestOptions) + + /** Retrieve a session summary by ID. */ + fun getSummary(sessionId: String): ChatGetSummaryResponse = + getSummary(sessionId, ChatGetSummaryParams.none()) + + /** @see getSummary */ + fun getSummary( + sessionId: String, + params: ChatGetSummaryParams = ChatGetSummaryParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ChatGetSummaryResponse = + getSummary(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see getSummary */ + fun getSummary( + sessionId: String, + params: ChatGetSummaryParams = ChatGetSummaryParams.none(), + ): ChatGetSummaryResponse = getSummary(sessionId, params, RequestOptions.none()) + + /** @see getSummary */ + fun getSummary( + params: ChatGetSummaryParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ChatGetSummaryResponse + + /** @see getSummary */ + fun getSummary(params: ChatGetSummaryParams): ChatGetSummaryResponse = + getSummary(params, RequestOptions.none()) + + /** @see getSummary */ + fun getSummary(sessionId: String, requestOptions: RequestOptions): ChatGetSummaryResponse = + getSummary(sessionId, ChatGetSummaryParams.none(), requestOptions) + + /** Stream agent events for a chat turn as Server-Sent Events. */ + fun stream(sessionId: String, params: ChatStreamParams): ChatStreamResponse = + stream(sessionId, params, RequestOptions.none()) + + /** @see stream */ + fun stream( + sessionId: String, + params: ChatStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ChatStreamResponse = stream(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see stream */ + fun stream(params: ChatStreamParams): ChatStreamResponse = stream(params, RequestOptions.none()) + + /** @see stream */ + fun stream( + params: ChatStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ChatStreamResponse + + /** A view of [ChatService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ChatService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /api/v1/chat`, but is otherwise the same as + * [ChatService.create]. + */ + @MustBeClosed + fun create(): HttpResponseFor = create(ChatCreateParams.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: ChatCreateParams = ChatCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see create */ + @MustBeClosed + fun create( + params: ChatCreateParams = ChatCreateParams.none() + ): HttpResponseFor = create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create(requestOptions: RequestOptions): HttpResponseFor = + create(ChatCreateParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/v1/chat/{session_id}`, but is otherwise the + * same as [ChatService.retrieve]. + */ + @MustBeClosed + fun retrieve(sessionId: String): HttpResponseFor = + retrieve(sessionId, ChatRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + sessionId: String, + params: ChatRetrieveParams = ChatRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + sessionId: String, + params: ChatRetrieveParams = ChatRetrieveParams.none(), + ): HttpResponseFor = + retrieve(sessionId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: ChatRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: ChatRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + sessionId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(sessionId, ChatRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/v1/chat`, but is otherwise the same as + * [ChatService.list]. + */ + @MustBeClosed fun list(): HttpResponseFor = list(ChatListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: ChatListParams = ChatListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list(params: ChatListParams = ChatListParams.none()): HttpResponseFor = + list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list(requestOptions: RequestOptions): HttpResponseFor = + list(ChatListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /api/v1/chat/{session_id}`, but is otherwise the + * same as [ChatService.delete]. + */ + @MustBeClosed + fun delete(sessionId: String): HttpResponse = delete(sessionId, ChatDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + sessionId: String, + params: ChatDeleteParams = ChatDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse = delete(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see delete */ + @MustBeClosed + fun delete( + sessionId: String, + params: ChatDeleteParams = ChatDeleteParams.none(), + ): HttpResponse = delete(sessionId, params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + params: ChatDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse + + /** @see delete */ + @MustBeClosed + fun delete(params: ChatDeleteParams): HttpResponse = delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(sessionId: String, requestOptions: RequestOptions): HttpResponse = + delete(sessionId, ChatDeleteParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/v1/chat/{session_id}/summary`, but is otherwise + * the same as [ChatService.getSummary]. + */ + @MustBeClosed + fun getSummary(sessionId: String): HttpResponseFor = + getSummary(sessionId, ChatGetSummaryParams.none()) + + /** @see getSummary */ + @MustBeClosed + fun getSummary( + sessionId: String, + params: ChatGetSummaryParams = ChatGetSummaryParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + getSummary(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see getSummary */ + @MustBeClosed + fun getSummary( + sessionId: String, + params: ChatGetSummaryParams = ChatGetSummaryParams.none(), + ): HttpResponseFor = + getSummary(sessionId, params, RequestOptions.none()) + + /** @see getSummary */ + @MustBeClosed + fun getSummary( + params: ChatGetSummaryParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see getSummary */ + @MustBeClosed + fun getSummary(params: ChatGetSummaryParams): HttpResponseFor = + getSummary(params, RequestOptions.none()) + + /** @see getSummary */ + @MustBeClosed + fun getSummary( + sessionId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + getSummary(sessionId, ChatGetSummaryParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /api/v1/chat/{session_id}/messages/stream`, but is + * otherwise the same as [ChatService.stream]. + */ + @MustBeClosed + fun stream( + sessionId: String, + params: ChatStreamParams, + ): HttpResponseFor = stream(sessionId, params, RequestOptions.none()) + + /** @see stream */ + @MustBeClosed + fun stream( + sessionId: String, + params: ChatStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + stream(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see stream */ + @MustBeClosed + fun stream(params: ChatStreamParams): HttpResponseFor = + stream(params, RequestOptions.none()) + + /** @see stream */ + @MustBeClosed + fun stream( + params: ChatStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/ChatServiceImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/ChatServiceImpl.kt new file mode 100644 index 0000000..560b546 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/ChatServiceImpl.kt @@ -0,0 +1,280 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.handlers.emptyHandler +import ai.llamaindex.llamacloud.core.handlers.errorBodyHandler +import ai.llamaindex.llamacloud.core.handlers.errorHandler +import ai.llamaindex.llamacloud.core.handlers.jsonHandler +import ai.llamaindex.llamacloud.core.http.HttpMethod +import ai.llamaindex.llamacloud.core.http.HttpRequest +import ai.llamaindex.llamacloud.core.http.HttpResponse +import ai.llamaindex.llamacloud.core.http.HttpResponse.Handler +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.core.http.json +import ai.llamaindex.llamacloud.core.http.parseable +import ai.llamaindex.llamacloud.core.prepare +import ai.llamaindex.llamacloud.models.chat.ChatCreateParams +import ai.llamaindex.llamacloud.models.chat.ChatCreateResponse +import ai.llamaindex.llamacloud.models.chat.ChatDeleteParams +import ai.llamaindex.llamacloud.models.chat.ChatGetSummaryParams +import ai.llamaindex.llamacloud.models.chat.ChatGetSummaryResponse +import ai.llamaindex.llamacloud.models.chat.ChatListPage +import ai.llamaindex.llamacloud.models.chat.ChatListPageResponse +import ai.llamaindex.llamacloud.models.chat.ChatListParams +import ai.llamaindex.llamacloud.models.chat.ChatRetrieveParams +import ai.llamaindex.llamacloud.models.chat.ChatRetrieveResponse +import ai.llamaindex.llamacloud.models.chat.ChatStreamParams +import ai.llamaindex.llamacloud.models.chat.ChatStreamResponse +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class ChatServiceImpl internal constructor(private val clientOptions: ClientOptions) : ChatService { + + private val withRawResponse: ChatService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): ChatService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): ChatService = + ChatServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: ChatCreateParams, + requestOptions: RequestOptions, + ): ChatCreateResponse = + // post /api/v1/chat + withRawResponse().create(params, requestOptions).parse() + + override fun retrieve( + params: ChatRetrieveParams, + requestOptions: RequestOptions, + ): ChatRetrieveResponse = + // get /api/v1/chat/{session_id} + withRawResponse().retrieve(params, requestOptions).parse() + + override fun list(params: ChatListParams, requestOptions: RequestOptions): ChatListPage = + // get /api/v1/chat + withRawResponse().list(params, requestOptions).parse() + + override fun delete(params: ChatDeleteParams, requestOptions: RequestOptions) { + // delete /api/v1/chat/{session_id} + withRawResponse().delete(params, requestOptions) + } + + override fun getSummary( + params: ChatGetSummaryParams, + requestOptions: RequestOptions, + ): ChatGetSummaryResponse = + // get /api/v1/chat/{session_id}/summary + withRawResponse().getSummary(params, requestOptions).parse() + + override fun stream( + params: ChatStreamParams, + requestOptions: RequestOptions, + ): ChatStreamResponse = + // post /api/v1/chat/{session_id}/messages/stream + withRawResponse().stream(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + ChatService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ChatService.WithRawResponse = + ChatServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: ChatCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "chat") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: ChatRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sessionId", params.sessionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "chat", params._pathParam(0)) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: ChatListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "chat") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + ChatListPage.builder() + .service(ChatServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } + } + } + + private val deleteHandler: Handler = emptyHandler() + + override fun delete( + params: ChatDeleteParams, + requestOptions: RequestOptions, + ): HttpResponse { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sessionId", params.sessionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "chat", params._pathParam(0)) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response.use { deleteHandler.handle(it) } + } + } + + private val getSummaryHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun getSummary( + params: ChatGetSummaryParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sessionId", params.sessionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "chat", params._pathParam(0), "summary") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { getSummaryHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val streamHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun stream( + params: ChatStreamParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("sessionId", params.sessionId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "api", + "v1", + "chat", + params._pathParam(0), + "messages", + "stream", + ) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { streamHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/IndexService.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/IndexService.kt new file mode 100644 index 0000000..bd43cd8 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/IndexService.kt @@ -0,0 +1,395 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.http.HttpResponse +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.models.indexes.IndexCancelSyncParams +import ai.llamaindex.llamacloud.models.indexes.IndexCancelSyncResponse +import ai.llamaindex.llamacloud.models.indexes.IndexCreateParams +import ai.llamaindex.llamacloud.models.indexes.IndexCreateResponse +import ai.llamaindex.llamacloud.models.indexes.IndexDeleteParams +import ai.llamaindex.llamacloud.models.indexes.IndexGetParams +import ai.llamaindex.llamacloud.models.indexes.IndexGetResponse +import ai.llamaindex.llamacloud.models.indexes.IndexListPage +import ai.llamaindex.llamacloud.models.indexes.IndexListParams +import ai.llamaindex.llamacloud.models.indexes.IndexSyncParams +import ai.llamaindex.llamacloud.models.indexes.IndexSyncResponse +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +interface IndexService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): IndexService + + /** Create a searchable index over a source directory. */ + fun create(params: IndexCreateParams): IndexCreateResponse = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: IndexCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): IndexCreateResponse + + /** List indexes for the current project. */ + fun list(): IndexListPage = list(IndexListParams.none()) + + /** @see list */ + fun list( + params: IndexListParams = IndexListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): IndexListPage + + /** @see list */ + fun list(params: IndexListParams = IndexListParams.none()): IndexListPage = + list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): IndexListPage = + list(IndexListParams.none(), requestOptions) + + /** Delete an index. */ + fun delete(indexId: String) = delete(indexId, IndexDeleteParams.none()) + + /** @see delete */ + fun delete( + indexId: String, + params: IndexDeleteParams = IndexDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ) = delete(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see delete */ + fun delete(indexId: String, params: IndexDeleteParams = IndexDeleteParams.none()) = + delete(indexId, params, RequestOptions.none()) + + /** @see delete */ + fun delete(params: IndexDeleteParams, requestOptions: RequestOptions = RequestOptions.none()) + + /** @see delete */ + fun delete(params: IndexDeleteParams) = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(indexId: String, requestOptions: RequestOptions) = + delete(indexId, IndexDeleteParams.none(), requestOptions) + + /** Cancel the running sync for an index. Returns 409 if no sync is running. */ + fun cancelSync(indexId: String): IndexCancelSyncResponse = + cancelSync(indexId, IndexCancelSyncParams.none()) + + /** @see cancelSync */ + fun cancelSync( + indexId: String, + params: IndexCancelSyncParams = IndexCancelSyncParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): IndexCancelSyncResponse = + cancelSync(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see cancelSync */ + fun cancelSync( + indexId: String, + params: IndexCancelSyncParams = IndexCancelSyncParams.none(), + ): IndexCancelSyncResponse = cancelSync(indexId, params, RequestOptions.none()) + + /** @see cancelSync */ + fun cancelSync( + params: IndexCancelSyncParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): IndexCancelSyncResponse + + /** @see cancelSync */ + fun cancelSync(params: IndexCancelSyncParams): IndexCancelSyncResponse = + cancelSync(params, RequestOptions.none()) + + /** @see cancelSync */ + fun cancelSync(indexId: String, requestOptions: RequestOptions): IndexCancelSyncResponse = + cancelSync(indexId, IndexCancelSyncParams.none(), requestOptions) + + /** Get an index by ID. */ + fun get(indexId: String): IndexGetResponse = get(indexId, IndexGetParams.none()) + + /** @see get */ + fun get( + indexId: String, + params: IndexGetParams = IndexGetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): IndexGetResponse = get(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see get */ + fun get(indexId: String, params: IndexGetParams = IndexGetParams.none()): IndexGetResponse = + get(indexId, params, RequestOptions.none()) + + /** @see get */ + fun get( + params: IndexGetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): IndexGetResponse + + /** @see get */ + fun get(params: IndexGetParams): IndexGetResponse = get(params, RequestOptions.none()) + + /** @see get */ + fun get(indexId: String, requestOptions: RequestOptions): IndexGetResponse = + get(indexId, IndexGetParams.none(), requestOptions) + + /** + * Trigger a sync and export for an existing index, re-parsing changed files and exporting + * updated chunks. + */ + fun sync(indexId: String): IndexSyncResponse = sync(indexId, IndexSyncParams.none()) + + /** @see sync */ + fun sync( + indexId: String, + params: IndexSyncParams = IndexSyncParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): IndexSyncResponse = sync(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see sync */ + fun sync(indexId: String, params: IndexSyncParams = IndexSyncParams.none()): IndexSyncResponse = + sync(indexId, params, RequestOptions.none()) + + /** @see sync */ + fun sync( + params: IndexSyncParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): IndexSyncResponse + + /** @see sync */ + fun sync(params: IndexSyncParams): IndexSyncResponse = sync(params, RequestOptions.none()) + + /** @see sync */ + fun sync(indexId: String, requestOptions: RequestOptions): IndexSyncResponse = + sync(indexId, IndexSyncParams.none(), requestOptions) + + /** A view of [IndexService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): IndexService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /api/v1/indexes`, but is otherwise the same as + * [IndexService.create]. + */ + @MustBeClosed + fun create(params: IndexCreateParams): HttpResponseFor = + create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: IndexCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /api/v1/indexes`, but is otherwise the same as + * [IndexService.list]. + */ + @MustBeClosed fun list(): HttpResponseFor = list(IndexListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: IndexListParams = IndexListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list(params: IndexListParams = IndexListParams.none()): HttpResponseFor = + list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list(requestOptions: RequestOptions): HttpResponseFor = + list(IndexListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /api/v1/indexes/{index_id}`, but is otherwise the + * same as [IndexService.delete]. + */ + @MustBeClosed + fun delete(indexId: String): HttpResponse = delete(indexId, IndexDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + indexId: String, + params: IndexDeleteParams = IndexDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse = delete(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see delete */ + @MustBeClosed + fun delete( + indexId: String, + params: IndexDeleteParams = IndexDeleteParams.none(), + ): HttpResponse = delete(indexId, params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + params: IndexDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponse + + /** @see delete */ + @MustBeClosed + fun delete(params: IndexDeleteParams): HttpResponse = delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(indexId: String, requestOptions: RequestOptions): HttpResponse = + delete(indexId, IndexDeleteParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /api/v1/indexes/{index_id}/sync/cancel`, but is + * otherwise the same as [IndexService.cancelSync]. + */ + @MustBeClosed + fun cancelSync(indexId: String): HttpResponseFor = + cancelSync(indexId, IndexCancelSyncParams.none()) + + /** @see cancelSync */ + @MustBeClosed + fun cancelSync( + indexId: String, + params: IndexCancelSyncParams = IndexCancelSyncParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + cancelSync(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see cancelSync */ + @MustBeClosed + fun cancelSync( + indexId: String, + params: IndexCancelSyncParams = IndexCancelSyncParams.none(), + ): HttpResponseFor = + cancelSync(indexId, params, RequestOptions.none()) + + /** @see cancelSync */ + @MustBeClosed + fun cancelSync( + params: IndexCancelSyncParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see cancelSync */ + @MustBeClosed + fun cancelSync(params: IndexCancelSyncParams): HttpResponseFor = + cancelSync(params, RequestOptions.none()) + + /** @see cancelSync */ + @MustBeClosed + fun cancelSync( + indexId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + cancelSync(indexId, IndexCancelSyncParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/v1/indexes/{index_id}`, but is otherwise the + * same as [IndexService.get]. + */ + @MustBeClosed + fun get(indexId: String): HttpResponseFor = + get(indexId, IndexGetParams.none()) + + /** @see get */ + @MustBeClosed + fun get( + indexId: String, + params: IndexGetParams = IndexGetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + get(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see get */ + @MustBeClosed + fun get( + indexId: String, + params: IndexGetParams = IndexGetParams.none(), + ): HttpResponseFor = get(indexId, params, RequestOptions.none()) + + /** @see get */ + @MustBeClosed + fun get( + params: IndexGetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see get */ + @MustBeClosed + fun get(params: IndexGetParams): HttpResponseFor = + get(params, RequestOptions.none()) + + /** @see get */ + @MustBeClosed + fun get( + indexId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = get(indexId, IndexGetParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /api/v1/indexes/{index_id}/sync`, but is otherwise + * the same as [IndexService.sync]. + */ + @MustBeClosed + fun sync(indexId: String): HttpResponseFor = + sync(indexId, IndexSyncParams.none()) + + /** @see sync */ + @MustBeClosed + fun sync( + indexId: String, + params: IndexSyncParams = IndexSyncParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + sync(params.toBuilder().indexId(indexId).build(), requestOptions) + + /** @see sync */ + @MustBeClosed + fun sync( + indexId: String, + params: IndexSyncParams = IndexSyncParams.none(), + ): HttpResponseFor = sync(indexId, params, RequestOptions.none()) + + /** @see sync */ + @MustBeClosed + fun sync( + params: IndexSyncParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see sync */ + @MustBeClosed + fun sync(params: IndexSyncParams): HttpResponseFor = + sync(params, RequestOptions.none()) + + /** @see sync */ + @MustBeClosed + fun sync( + indexId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + sync(indexId, IndexSyncParams.none(), requestOptions) + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/IndexServiceImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/IndexServiceImpl.kt new file mode 100644 index 0000000..d50f677 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/IndexServiceImpl.kt @@ -0,0 +1,269 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.handlers.emptyHandler +import ai.llamaindex.llamacloud.core.handlers.errorBodyHandler +import ai.llamaindex.llamacloud.core.handlers.errorHandler +import ai.llamaindex.llamacloud.core.handlers.jsonHandler +import ai.llamaindex.llamacloud.core.http.HttpMethod +import ai.llamaindex.llamacloud.core.http.HttpRequest +import ai.llamaindex.llamacloud.core.http.HttpResponse +import ai.llamaindex.llamacloud.core.http.HttpResponse.Handler +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.core.http.json +import ai.llamaindex.llamacloud.core.http.parseable +import ai.llamaindex.llamacloud.core.prepare +import ai.llamaindex.llamacloud.models.indexes.IndexCancelSyncParams +import ai.llamaindex.llamacloud.models.indexes.IndexCancelSyncResponse +import ai.llamaindex.llamacloud.models.indexes.IndexCreateParams +import ai.llamaindex.llamacloud.models.indexes.IndexCreateResponse +import ai.llamaindex.llamacloud.models.indexes.IndexDeleteParams +import ai.llamaindex.llamacloud.models.indexes.IndexGetParams +import ai.llamaindex.llamacloud.models.indexes.IndexGetResponse +import ai.llamaindex.llamacloud.models.indexes.IndexListPage +import ai.llamaindex.llamacloud.models.indexes.IndexListPageResponse +import ai.llamaindex.llamacloud.models.indexes.IndexListParams +import ai.llamaindex.llamacloud.models.indexes.IndexSyncParams +import ai.llamaindex.llamacloud.models.indexes.IndexSyncResponse +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class IndexServiceImpl internal constructor(private val clientOptions: ClientOptions) : + IndexService { + + private val withRawResponse: IndexService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): IndexService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): IndexService = + IndexServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: IndexCreateParams, + requestOptions: RequestOptions, + ): IndexCreateResponse = + // post /api/v1/indexes + withRawResponse().create(params, requestOptions).parse() + + override fun list(params: IndexListParams, requestOptions: RequestOptions): IndexListPage = + // get /api/v1/indexes + withRawResponse().list(params, requestOptions).parse() + + override fun delete(params: IndexDeleteParams, requestOptions: RequestOptions) { + // delete /api/v1/indexes/{index_id} + withRawResponse().delete(params, requestOptions) + } + + override fun cancelSync( + params: IndexCancelSyncParams, + requestOptions: RequestOptions, + ): IndexCancelSyncResponse = + // post /api/v1/indexes/{index_id}/sync/cancel + withRawResponse().cancelSync(params, requestOptions).parse() + + override fun get(params: IndexGetParams, requestOptions: RequestOptions): IndexGetResponse = + // get /api/v1/indexes/{index_id} + withRawResponse().get(params, requestOptions).parse() + + override fun sync(params: IndexSyncParams, requestOptions: RequestOptions): IndexSyncResponse = + // post /api/v1/indexes/{index_id}/sync + withRawResponse().sync(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + IndexService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): IndexService.WithRawResponse = + IndexServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: IndexCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "indexes") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: IndexListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "indexes") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + IndexListPage.builder() + .service(IndexServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } + } + } + + private val deleteHandler: Handler = emptyHandler() + + override fun delete( + params: IndexDeleteParams, + requestOptions: RequestOptions, + ): HttpResponse { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("indexId", params.indexId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "indexes", params._pathParam(0)) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response.use { deleteHandler.handle(it) } + } + } + + private val cancelSyncHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun cancelSync( + params: IndexCancelSyncParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("indexId", params.indexId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "indexes", params._pathParam(0), "sync", "cancel") + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { cancelSyncHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val getHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun get( + params: IndexGetParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("indexId", params.indexId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "indexes", params._pathParam(0)) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { getHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val syncHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun sync( + params: IndexSyncParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("indexId", params.indexId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "indexes", params._pathParam(0), "sync") + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { syncHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/RetrievalService.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/RetrievalService.kt new file mode 100644 index 0000000..5cf576e --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/RetrievalService.kt @@ -0,0 +1,144 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.models.retrieval.RetrievalFindPage +import ai.llamaindex.llamacloud.models.retrieval.RetrievalFindParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalGrepPage +import ai.llamaindex.llamacloud.models.retrieval.RetrievalGrepParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalReadParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalReadResponse +import ai.llamaindex.llamacloud.models.retrieval.RetrievalRetrieveParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalRetrieveResponse +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +interface RetrievalService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RetrievalService + + /** + * Retrieve relevant chunks via hybrid search (vector + full-text), with filtering on built-in + * or user-defined metadata. + */ + fun retrieve(params: RetrievalRetrieveParams): RetrievalRetrieveResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RetrievalRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RetrievalRetrieveResponse + + /** Search for files by name. */ + fun find(params: RetrievalFindParams): RetrievalFindPage = find(params, RequestOptions.none()) + + /** @see find */ + fun find( + params: RetrievalFindParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RetrievalFindPage + + /** Grep within a file's parsed content using a regex pattern. */ + fun grep(params: RetrievalGrepParams): RetrievalGrepPage = grep(params, RequestOptions.none()) + + /** @see grep */ + fun grep( + params: RetrievalGrepParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RetrievalGrepPage + + /** Read the parsed text content of a specific file. */ + fun read(params: RetrievalReadParams): RetrievalReadResponse = + read(params, RequestOptions.none()) + + /** @see read */ + fun read( + params: RetrievalReadParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): RetrievalReadResponse + + /** A view of [RetrievalService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RetrievalService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /api/v1/retrieval/retrieve`, but is otherwise the + * same as [RetrievalService.retrieve]. + */ + @MustBeClosed + fun retrieve(params: RetrievalRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: RetrievalRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `post /api/v1/retrieval/files/find`, but is otherwise the + * same as [RetrievalService.find]. + */ + @MustBeClosed + fun find(params: RetrievalFindParams): HttpResponseFor = + find(params, RequestOptions.none()) + + /** @see find */ + @MustBeClosed + fun find( + params: RetrievalFindParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `post /api/v1/retrieval/files/grep`, but is otherwise the + * same as [RetrievalService.grep]. + */ + @MustBeClosed + fun grep(params: RetrievalGrepParams): HttpResponseFor = + grep(params, RequestOptions.none()) + + /** @see grep */ + @MustBeClosed + fun grep( + params: RetrievalGrepParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `post /api/v1/retrieval/files/read`, but is otherwise the + * same as [RetrievalService.read]. + */ + @MustBeClosed + fun read(params: RetrievalReadParams): HttpResponseFor = + read(params, RequestOptions.none()) + + /** @see read */ + @MustBeClosed + fun read( + params: RetrievalReadParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/RetrievalServiceImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/RetrievalServiceImpl.kt new file mode 100644 index 0000000..a7ef7d1 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/RetrievalServiceImpl.kt @@ -0,0 +1,209 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.handlers.errorBodyHandler +import ai.llamaindex.llamacloud.core.handlers.errorHandler +import ai.llamaindex.llamacloud.core.handlers.jsonHandler +import ai.llamaindex.llamacloud.core.http.HttpMethod +import ai.llamaindex.llamacloud.core.http.HttpRequest +import ai.llamaindex.llamacloud.core.http.HttpResponse +import ai.llamaindex.llamacloud.core.http.HttpResponse.Handler +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.core.http.json +import ai.llamaindex.llamacloud.core.http.parseable +import ai.llamaindex.llamacloud.core.prepare +import ai.llamaindex.llamacloud.models.retrieval.RetrievalFindPage +import ai.llamaindex.llamacloud.models.retrieval.RetrievalFindPageResponse +import ai.llamaindex.llamacloud.models.retrieval.RetrievalFindParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalGrepPage +import ai.llamaindex.llamacloud.models.retrieval.RetrievalGrepPageResponse +import ai.llamaindex.llamacloud.models.retrieval.RetrievalGrepParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalReadParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalReadResponse +import ai.llamaindex.llamacloud.models.retrieval.RetrievalRetrieveParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalRetrieveResponse +import java.util.function.Consumer + +class RetrievalServiceImpl internal constructor(private val clientOptions: ClientOptions) : + RetrievalService { + + private val withRawResponse: RetrievalService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): RetrievalService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): RetrievalService = + RetrievalServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: RetrievalRetrieveParams, + requestOptions: RequestOptions, + ): RetrievalRetrieveResponse = + // post /api/v1/retrieval/retrieve + withRawResponse().retrieve(params, requestOptions).parse() + + override fun find( + params: RetrievalFindParams, + requestOptions: RequestOptions, + ): RetrievalFindPage = + // post /api/v1/retrieval/files/find + withRawResponse().find(params, requestOptions).parse() + + override fun grep( + params: RetrievalGrepParams, + requestOptions: RequestOptions, + ): RetrievalGrepPage = + // post /api/v1/retrieval/files/grep + withRawResponse().grep(params, requestOptions).parse() + + override fun read( + params: RetrievalReadParams, + requestOptions: RequestOptions, + ): RetrievalReadResponse = + // post /api/v1/retrieval/files/read + withRawResponse().read(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + RetrievalService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): RetrievalService.WithRawResponse = + RetrievalServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RetrievalRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "retrieval", "retrieve") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val findHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun find( + params: RetrievalFindParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "retrieval", "files", "find") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { findHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + RetrievalFindPage.builder() + .service(RetrievalServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } + } + } + + private val grepHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun grep( + params: RetrievalGrepParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "retrieval", "files", "grep") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { grepHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + RetrievalGrepPage.builder() + .service(RetrievalServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } + } + } + + private val readHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun read( + params: RetrievalReadParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "retrieval", "files", "read") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { readHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/alpha/VerifyService.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/alpha/VerifyService.kt new file mode 100644 index 0000000..31e06d3 --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/alpha/VerifyService.kt @@ -0,0 +1,379 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking.alpha + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCancelParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCancelResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCreateParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCreateResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetDetailsParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetDetailsResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyListPage +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyListParams +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +interface VerifyService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): VerifyService + + /** + * Create a Verify job. + * + * Analyzes a document for signs of doctoring (splicing, copy-move, AI generation, metadata + * tampering, ...). Set `file_input` to a file ID (`dfl-...`). Optionally provide a + * `configuration` object to control the semantic agent. + * + * The job runs asynchronously. Poll `GET /verify/{job_id}` with `expand=result` to check status + * and retrieve results. + */ + fun create(): VerifyCreateResponse = create(VerifyCreateParams.none()) + + /** @see create */ + fun create( + params: VerifyCreateParams = VerifyCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): VerifyCreateResponse + + /** @see create */ + fun create(params: VerifyCreateParams = VerifyCreateParams.none()): VerifyCreateResponse = + create(params, RequestOptions.none()) + + /** @see create */ + fun create(requestOptions: RequestOptions): VerifyCreateResponse = + create(VerifyCreateParams.none(), requestOptions) + + /** + * List Verify jobs with optional filtering and pagination. + * + * Filter by `status`, specific `job_ids`, or creation date range. + */ + fun list(): VerifyListPage = list(VerifyListParams.none()) + + /** @see list */ + fun list( + params: VerifyListParams = VerifyListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): VerifyListPage + + /** @see list */ + fun list(params: VerifyListParams = VerifyListParams.none()): VerifyListPage = + list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): VerifyListPage = + list(VerifyListParams.none(), requestOptions) + + /** + * Cancel a running Verify job. + * + * Stops processing and marks the job as CANCELLED. Returns the updated job. Jobs already in a + * terminal state (COMPLETED, FAILED, CANCELLED) cannot be cancelled. + */ + fun cancel(jobId: String): VerifyCancelResponse = cancel(jobId, VerifyCancelParams.none()) + + /** @see cancel */ + fun cancel( + jobId: String, + params: VerifyCancelParams = VerifyCancelParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): VerifyCancelResponse = cancel(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see cancel */ + fun cancel( + jobId: String, + params: VerifyCancelParams = VerifyCancelParams.none(), + ): VerifyCancelResponse = cancel(jobId, params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + params: VerifyCancelParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): VerifyCancelResponse + + /** @see cancel */ + fun cancel(params: VerifyCancelParams): VerifyCancelResponse = + cancel(params, RequestOptions.none()) + + /** @see cancel */ + fun cancel(jobId: String, requestOptions: RequestOptions): VerifyCancelResponse = + cancel(jobId, VerifyCancelParams.none(), requestOptions) + + /** + * Get a Verify job by ID. + * + * Returns the job status and configuration. Pass `expand=result` to include the Verify result + * (overall score, verdict, confidence, composite scores, and suspect regions) when the job is + * complete. + * + * Raw per-signal detail is available via `GET /verify/{job_id}/details`. + */ + fun get(jobId: String): VerifyGetResponse = get(jobId, VerifyGetParams.none()) + + /** @see get */ + fun get( + jobId: String, + params: VerifyGetParams = VerifyGetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): VerifyGetResponse = get(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see get */ + fun get(jobId: String, params: VerifyGetParams = VerifyGetParams.none()): VerifyGetResponse = + get(jobId, params, RequestOptions.none()) + + /** @see get */ + fun get( + params: VerifyGetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): VerifyGetResponse + + /** @see get */ + fun get(params: VerifyGetParams): VerifyGetResponse = get(params, RequestOptions.none()) + + /** @see get */ + fun get(jobId: String, requestOptions: RequestOptions): VerifyGetResponse = + get(jobId, VerifyGetParams.none(), requestOptions) + + /** + * Get the raw per-signal detail for a completed Verify job. + * + * Forensic drill-down behind the simplified result: the full evidence list, per-family + * sub-scores, raw localized regions, and per-page forensic heatmap overlays (presigned image + * URLs). + */ + fun getDetails(jobId: String): VerifyGetDetailsResponse = + getDetails(jobId, VerifyGetDetailsParams.none()) + + /** @see getDetails */ + fun getDetails( + jobId: String, + params: VerifyGetDetailsParams = VerifyGetDetailsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): VerifyGetDetailsResponse = + getDetails(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see getDetails */ + fun getDetails( + jobId: String, + params: VerifyGetDetailsParams = VerifyGetDetailsParams.none(), + ): VerifyGetDetailsResponse = getDetails(jobId, params, RequestOptions.none()) + + /** @see getDetails */ + fun getDetails( + params: VerifyGetDetailsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): VerifyGetDetailsResponse + + /** @see getDetails */ + fun getDetails(params: VerifyGetDetailsParams): VerifyGetDetailsResponse = + getDetails(params, RequestOptions.none()) + + /** @see getDetails */ + fun getDetails(jobId: String, requestOptions: RequestOptions): VerifyGetDetailsResponse = + getDetails(jobId, VerifyGetDetailsParams.none(), requestOptions) + + /** A view of [VerifyService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): VerifyService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /api/alpha/verify`, but is otherwise the same as + * [VerifyService.create]. + */ + @MustBeClosed + fun create(): HttpResponseFor = create(VerifyCreateParams.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: VerifyCreateParams = VerifyCreateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see create */ + @MustBeClosed + fun create( + params: VerifyCreateParams = VerifyCreateParams.none() + ): HttpResponseFor = create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create(requestOptions: RequestOptions): HttpResponseFor = + create(VerifyCreateParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/alpha/verify`, but is otherwise the same as + * [VerifyService.list]. + */ + @MustBeClosed fun list(): HttpResponseFor = list(VerifyListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: VerifyListParams = VerifyListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list( + params: VerifyListParams = VerifyListParams.none() + ): HttpResponseFor = list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list(requestOptions: RequestOptions): HttpResponseFor = + list(VerifyListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /api/alpha/verify/{job_id}/cancel`, but is + * otherwise the same as [VerifyService.cancel]. + */ + @MustBeClosed + fun cancel(jobId: String): HttpResponseFor = + cancel(jobId, VerifyCancelParams.none()) + + /** @see cancel */ + @MustBeClosed + fun cancel( + jobId: String, + params: VerifyCancelParams = VerifyCancelParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + cancel(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see cancel */ + @MustBeClosed + fun cancel( + jobId: String, + params: VerifyCancelParams = VerifyCancelParams.none(), + ): HttpResponseFor = cancel(jobId, params, RequestOptions.none()) + + /** @see cancel */ + @MustBeClosed + fun cancel( + params: VerifyCancelParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see cancel */ + @MustBeClosed + fun cancel(params: VerifyCancelParams): HttpResponseFor = + cancel(params, RequestOptions.none()) + + /** @see cancel */ + @MustBeClosed + fun cancel( + jobId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + cancel(jobId, VerifyCancelParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/alpha/verify/{job_id}`, but is otherwise the + * same as [VerifyService.get]. + */ + @MustBeClosed + fun get(jobId: String): HttpResponseFor = + get(jobId, VerifyGetParams.none()) + + /** @see get */ + @MustBeClosed + fun get( + jobId: String, + params: VerifyGetParams = VerifyGetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + get(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see get */ + @MustBeClosed + fun get( + jobId: String, + params: VerifyGetParams = VerifyGetParams.none(), + ): HttpResponseFor = get(jobId, params, RequestOptions.none()) + + /** @see get */ + @MustBeClosed + fun get( + params: VerifyGetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see get */ + @MustBeClosed + fun get(params: VerifyGetParams): HttpResponseFor = + get(params, RequestOptions.none()) + + /** @see get */ + @MustBeClosed + fun get(jobId: String, requestOptions: RequestOptions): HttpResponseFor = + get(jobId, VerifyGetParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/alpha/verify/{job_id}/details`, but is + * otherwise the same as [VerifyService.getDetails]. + */ + @MustBeClosed + fun getDetails(jobId: String): HttpResponseFor = + getDetails(jobId, VerifyGetDetailsParams.none()) + + /** @see getDetails */ + @MustBeClosed + fun getDetails( + jobId: String, + params: VerifyGetDetailsParams = VerifyGetDetailsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + getDetails(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see getDetails */ + @MustBeClosed + fun getDetails( + jobId: String, + params: VerifyGetDetailsParams = VerifyGetDetailsParams.none(), + ): HttpResponseFor = + getDetails(jobId, params, RequestOptions.none()) + + /** @see getDetails */ + @MustBeClosed + fun getDetails( + params: VerifyGetDetailsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see getDetails */ + @MustBeClosed + fun getDetails(params: VerifyGetDetailsParams): HttpResponseFor = + getDetails(params, RequestOptions.none()) + + /** @see getDetails */ + @MustBeClosed + fun getDetails( + jobId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + getDetails(jobId, VerifyGetDetailsParams.none(), requestOptions) + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/alpha/VerifyServiceImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/alpha/VerifyServiceImpl.kt new file mode 100644 index 0000000..a00a83c --- /dev/null +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/alpha/VerifyServiceImpl.kt @@ -0,0 +1,240 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking.alpha + +import ai.llamaindex.llamacloud.core.ClientOptions +import ai.llamaindex.llamacloud.core.RequestOptions +import ai.llamaindex.llamacloud.core.checkRequired +import ai.llamaindex.llamacloud.core.handlers.errorBodyHandler +import ai.llamaindex.llamacloud.core.handlers.errorHandler +import ai.llamaindex.llamacloud.core.handlers.jsonHandler +import ai.llamaindex.llamacloud.core.http.HttpMethod +import ai.llamaindex.llamacloud.core.http.HttpRequest +import ai.llamaindex.llamacloud.core.http.HttpResponse +import ai.llamaindex.llamacloud.core.http.HttpResponse.Handler +import ai.llamaindex.llamacloud.core.http.HttpResponseFor +import ai.llamaindex.llamacloud.core.http.json +import ai.llamaindex.llamacloud.core.http.parseable +import ai.llamaindex.llamacloud.core.prepare +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCancelParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCancelResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCreateParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCreateResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetDetailsParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetDetailsResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyListPage +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyListPageResponse +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyListParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class VerifyServiceImpl internal constructor(private val clientOptions: ClientOptions) : + VerifyService { + + private val withRawResponse: VerifyService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): VerifyService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): VerifyService = + VerifyServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: VerifyCreateParams, + requestOptions: RequestOptions, + ): VerifyCreateResponse = + // post /api/alpha/verify + withRawResponse().create(params, requestOptions).parse() + + override fun list(params: VerifyListParams, requestOptions: RequestOptions): VerifyListPage = + // get /api/alpha/verify + withRawResponse().list(params, requestOptions).parse() + + override fun cancel( + params: VerifyCancelParams, + requestOptions: RequestOptions, + ): VerifyCancelResponse = + // post /api/alpha/verify/{job_id}/cancel + withRawResponse().cancel(params, requestOptions).parse() + + override fun get(params: VerifyGetParams, requestOptions: RequestOptions): VerifyGetResponse = + // get /api/alpha/verify/{job_id} + withRawResponse().get(params, requestOptions).parse() + + override fun getDetails( + params: VerifyGetDetailsParams, + requestOptions: RequestOptions, + ): VerifyGetDetailsResponse = + // get /api/alpha/verify/{job_id}/details + withRawResponse().getDetails(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + VerifyService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): VerifyService.WithRawResponse = + VerifyServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: VerifyCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "alpha", "verify") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: VerifyListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "alpha", "verify") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + .let { + VerifyListPage.builder() + .service(VerifyServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } + } + } + + private val cancelHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun cancel( + params: VerifyCancelParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "alpha", "verify", params._pathParam(0), "cancel") + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { cancelHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val getHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun get( + params: VerifyGetParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "alpha", "verify", params._pathParam(0)) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { getHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val getDetailsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun getDetails( + params: VerifyGetDetailsParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "alpha", "verify", params._pathParam(0), "details") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { getDetailsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/ChatService.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/ChatService.kt index 55fd3b7..0d08532 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/ChatService.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/ChatService.kt @@ -35,27 +35,33 @@ interface ChatService { fun withOptions(modifier: Consumer): ChatService /** Create a chat session, optionally bound to indexes (locked after the first message). */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun create(): ChatCreateResponse = create(ChatCreateParams.none()) /** @see create */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun create( params: ChatCreateParams = ChatCreateParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): ChatCreateResponse /** @see create */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun create(params: ChatCreateParams = ChatCreateParams.none()): ChatCreateResponse = create(params, RequestOptions.none()) /** @see create */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun create(requestOptions: RequestOptions): ChatCreateResponse = create(ChatCreateParams.none(), requestOptions) /** Retrieve a full session by ID, including its event history. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve(sessionId: String): ChatRetrieveResponse = retrieve(sessionId, ChatRetrieveParams.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve( sessionId: String, params: ChatRetrieveParams = ChatRetrieveParams.none(), @@ -64,46 +70,56 @@ interface ChatService { retrieve(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve( sessionId: String, params: ChatRetrieveParams = ChatRetrieveParams.none(), ): ChatRetrieveResponse = retrieve(sessionId, params, RequestOptions.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve( params: ChatRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): ChatRetrieveResponse /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve(params: ChatRetrieveParams): ChatRetrieveResponse = retrieve(params, RequestOptions.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun retrieve(sessionId: String, requestOptions: RequestOptions): ChatRetrieveResponse = retrieve(sessionId, ChatRetrieveParams.none(), requestOptions) /** List all chat sessions for the current project. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun list(): ChatListPage = list(ChatListParams.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun list( params: ChatListParams = ChatListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): ChatListPage /** @see list */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun list(params: ChatListParams = ChatListParams.none()): ChatListPage = list(params, RequestOptions.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun list(requestOptions: RequestOptions): ChatListPage = list(ChatListParams.none(), requestOptions) /** Delete a session. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete(sessionId: String) = delete(sessionId, ChatDeleteParams.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete( sessionId: String, params: ChatDeleteParams = ChatDeleteParams.none(), @@ -111,24 +127,30 @@ interface ChatService { ) = delete(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete(sessionId: String, params: ChatDeleteParams = ChatDeleteParams.none()) = delete(sessionId, params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete(params: ChatDeleteParams, requestOptions: RequestOptions = RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete(params: ChatDeleteParams) = delete(params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun delete(sessionId: String, requestOptions: RequestOptions) = delete(sessionId, ChatDeleteParams.none(), requestOptions) /** Retrieve a session summary by ID. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary(sessionId: String): ChatGetSummaryResponse = getSummary(sessionId, ChatGetSummaryParams.none()) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( sessionId: String, params: ChatGetSummaryParams = ChatGetSummaryParams.none(), @@ -137,30 +159,36 @@ interface ChatService { getSummary(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( sessionId: String, params: ChatGetSummaryParams = ChatGetSummaryParams.none(), ): ChatGetSummaryResponse = getSummary(sessionId, params, RequestOptions.none()) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary( params: ChatGetSummaryParams, requestOptions: RequestOptions = RequestOptions.none(), ): ChatGetSummaryResponse /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary(params: ChatGetSummaryParams): ChatGetSummaryResponse = getSummary(params, RequestOptions.none()) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun getSummary(sessionId: String, requestOptions: RequestOptions): ChatGetSummaryResponse = getSummary(sessionId, ChatGetSummaryParams.none(), requestOptions) /** Stream agent events for a chat turn as Server-Sent Events. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun stream(sessionId: String, params: ChatStreamParams): ChatStreamResponse = stream(sessionId, params, RequestOptions.none()) /** @see stream */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun stream( sessionId: String, params: ChatStreamParams, @@ -168,9 +196,11 @@ interface ChatService { ): ChatStreamResponse = stream(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see stream */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun stream(params: ChatStreamParams): ChatStreamResponse = stream(params, RequestOptions.none()) /** @see stream */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") fun stream( params: ChatStreamParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -190,10 +220,12 @@ interface ChatService { * Returns a raw HTTP response for `post /api/v1/chat`, but is otherwise the same as * [ChatService.create]. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun create(): HttpResponseFor = create(ChatCreateParams.none()) /** @see create */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun create( params: ChatCreateParams = ChatCreateParams.none(), @@ -201,12 +233,14 @@ interface ChatService { ): HttpResponseFor /** @see create */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun create( params: ChatCreateParams = ChatCreateParams.none() ): HttpResponseFor = create(params, RequestOptions.none()) /** @see create */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun create(requestOptions: RequestOptions): HttpResponseFor = create(ChatCreateParams.none(), requestOptions) @@ -215,11 +249,13 @@ interface ChatService { * Returns a raw HTTP response for `get /api/v1/chat/{session_id}`, but is otherwise the * same as [ChatService.retrieve]. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun retrieve(sessionId: String): HttpResponseFor = retrieve(sessionId, ChatRetrieveParams.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun retrieve( sessionId: String, @@ -229,6 +265,7 @@ interface ChatService { retrieve(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun retrieve( sessionId: String, @@ -237,6 +274,7 @@ interface ChatService { retrieve(sessionId, params, RequestOptions.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun retrieve( params: ChatRetrieveParams, @@ -244,11 +282,13 @@ interface ChatService { ): HttpResponseFor /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun retrieve(params: ChatRetrieveParams): HttpResponseFor = retrieve(params, RequestOptions.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun retrieve( sessionId: String, @@ -260,9 +300,12 @@ interface ChatService { * Returns a raw HTTP response for `get /api/v1/chat`, but is otherwise the same as * [ChatService.list]. */ - @MustBeClosed fun list(): HttpResponseFor = list(ChatListParams.none()) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") + @MustBeClosed + fun list(): HttpResponseFor = list(ChatListParams.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun list( params: ChatListParams = ChatListParams.none(), @@ -270,11 +313,13 @@ interface ChatService { ): HttpResponseFor /** @see list */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun list(params: ChatListParams = ChatListParams.none()): HttpResponseFor = list(params, RequestOptions.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(ChatListParams.none(), requestOptions) @@ -283,10 +328,12 @@ interface ChatService { * Returns a raw HTTP response for `delete /api/v1/chat/{session_id}`, but is otherwise the * same as [ChatService.delete]. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun delete(sessionId: String): HttpResponse = delete(sessionId, ChatDeleteParams.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun delete( sessionId: String, @@ -295,6 +342,7 @@ interface ChatService { ): HttpResponse = delete(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun delete( sessionId: String, @@ -302,6 +350,7 @@ interface ChatService { ): HttpResponse = delete(sessionId, params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun delete( params: ChatDeleteParams, @@ -309,10 +358,12 @@ interface ChatService { ): HttpResponse /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun delete(params: ChatDeleteParams): HttpResponse = delete(params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun delete(sessionId: String, requestOptions: RequestOptions): HttpResponse = delete(sessionId, ChatDeleteParams.none(), requestOptions) @@ -321,11 +372,13 @@ interface ChatService { * Returns a raw HTTP response for `get /api/v1/chat/{session_id}/summary`, but is otherwise * the same as [ChatService.getSummary]. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun getSummary(sessionId: String): HttpResponseFor = getSummary(sessionId, ChatGetSummaryParams.none()) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun getSummary( sessionId: String, @@ -335,6 +388,7 @@ interface ChatService { getSummary(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun getSummary( sessionId: String, @@ -343,6 +397,7 @@ interface ChatService { getSummary(sessionId, params, RequestOptions.none()) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun getSummary( params: ChatGetSummaryParams, @@ -350,11 +405,13 @@ interface ChatService { ): HttpResponseFor /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun getSummary(params: ChatGetSummaryParams): HttpResponseFor = getSummary(params, RequestOptions.none()) /** @see getSummary */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun getSummary( sessionId: String, @@ -366,6 +423,7 @@ interface ChatService { * Returns a raw HTTP response for `post /api/v1/chat/{session_id}/messages/stream`, but is * otherwise the same as [ChatService.stream]. */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun stream( sessionId: String, @@ -373,6 +431,7 @@ interface ChatService { ): HttpResponseFor = stream(sessionId, params, RequestOptions.none()) /** @see stream */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun stream( sessionId: String, @@ -382,11 +441,13 @@ interface ChatService { stream(params.toBuilder().sessionId(sessionId).build(), requestOptions) /** @see stream */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun stream(params: ChatStreamParams): HttpResponseFor = stream(params, RequestOptions.none()) /** @see stream */ + @Deprecated("Moved out of beta. Use the top-level chat resource instead") @MustBeClosed fun stream( params: ChatStreamParams, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/ChatServiceImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/ChatServiceImpl.kt index 9b34aa8..c53ab7f 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/ChatServiceImpl.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/ChatServiceImpl.kt @@ -43,6 +43,7 @@ class ChatServiceImpl internal constructor(private val clientOptions: ClientOpti override fun withOptions(modifier: Consumer): ChatService = ChatServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun create( params: ChatCreateParams, requestOptions: RequestOptions, @@ -50,6 +51,7 @@ class ChatServiceImpl internal constructor(private val clientOptions: ClientOpti // post /api/v1/chat withRawResponse().create(params, requestOptions).parse() + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun retrieve( params: ChatRetrieveParams, requestOptions: RequestOptions, @@ -57,15 +59,18 @@ class ChatServiceImpl internal constructor(private val clientOptions: ClientOpti // get /api/v1/chat/{session_id} withRawResponse().retrieve(params, requestOptions).parse() + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun list(params: ChatListParams, requestOptions: RequestOptions): ChatListPage = // get /api/v1/chat withRawResponse().list(params, requestOptions).parse() + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun delete(params: ChatDeleteParams, requestOptions: RequestOptions) { // delete /api/v1/chat/{session_id} withRawResponse().delete(params, requestOptions) } + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun getSummary( params: ChatGetSummaryParams, requestOptions: RequestOptions, @@ -73,6 +78,7 @@ class ChatServiceImpl internal constructor(private val clientOptions: ClientOpti // get /api/v1/chat/{session_id}/summary withRawResponse().getSummary(params, requestOptions).parse() + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun stream( params: ChatStreamParams, requestOptions: RequestOptions, @@ -96,6 +102,7 @@ class ChatServiceImpl internal constructor(private val clientOptions: ClientOpti private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun create( params: ChatCreateParams, requestOptions: RequestOptions, @@ -124,6 +131,7 @@ class ChatServiceImpl internal constructor(private val clientOptions: ClientOpti private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun retrieve( params: ChatRetrieveParams, requestOptions: RequestOptions, @@ -154,6 +162,7 @@ class ChatServiceImpl internal constructor(private val clientOptions: ClientOpti private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun list( params: ChatListParams, requestOptions: RequestOptions, @@ -187,6 +196,7 @@ class ChatServiceImpl internal constructor(private val clientOptions: ClientOpti private val deleteHandler: Handler = emptyHandler() + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun delete( params: ChatDeleteParams, requestOptions: RequestOptions, @@ -212,6 +222,7 @@ class ChatServiceImpl internal constructor(private val clientOptions: ClientOpti private val getSummaryHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun getSummary( params: ChatGetSummaryParams, requestOptions: RequestOptions, @@ -242,6 +253,7 @@ class ChatServiceImpl internal constructor(private val clientOptions: ClientOpti private val streamHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level chat resource instead") override fun stream( params: ChatStreamParams, requestOptions: RequestOptions, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/IndexService.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/IndexService.kt index 4b06dc6..faeb56d 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/IndexService.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/IndexService.kt @@ -33,36 +33,44 @@ interface IndexService { fun withOptions(modifier: Consumer): IndexService /** Create a searchable index over a source directory. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun create(params: IndexCreateParams): IndexCreateResponse = create(params, RequestOptions.none()) /** @see create */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun create( params: IndexCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): IndexCreateResponse /** List indexes for the current project. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun list(): IndexListPage = list(IndexListParams.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun list( params: IndexListParams = IndexListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): IndexListPage /** @see list */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun list(params: IndexListParams = IndexListParams.none()): IndexListPage = list(params, RequestOptions.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun list(requestOptions: RequestOptions): IndexListPage = list(IndexListParams.none(), requestOptions) /** Delete an index. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete(indexId: String) = delete(indexId, IndexDeleteParams.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete( indexId: String, params: IndexDeleteParams = IndexDeleteParams.none(), @@ -70,23 +78,29 @@ interface IndexService { ) = delete(params.toBuilder().indexId(indexId).build(), requestOptions) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete(indexId: String, params: IndexDeleteParams = IndexDeleteParams.none()) = delete(indexId, params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete(params: IndexDeleteParams, requestOptions: RequestOptions = RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete(params: IndexDeleteParams) = delete(params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun delete(indexId: String, requestOptions: RequestOptions) = delete(indexId, IndexDeleteParams.none(), requestOptions) /** Get an index by ID. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get(indexId: String): IndexGetResponse = get(indexId, IndexGetParams.none()) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get( indexId: String, params: IndexGetParams = IndexGetParams.none(), @@ -94,19 +108,23 @@ interface IndexService { ): IndexGetResponse = get(params.toBuilder().indexId(indexId).build(), requestOptions) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get(indexId: String, params: IndexGetParams = IndexGetParams.none()): IndexGetResponse = get(indexId, params, RequestOptions.none()) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get( params: IndexGetParams, requestOptions: RequestOptions = RequestOptions.none(), ): IndexGetResponse /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get(params: IndexGetParams): IndexGetResponse = get(params, RequestOptions.none()) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun get(indexId: String, requestOptions: RequestOptions): IndexGetResponse = get(indexId, IndexGetParams.none(), requestOptions) @@ -114,9 +132,11 @@ interface IndexService { * Trigger a sync and export for an existing index, re-parsing changed files and exporting * updated chunks. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync(indexId: String): IndexSyncResponse = sync(indexId, IndexSyncParams.none()) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync( indexId: String, params: IndexSyncParams = IndexSyncParams.none(), @@ -124,19 +144,23 @@ interface IndexService { ): IndexSyncResponse = sync(params.toBuilder().indexId(indexId).build(), requestOptions) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync(indexId: String, params: IndexSyncParams = IndexSyncParams.none()): IndexSyncResponse = sync(indexId, params, RequestOptions.none()) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync( params: IndexSyncParams, requestOptions: RequestOptions = RequestOptions.none(), ): IndexSyncResponse /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync(params: IndexSyncParams): IndexSyncResponse = sync(params, RequestOptions.none()) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") fun sync(indexId: String, requestOptions: RequestOptions): IndexSyncResponse = sync(indexId, IndexSyncParams.none(), requestOptions) @@ -154,11 +178,13 @@ interface IndexService { * Returns a raw HTTP response for `post /api/v1/indexes`, but is otherwise the same as * [IndexService.create]. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun create(params: IndexCreateParams): HttpResponseFor = create(params, RequestOptions.none()) /** @see create */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun create( params: IndexCreateParams, @@ -169,9 +195,12 @@ interface IndexService { * Returns a raw HTTP response for `get /api/v1/indexes`, but is otherwise the same as * [IndexService.list]. */ - @MustBeClosed fun list(): HttpResponseFor = list(IndexListParams.none()) + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") + @MustBeClosed + fun list(): HttpResponseFor = list(IndexListParams.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun list( params: IndexListParams = IndexListParams.none(), @@ -179,11 +208,13 @@ interface IndexService { ): HttpResponseFor /** @see list */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun list(params: IndexListParams = IndexListParams.none()): HttpResponseFor = list(params, RequestOptions.none()) /** @see list */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(IndexListParams.none(), requestOptions) @@ -192,10 +223,12 @@ interface IndexService { * Returns a raw HTTP response for `delete /api/v1/indexes/{index_id}`, but is otherwise the * same as [IndexService.delete]. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun delete(indexId: String): HttpResponse = delete(indexId, IndexDeleteParams.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun delete( indexId: String, @@ -204,6 +237,7 @@ interface IndexService { ): HttpResponse = delete(params.toBuilder().indexId(indexId).build(), requestOptions) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun delete( indexId: String, @@ -211,6 +245,7 @@ interface IndexService { ): HttpResponse = delete(indexId, params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun delete( params: IndexDeleteParams, @@ -218,10 +253,12 @@ interface IndexService { ): HttpResponse /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun delete(params: IndexDeleteParams): HttpResponse = delete(params, RequestOptions.none()) /** @see delete */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun delete(indexId: String, requestOptions: RequestOptions): HttpResponse = delete(indexId, IndexDeleteParams.none(), requestOptions) @@ -230,11 +267,13 @@ interface IndexService { * Returns a raw HTTP response for `get /api/v1/indexes/{index_id}`, but is otherwise the * same as [IndexService.get]. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun get(indexId: String): HttpResponseFor = get(indexId, IndexGetParams.none()) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun get( indexId: String, @@ -244,6 +283,7 @@ interface IndexService { get(params.toBuilder().indexId(indexId).build(), requestOptions) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun get( indexId: String, @@ -251,6 +291,7 @@ interface IndexService { ): HttpResponseFor = get(indexId, params, RequestOptions.none()) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun get( params: IndexGetParams, @@ -258,11 +299,13 @@ interface IndexService { ): HttpResponseFor /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun get(params: IndexGetParams): HttpResponseFor = get(params, RequestOptions.none()) /** @see get */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun get( indexId: String, @@ -273,11 +316,13 @@ interface IndexService { * Returns a raw HTTP response for `post /api/v1/indexes/{index_id}/sync`, but is otherwise * the same as [IndexService.sync]. */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun sync(indexId: String): HttpResponseFor = sync(indexId, IndexSyncParams.none()) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun sync( indexId: String, @@ -287,6 +332,7 @@ interface IndexService { sync(params.toBuilder().indexId(indexId).build(), requestOptions) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun sync( indexId: String, @@ -294,6 +340,7 @@ interface IndexService { ): HttpResponseFor = sync(indexId, params, RequestOptions.none()) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun sync( params: IndexSyncParams, @@ -301,11 +348,13 @@ interface IndexService { ): HttpResponseFor /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun sync(params: IndexSyncParams): HttpResponseFor = sync(params, RequestOptions.none()) /** @see sync */ + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") @MustBeClosed fun sync( indexId: String, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/IndexServiceImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/IndexServiceImpl.kt index 84d16f0..2cc75bf 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/IndexServiceImpl.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/IndexServiceImpl.kt @@ -42,6 +42,7 @@ class IndexServiceImpl internal constructor(private val clientOptions: ClientOpt override fun withOptions(modifier: Consumer): IndexService = IndexServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun create( params: IndexCreateParams, requestOptions: RequestOptions, @@ -49,19 +50,23 @@ class IndexServiceImpl internal constructor(private val clientOptions: ClientOpt // post /api/v1/indexes withRawResponse().create(params, requestOptions).parse() + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun list(params: IndexListParams, requestOptions: RequestOptions): IndexListPage = // get /api/v1/indexes withRawResponse().list(params, requestOptions).parse() + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun delete(params: IndexDeleteParams, requestOptions: RequestOptions) { // delete /api/v1/indexes/{index_id} withRawResponse().delete(params, requestOptions) } + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun get(params: IndexGetParams, requestOptions: RequestOptions): IndexGetResponse = // get /api/v1/indexes/{index_id} withRawResponse().get(params, requestOptions).parse() + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun sync(params: IndexSyncParams, requestOptions: RequestOptions): IndexSyncResponse = // post /api/v1/indexes/{index_id}/sync withRawResponse().sync(params, requestOptions).parse() @@ -82,6 +87,7 @@ class IndexServiceImpl internal constructor(private val clientOptions: ClientOpt private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun create( params: IndexCreateParams, requestOptions: RequestOptions, @@ -110,6 +116,7 @@ class IndexServiceImpl internal constructor(private val clientOptions: ClientOpt private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun list( params: IndexListParams, requestOptions: RequestOptions, @@ -143,6 +150,7 @@ class IndexServiceImpl internal constructor(private val clientOptions: ClientOpt private val deleteHandler: Handler = emptyHandler() + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun delete( params: IndexDeleteParams, requestOptions: RequestOptions, @@ -168,6 +176,7 @@ class IndexServiceImpl internal constructor(private val clientOptions: ClientOpt private val getHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun get( params: IndexGetParams, requestOptions: RequestOptions, @@ -198,6 +207,7 @@ class IndexServiceImpl internal constructor(private val clientOptions: ClientOpt private val syncHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level indexes resource instead") override fun sync( params: IndexSyncParams, requestOptions: RequestOptions, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/RetrievalService.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/RetrievalService.kt index 4b1b97e..b1d43bb 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/RetrievalService.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/RetrievalService.kt @@ -34,38 +34,46 @@ interface RetrievalService { * Retrieve relevant chunks via hybrid search (vector + full-text), with filtering on built-in * or user-defined metadata. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun retrieve(params: RetrievalRetrieveParams): RetrievalRetrieveResponse = retrieve(params, RequestOptions.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun retrieve( params: RetrievalRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): RetrievalRetrieveResponse /** Search for files by name. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun find(params: RetrievalFindParams): RetrievalFindPage = find(params, RequestOptions.none()) /** @see find */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun find( params: RetrievalFindParams, requestOptions: RequestOptions = RequestOptions.none(), ): RetrievalFindPage /** Grep within a file's parsed content using a regex pattern. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun grep(params: RetrievalGrepParams): RetrievalGrepPage = grep(params, RequestOptions.none()) /** @see grep */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun grep( params: RetrievalGrepParams, requestOptions: RequestOptions = RequestOptions.none(), ): RetrievalGrepPage /** Read the parsed text content of a specific file. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun read(params: RetrievalReadParams): RetrievalReadResponse = read(params, RequestOptions.none()) /** @see read */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") fun read( params: RetrievalReadParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -85,11 +93,13 @@ interface RetrievalService { * Returns a raw HTTP response for `post /api/v1/retrieval/retrieve`, but is otherwise the * same as [RetrievalService.retrieve]. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") @MustBeClosed fun retrieve(params: RetrievalRetrieveParams): HttpResponseFor = retrieve(params, RequestOptions.none()) /** @see retrieve */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") @MustBeClosed fun retrieve( params: RetrievalRetrieveParams, @@ -100,11 +110,13 @@ interface RetrievalService { * Returns a raw HTTP response for `post /api/v1/retrieval/files/find`, but is otherwise the * same as [RetrievalService.find]. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") @MustBeClosed fun find(params: RetrievalFindParams): HttpResponseFor = find(params, RequestOptions.none()) /** @see find */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") @MustBeClosed fun find( params: RetrievalFindParams, @@ -115,11 +127,13 @@ interface RetrievalService { * Returns a raw HTTP response for `post /api/v1/retrieval/files/grep`, but is otherwise the * same as [RetrievalService.grep]. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") @MustBeClosed fun grep(params: RetrievalGrepParams): HttpResponseFor = grep(params, RequestOptions.none()) /** @see grep */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") @MustBeClosed fun grep( params: RetrievalGrepParams, @@ -130,11 +144,13 @@ interface RetrievalService { * Returns a raw HTTP response for `post /api/v1/retrieval/files/read`, but is otherwise the * same as [RetrievalService.read]. */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") @MustBeClosed fun read(params: RetrievalReadParams): HttpResponseFor = read(params, RequestOptions.none()) /** @see read */ + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") @MustBeClosed fun read( params: RetrievalReadParams, diff --git a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/RetrievalServiceImpl.kt b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/RetrievalServiceImpl.kt index 1f49a4e..4933b80 100644 --- a/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/RetrievalServiceImpl.kt +++ b/llama-cloud-core/src/main/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/RetrievalServiceImpl.kt @@ -39,6 +39,7 @@ class RetrievalServiceImpl internal constructor(private val clientOptions: Clien override fun withOptions(modifier: Consumer): RetrievalService = RetrievalServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun retrieve( params: RetrievalRetrieveParams, requestOptions: RequestOptions, @@ -46,6 +47,7 @@ class RetrievalServiceImpl internal constructor(private val clientOptions: Clien // post /api/v1/retrieval/retrieve withRawResponse().retrieve(params, requestOptions).parse() + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun find( params: RetrievalFindParams, requestOptions: RequestOptions, @@ -53,6 +55,7 @@ class RetrievalServiceImpl internal constructor(private val clientOptions: Clien // post /api/v1/retrieval/files/find withRawResponse().find(params, requestOptions).parse() + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun grep( params: RetrievalGrepParams, requestOptions: RequestOptions, @@ -60,6 +63,7 @@ class RetrievalServiceImpl internal constructor(private val clientOptions: Clien // post /api/v1/retrieval/files/grep withRawResponse().grep(params, requestOptions).parse() + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun read( params: RetrievalReadParams, requestOptions: RequestOptions, @@ -83,6 +87,7 @@ class RetrievalServiceImpl internal constructor(private val clientOptions: Clien private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun retrieve( params: RetrievalRetrieveParams, requestOptions: RequestOptions, @@ -111,6 +116,7 @@ class RetrievalServiceImpl internal constructor(private val clientOptions: Clien private val findHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun find( params: RetrievalFindParams, requestOptions: RequestOptions, @@ -146,6 +152,7 @@ class RetrievalServiceImpl internal constructor(private val clientOptions: Clien private val grepHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun grep( params: RetrievalGrepParams, requestOptions: RequestOptions, @@ -181,6 +188,7 @@ class RetrievalServiceImpl internal constructor(private val clientOptions: Clien private val readHandler: Handler = jsonHandler(clientOptions.jsonMapper) + @Deprecated("Moved out of beta. Use the top-level retrieval resource instead") override fun read( params: RetrievalReadParams, requestOptions: RequestOptions, diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCancelParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCancelParamsTest.kt new file mode 100644 index 0000000..5f0ab64 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCancelParamsTest.kt @@ -0,0 +1,57 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VerifyCancelParamsTest { + + @Test + fun create() { + VerifyCancelParams.builder() + .jobId("job_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + } + + @Test + fun pathParams() { + val params = VerifyCancelParams.builder().jobId("job_id").build() + + assertThat(params._pathParam(0)).isEqualTo("job_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + VerifyCancelParams.builder() + .jobId("job_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = VerifyCancelParams.builder().jobId("job_id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCancelResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCancelResponseTest.kt new file mode 100644 index 0000000..c955324 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCancelResponseTest.kt @@ -0,0 +1,315 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VerifyCancelResponseTest { + + @Test + fun create() { + val verifyCancelResponse = + VerifyCancelResponse.builder() + .id("id") + .configuration( + VerifyCancelResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyCancelResponse.Configuration.Tier.AGENTIC) + .build() + ) + .documentInputType(VerifyCancelResponse.DocumentInputType.FILE_ID) + .fileInput("file_input") + .projectId("project_id") + .status(VerifyCancelResponse.Status.CANCELLED) + .userId("user_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .errorMessage("error_message") + .result( + VerifyCancelResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyCancelResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyCancelResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyCancelResponse.Result.CompositeScores.AiGenerated + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyCancelResponse.Result.CompositeScores.DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyCancelResponse.Result.CompositeScores.DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyCancelResponse.Result.CompositeScores.KnownFraud.builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyCancelResponse.Result.CompositeScores.ManuallyEdited + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyCancelResponse.Result.CompositeScores.Recapture.builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyCancelResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyCancelResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + .transactionId("transaction_id") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + assertThat(verifyCancelResponse.id()).isEqualTo("id") + assertThat(verifyCancelResponse.configuration()) + .isEqualTo( + VerifyCancelResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyCancelResponse.Configuration.Tier.AGENTIC) + .build() + ) + assertThat(verifyCancelResponse.documentInputType()) + .isEqualTo(VerifyCancelResponse.DocumentInputType.FILE_ID) + assertThat(verifyCancelResponse.fileInput()).isEqualTo("file_input") + assertThat(verifyCancelResponse.projectId()).isEqualTo("project_id") + assertThat(verifyCancelResponse.status()).isEqualTo(VerifyCancelResponse.Status.CANCELLED) + assertThat(verifyCancelResponse.userId()).isEqualTo("user_id") + assertThat(verifyCancelResponse.createdAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(verifyCancelResponse.errorMessage()).contains("error_message") + assertThat(verifyCancelResponse.result()) + .contains( + VerifyCancelResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyCancelResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyCancelResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyCancelResponse.Result.CompositeScores.AiGenerated.builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyCancelResponse.Result.CompositeScores.DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyCancelResponse.Result.CompositeScores.DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyCancelResponse.Result.CompositeScores.KnownFraud.builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyCancelResponse.Result.CompositeScores.ManuallyEdited.builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyCancelResponse.Result.CompositeScores.Recapture.builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyCancelResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyCancelResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + assertThat(verifyCancelResponse.transactionId()).contains("transaction_id") + assertThat(verifyCancelResponse.updatedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val verifyCancelResponse = + VerifyCancelResponse.builder() + .id("id") + .configuration( + VerifyCancelResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyCancelResponse.Configuration.Tier.AGENTIC) + .build() + ) + .documentInputType(VerifyCancelResponse.DocumentInputType.FILE_ID) + .fileInput("file_input") + .projectId("project_id") + .status(VerifyCancelResponse.Status.CANCELLED) + .userId("user_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .errorMessage("error_message") + .result( + VerifyCancelResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyCancelResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyCancelResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyCancelResponse.Result.CompositeScores.AiGenerated + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyCancelResponse.Result.CompositeScores.DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyCancelResponse.Result.CompositeScores.DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyCancelResponse.Result.CompositeScores.KnownFraud.builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyCancelResponse.Result.CompositeScores.ManuallyEdited + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyCancelResponse.Result.CompositeScores.Recapture.builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyCancelResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyCancelResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + .transactionId("transaction_id") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + val roundtrippedVerifyCancelResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(verifyCancelResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVerifyCancelResponse).isEqualTo(verifyCancelResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateParamsTest.kt new file mode 100644 index 0000000..367a449 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateParamsTest.kt @@ -0,0 +1,190 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.http.QueryParams +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VerifyCreateParamsTest { + + @Test + fun create() { + VerifyCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .configuration( + VerifyCreateParams.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyCreateParams.Configuration.Tier.AGENTIC) + .build() + ) + .fileId("dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .fileInput("dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .transactionId("tx-unique-idempotency-key") + .addWebhookConfigurationId("whc-...") + .addWebhookConfigurationId("whc-...") + .addWebhookConfiguration( + VerifyCreateParams.WebhookConfiguration.builder() + .addWebhookEvent( + VerifyCreateParams.WebhookConfiguration.WebhookEvent.PARSE_SUCCESS + ) + .addWebhookEvent( + VerifyCreateParams.WebhookConfiguration.WebhookEvent.PARSE_ERROR + ) + .webhookHeaders( + VerifyCreateParams.WebhookConfiguration.WebhookHeaders.builder() + .putAdditionalProperty("Authorization", JsonValue.from("Bearer sk-...")) + .build() + ) + .webhookOutputFormat("json") + .webhookSigningSecret("whsec_...") + .webhookUrl("https://example.com/webhooks/llamacloud") + .build() + ) + .build() + } + + @Test + fun queryParams() { + val params = + VerifyCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .configuration( + VerifyCreateParams.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyCreateParams.Configuration.Tier.AGENTIC) + .build() + ) + .fileId("dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .fileInput("dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .transactionId("tx-unique-idempotency-key") + .addWebhookConfigurationId("whc-...") + .addWebhookConfigurationId("whc-...") + .addWebhookConfiguration( + VerifyCreateParams.WebhookConfiguration.builder() + .addWebhookEvent( + VerifyCreateParams.WebhookConfiguration.WebhookEvent.PARSE_SUCCESS + ) + .addWebhookEvent( + VerifyCreateParams.WebhookConfiguration.WebhookEvent.PARSE_ERROR + ) + .webhookHeaders( + VerifyCreateParams.WebhookConfiguration.WebhookHeaders.builder() + .putAdditionalProperty( + "Authorization", + JsonValue.from("Bearer sk-..."), + ) + .build() + ) + .webhookOutputFormat("json") + .webhookSigningSecret("whsec_...") + .webhookUrl("https://example.com/webhooks/llamacloud") + .build() + ) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = VerifyCreateParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } + + @Test + fun body() { + val params = + VerifyCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .configuration( + VerifyCreateParams.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyCreateParams.Configuration.Tier.AGENTIC) + .build() + ) + .fileId("dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .fileInput("dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .transactionId("tx-unique-idempotency-key") + .addWebhookConfigurationId("whc-...") + .addWebhookConfigurationId("whc-...") + .addWebhookConfiguration( + VerifyCreateParams.WebhookConfiguration.builder() + .addWebhookEvent( + VerifyCreateParams.WebhookConfiguration.WebhookEvent.PARSE_SUCCESS + ) + .addWebhookEvent( + VerifyCreateParams.WebhookConfiguration.WebhookEvent.PARSE_ERROR + ) + .webhookHeaders( + VerifyCreateParams.WebhookConfiguration.WebhookHeaders.builder() + .putAdditionalProperty( + "Authorization", + JsonValue.from("Bearer sk-..."), + ) + .build() + ) + .webhookOutputFormat("json") + .webhookSigningSecret("whsec_...") + .webhookUrl("https://example.com/webhooks/llamacloud") + .build() + ) + .build() + + val body = params._body() + + assertThat(body.configuration()) + .contains( + VerifyCreateParams.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyCreateParams.Configuration.Tier.AGENTIC) + .build() + ) + assertThat(body.fileId()).contains("dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + assertThat(body.fileInput()).contains("dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + assertThat(body.transactionId()).contains("tx-unique-idempotency-key") + assertThat(body.webhookConfigurationIds().getOrNull()).containsExactly("whc-...", "whc-...") + assertThat(body.webhookConfigurations().getOrNull()) + .containsExactly( + VerifyCreateParams.WebhookConfiguration.builder() + .addWebhookEvent( + VerifyCreateParams.WebhookConfiguration.WebhookEvent.PARSE_SUCCESS + ) + .addWebhookEvent( + VerifyCreateParams.WebhookConfiguration.WebhookEvent.PARSE_ERROR + ) + .webhookHeaders( + VerifyCreateParams.WebhookConfiguration.WebhookHeaders.builder() + .putAdditionalProperty("Authorization", JsonValue.from("Bearer sk-...")) + .build() + ) + .webhookOutputFormat("json") + .webhookSigningSecret("whsec_...") + .webhookUrl("https://example.com/webhooks/llamacloud") + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = VerifyCreateParams.builder().build() + + val body = params._body() + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateResponseTest.kt new file mode 100644 index 0000000..5c41bd3 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyCreateResponseTest.kt @@ -0,0 +1,315 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VerifyCreateResponseTest { + + @Test + fun create() { + val verifyCreateResponse = + VerifyCreateResponse.builder() + .id("id") + .configuration( + VerifyCreateResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyCreateResponse.Configuration.Tier.AGENTIC) + .build() + ) + .documentInputType(VerifyCreateResponse.DocumentInputType.FILE_ID) + .fileInput("file_input") + .projectId("project_id") + .status(VerifyCreateResponse.Status.CANCELLED) + .userId("user_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .errorMessage("error_message") + .result( + VerifyCreateResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyCreateResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyCreateResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyCreateResponse.Result.CompositeScores.AiGenerated + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyCreateResponse.Result.CompositeScores.DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyCreateResponse.Result.CompositeScores.DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyCreateResponse.Result.CompositeScores.KnownFraud.builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyCreateResponse.Result.CompositeScores.ManuallyEdited + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyCreateResponse.Result.CompositeScores.Recapture.builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyCreateResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyCreateResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + .transactionId("transaction_id") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + assertThat(verifyCreateResponse.id()).isEqualTo("id") + assertThat(verifyCreateResponse.configuration()) + .isEqualTo( + VerifyCreateResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyCreateResponse.Configuration.Tier.AGENTIC) + .build() + ) + assertThat(verifyCreateResponse.documentInputType()) + .isEqualTo(VerifyCreateResponse.DocumentInputType.FILE_ID) + assertThat(verifyCreateResponse.fileInput()).isEqualTo("file_input") + assertThat(verifyCreateResponse.projectId()).isEqualTo("project_id") + assertThat(verifyCreateResponse.status()).isEqualTo(VerifyCreateResponse.Status.CANCELLED) + assertThat(verifyCreateResponse.userId()).isEqualTo("user_id") + assertThat(verifyCreateResponse.createdAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(verifyCreateResponse.errorMessage()).contains("error_message") + assertThat(verifyCreateResponse.result()) + .contains( + VerifyCreateResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyCreateResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyCreateResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyCreateResponse.Result.CompositeScores.AiGenerated.builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyCreateResponse.Result.CompositeScores.DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyCreateResponse.Result.CompositeScores.DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyCreateResponse.Result.CompositeScores.KnownFraud.builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyCreateResponse.Result.CompositeScores.ManuallyEdited.builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyCreateResponse.Result.CompositeScores.Recapture.builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyCreateResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyCreateResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + assertThat(verifyCreateResponse.transactionId()).contains("transaction_id") + assertThat(verifyCreateResponse.updatedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val verifyCreateResponse = + VerifyCreateResponse.builder() + .id("id") + .configuration( + VerifyCreateResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyCreateResponse.Configuration.Tier.AGENTIC) + .build() + ) + .documentInputType(VerifyCreateResponse.DocumentInputType.FILE_ID) + .fileInput("file_input") + .projectId("project_id") + .status(VerifyCreateResponse.Status.CANCELLED) + .userId("user_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .errorMessage("error_message") + .result( + VerifyCreateResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyCreateResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyCreateResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyCreateResponse.Result.CompositeScores.AiGenerated + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyCreateResponse.Result.CompositeScores.DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyCreateResponse.Result.CompositeScores.DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyCreateResponse.Result.CompositeScores.KnownFraud.builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyCreateResponse.Result.CompositeScores.ManuallyEdited + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyCreateResponse.Result.CompositeScores.Recapture.builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyCreateResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyCreateResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + .transactionId("transaction_id") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + val roundtrippedVerifyCreateResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(verifyCreateResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVerifyCreateResponse).isEqualTo(verifyCreateResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsParamsTest.kt new file mode 100644 index 0000000..bd9a451 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsParamsTest.kt @@ -0,0 +1,57 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VerifyGetDetailsParamsTest { + + @Test + fun create() { + VerifyGetDetailsParams.builder() + .jobId("job_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + } + + @Test + fun pathParams() { + val params = VerifyGetDetailsParams.builder().jobId("job_id").build() + + assertThat(params._pathParam(0)).isEqualTo("job_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + VerifyGetDetailsParams.builder() + .jobId("job_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = VerifyGetDetailsParams.builder().jobId("job_id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsResponseTest.kt new file mode 100644 index 0000000..32ff3ea --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetDetailsResponseTest.kt @@ -0,0 +1,212 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VerifyGetDetailsResponseTest { + + @Test + fun create() { + val verifyGetDetailsResponse = + VerifyGetDetailsResponse.builder() + .jobId("job_id") + .addDegradedTool( + VerifyGetDetailsResponse.DegradedTool.builder() + .tool("tool") + .reason("reason") + .build() + ) + .addEvidence( + VerifyGetDetailsResponse.Evidence.builder() + .code("code") + .detail("detail") + .family("family") + .score(0.0) + .tool("tool") + .data( + VerifyGetDetailsResponse.Evidence.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .hard(true) + .build() + ) + .addHeatmap( + VerifyGetDetailsResponse.Heatmap.builder() + .expiresAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .kind("kind") + .page(0L) + .url("url") + .score(0.0) + .build() + ) + .addPageDimension( + VerifyGetDetailsResponse.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .addRegion( + VerifyGetDetailsResponse.Region.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .detail("detail") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .reviewNote("review_note") + .build() + ) + .subScores( + VerifyGetDetailsResponse.SubScores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .build() + + assertThat(verifyGetDetailsResponse.jobId()).isEqualTo("job_id") + assertThat(verifyGetDetailsResponse.degradedTools().getOrNull()) + .containsExactly( + VerifyGetDetailsResponse.DegradedTool.builder() + .tool("tool") + .reason("reason") + .build() + ) + assertThat(verifyGetDetailsResponse.evidence().getOrNull()) + .containsExactly( + VerifyGetDetailsResponse.Evidence.builder() + .code("code") + .detail("detail") + .family("family") + .score(0.0) + .tool("tool") + .data( + VerifyGetDetailsResponse.Evidence.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .hard(true) + .build() + ) + assertThat(verifyGetDetailsResponse.heatmaps().getOrNull()) + .containsExactly( + VerifyGetDetailsResponse.Heatmap.builder() + .expiresAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .kind("kind") + .page(0L) + .url("url") + .score(0.0) + .build() + ) + assertThat(verifyGetDetailsResponse.pageDimensions().getOrNull()) + .containsExactly( + VerifyGetDetailsResponse.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + assertThat(verifyGetDetailsResponse.regions().getOrNull()) + .containsExactly( + VerifyGetDetailsResponse.Region.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .detail("detail") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .reviewNote("review_note") + .build() + ) + assertThat(verifyGetDetailsResponse.subScores()) + .contains( + VerifyGetDetailsResponse.SubScores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val verifyGetDetailsResponse = + VerifyGetDetailsResponse.builder() + .jobId("job_id") + .addDegradedTool( + VerifyGetDetailsResponse.DegradedTool.builder() + .tool("tool") + .reason("reason") + .build() + ) + .addEvidence( + VerifyGetDetailsResponse.Evidence.builder() + .code("code") + .detail("detail") + .family("family") + .score(0.0) + .tool("tool") + .data( + VerifyGetDetailsResponse.Evidence.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .hard(true) + .build() + ) + .addHeatmap( + VerifyGetDetailsResponse.Heatmap.builder() + .expiresAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .kind("kind") + .page(0L) + .url("url") + .score(0.0) + .build() + ) + .addPageDimension( + VerifyGetDetailsResponse.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .addRegion( + VerifyGetDetailsResponse.Region.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .detail("detail") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .reviewNote("review_note") + .build() + ) + .subScores( + VerifyGetDetailsResponse.SubScores.builder() + .putAdditionalProperty("foo", JsonValue.from(0)) + .build() + ) + .build() + + val roundtrippedVerifyGetDetailsResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(verifyGetDetailsResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVerifyGetDetailsResponse).isEqualTo(verifyGetDetailsResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetParamsTest.kt new file mode 100644 index 0000000..c50be70 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetParamsTest.kt @@ -0,0 +1,60 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VerifyGetParamsTest { + + @Test + fun create() { + VerifyGetParams.builder() + .jobId("job_id") + .addExpand("string") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + } + + @Test + fun pathParams() { + val params = VerifyGetParams.builder().jobId("job_id").build() + + assertThat(params._pathParam(0)).isEqualTo("job_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + VerifyGetParams.builder() + .jobId("job_id") + .addExpand("string") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("expand", "string") + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = VerifyGetParams.builder().jobId("job_id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetResponseTest.kt new file mode 100644 index 0000000..8a637a9 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyGetResponseTest.kt @@ -0,0 +1,311 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VerifyGetResponseTest { + + @Test + fun create() { + val verifyGetResponse = + VerifyGetResponse.builder() + .id("id") + .configuration( + VerifyGetResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyGetResponse.Configuration.Tier.AGENTIC) + .build() + ) + .documentInputType(VerifyGetResponse.DocumentInputType.FILE_ID) + .fileInput("file_input") + .projectId("project_id") + .status(VerifyGetResponse.Status.CANCELLED) + .userId("user_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .errorMessage("error_message") + .result( + VerifyGetResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyGetResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyGetResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyGetResponse.Result.CompositeScores.AiGenerated.builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyGetResponse.Result.CompositeScores.DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyGetResponse.Result.CompositeScores.DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyGetResponse.Result.CompositeScores.KnownFraud.builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyGetResponse.Result.CompositeScores.ManuallyEdited + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyGetResponse.Result.CompositeScores.Recapture.builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyGetResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyGetResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + .transactionId("transaction_id") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + assertThat(verifyGetResponse.id()).isEqualTo("id") + assertThat(verifyGetResponse.configuration()) + .isEqualTo( + VerifyGetResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyGetResponse.Configuration.Tier.AGENTIC) + .build() + ) + assertThat(verifyGetResponse.documentInputType()) + .isEqualTo(VerifyGetResponse.DocumentInputType.FILE_ID) + assertThat(verifyGetResponse.fileInput()).isEqualTo("file_input") + assertThat(verifyGetResponse.projectId()).isEqualTo("project_id") + assertThat(verifyGetResponse.status()).isEqualTo(VerifyGetResponse.Status.CANCELLED) + assertThat(verifyGetResponse.userId()).isEqualTo("user_id") + assertThat(verifyGetResponse.createdAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(verifyGetResponse.errorMessage()).contains("error_message") + assertThat(verifyGetResponse.result()) + .contains( + VerifyGetResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyGetResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyGetResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyGetResponse.Result.CompositeScores.AiGenerated.builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyGetResponse.Result.CompositeScores.DocumentCoherence.builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyGetResponse.Result.CompositeScores.DocumentMetadata.builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyGetResponse.Result.CompositeScores.KnownFraud.builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyGetResponse.Result.CompositeScores.ManuallyEdited.builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyGetResponse.Result.CompositeScores.Recapture.builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyGetResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyGetResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + assertThat(verifyGetResponse.transactionId()).contains("transaction_id") + assertThat(verifyGetResponse.updatedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val verifyGetResponse = + VerifyGetResponse.builder() + .id("id") + .configuration( + VerifyGetResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyGetResponse.Configuration.Tier.AGENTIC) + .build() + ) + .documentInputType(VerifyGetResponse.DocumentInputType.FILE_ID) + .fileInput("file_input") + .projectId("project_id") + .status(VerifyGetResponse.Status.CANCELLED) + .userId("user_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .errorMessage("error_message") + .result( + VerifyGetResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyGetResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyGetResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyGetResponse.Result.CompositeScores.AiGenerated.builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyGetResponse.Result.CompositeScores.DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyGetResponse.Result.CompositeScores.DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyGetResponse.Result.CompositeScores.KnownFraud.builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyGetResponse.Result.CompositeScores.ManuallyEdited + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyGetResponse.Result.CompositeScores.Recapture.builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyGetResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyGetResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + .transactionId("transaction_id") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + val roundtrippedVerifyGetResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(verifyGetResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVerifyGetResponse).isEqualTo(verifyGetResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListPageResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListPageResponseTest.kt new file mode 100644 index 0000000..d294dd9 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListPageResponseTest.kt @@ -0,0 +1,341 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VerifyListPageResponseTest { + + @Test + fun create() { + val verifyListPageResponse = + VerifyListPageResponse.builder() + .addItem( + VerifyListResponse.builder() + .id("id") + .configuration( + VerifyListResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyListResponse.Configuration.Tier.AGENTIC) + .build() + ) + .documentInputType(VerifyListResponse.DocumentInputType.FILE_ID) + .fileInput("file_input") + .projectId("project_id") + .status(VerifyListResponse.Status.CANCELLED) + .userId("user_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .errorMessage("error_message") + .result( + VerifyListResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyListResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyListResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyListResponse.Result.CompositeScores.AiGenerated + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyListResponse.Result.CompositeScores + .DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyListResponse.Result.CompositeScores + .DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyListResponse.Result.CompositeScores.KnownFraud + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyListResponse.Result.CompositeScores.ManuallyEdited + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyListResponse.Result.CompositeScores.Recapture + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyListResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyListResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + .transactionId("transaction_id") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .nextPageToken("next_page_token") + .totalSize(0L) + .build() + + assertThat(verifyListPageResponse.items()) + .containsExactly( + VerifyListResponse.builder() + .id("id") + .configuration( + VerifyListResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyListResponse.Configuration.Tier.AGENTIC) + .build() + ) + .documentInputType(VerifyListResponse.DocumentInputType.FILE_ID) + .fileInput("file_input") + .projectId("project_id") + .status(VerifyListResponse.Status.CANCELLED) + .userId("user_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .errorMessage("error_message") + .result( + VerifyListResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyListResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyListResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyListResponse.Result.CompositeScores.AiGenerated + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyListResponse.Result.CompositeScores.DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyListResponse.Result.CompositeScores.DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyListResponse.Result.CompositeScores.KnownFraud + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyListResponse.Result.CompositeScores.ManuallyEdited + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyListResponse.Result.CompositeScores.Recapture + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyListResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyListResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + .transactionId("transaction_id") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + assertThat(verifyListPageResponse.nextPageToken()).contains("next_page_token") + assertThat(verifyListPageResponse.totalSize()).contains(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val verifyListPageResponse = + VerifyListPageResponse.builder() + .addItem( + VerifyListResponse.builder() + .id("id") + .configuration( + VerifyListResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyListResponse.Configuration.Tier.AGENTIC) + .build() + ) + .documentInputType(VerifyListResponse.DocumentInputType.FILE_ID) + .fileInput("file_input") + .projectId("project_id") + .status(VerifyListResponse.Status.CANCELLED) + .userId("user_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .errorMessage("error_message") + .result( + VerifyListResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyListResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyListResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyListResponse.Result.CompositeScores.AiGenerated + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyListResponse.Result.CompositeScores + .DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyListResponse.Result.CompositeScores + .DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyListResponse.Result.CompositeScores.KnownFraud + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyListResponse.Result.CompositeScores.ManuallyEdited + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyListResponse.Result.CompositeScores.Recapture + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyListResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyListResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + .transactionId("transaction_id") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .nextPageToken("next_page_token") + .totalSize(0L) + .build() + + val roundtrippedVerifyListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(verifyListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVerifyListPageResponse).isEqualTo(verifyListPageResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListParamsTest.kt new file mode 100644 index 0000000..664500d --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListParamsTest.kt @@ -0,0 +1,71 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.http.QueryParams +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VerifyListParamsTest { + + @Test + fun create() { + VerifyListParams.builder() + .createdAtOnOrAfter(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAtOnOrBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addExpand("string") + .addJobId("string") + .addJobId("string") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .pageSize(1L) + .pageToken("page_token") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .status(VerifyListParams.Status.CANCELLED) + .build() + } + + @Test + fun queryParams() { + val params = + VerifyListParams.builder() + .createdAtOnOrAfter(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAtOnOrBefore(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addExpand("string") + .addJobId("string") + .addJobId("string") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .pageSize(1L) + .pageToken("page_token") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .status(VerifyListParams.Status.CANCELLED) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("created_at_on_or_after", "2019-12-27T18:11:19.117Z") + .put("created_at_on_or_before", "2019-12-27T18:11:19.117Z") + .put("expand", "string") + .put("job_ids", "string") + .put("job_ids", "string") + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("page_size", "1") + .put("page_token", "page_token") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("status", "CANCELLED") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = VerifyListParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListResponseTest.kt new file mode 100644 index 0000000..ea57d2f --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/alpha/verify/VerifyListResponseTest.kt @@ -0,0 +1,312 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.alpha.verify + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VerifyListResponseTest { + + @Test + fun create() { + val verifyListResponse = + VerifyListResponse.builder() + .id("id") + .configuration( + VerifyListResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyListResponse.Configuration.Tier.AGENTIC) + .build() + ) + .documentInputType(VerifyListResponse.DocumentInputType.FILE_ID) + .fileInput("file_input") + .projectId("project_id") + .status(VerifyListResponse.Status.CANCELLED) + .userId("user_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .errorMessage("error_message") + .result( + VerifyListResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyListResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyListResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyListResponse.Result.CompositeScores.AiGenerated.builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyListResponse.Result.CompositeScores.DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyListResponse.Result.CompositeScores.DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyListResponse.Result.CompositeScores.KnownFraud.builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyListResponse.Result.CompositeScores.ManuallyEdited + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyListResponse.Result.CompositeScores.Recapture.builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyListResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyListResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + .transactionId("transaction_id") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + assertThat(verifyListResponse.id()).isEqualTo("id") + assertThat(verifyListResponse.configuration()) + .isEqualTo( + VerifyListResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyListResponse.Configuration.Tier.AGENTIC) + .build() + ) + assertThat(verifyListResponse.documentInputType()) + .isEqualTo(VerifyListResponse.DocumentInputType.FILE_ID) + assertThat(verifyListResponse.fileInput()).isEqualTo("file_input") + assertThat(verifyListResponse.projectId()).isEqualTo("project_id") + assertThat(verifyListResponse.status()).isEqualTo(VerifyListResponse.Status.CANCELLED) + assertThat(verifyListResponse.userId()).isEqualTo("user_id") + assertThat(verifyListResponse.createdAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(verifyListResponse.errorMessage()).contains("error_message") + assertThat(verifyListResponse.result()) + .contains( + VerifyListResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyListResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyListResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyListResponse.Result.CompositeScores.AiGenerated.builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyListResponse.Result.CompositeScores.DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyListResponse.Result.CompositeScores.DocumentMetadata.builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyListResponse.Result.CompositeScores.KnownFraud.builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyListResponse.Result.CompositeScores.ManuallyEdited.builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyListResponse.Result.CompositeScores.Recapture.builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyListResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyListResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + assertThat(verifyListResponse.transactionId()).contains("transaction_id") + assertThat(verifyListResponse.updatedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val verifyListResponse = + VerifyListResponse.builder() + .id("id") + .configuration( + VerifyListResponse.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyListResponse.Configuration.Tier.AGENTIC) + .build() + ) + .documentInputType(VerifyListResponse.DocumentInputType.FILE_ID) + .fileInput("file_input") + .projectId("project_id") + .status(VerifyListResponse.Status.CANCELLED) + .userId("user_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .errorMessage("error_message") + .result( + VerifyListResponse.Result.builder() + .detectorVersion("detector_version") + .overallScore(0.0) + .verdict(VerifyListResponse.Result.Verdict.AUTHENTIC) + .compositeScores( + VerifyListResponse.Result.CompositeScores.builder() + .aiGenerated( + VerifyListResponse.Result.CompositeScores.AiGenerated.builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentCoherence( + VerifyListResponse.Result.CompositeScores.DocumentCoherence + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .documentMetadata( + VerifyListResponse.Result.CompositeScores.DocumentMetadata + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .knownFraud( + VerifyListResponse.Result.CompositeScores.KnownFraud.builder() + .applicable(true) + .score(0.0) + .build() + ) + .manuallyEdited( + VerifyListResponse.Result.CompositeScores.ManuallyEdited + .builder() + .applicable(true) + .score(0.0) + .build() + ) + .recapture( + VerifyListResponse.Result.CompositeScores.Recapture.builder() + .applicable(true) + .score(0.0) + .build() + ) + .build() + ) + .confidence(0.0) + .error("error") + .pageCount(1L) + .addPageDimension( + VerifyListResponse.Result.PageDimension.builder() + .height(0L) + .page(0L) + .width(0L) + .build() + ) + .reasoning("reasoning") + .addSuspectRegion( + VerifyListResponse.Result.SuspectRegion.builder() + .bbox(listOf(0L, 0L, 0L, 0L)) + .explanation("explanation") + .kind("kind") + .page(0L) + .score(0.0) + .source("source") + .primary(true) + .review("review") + .build() + ) + .syntheticScore(0.0) + .tamperingScore(0.0) + .build() + ) + .transactionId("transaction_id") + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + val roundtrippedVerifyListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(verifyListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVerifyListResponse).isEqualTo(verifyListResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexGetParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexGetParamsTest.kt index f06c471..11285a6 100644 --- a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexGetParamsTest.kt +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/beta/indexes/IndexGetParamsTest.kt @@ -12,6 +12,7 @@ internal class IndexGetParamsTest { fun create() { IndexGetParams.builder() .indexId("index_id") + .addExpand(IndexGetParams.Expand.SYNC_IN_PROGRESS) .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() @@ -31,6 +32,7 @@ internal class IndexGetParamsTest { val params = IndexGetParams.builder() .indexId("index_id") + .addExpand(IndexGetParams.Expand.SYNC_IN_PROGRESS) .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() @@ -40,6 +42,7 @@ internal class IndexGetParamsTest { assertThat(queryParams) .isEqualTo( QueryParams.builder() + .put("expand", "sync_in_progress") .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatCreateParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatCreateParamsTest.kt new file mode 100644 index 0000000..d71b1cb --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatCreateParamsTest.kt @@ -0,0 +1,77 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.http.QueryParams +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatCreateParamsTest { + + @Test + fun create() { + ChatCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .sharedAccess(ChatCreateParams.SharedAccess.READ_ONLY) + .build() + } + + @Test + fun queryParams() { + val params = + ChatCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .sharedAccess(ChatCreateParams.SharedAccess.READ_ONLY) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = ChatCreateParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } + + @Test + fun body() { + val params = + ChatCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .sharedAccess(ChatCreateParams.SharedAccess.READ_ONLY) + .build() + + val body = params._body() + + assertThat(body.indexIds().getOrNull()).containsExactly("idx-abc123", "idx-def456") + assertThat(body.sharedAccess()).contains(ChatCreateParams.SharedAccess.READ_ONLY) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = ChatCreateParams.builder().build() + + val body = params._body() + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatCreateResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatCreateResponseTest.kt new file mode 100644 index 0000000..92927de --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatCreateResponseTest.kt @@ -0,0 +1,90 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatCreateResponseTest { + + @Test + fun create() { + val chatCreateResponse = + ChatCreateResponse.builder() + .lastUpdatedAt("2026-04-22T12:34:41.342245") + .sessionId("ses-abc123") + .sharedAccess(ChatCreateResponse.SharedAccess.READ_ONLY) + .generatedTitle("What were the main findings in Q3?...") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .jobMetadata( + ChatCreateResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .build() + + assertThat(chatCreateResponse.lastUpdatedAt()).isEqualTo("2026-04-22T12:34:41.342245") + assertThat(chatCreateResponse.sessionId()).isEqualTo("ses-abc123") + assertThat(chatCreateResponse.sharedAccess()) + .isEqualTo(ChatCreateResponse.SharedAccess.READ_ONLY) + assertThat(chatCreateResponse.generatedTitle()) + .contains("What were the main findings in Q3?...") + assertThat(chatCreateResponse.indexIds().getOrNull()) + .containsExactly("idx-abc123", "idx-def456") + assertThat(chatCreateResponse.jobMetadata()) + .contains( + ChatCreateResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val chatCreateResponse = + ChatCreateResponse.builder() + .lastUpdatedAt("2026-04-22T12:34:41.342245") + .sessionId("ses-abc123") + .sharedAccess(ChatCreateResponse.SharedAccess.READ_ONLY) + .generatedTitle("What were the main findings in Q3?...") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .jobMetadata( + ChatCreateResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .build() + + val roundtrippedChatCreateResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(chatCreateResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedChatCreateResponse).isEqualTo(chatCreateResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatDeleteParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatDeleteParamsTest.kt new file mode 100644 index 0000000..98983cc --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatDeleteParamsTest.kt @@ -0,0 +1,57 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatDeleteParamsTest { + + @Test + fun create() { + ChatDeleteParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + } + + @Test + fun pathParams() { + val params = ChatDeleteParams.builder().sessionId("session_id").build() + + assertThat(params._pathParam(0)).isEqualTo("session_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + ChatDeleteParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = ChatDeleteParams.builder().sessionId("session_id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatGetSummaryParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatGetSummaryParamsTest.kt new file mode 100644 index 0000000..00f9c48 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatGetSummaryParamsTest.kt @@ -0,0 +1,57 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatGetSummaryParamsTest { + + @Test + fun create() { + ChatGetSummaryParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + } + + @Test + fun pathParams() { + val params = ChatGetSummaryParams.builder().sessionId("session_id").build() + + assertThat(params._pathParam(0)).isEqualTo("session_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + ChatGetSummaryParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = ChatGetSummaryParams.builder().sessionId("session_id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatGetSummaryResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatGetSummaryResponseTest.kt new file mode 100644 index 0000000..faaf639 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatGetSummaryResponseTest.kt @@ -0,0 +1,90 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatGetSummaryResponseTest { + + @Test + fun create() { + val chatGetSummaryResponse = + ChatGetSummaryResponse.builder() + .lastUpdatedAt("2026-04-22T12:34:41.342245") + .sessionId("ses-abc123") + .sharedAccess(ChatGetSummaryResponse.SharedAccess.READ_ONLY) + .generatedTitle("What were the main findings in Q3?...") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .jobMetadata( + ChatGetSummaryResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .build() + + assertThat(chatGetSummaryResponse.lastUpdatedAt()).isEqualTo("2026-04-22T12:34:41.342245") + assertThat(chatGetSummaryResponse.sessionId()).isEqualTo("ses-abc123") + assertThat(chatGetSummaryResponse.sharedAccess()) + .isEqualTo(ChatGetSummaryResponse.SharedAccess.READ_ONLY) + assertThat(chatGetSummaryResponse.generatedTitle()) + .contains("What were the main findings in Q3?...") + assertThat(chatGetSummaryResponse.indexIds().getOrNull()) + .containsExactly("idx-abc123", "idx-def456") + assertThat(chatGetSummaryResponse.jobMetadata()) + .contains( + ChatGetSummaryResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val chatGetSummaryResponse = + ChatGetSummaryResponse.builder() + .lastUpdatedAt("2026-04-22T12:34:41.342245") + .sessionId("ses-abc123") + .sharedAccess(ChatGetSummaryResponse.SharedAccess.READ_ONLY) + .generatedTitle("What were the main findings in Q3?...") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .jobMetadata( + ChatGetSummaryResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .build() + + val roundtrippedChatGetSummaryResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(chatGetSummaryResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedChatGetSummaryResponse).isEqualTo(chatGetSummaryResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListPageResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListPageResponseTest.kt new file mode 100644 index 0000000..720628b --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListPageResponseTest.kt @@ -0,0 +1,102 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatListPageResponseTest { + + @Test + fun create() { + val chatListPageResponse = + ChatListPageResponse.builder() + .addItem( + ChatListResponse.builder() + .lastUpdatedAt("2026-04-22T12:34:41.342245") + .sessionId("ses-abc123") + .sharedAccess(ChatListResponse.SharedAccess.READ_ONLY) + .generatedTitle("What were the main findings in Q3?...") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .jobMetadata( + ChatListResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .build() + ) + .nextPageToken("next_page_token") + .build() + + assertThat(chatListPageResponse.items()) + .containsExactly( + ChatListResponse.builder() + .lastUpdatedAt("2026-04-22T12:34:41.342245") + .sessionId("ses-abc123") + .sharedAccess(ChatListResponse.SharedAccess.READ_ONLY) + .generatedTitle("What were the main findings in Q3?...") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .jobMetadata( + ChatListResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .build() + ) + assertThat(chatListPageResponse.nextPageToken()).contains("next_page_token") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val chatListPageResponse = + ChatListPageResponse.builder() + .addItem( + ChatListResponse.builder() + .lastUpdatedAt("2026-04-22T12:34:41.342245") + .sessionId("ses-abc123") + .sharedAccess(ChatListResponse.SharedAccess.READ_ONLY) + .generatedTitle("What were the main findings in Q3?...") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .jobMetadata( + ChatListResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .build() + ) + .nextPageToken("next_page_token") + .build() + + val roundtrippedChatListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(chatListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedChatListPageResponse).isEqualTo(chatListPageResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListParamsTest.kt new file mode 100644 index 0000000..c2815be --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListParamsTest.kt @@ -0,0 +1,52 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatListParamsTest { + + @Test + fun create() { + ChatListParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .pageSize(0L) + .pageToken("page_token") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + } + + @Test + fun queryParams() { + val params = + ChatListParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .pageSize(0L) + .pageToken("page_token") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("page_size", "0") + .put("page_token", "page_token") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = ChatListParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListResponseTest.kt new file mode 100644 index 0000000..b264667 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatListResponseTest.kt @@ -0,0 +1,90 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatListResponseTest { + + @Test + fun create() { + val chatListResponse = + ChatListResponse.builder() + .lastUpdatedAt("2026-04-22T12:34:41.342245") + .sessionId("ses-abc123") + .sharedAccess(ChatListResponse.SharedAccess.READ_ONLY) + .generatedTitle("What were the main findings in Q3?...") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .jobMetadata( + ChatListResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .build() + + assertThat(chatListResponse.lastUpdatedAt()).isEqualTo("2026-04-22T12:34:41.342245") + assertThat(chatListResponse.sessionId()).isEqualTo("ses-abc123") + assertThat(chatListResponse.sharedAccess()) + .isEqualTo(ChatListResponse.SharedAccess.READ_ONLY) + assertThat(chatListResponse.generatedTitle()) + .contains("What were the main findings in Q3?...") + assertThat(chatListResponse.indexIds().getOrNull()) + .containsExactly("idx-abc123", "idx-def456") + assertThat(chatListResponse.jobMetadata()) + .contains( + ChatListResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val chatListResponse = + ChatListResponse.builder() + .lastUpdatedAt("2026-04-22T12:34:41.342245") + .sessionId("ses-abc123") + .sharedAccess(ChatListResponse.SharedAccess.READ_ONLY) + .generatedTitle("What were the main findings in Q3?...") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .jobMetadata( + ChatListResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .build() + + val roundtrippedChatListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(chatListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedChatListResponse).isEqualTo(chatListResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatRetrieveParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatRetrieveParamsTest.kt new file mode 100644 index 0000000..8ac87bc --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatRetrieveParamsTest.kt @@ -0,0 +1,57 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatRetrieveParamsTest { + + @Test + fun create() { + ChatRetrieveParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + } + + @Test + fun pathParams() { + val params = ChatRetrieveParams.builder().sessionId("session_id").build() + + assertThat(params._pathParam(0)).isEqualTo("session_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + ChatRetrieveParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = ChatRetrieveParams.builder().sessionId("session_id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatRetrieveResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatRetrieveResponseTest.kt new file mode 100644 index 0000000..e7ce485 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatRetrieveResponseTest.kt @@ -0,0 +1,141 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatRetrieveResponseTest { + + @Test + fun create() { + val chatRetrieveResponse = + ChatRetrieveResponse.builder() + .addEvent( + ChatRetrieveResponse.Event.Stop.builder() + .error("error") + .isError(true) + .usage( + ChatRetrieveResponse.Event.Stop.Usage.builder() + .durationMs(0.0) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .addSkippedIndexId("string") + .type(ChatRetrieveResponse.Event.Stop.Type.STOP) + .build() + ) + .lastUpdatedAt("2026-04-22T12:34:41.342245") + .sessionId("ses-abc123") + .sharedAccess(ChatRetrieveResponse.SharedAccess.READ_ONLY) + .generatedTitle("What were the main findings in Q3?...") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .jobMetadata( + ChatRetrieveResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .build() + + assertThat(chatRetrieveResponse.events()) + .containsExactly( + ChatRetrieveResponse.Event.ofStop( + ChatRetrieveResponse.Event.Stop.builder() + .error("error") + .isError(true) + .usage( + ChatRetrieveResponse.Event.Stop.Usage.builder() + .durationMs(0.0) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .addSkippedIndexId("string") + .type(ChatRetrieveResponse.Event.Stop.Type.STOP) + .build() + ) + ) + assertThat(chatRetrieveResponse.lastUpdatedAt()).isEqualTo("2026-04-22T12:34:41.342245") + assertThat(chatRetrieveResponse.sessionId()).isEqualTo("ses-abc123") + assertThat(chatRetrieveResponse.sharedAccess()) + .isEqualTo(ChatRetrieveResponse.SharedAccess.READ_ONLY) + assertThat(chatRetrieveResponse.generatedTitle()) + .contains("What were the main findings in Q3?...") + assertThat(chatRetrieveResponse.indexIds().getOrNull()) + .containsExactly("idx-abc123", "idx-def456") + assertThat(chatRetrieveResponse.jobMetadata()) + .contains( + ChatRetrieveResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val chatRetrieveResponse = + ChatRetrieveResponse.builder() + .addEvent( + ChatRetrieveResponse.Event.Stop.builder() + .error("error") + .isError(true) + .usage( + ChatRetrieveResponse.Event.Stop.Usage.builder() + .durationMs(0.0) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .addSkippedIndexId("string") + .type(ChatRetrieveResponse.Event.Stop.Type.STOP) + .build() + ) + .lastUpdatedAt("2026-04-22T12:34:41.342245") + .sessionId("ses-abc123") + .sharedAccess(ChatRetrieveResponse.SharedAccess.READ_ONLY) + .generatedTitle("What were the main findings in Q3?...") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .jobMetadata( + ChatRetrieveResponse.JobMetadata.builder() + .durationMs(0.0) + .error("error") + .addExportConfigId("string") + .isError(true) + .totalInputTokens(0L) + .totalOutputTokens(0L) + .turns(0L) + .build() + ) + .build() + + val roundtrippedChatRetrieveResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(chatRetrieveResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedChatRetrieveResponse).isEqualTo(chatRetrieveResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatStreamParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatStreamParamsTest.kt new file mode 100644 index 0000000..fe29295 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatStreamParamsTest.kt @@ -0,0 +1,113 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatStreamParamsTest { + + @Test + fun create() { + ChatStreamParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .prompt("What were the main findings in Q3?") + .requireAllIndexes(true) + .build() + } + + @Test + fun pathParams() { + val params = + ChatStreamParams.builder() + .sessionId("session_id") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .prompt("What were the main findings in Q3?") + .build() + + assertThat(params._pathParam(0)).isEqualTo("session_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + ChatStreamParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .prompt("What were the main findings in Q3?") + .requireAllIndexes(true) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = + ChatStreamParams.builder() + .sessionId("session_id") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .prompt("What were the main findings in Q3?") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } + + @Test + fun body() { + val params = + ChatStreamParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .prompt("What were the main findings in Q3?") + .requireAllIndexes(true) + .build() + + val body = params._body() + + assertThat(body.indexIds()).containsExactly("idx-abc123", "idx-def456") + assertThat(body.prompt()).isEqualTo("What were the main findings in Q3?") + assertThat(body.requireAllIndexes()).contains(true) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + ChatStreamParams.builder() + .sessionId("session_id") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .prompt("What were the main findings in Q3?") + .build() + + val body = params._body() + + assertThat(body.indexIds()).containsExactly("idx-abc123", "idx-def456") + assertThat(body.prompt()).isEqualTo("What were the main findings in Q3?") + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatStreamResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatStreamResponseTest.kt new file mode 100644 index 0000000..e5a67a1 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/chat/ChatStreamResponseTest.kt @@ -0,0 +1,30 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.chat + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatStreamResponseTest { + + @Test + fun create() { + val chatStreamResponse = ChatStreamResponse.builder().build() + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val chatStreamResponse = ChatStreamResponse.builder().build() + + val roundtrippedChatStreamResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(chatStreamResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedChatStreamResponse).isEqualTo(chatStreamResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCancelSyncParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCancelSyncParamsTest.kt new file mode 100644 index 0000000..91f1c5b --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCancelSyncParamsTest.kt @@ -0,0 +1,57 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class IndexCancelSyncParamsTest { + + @Test + fun create() { + IndexCancelSyncParams.builder() + .indexId("index_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + } + + @Test + fun pathParams() { + val params = IndexCancelSyncParams.builder().indexId("index_id").build() + + assertThat(params._pathParam(0)).isEqualTo("index_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + IndexCancelSyncParams.builder() + .indexId("index_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = IndexCancelSyncParams.builder().indexId("index_id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCancelSyncResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCancelSyncResponseTest.kt new file mode 100644 index 0000000..3705dcf --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCancelSyncResponseTest.kt @@ -0,0 +1,30 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class IndexCancelSyncResponseTest { + + @Test + fun create() { + val indexCancelSyncResponse = IndexCancelSyncResponse.builder().build() + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val indexCancelSyncResponse = IndexCancelSyncResponse.builder().build() + + val roundtrippedIndexCancelSyncResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(indexCancelSyncResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedIndexCancelSyncResponse).isEqualTo(indexCancelSyncResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCreateParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCreateParamsTest.kt new file mode 100644 index 0000000..b4b9afd --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCreateParamsTest.kt @@ -0,0 +1,117 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.http.QueryParams +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class IndexCreateParamsTest { + + @Test + fun create() { + IndexCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .sourceDirectoryId("dir-abc123") + .description("description") + .name("name") + .addProduct( + IndexCreateParams.Product.builder() + .productConfigId("cfg-abc123") + .productType("parse") + .build() + ) + .addStoreAttachment("screenshots") + .syncFrequency("manual") + .vectorTarget(IndexCreateParams.VectorTarget.DEFAULT) + .build() + } + + @Test + fun queryParams() { + val params = + IndexCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .sourceDirectoryId("dir-abc123") + .description("description") + .name("name") + .addProduct( + IndexCreateParams.Product.builder() + .productConfigId("cfg-abc123") + .productType("parse") + .build() + ) + .addStoreAttachment("screenshots") + .syncFrequency("manual") + .vectorTarget(IndexCreateParams.VectorTarget.DEFAULT) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = IndexCreateParams.builder().sourceDirectoryId("dir-abc123").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } + + @Test + fun body() { + val params = + IndexCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .sourceDirectoryId("dir-abc123") + .description("description") + .name("name") + .addProduct( + IndexCreateParams.Product.builder() + .productConfigId("cfg-abc123") + .productType("parse") + .build() + ) + .addStoreAttachment("screenshots") + .syncFrequency("manual") + .vectorTarget(IndexCreateParams.VectorTarget.DEFAULT) + .build() + + val body = params._body() + + assertThat(body.sourceDirectoryId()).isEqualTo("dir-abc123") + assertThat(body.description()).contains("description") + assertThat(body.name()).contains("name") + assertThat(body.products().getOrNull()) + .containsExactly( + IndexCreateParams.Product.builder() + .productConfigId("cfg-abc123") + .productType("parse") + .build() + ) + assertThat(body.storeAttachments().getOrNull()).containsExactly("screenshots") + assertThat(body.syncFrequency()).contains("manual") + assertThat(body.vectorTarget()).contains(IndexCreateParams.VectorTarget.DEFAULT) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = IndexCreateParams.builder().sourceDirectoryId("dir-abc123").build() + + val body = params._body() + + assertThat(body.sourceDirectoryId()).isEqualTo("dir-abc123") + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCreateResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCreateResponseTest.kt new file mode 100644 index 0000000..c87d092 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexCreateResponseTest.kt @@ -0,0 +1,96 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class IndexCreateResponseTest { + + @Test + fun create() { + val indexCreateResponse = + IndexCreateResponse.builder() + .id("id") + .exportConfigId("export_config_id") + .name("name") + .outputDirectoryId("output_directory_id") + .projectId("project_id") + .sourceDirectoryId("source_directory_id") + .syncConfigId("sync_config_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .lastExportedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .lastSyncedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .metadata( + IndexCreateResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .syncInProgress(true) + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + assertThat(indexCreateResponse.id()).isEqualTo("id") + assertThat(indexCreateResponse.exportConfigId()).isEqualTo("export_config_id") + assertThat(indexCreateResponse.name()).isEqualTo("name") + assertThat(indexCreateResponse.outputDirectoryId()).isEqualTo("output_directory_id") + assertThat(indexCreateResponse.projectId()).isEqualTo("project_id") + assertThat(indexCreateResponse.sourceDirectoryId()).isEqualTo("source_directory_id") + assertThat(indexCreateResponse.syncConfigId()).isEqualTo("sync_config_id") + assertThat(indexCreateResponse.createdAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(indexCreateResponse.description()).contains("description") + assertThat(indexCreateResponse.lastExportedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(indexCreateResponse.lastSyncedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(indexCreateResponse.metadata()) + .contains( + IndexCreateResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(indexCreateResponse.syncInProgress()).contains(true) + assertThat(indexCreateResponse.updatedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val indexCreateResponse = + IndexCreateResponse.builder() + .id("id") + .exportConfigId("export_config_id") + .name("name") + .outputDirectoryId("output_directory_id") + .projectId("project_id") + .sourceDirectoryId("source_directory_id") + .syncConfigId("sync_config_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .lastExportedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .lastSyncedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .metadata( + IndexCreateResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .syncInProgress(true) + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + val roundtrippedIndexCreateResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(indexCreateResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedIndexCreateResponse).isEqualTo(indexCreateResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexDeleteParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexDeleteParamsTest.kt new file mode 100644 index 0000000..3c2ebc2 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexDeleteParamsTest.kt @@ -0,0 +1,57 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class IndexDeleteParamsTest { + + @Test + fun create() { + IndexDeleteParams.builder() + .indexId("index_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + } + + @Test + fun pathParams() { + val params = IndexDeleteParams.builder().indexId("index_id").build() + + assertThat(params._pathParam(0)).isEqualTo("index_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + IndexDeleteParams.builder() + .indexId("index_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = IndexDeleteParams.builder().indexId("index_id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexGetParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexGetParamsTest.kt new file mode 100644 index 0000000..0eadc8b --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexGetParamsTest.kt @@ -0,0 +1,60 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class IndexGetParamsTest { + + @Test + fun create() { + IndexGetParams.builder() + .indexId("index_id") + .addExpand(IndexGetParams.Expand.SYNC_IN_PROGRESS) + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + } + + @Test + fun pathParams() { + val params = IndexGetParams.builder().indexId("index_id").build() + + assertThat(params._pathParam(0)).isEqualTo("index_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + IndexGetParams.builder() + .indexId("index_id") + .addExpand(IndexGetParams.Expand.SYNC_IN_PROGRESS) + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("expand", "sync_in_progress") + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = IndexGetParams.builder().indexId("index_id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexGetResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexGetResponseTest.kt new file mode 100644 index 0000000..0047ef9 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexGetResponseTest.kt @@ -0,0 +1,96 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class IndexGetResponseTest { + + @Test + fun create() { + val indexGetResponse = + IndexGetResponse.builder() + .id("id") + .exportConfigId("export_config_id") + .name("name") + .outputDirectoryId("output_directory_id") + .projectId("project_id") + .sourceDirectoryId("source_directory_id") + .syncConfigId("sync_config_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .lastExportedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .lastSyncedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .metadata( + IndexGetResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .syncInProgress(true) + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + assertThat(indexGetResponse.id()).isEqualTo("id") + assertThat(indexGetResponse.exportConfigId()).isEqualTo("export_config_id") + assertThat(indexGetResponse.name()).isEqualTo("name") + assertThat(indexGetResponse.outputDirectoryId()).isEqualTo("output_directory_id") + assertThat(indexGetResponse.projectId()).isEqualTo("project_id") + assertThat(indexGetResponse.sourceDirectoryId()).isEqualTo("source_directory_id") + assertThat(indexGetResponse.syncConfigId()).isEqualTo("sync_config_id") + assertThat(indexGetResponse.createdAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(indexGetResponse.description()).contains("description") + assertThat(indexGetResponse.lastExportedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(indexGetResponse.lastSyncedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(indexGetResponse.metadata()) + .contains( + IndexGetResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(indexGetResponse.syncInProgress()).contains(true) + assertThat(indexGetResponse.updatedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val indexGetResponse = + IndexGetResponse.builder() + .id("id") + .exportConfigId("export_config_id") + .name("name") + .outputDirectoryId("output_directory_id") + .projectId("project_id") + .sourceDirectoryId("source_directory_id") + .syncConfigId("sync_config_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .lastExportedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .lastSyncedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .metadata( + IndexGetResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .syncInProgress(true) + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + val roundtrippedIndexGetResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(indexGetResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedIndexGetResponse).isEqualTo(indexGetResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListPageResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListPageResponseTest.kt new file mode 100644 index 0000000..cba3afc --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListPageResponseTest.kt @@ -0,0 +1,110 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class IndexListPageResponseTest { + + @Test + fun create() { + val indexListPageResponse = + IndexListPageResponse.builder() + .addItem( + IndexListResponse.builder() + .id("id") + .exportConfigId("export_config_id") + .name("name") + .outputDirectoryId("output_directory_id") + .projectId("project_id") + .sourceDirectoryId("source_directory_id") + .syncConfigId("sync_config_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .lastExportedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .lastSyncedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .metadata( + IndexListResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .syncInProgress(true) + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .nextPageToken("next_page_token") + .totalSize(0L) + .build() + + assertThat(indexListPageResponse.items()) + .containsExactly( + IndexListResponse.builder() + .id("id") + .exportConfigId("export_config_id") + .name("name") + .outputDirectoryId("output_directory_id") + .projectId("project_id") + .sourceDirectoryId("source_directory_id") + .syncConfigId("sync_config_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .lastExportedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .lastSyncedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .metadata( + IndexListResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .syncInProgress(true) + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + assertThat(indexListPageResponse.nextPageToken()).contains("next_page_token") + assertThat(indexListPageResponse.totalSize()).contains(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val indexListPageResponse = + IndexListPageResponse.builder() + .addItem( + IndexListResponse.builder() + .id("id") + .exportConfigId("export_config_id") + .name("name") + .outputDirectoryId("output_directory_id") + .projectId("project_id") + .sourceDirectoryId("source_directory_id") + .syncConfigId("sync_config_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .lastExportedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .lastSyncedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .metadata( + IndexListResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .syncInProgress(true) + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .nextPageToken("next_page_token") + .totalSize(0L) + .build() + + val roundtrippedIndexListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(indexListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedIndexListPageResponse).isEqualTo(indexListPageResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListParamsTest.kt new file mode 100644 index 0000000..f3646d3 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListParamsTest.kt @@ -0,0 +1,55 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class IndexListParamsTest { + + @Test + fun create() { + IndexListParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .pageSize(0L) + .pageToken("page_token") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .sourceDirectoryId("source_directory_id") + .build() + } + + @Test + fun queryParams() { + val params = + IndexListParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .pageSize(0L) + .pageToken("page_token") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .sourceDirectoryId("source_directory_id") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("page_size", "0") + .put("page_token", "page_token") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("source_directory_id", "source_directory_id") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = IndexListParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListResponseTest.kt new file mode 100644 index 0000000..0545632 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexListResponseTest.kt @@ -0,0 +1,96 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class IndexListResponseTest { + + @Test + fun create() { + val indexListResponse = + IndexListResponse.builder() + .id("id") + .exportConfigId("export_config_id") + .name("name") + .outputDirectoryId("output_directory_id") + .projectId("project_id") + .sourceDirectoryId("source_directory_id") + .syncConfigId("sync_config_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .lastExportedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .lastSyncedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .metadata( + IndexListResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .syncInProgress(true) + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + assertThat(indexListResponse.id()).isEqualTo("id") + assertThat(indexListResponse.exportConfigId()).isEqualTo("export_config_id") + assertThat(indexListResponse.name()).isEqualTo("name") + assertThat(indexListResponse.outputDirectoryId()).isEqualTo("output_directory_id") + assertThat(indexListResponse.projectId()).isEqualTo("project_id") + assertThat(indexListResponse.sourceDirectoryId()).isEqualTo("source_directory_id") + assertThat(indexListResponse.syncConfigId()).isEqualTo("sync_config_id") + assertThat(indexListResponse.createdAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(indexListResponse.description()).contains("description") + assertThat(indexListResponse.lastExportedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(indexListResponse.lastSyncedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(indexListResponse.metadata()) + .contains( + IndexListResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(indexListResponse.syncInProgress()).contains(true) + assertThat(indexListResponse.updatedAt()) + .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val indexListResponse = + IndexListResponse.builder() + .id("id") + .exportConfigId("export_config_id") + .name("name") + .outputDirectoryId("output_directory_id") + .projectId("project_id") + .sourceDirectoryId("source_directory_id") + .syncConfigId("sync_config_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .description("description") + .lastExportedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .lastSyncedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .metadata( + IndexListResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .syncInProgress(true) + .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + + val roundtrippedIndexListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(indexListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedIndexListResponse).isEqualTo(indexListResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexSyncParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexSyncParamsTest.kt new file mode 100644 index 0000000..3ac251e --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexSyncParamsTest.kt @@ -0,0 +1,57 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class IndexSyncParamsTest { + + @Test + fun create() { + IndexSyncParams.builder() + .indexId("index_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + } + + @Test + fun pathParams() { + val params = IndexSyncParams.builder().indexId("index_id").build() + + assertThat(params._pathParam(0)).isEqualTo("index_id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + IndexSyncParams.builder() + .indexId("index_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = IndexSyncParams.builder().indexId("index_id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexSyncResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexSyncResponseTest.kt new file mode 100644 index 0000000..0c78194 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/indexes/IndexSyncResponseTest.kt @@ -0,0 +1,30 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.indexes + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class IndexSyncResponseTest { + + @Test + fun create() { + val indexSyncResponse = IndexSyncResponse.builder().build() + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val indexSyncResponse = IndexSyncResponse.builder().build() + + val roundtrippedIndexSyncResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(indexSyncResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedIndexSyncResponse).isEqualTo(indexSyncResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindPageResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindPageResponseTest.kt new file mode 100644 index 0000000..089ba07 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindPageResponseTest.kt @@ -0,0 +1,51 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RetrievalFindPageResponseTest { + + @Test + fun create() { + val retrievalFindPageResponse = + RetrievalFindPageResponse.builder() + .addItem( + RetrievalFindResponse.builder().fileId("file_id").fileName("file_name").build() + ) + .nextPageToken("next_page_token") + .totalSize(0L) + .build() + + assertThat(retrievalFindPageResponse.items()) + .containsExactly( + RetrievalFindResponse.builder().fileId("file_id").fileName("file_name").build() + ) + assertThat(retrievalFindPageResponse.nextPageToken()).contains("next_page_token") + assertThat(retrievalFindPageResponse.totalSize()).contains(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val retrievalFindPageResponse = + RetrievalFindPageResponse.builder() + .addItem( + RetrievalFindResponse.builder().fileId("file_id").fileName("file_name").build() + ) + .nextPageToken("next_page_token") + .totalSize(0L) + .build() + + val roundtrippedRetrievalFindPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(retrievalFindPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRetrievalFindPageResponse).isEqualTo(retrievalFindPageResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindParamsTest.kt new file mode 100644 index 0000000..48b8cca --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindParamsTest.kt @@ -0,0 +1,87 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RetrievalFindParamsTest { + + @Test + fun create() { + RetrievalFindParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .indexId("idx-abc123") + .fileName("file_name") + .fileNameContains("file_name_contains") + .pageSize(0L) + .pageToken("page_token") + .build() + } + + @Test + fun queryParams() { + val params = + RetrievalFindParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .indexId("idx-abc123") + .fileName("file_name") + .fileNameContains("file_name_contains") + .pageSize(0L) + .pageToken("page_token") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = RetrievalFindParams.builder().indexId("idx-abc123").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } + + @Test + fun body() { + val params = + RetrievalFindParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .indexId("idx-abc123") + .fileName("file_name") + .fileNameContains("file_name_contains") + .pageSize(0L) + .pageToken("page_token") + .build() + + val body = params._body() + + assertThat(body.indexId()).isEqualTo("idx-abc123") + assertThat(body.fileName()).contains("file_name") + assertThat(body.fileNameContains()).contains("file_name_contains") + assertThat(body.pageSize()).contains(0L) + assertThat(body.pageToken()).contains("page_token") + } + + @Test + fun bodyWithoutOptionalFields() { + val params = RetrievalFindParams.builder().indexId("idx-abc123").build() + + val body = params._body() + + assertThat(body.indexId()).isEqualTo("idx-abc123") + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindResponseTest.kt new file mode 100644 index 0000000..45622c2 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalFindResponseTest.kt @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RetrievalFindResponseTest { + + @Test + fun create() { + val retrievalFindResponse = + RetrievalFindResponse.builder().fileId("file_id").fileName("file_name").build() + + assertThat(retrievalFindResponse.fileId()).isEqualTo("file_id") + assertThat(retrievalFindResponse.fileName()).isEqualTo("file_name") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val retrievalFindResponse = + RetrievalFindResponse.builder().fileId("file_id").fileName("file_name").build() + + val roundtrippedRetrievalFindResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(retrievalFindResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRetrievalFindResponse).isEqualTo(retrievalFindResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepPageResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepPageResponseTest.kt new file mode 100644 index 0000000..bea96c8 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepPageResponseTest.kt @@ -0,0 +1,59 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RetrievalGrepPageResponseTest { + + @Test + fun create() { + val retrievalGrepPageResponse = + RetrievalGrepPageResponse.builder() + .addItem( + RetrievalGrepResponse.builder() + .content("content") + .endChar(0L) + .startChar(0L) + .build() + ) + .nextPageToken("next_page_token") + .totalSize(0L) + .build() + + assertThat(retrievalGrepPageResponse.items()) + .containsExactly( + RetrievalGrepResponse.builder().content("content").endChar(0L).startChar(0L).build() + ) + assertThat(retrievalGrepPageResponse.nextPageToken()).contains("next_page_token") + assertThat(retrievalGrepPageResponse.totalSize()).contains(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val retrievalGrepPageResponse = + RetrievalGrepPageResponse.builder() + .addItem( + RetrievalGrepResponse.builder() + .content("content") + .endChar(0L) + .startChar(0L) + .build() + ) + .nextPageToken("next_page_token") + .totalSize(0L) + .build() + + val roundtrippedRetrievalGrepPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(retrievalGrepPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRetrievalGrepPageResponse).isEqualTo(retrievalGrepPageResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepParamsTest.kt new file mode 100644 index 0000000..3d2b732 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepParamsTest.kt @@ -0,0 +1,103 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RetrievalGrepParamsTest { + + @Test + fun create() { + RetrievalGrepParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .fileId("file_id") + .indexId("idx-abc123") + .pattern("revenue|profit") + .contextChars(0L) + .pageSize(0L) + .pageToken("page_token") + .build() + } + + @Test + fun queryParams() { + val params = + RetrievalGrepParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .fileId("file_id") + .indexId("idx-abc123") + .pattern("revenue|profit") + .contextChars(0L) + .pageSize(0L) + .pageToken("page_token") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = + RetrievalGrepParams.builder() + .fileId("file_id") + .indexId("idx-abc123") + .pattern("revenue|profit") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } + + @Test + fun body() { + val params = + RetrievalGrepParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .fileId("file_id") + .indexId("idx-abc123") + .pattern("revenue|profit") + .contextChars(0L) + .pageSize(0L) + .pageToken("page_token") + .build() + + val body = params._body() + + assertThat(body.fileId()).isEqualTo("file_id") + assertThat(body.indexId()).isEqualTo("idx-abc123") + assertThat(body.pattern()).isEqualTo("revenue|profit") + assertThat(body.contextChars()).contains(0L) + assertThat(body.pageSize()).contains(0L) + assertThat(body.pageToken()).contains("page_token") + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + RetrievalGrepParams.builder() + .fileId("file_id") + .indexId("idx-abc123") + .pattern("revenue|profit") + .build() + + val body = params._body() + + assertThat(body.fileId()).isEqualTo("file_id") + assertThat(body.indexId()).isEqualTo("idx-abc123") + assertThat(body.pattern()).isEqualTo("revenue|profit") + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepResponseTest.kt new file mode 100644 index 0000000..c47e72e --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalGrepResponseTest.kt @@ -0,0 +1,36 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RetrievalGrepResponseTest { + + @Test + fun create() { + val retrievalGrepResponse = + RetrievalGrepResponse.builder().content("content").endChar(0L).startChar(0L).build() + + assertThat(retrievalGrepResponse.content()).isEqualTo("content") + assertThat(retrievalGrepResponse.endChar()).isEqualTo(0L) + assertThat(retrievalGrepResponse.startChar()).isEqualTo(0L) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val retrievalGrepResponse = + RetrievalGrepResponse.builder().content("content").endChar(0L).startChar(0L).build() + + val roundtrippedRetrievalGrepResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(retrievalGrepResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRetrievalGrepResponse).isEqualTo(retrievalGrepResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalReadParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalReadParamsTest.kt new file mode 100644 index 0000000..44fa510 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalReadParamsTest.kt @@ -0,0 +1,84 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RetrievalReadParamsTest { + + @Test + fun create() { + RetrievalReadParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .fileId("file_id") + .indexId("idx-abc123") + .maxLength(0L) + .offset(0L) + .build() + } + + @Test + fun queryParams() { + val params = + RetrievalReadParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .fileId("file_id") + .indexId("idx-abc123") + .maxLength(0L) + .offset(0L) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = RetrievalReadParams.builder().fileId("file_id").indexId("idx-abc123").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } + + @Test + fun body() { + val params = + RetrievalReadParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .fileId("file_id") + .indexId("idx-abc123") + .maxLength(0L) + .offset(0L) + .build() + + val body = params._body() + + assertThat(body.fileId()).isEqualTo("file_id") + assertThat(body.indexId()).isEqualTo("idx-abc123") + assertThat(body.maxLength()).contains(0L) + assertThat(body.offset()).contains(0L) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = RetrievalReadParams.builder().fileId("file_id").indexId("idx-abc123").build() + + val body = params._body() + + assertThat(body.fileId()).isEqualTo("file_id") + assertThat(body.indexId()).isEqualTo("idx-abc123") + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalReadResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalReadResponseTest.kt new file mode 100644 index 0000000..d0b738c --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalReadResponseTest.kt @@ -0,0 +1,32 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RetrievalReadResponseTest { + + @Test + fun create() { + val retrievalReadResponse = RetrievalReadResponse.builder().content("content").build() + + assertThat(retrievalReadResponse.content()).isEqualTo("content") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val retrievalReadResponse = RetrievalReadResponse.builder().content("content").build() + + val roundtrippedRetrievalReadResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(retrievalReadResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRetrievalReadResponse).isEqualTo(retrievalReadResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalRetrieveParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalRetrieveParamsTest.kt new file mode 100644 index 0000000..cf3945c --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalRetrieveParamsTest.kt @@ -0,0 +1,198 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RetrievalRetrieveParamsTest { + + @Test + fun create() { + RetrievalRetrieveParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .indexId("idx-abc123") + .query("What are the key findings?") + .customFilters( + RetrievalRetrieveParams.CustomFilters.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("operator" to "eq", "value" to "string")), + ) + .build() + ) + .fullTextPipelineWeight(0.0) + .numCandidates(1L) + .rerank(RetrievalRetrieveParams.Rerank.builder().enabled(true).topN(5L).build()) + .scoreThreshold(0.0) + .staticFilters( + RetrievalRetrieveParams.StaticFilters.builder() + .parsedDirectoryFileId( + RetrievalRetrieveParams.StaticFilters.ParsedDirectoryFileId.builder() + .operator( + RetrievalRetrieveParams.StaticFilters.ParsedDirectoryFileId.Operator + .EQ + ) + .value("string") + .build() + ) + .build() + ) + .topK(10L) + .vectorPipelineWeight(0.0) + .build() + } + + @Test + fun queryParams() { + val params = + RetrievalRetrieveParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .indexId("idx-abc123") + .query("What are the key findings?") + .customFilters( + RetrievalRetrieveParams.CustomFilters.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("operator" to "eq", "value" to "string")), + ) + .build() + ) + .fullTextPipelineWeight(0.0) + .numCandidates(1L) + .rerank(RetrievalRetrieveParams.Rerank.builder().enabled(true).topN(5L).build()) + .scoreThreshold(0.0) + .staticFilters( + RetrievalRetrieveParams.StaticFilters.builder() + .parsedDirectoryFileId( + RetrievalRetrieveParams.StaticFilters.ParsedDirectoryFileId.builder() + .operator( + RetrievalRetrieveParams.StaticFilters.ParsedDirectoryFileId + .Operator + .EQ + ) + .value("string") + .build() + ) + .build() + ) + .topK(10L) + .vectorPipelineWeight(0.0) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("organization_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .put("project_id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = + RetrievalRetrieveParams.builder() + .indexId("idx-abc123") + .query("What are the key findings?") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } + + @Test + fun body() { + val params = + RetrievalRetrieveParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .indexId("idx-abc123") + .query("What are the key findings?") + .customFilters( + RetrievalRetrieveParams.CustomFilters.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("operator" to "eq", "value" to "string")), + ) + .build() + ) + .fullTextPipelineWeight(0.0) + .numCandidates(1L) + .rerank(RetrievalRetrieveParams.Rerank.builder().enabled(true).topN(5L).build()) + .scoreThreshold(0.0) + .staticFilters( + RetrievalRetrieveParams.StaticFilters.builder() + .parsedDirectoryFileId( + RetrievalRetrieveParams.StaticFilters.ParsedDirectoryFileId.builder() + .operator( + RetrievalRetrieveParams.StaticFilters.ParsedDirectoryFileId + .Operator + .EQ + ) + .value("string") + .build() + ) + .build() + ) + .topK(10L) + .vectorPipelineWeight(0.0) + .build() + + val body = params._body() + + assertThat(body.indexId()).isEqualTo("idx-abc123") + assertThat(body.query()).isEqualTo("What are the key findings?") + assertThat(body.customFilters()) + .contains( + RetrievalRetrieveParams.CustomFilters.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("operator" to "eq", "value" to "string")), + ) + .build() + ) + assertThat(body.fullTextPipelineWeight()).contains(0.0) + assertThat(body.numCandidates()).contains(1L) + assertThat(body.rerank()) + .contains(RetrievalRetrieveParams.Rerank.builder().enabled(true).topN(5L).build()) + assertThat(body.scoreThreshold()).contains(0.0) + assertThat(body.staticFilters()) + .contains( + RetrievalRetrieveParams.StaticFilters.builder() + .parsedDirectoryFileId( + RetrievalRetrieveParams.StaticFilters.ParsedDirectoryFileId.builder() + .operator( + RetrievalRetrieveParams.StaticFilters.ParsedDirectoryFileId.Operator + .EQ + ) + .value("string") + .build() + ) + .build() + ) + assertThat(body.topK()).contains(10L) + assertThat(body.vectorPipelineWeight()).contains(0.0) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + RetrievalRetrieveParams.builder() + .indexId("idx-abc123") + .query("What are the key findings?") + .build() + + val body = params._body() + + assertThat(body.indexId()).isEqualTo("idx-abc123") + assertThat(body.query()).isEqualTo("What are the key findings?") + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalRetrieveResponseTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalRetrieveResponseTest.kt new file mode 100644 index 0000000..b0c6bab --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/models/retrieval/RetrievalRetrieveResponseTest.kt @@ -0,0 +1,129 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.models.retrieval + +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RetrievalRetrieveResponseTest { + + @Test + fun create() { + val retrievalRetrieveResponse = + RetrievalRetrieveResponse.builder() + .addResult( + RetrievalRetrieveResponse.Result.builder() + .content("content") + .metadata( + RetrievalRetrieveResponse.Result.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .rerankScore(0.0) + .score(0.0) + .staticFields( + RetrievalRetrieveResponse.Result.StaticFields.builder() + .addAttachment( + RetrievalRetrieveResponse.Result.StaticFields.Attachment + .builder() + .attachmentName("attachment_name") + .sourceId("source_id") + .type("type") + .build() + ) + .chunkEndChar(0L) + .chunkIndex(0L) + .chunkStartChar(0L) + .chunkTokenCount(0L) + .pageRangeEnd(0L) + .pageRangeStart(0L) + .parsedDirectoryFileId("parsed_directory_file_id") + .build() + ) + .build() + ) + .build() + + assertThat(retrievalRetrieveResponse.results()) + .containsExactly( + RetrievalRetrieveResponse.Result.builder() + .content("content") + .metadata( + RetrievalRetrieveResponse.Result.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .rerankScore(0.0) + .score(0.0) + .staticFields( + RetrievalRetrieveResponse.Result.StaticFields.builder() + .addAttachment( + RetrievalRetrieveResponse.Result.StaticFields.Attachment.builder() + .attachmentName("attachment_name") + .sourceId("source_id") + .type("type") + .build() + ) + .chunkEndChar(0L) + .chunkIndex(0L) + .chunkStartChar(0L) + .chunkTokenCount(0L) + .pageRangeEnd(0L) + .pageRangeStart(0L) + .parsedDirectoryFileId("parsed_directory_file_id") + .build() + ) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val retrievalRetrieveResponse = + RetrievalRetrieveResponse.builder() + .addResult( + RetrievalRetrieveResponse.Result.builder() + .content("content") + .metadata( + RetrievalRetrieveResponse.Result.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .rerankScore(0.0) + .score(0.0) + .staticFields( + RetrievalRetrieveResponse.Result.StaticFields.builder() + .addAttachment( + RetrievalRetrieveResponse.Result.StaticFields.Attachment + .builder() + .attachmentName("attachment_name") + .sourceId("source_id") + .type("type") + .build() + ) + .chunkEndChar(0L) + .chunkIndex(0L) + .chunkStartChar(0L) + .chunkTokenCount(0L) + .pageRangeEnd(0L) + .pageRangeStart(0L) + .parsedDirectoryFileId("parsed_directory_file_id") + .build() + ) + .build() + ) + .build() + + val roundtrippedRetrievalRetrieveResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(retrievalRetrieveResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRetrievalRetrieveResponse).isEqualTo(retrievalRetrieveResponse) + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/ErrorHandlingTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/ErrorHandlingTest.kt index 5d58345..09ce73a 100644 --- a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/ErrorHandlingTest.kt +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/ErrorHandlingTest.kt @@ -59,7 +59,7 @@ internal class ErrorHandlingTest { @Test fun indexesList400() { - val indexService = client.beta().indexes() + val indexService = client.indexes() stubFor( get(anyUrl()) .willReturn( @@ -76,7 +76,7 @@ internal class ErrorHandlingTest { @Test fun indexesList400WithRawResponse() { - val indexService = client.beta().indexes().withRawResponse() + val indexService = client.indexes().withRawResponse() stubFor( get(anyUrl()) .willReturn( @@ -93,7 +93,7 @@ internal class ErrorHandlingTest { @Test fun indexesList401() { - val indexService = client.beta().indexes() + val indexService = client.indexes() stubFor( get(anyUrl()) .willReturn( @@ -110,7 +110,7 @@ internal class ErrorHandlingTest { @Test fun indexesList401WithRawResponse() { - val indexService = client.beta().indexes().withRawResponse() + val indexService = client.indexes().withRawResponse() stubFor( get(anyUrl()) .willReturn( @@ -127,7 +127,7 @@ internal class ErrorHandlingTest { @Test fun indexesList403() { - val indexService = client.beta().indexes() + val indexService = client.indexes() stubFor( get(anyUrl()) .willReturn( @@ -144,7 +144,7 @@ internal class ErrorHandlingTest { @Test fun indexesList403WithRawResponse() { - val indexService = client.beta().indexes().withRawResponse() + val indexService = client.indexes().withRawResponse() stubFor( get(anyUrl()) .willReturn( @@ -161,7 +161,7 @@ internal class ErrorHandlingTest { @Test fun indexesList404() { - val indexService = client.beta().indexes() + val indexService = client.indexes() stubFor( get(anyUrl()) .willReturn( @@ -178,7 +178,7 @@ internal class ErrorHandlingTest { @Test fun indexesList404WithRawResponse() { - val indexService = client.beta().indexes().withRawResponse() + val indexService = client.indexes().withRawResponse() stubFor( get(anyUrl()) .willReturn( @@ -195,7 +195,7 @@ internal class ErrorHandlingTest { @Test fun indexesList422() { - val indexService = client.beta().indexes() + val indexService = client.indexes() stubFor( get(anyUrl()) .willReturn( @@ -212,7 +212,7 @@ internal class ErrorHandlingTest { @Test fun indexesList422WithRawResponse() { - val indexService = client.beta().indexes().withRawResponse() + val indexService = client.indexes().withRawResponse() stubFor( get(anyUrl()) .willReturn( @@ -229,7 +229,7 @@ internal class ErrorHandlingTest { @Test fun indexesList429() { - val indexService = client.beta().indexes() + val indexService = client.indexes() stubFor( get(anyUrl()) .willReturn( @@ -246,7 +246,7 @@ internal class ErrorHandlingTest { @Test fun indexesList429WithRawResponse() { - val indexService = client.beta().indexes().withRawResponse() + val indexService = client.indexes().withRawResponse() stubFor( get(anyUrl()) .willReturn( @@ -263,7 +263,7 @@ internal class ErrorHandlingTest { @Test fun indexesList500() { - val indexService = client.beta().indexes() + val indexService = client.indexes() stubFor( get(anyUrl()) .willReturn( @@ -280,7 +280,7 @@ internal class ErrorHandlingTest { @Test fun indexesList500WithRawResponse() { - val indexService = client.beta().indexes().withRawResponse() + val indexService = client.indexes().withRawResponse() stubFor( get(anyUrl()) .willReturn( @@ -297,7 +297,7 @@ internal class ErrorHandlingTest { @Test fun indexesList999() { - val indexService = client.beta().indexes() + val indexService = client.indexes() stubFor( get(anyUrl()) .willReturn( @@ -314,7 +314,7 @@ internal class ErrorHandlingTest { @Test fun indexesList999WithRawResponse() { - val indexService = client.beta().indexes().withRawResponse() + val indexService = client.indexes().withRawResponse() stubFor( get(anyUrl()) .willReturn( @@ -331,7 +331,7 @@ internal class ErrorHandlingTest { @Test fun indexesListInvalidJsonBody() { - val indexService = client.beta().indexes() + val indexService = client.indexes() stubFor( get(anyUrl()) .willReturn(status(200).withHeader(HEADER_NAME, HEADER_VALUE).withBody(NOT_JSON)) diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/ServiceParamsTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/ServiceParamsTest.kt index cc87661..b475862 100644 --- a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/ServiceParamsTest.kt +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/ServiceParamsTest.kt @@ -5,7 +5,7 @@ package ai.llamaindex.llamacloud.services import ai.llamaindex.llamacloud.client.LlamaCloudClient import ai.llamaindex.llamacloud.client.okhttp.LlamaCloudOkHttpClient import ai.llamaindex.llamacloud.core.JsonValue -import ai.llamaindex.llamacloud.models.beta.indexes.IndexListParams +import ai.llamaindex.llamacloud.models.indexes.IndexListParams import ai.llamaindex.llamacloud.models.parsing.ParsingCreateParams import ai.llamaindex.llamacloud.models.parsing.ParsingLanguages import com.github.tomakehurst.wiremock.client.WireMock.anyUrl @@ -43,7 +43,7 @@ internal class ServiceParamsTest { @Disabled("Mock server tests are disabled") @Test fun list() { - val indexService = client.beta().indexes() + val indexService = client.indexes() stubFor(get(anyUrl()).willReturn(ok("{}"))) indexService.list( diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/ChatServiceAsyncTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/ChatServiceAsyncTest.kt new file mode 100644 index 0000000..e55bc13 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/ChatServiceAsyncTest.kt @@ -0,0 +1,127 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async + +import ai.llamaindex.llamacloud.client.okhttp.LlamaCloudOkHttpClientAsync +import ai.llamaindex.llamacloud.models.chat.ChatCreateParams +import ai.llamaindex.llamacloud.models.chat.ChatDeleteParams +import ai.llamaindex.llamacloud.models.chat.ChatGetSummaryParams +import ai.llamaindex.llamacloud.models.chat.ChatRetrieveParams +import ai.llamaindex.llamacloud.models.chat.ChatStreamParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class ChatServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val chatServiceAsync = client.chat() + + val chatFuture = + chatServiceAsync.create( + ChatCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .sharedAccess(ChatCreateParams.SharedAccess.READ_ONLY) + .build() + ) + + val chat = chatFuture.get() + chat.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val chatServiceAsync = client.chat() + + val chatFuture = + chatServiceAsync.retrieve( + ChatRetrieveParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + val chat = chatFuture.get() + chat.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val chatServiceAsync = client.chat() + + val pageFuture = chatServiceAsync.list() + + val page = pageFuture.get() + page.response().validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun delete() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val chatServiceAsync = client.chat() + + val future = + chatServiceAsync.delete( + ChatDeleteParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + val response = future.get() + } + + @Disabled("Mock server tests are disabled") + @Test + fun getSummary() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val chatServiceAsync = client.chat() + + val responseFuture = + chatServiceAsync.getSummary( + ChatGetSummaryParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + val response = responseFuture.get() + response.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun stream() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val chatServiceAsync = client.chat() + + val responseFuture = + chatServiceAsync.stream( + ChatStreamParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .prompt("What were the main findings in Q3?") + .requireAllIndexes(true) + .build() + ) + + val response = responseFuture.get() + response.validate() + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/IndexServiceAsyncTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/IndexServiceAsyncTest.kt new file mode 100644 index 0000000..9190f67 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/IndexServiceAsyncTest.kt @@ -0,0 +1,133 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async + +import ai.llamaindex.llamacloud.client.okhttp.LlamaCloudOkHttpClientAsync +import ai.llamaindex.llamacloud.models.indexes.IndexCancelSyncParams +import ai.llamaindex.llamacloud.models.indexes.IndexCreateParams +import ai.llamaindex.llamacloud.models.indexes.IndexDeleteParams +import ai.llamaindex.llamacloud.models.indexes.IndexGetParams +import ai.llamaindex.llamacloud.models.indexes.IndexSyncParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class IndexServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val indexServiceAsync = client.indexes() + + val indexFuture = + indexServiceAsync.create( + IndexCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .sourceDirectoryId("dir-abc123") + .description("description") + .name("name") + .addProduct( + IndexCreateParams.Product.builder() + .productConfigId("cfg-abc123") + .productType("parse") + .build() + ) + .addStoreAttachment("screenshots") + .syncFrequency("manual") + .vectorTarget(IndexCreateParams.VectorTarget.DEFAULT) + .build() + ) + + val index = indexFuture.get() + index.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val indexServiceAsync = client.indexes() + + val pageFuture = indexServiceAsync.list() + + val page = pageFuture.get() + page.response().validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun delete() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val indexServiceAsync = client.indexes() + + val future = + indexServiceAsync.delete( + IndexDeleteParams.builder() + .indexId("index_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + val response = future.get() + } + + @Disabled("Mock server tests are disabled") + @Test + fun cancelSync() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val indexServiceAsync = client.indexes() + + val responseFuture = + indexServiceAsync.cancelSync( + IndexCancelSyncParams.builder() + .indexId("index_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + val response = responseFuture.get() + response.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun get() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val indexServiceAsync = client.indexes() + + val indexFuture = + indexServiceAsync.get( + IndexGetParams.builder() + .indexId("index_id") + .addExpand(IndexGetParams.Expand.SYNC_IN_PROGRESS) + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + val index = indexFuture.get() + index.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun sync() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val indexServiceAsync = client.indexes() + + val responseFuture = + indexServiceAsync.sync( + IndexSyncParams.builder() + .indexId("index_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + val response = responseFuture.get() + response.validate() + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/RetrievalServiceAsyncTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/RetrievalServiceAsyncTest.kt new file mode 100644 index 0000000..29e29cc --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/RetrievalServiceAsyncTest.kt @@ -0,0 +1,118 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async + +import ai.llamaindex.llamacloud.client.okhttp.LlamaCloudOkHttpClientAsync +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.models.retrieval.RetrievalFindParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalGrepParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalReadParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalRetrieveParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class RetrievalServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val retrievalServiceAsync = client.retrieval() + + val retrievalFuture = + retrievalServiceAsync.retrieve( + RetrievalRetrieveParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .indexId("idx-abc123") + .query("What are the key findings?") + .customFilters( + RetrievalRetrieveParams.CustomFilters.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("operator" to "eq", "value" to "string")), + ) + .build() + ) + .fullTextPipelineWeight(0.0) + .numCandidates(1L) + .rerank(RetrievalRetrieveParams.Rerank.builder().enabled(true).topN(5L).build()) + .scoreThreshold(0.0) + .staticFilters( + RetrievalRetrieveParams.StaticFilters.builder() + .parsedDirectoryFileId( + RetrievalRetrieveParams.StaticFilters.ParsedDirectoryFileId + .builder() + .operator( + RetrievalRetrieveParams.StaticFilters.ParsedDirectoryFileId + .Operator + .EQ + ) + .value("string") + .build() + ) + .build() + ) + .topK(10L) + .vectorPipelineWeight(0.0) + .build() + ) + + val retrieval = retrievalFuture.get() + retrieval.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun find() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val retrievalServiceAsync = client.retrieval() + + val pageFuture = + retrievalServiceAsync.find(RetrievalFindParams.builder().indexId("idx-abc123").build()) + + val page = pageFuture.get() + page.response().validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun grep() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val retrievalServiceAsync = client.retrieval() + + val pageFuture = + retrievalServiceAsync.grep( + RetrievalGrepParams.builder() + .fileId("file_id") + .indexId("idx-abc123") + .pattern("revenue|profit") + .build() + ) + + val page = pageFuture.get() + page.response().validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun read() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val retrievalServiceAsync = client.retrieval() + + val responseFuture = + retrievalServiceAsync.read( + RetrievalReadParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .fileId("file_id") + .indexId("idx-abc123") + .maxLength(0L) + .offset(0L) + .build() + ) + + val response = responseFuture.get() + response.validate() + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/alpha/VerifyServiceAsyncTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/alpha/VerifyServiceAsyncTest.kt new file mode 100644 index 0000000..aa4cdf9 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/alpha/VerifyServiceAsyncTest.kt @@ -0,0 +1,135 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.async.alpha + +import ai.llamaindex.llamacloud.client.okhttp.LlamaCloudOkHttpClientAsync +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCancelParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCreateParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetDetailsParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class VerifyServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val verifyServiceAsync = client.alpha().verify() + + val verifyFuture = + verifyServiceAsync.create( + VerifyCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .configuration( + VerifyCreateParams.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyCreateParams.Configuration.Tier.AGENTIC) + .build() + ) + .fileId("dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .fileInput("dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .transactionId("tx-unique-idempotency-key") + .addWebhookConfigurationId("whc-...") + .addWebhookConfigurationId("whc-...") + .addWebhookConfiguration( + VerifyCreateParams.WebhookConfiguration.builder() + .addWebhookEvent( + VerifyCreateParams.WebhookConfiguration.WebhookEvent.PARSE_SUCCESS + ) + .addWebhookEvent( + VerifyCreateParams.WebhookConfiguration.WebhookEvent.PARSE_ERROR + ) + .webhookHeaders( + VerifyCreateParams.WebhookConfiguration.WebhookHeaders.builder() + .putAdditionalProperty( + "Authorization", + JsonValue.from("Bearer sk-..."), + ) + .build() + ) + .webhookOutputFormat("json") + .webhookSigningSecret("whsec_...") + .webhookUrl("https://example.com/webhooks/llamacloud") + .build() + ) + .build() + ) + + val verify = verifyFuture.get() + verify.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val verifyServiceAsync = client.alpha().verify() + + val pageFuture = verifyServiceAsync.list() + + val page = pageFuture.get() + page.response().validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun cancel() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val verifyServiceAsync = client.alpha().verify() + + val responseFuture = + verifyServiceAsync.cancel( + VerifyCancelParams.builder() + .jobId("job_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + val response = responseFuture.get() + response.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun get() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val verifyServiceAsync = client.alpha().verify() + + val verifyFuture = + verifyServiceAsync.get( + VerifyGetParams.builder() + .jobId("job_id") + .addExpand("string") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + val verify = verifyFuture.get() + verify.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun getDetails() { + val client = LlamaCloudOkHttpClientAsync.builder().apiKey("My API Key").build() + val verifyServiceAsync = client.alpha().verify() + + val responseFuture = + verifyServiceAsync.getDetails( + VerifyGetDetailsParams.builder() + .jobId("job_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + val response = responseFuture.get() + response.validate() + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/beta/IndexServiceAsyncTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/beta/IndexServiceAsyncTest.kt index c8c3498..69c35d0 100644 --- a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/beta/IndexServiceAsyncTest.kt +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/async/beta/IndexServiceAsyncTest.kt @@ -82,6 +82,7 @@ internal class IndexServiceAsyncTest { indexServiceAsync.get( IndexGetParams.builder() .indexId("index_id") + .addExpand(IndexGetParams.Expand.SYNC_IN_PROGRESS) .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/ChatServiceTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/ChatServiceTest.kt new file mode 100644 index 0000000..eb5a677 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/ChatServiceTest.kt @@ -0,0 +1,119 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking + +import ai.llamaindex.llamacloud.client.okhttp.LlamaCloudOkHttpClient +import ai.llamaindex.llamacloud.models.chat.ChatCreateParams +import ai.llamaindex.llamacloud.models.chat.ChatDeleteParams +import ai.llamaindex.llamacloud.models.chat.ChatGetSummaryParams +import ai.llamaindex.llamacloud.models.chat.ChatRetrieveParams +import ai.llamaindex.llamacloud.models.chat.ChatStreamParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class ChatServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val chatService = client.chat() + + val chat = + chatService.create( + ChatCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .sharedAccess(ChatCreateParams.SharedAccess.READ_ONLY) + .build() + ) + + chat.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val chatService = client.chat() + + val chat = + chatService.retrieve( + ChatRetrieveParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + chat.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val chatService = client.chat() + + val page = chatService.list() + + page.response().validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun delete() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val chatService = client.chat() + + chatService.delete( + ChatDeleteParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Disabled("Mock server tests are disabled") + @Test + fun getSummary() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val chatService = client.chat() + + val response = + chatService.getSummary( + ChatGetSummaryParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + response.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun stream() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val chatService = client.chat() + + val response = + chatService.stream( + ChatStreamParams.builder() + .sessionId("session_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addIndexId("idx-abc123") + .addIndexId("idx-def456") + .prompt("What were the main findings in Q3?") + .requireAllIndexes(true) + .build() + ) + + response.validate() + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/IndexServiceTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/IndexServiceTest.kt new file mode 100644 index 0000000..7b278b6 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/IndexServiceTest.kt @@ -0,0 +1,125 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking + +import ai.llamaindex.llamacloud.client.okhttp.LlamaCloudOkHttpClient +import ai.llamaindex.llamacloud.models.indexes.IndexCancelSyncParams +import ai.llamaindex.llamacloud.models.indexes.IndexCreateParams +import ai.llamaindex.llamacloud.models.indexes.IndexDeleteParams +import ai.llamaindex.llamacloud.models.indexes.IndexGetParams +import ai.llamaindex.llamacloud.models.indexes.IndexSyncParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class IndexServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val indexService = client.indexes() + + val index = + indexService.create( + IndexCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .sourceDirectoryId("dir-abc123") + .description("description") + .name("name") + .addProduct( + IndexCreateParams.Product.builder() + .productConfigId("cfg-abc123") + .productType("parse") + .build() + ) + .addStoreAttachment("screenshots") + .syncFrequency("manual") + .vectorTarget(IndexCreateParams.VectorTarget.DEFAULT) + .build() + ) + + index.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val indexService = client.indexes() + + val page = indexService.list() + + page.response().validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun delete() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val indexService = client.indexes() + + indexService.delete( + IndexDeleteParams.builder() + .indexId("index_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + } + + @Disabled("Mock server tests are disabled") + @Test + fun cancelSync() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val indexService = client.indexes() + + val response = + indexService.cancelSync( + IndexCancelSyncParams.builder() + .indexId("index_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + response.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun get() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val indexService = client.indexes() + + val index = + indexService.get( + IndexGetParams.builder() + .indexId("index_id") + .addExpand(IndexGetParams.Expand.SYNC_IN_PROGRESS) + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + index.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun sync() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val indexService = client.indexes() + + val response = + indexService.sync( + IndexSyncParams.builder() + .indexId("index_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + response.validate() + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/RetrievalServiceTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/RetrievalServiceTest.kt new file mode 100644 index 0000000..9234543 --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/RetrievalServiceTest.kt @@ -0,0 +1,114 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking + +import ai.llamaindex.llamacloud.client.okhttp.LlamaCloudOkHttpClient +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.models.retrieval.RetrievalFindParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalGrepParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalReadParams +import ai.llamaindex.llamacloud.models.retrieval.RetrievalRetrieveParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class RetrievalServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val retrievalService = client.retrieval() + + val retrieval = + retrievalService.retrieve( + RetrievalRetrieveParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .indexId("idx-abc123") + .query("What are the key findings?") + .customFilters( + RetrievalRetrieveParams.CustomFilters.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("operator" to "eq", "value" to "string")), + ) + .build() + ) + .fullTextPipelineWeight(0.0) + .numCandidates(1L) + .rerank(RetrievalRetrieveParams.Rerank.builder().enabled(true).topN(5L).build()) + .scoreThreshold(0.0) + .staticFilters( + RetrievalRetrieveParams.StaticFilters.builder() + .parsedDirectoryFileId( + RetrievalRetrieveParams.StaticFilters.ParsedDirectoryFileId + .builder() + .operator( + RetrievalRetrieveParams.StaticFilters.ParsedDirectoryFileId + .Operator + .EQ + ) + .value("string") + .build() + ) + .build() + ) + .topK(10L) + .vectorPipelineWeight(0.0) + .build() + ) + + retrieval.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun find() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val retrievalService = client.retrieval() + + val page = + retrievalService.find(RetrievalFindParams.builder().indexId("idx-abc123").build()) + + page.response().validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun grep() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val retrievalService = client.retrieval() + + val page = + retrievalService.grep( + RetrievalGrepParams.builder() + .fileId("file_id") + .indexId("idx-abc123") + .pattern("revenue|profit") + .build() + ) + + page.response().validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun read() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val retrievalService = client.retrieval() + + val response = + retrievalService.read( + RetrievalReadParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .fileId("file_id") + .indexId("idx-abc123") + .maxLength(0L) + .offset(0L) + .build() + ) + + response.validate() + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/alpha/VerifyServiceTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/alpha/VerifyServiceTest.kt new file mode 100644 index 0000000..ead954c --- /dev/null +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/alpha/VerifyServiceTest.kt @@ -0,0 +1,130 @@ +// File generated from our OpenAPI spec by Stainless. + +package ai.llamaindex.llamacloud.services.blocking.alpha + +import ai.llamaindex.llamacloud.client.okhttp.LlamaCloudOkHttpClient +import ai.llamaindex.llamacloud.core.JsonValue +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCancelParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyCreateParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetDetailsParams +import ai.llamaindex.llamacloud.models.alpha.verify.VerifyGetParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class VerifyServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val verifyService = client.alpha().verify() + + val verify = + verifyService.create( + VerifyCreateParams.builder() + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .configuration( + VerifyCreateParams.Configuration.builder() + .targetPages("1,3,5-7") + .tier(VerifyCreateParams.Configuration.Tier.AGENTIC) + .build() + ) + .fileId("dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .fileInput("dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .transactionId("tx-unique-idempotency-key") + .addWebhookConfigurationId("whc-...") + .addWebhookConfigurationId("whc-...") + .addWebhookConfiguration( + VerifyCreateParams.WebhookConfiguration.builder() + .addWebhookEvent( + VerifyCreateParams.WebhookConfiguration.WebhookEvent.PARSE_SUCCESS + ) + .addWebhookEvent( + VerifyCreateParams.WebhookConfiguration.WebhookEvent.PARSE_ERROR + ) + .webhookHeaders( + VerifyCreateParams.WebhookConfiguration.WebhookHeaders.builder() + .putAdditionalProperty( + "Authorization", + JsonValue.from("Bearer sk-..."), + ) + .build() + ) + .webhookOutputFormat("json") + .webhookSigningSecret("whsec_...") + .webhookUrl("https://example.com/webhooks/llamacloud") + .build() + ) + .build() + ) + + verify.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val verifyService = client.alpha().verify() + + val page = verifyService.list() + + page.response().validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun cancel() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val verifyService = client.alpha().verify() + + val response = + verifyService.cancel( + VerifyCancelParams.builder() + .jobId("job_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + response.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun get() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val verifyService = client.alpha().verify() + + val verify = + verifyService.get( + VerifyGetParams.builder() + .jobId("job_id") + .addExpand("string") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + verify.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun getDetails() { + val client = LlamaCloudOkHttpClient.builder().apiKey("My API Key").build() + val verifyService = client.alpha().verify() + + val response = + verifyService.getDetails( + VerifyGetDetailsParams.builder() + .jobId("job_id") + .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + response.validate() + } +} diff --git a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/IndexServiceTest.kt b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/IndexServiceTest.kt index 8d02264..58d38ba 100644 --- a/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/IndexServiceTest.kt +++ b/llama-cloud-core/src/test/kotlin/ai/llamaindex/llamacloud/services/blocking/beta/IndexServiceTest.kt @@ -77,6 +77,7 @@ internal class IndexServiceTest { indexService.get( IndexGetParams.builder() .indexId("index_id") + .addExpand(IndexGetParams.Expand.SYNC_IN_PROGRESS) .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() diff --git a/llama-cloud-proguard-test/src/test/kotlin/ai/llamaindex/llamacloud/proguard/ProGuardCompatibilityTest.kt b/llama-cloud-proguard-test/src/test/kotlin/ai/llamaindex/llamacloud/proguard/ProGuardCompatibilityTest.kt index 2bc424a..b424e21 100644 --- a/llama-cloud-proguard-test/src/test/kotlin/ai/llamaindex/llamacloud/proguard/ProGuardCompatibilityTest.kt +++ b/llama-cloud-proguard-test/src/test/kotlin/ai/llamaindex/llamacloud/proguard/ProGuardCompatibilityTest.kt @@ -5,7 +5,7 @@ package ai.llamaindex.llamacloud.proguard import ai.llamaindex.llamacloud.client.okhttp.LlamaCloudOkHttpClient import ai.llamaindex.llamacloud.core.JsonValue import ai.llamaindex.llamacloud.core.jsonMapper -import ai.llamaindex.llamacloud.models.beta.indexes.IndexCreateResponse +import ai.llamaindex.llamacloud.models.indexes.IndexCreateResponse import ai.llamaindex.llamacloud.models.parsing.FailPageMode import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime @@ -66,7 +66,11 @@ internal class ProGuardCompatibilityTest { assertThat(client.dataSources()).isNotNull() assertThat(client.pipelines()).isNotNull() assertThat(client.retrievers()).isNotNull() + assertThat(client.indexes()).isNotNull() + assertThat(client.retrieval()).isNotNull() + assertThat(client.chat()).isNotNull() assertThat(client.beta()).isNotNull() + assertThat(client.alpha()).isNotNull() } @Test