From d91fea2762368d5b52296dddd36e1b9b67ff1bf5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 5 May 2026 18:50:23 +0000 Subject: [PATCH 1/6] feat(client): support proxy authentication --- .../client/okhttp/AnthropicOkHttpClient.kt | 17 ++ .../okhttp/AnthropicOkHttpClientAsync.kt | 17 ++ .../anthropic/client/okhttp/OkHttpClient.kt | 197 ++++++++++++++---- .../anthropic/core/http/ProxyAuthenticator.kt | 59 ++++++ 4 files changed, 244 insertions(+), 46 deletions(-) create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/core/http/ProxyAuthenticator.kt diff --git a/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClient.kt b/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClient.kt index f810c3ed3..1134ca0a5 100644 --- a/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClient.kt +++ b/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClient.kt @@ -13,6 +13,7 @@ import com.anthropic.core.Timeout import com.anthropic.core.http.AsyncStreamResponse import com.anthropic.core.http.Headers import com.anthropic.core.http.HttpClient +import com.anthropic.core.http.ProxyAuthenticator import com.anthropic.core.http.QueryParams import com.fasterxml.jackson.databind.json.JsonMapper import java.net.Proxy @@ -51,6 +52,7 @@ class AnthropicOkHttpClient private constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() private var dispatcherExecutorService: ExecutorService? = null private var proxy: Proxy? = null + private var proxyAuthenticator: ProxyAuthenticator? = null private var maxIdleConnections: Int? = null private var keepAliveDuration: Duration? = null private var sslSocketFactory: SSLSocketFactory? = null @@ -83,6 +85,20 @@ class AnthropicOkHttpClient private constructor() { /** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */ fun proxy(proxy: Optional) = proxy(proxy.getOrNull()) + /** + * Provides credentials when an HTTP proxy responds with `407 Proxy Authentication + * Required`. + */ + fun proxyAuthenticator(proxyAuthenticator: ProxyAuthenticator?) = apply { + this.proxyAuthenticator = proxyAuthenticator + } + + /** + * Alias for calling [Builder.proxyAuthenticator] with `proxyAuthenticator.orElse(null)`. + */ + fun proxyAuthenticator(proxyAuthenticator: Optional) = + proxyAuthenticator(proxyAuthenticator.getOrNull()) + /** * The maximum number of idle connections kept by the underlying OkHttp connection pool. * @@ -445,6 +461,7 @@ class AnthropicOkHttpClient private constructor() { OkHttpClient.builder() .timeout(clientOptions.timeout()) .proxy(proxy) + .proxyAuthenticator(proxyAuthenticator) .maxIdleConnections(maxIdleConnections) .keepAliveDuration(keepAliveDuration) .dispatcherExecutorService(dispatcherExecutorService) diff --git a/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClientAsync.kt b/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClientAsync.kt index cceb51d63..04f58d8bd 100644 --- a/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClientAsync.kt +++ b/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClientAsync.kt @@ -13,6 +13,7 @@ import com.anthropic.core.Timeout import com.anthropic.core.http.AsyncStreamResponse import com.anthropic.core.http.Headers import com.anthropic.core.http.HttpClient +import com.anthropic.core.http.ProxyAuthenticator import com.anthropic.core.http.QueryParams import com.fasterxml.jackson.databind.json.JsonMapper import java.net.Proxy @@ -51,6 +52,7 @@ class AnthropicOkHttpClientAsync private constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() private var dispatcherExecutorService: ExecutorService? = null private var proxy: Proxy? = null + private var proxyAuthenticator: ProxyAuthenticator? = null private var maxIdleConnections: Int? = null private var keepAliveDuration: Duration? = null private var sslSocketFactory: SSLSocketFactory? = null @@ -83,6 +85,20 @@ class AnthropicOkHttpClientAsync private constructor() { /** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */ fun proxy(proxy: Optional) = proxy(proxy.getOrNull()) + /** + * Provides credentials when an HTTP proxy responds with `407 Proxy Authentication + * Required`. + */ + fun proxyAuthenticator(proxyAuthenticator: ProxyAuthenticator?) = apply { + this.proxyAuthenticator = proxyAuthenticator + } + + /** + * Alias for calling [Builder.proxyAuthenticator] with `proxyAuthenticator.orElse(null)`. + */ + fun proxyAuthenticator(proxyAuthenticator: Optional) = + proxyAuthenticator(proxyAuthenticator.getOrNull()) + /** * The maximum number of idle connections kept by the underlying OkHttp connection pool. * @@ -445,6 +461,7 @@ class AnthropicOkHttpClientAsync private constructor() { OkHttpClient.builder() .timeout(clientOptions.timeout()) .proxy(proxy) + .proxyAuthenticator(proxyAuthenticator) .maxIdleConnections(maxIdleConnections) .keepAliveDuration(keepAliveDuration) .dispatcherExecutorService(dispatcherExecutorService) diff --git a/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/OkHttpClient.kt b/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/OkHttpClient.kt index 9716b2933..08a39db0c 100644 --- a/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/OkHttpClient.kt +++ b/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/OkHttpClient.kt @@ -10,9 +10,11 @@ import com.anthropic.core.http.HttpMethod import com.anthropic.core.http.HttpRequest import com.anthropic.core.http.HttpRequestBody import com.anthropic.core.http.HttpResponse +import com.anthropic.core.http.ProxyAuthenticator import com.anthropic.errors.AnthropicIoException import java.io.IOException import java.io.InputStream +import java.io.OutputStream import java.net.Proxy import java.time.Duration import java.util.concurrent.CancellationException @@ -22,10 +24,12 @@ import java.util.concurrent.TimeUnit import javax.net.ssl.HostnameVerifier import javax.net.ssl.SSLSocketFactory import javax.net.ssl.X509TrustManager +import kotlin.jvm.optionals.getOrNull import okhttp3.Call import okhttp3.Callback import okhttp3.ConnectionPool import okhttp3.Dispatcher +import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.MediaType import okhttp3.MediaType.Companion.toMediaType @@ -35,6 +39,8 @@ import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response import okhttp3.logging.HttpLoggingInterceptor import okio.BufferedSink +import okio.buffer +import okio.sink class OkHttpClient internal constructor( @@ -47,7 +53,8 @@ internal constructor( val call = newCall(preparedRequest, requestOptions) return try { - backend.prepareResponse(call.execute().toResponse()) + backend.prepareResponse( + call.execute().toHttpResponse()) } catch (e: IOException) { throw AnthropicIoException("Request failed", e) } finally { @@ -66,7 +73,7 @@ internal constructor( call.enqueue( object : Callback { override fun onResponse(call: Call, response: Response) { - future.complete(backend.prepareResponse(response.toResponse())) + future.complete(backend.prepareResponse(response.toHttpResponse())) } override fun onFailure(call: Call, e: IOException) { @@ -158,15 +165,6 @@ internal constructor( return builder.build() } - /** `OkHttpClient` always requires a request body for some methods. */ - private fun requiresBody(method: HttpMethod): Boolean = - when (method) { - HttpMethod.POST, - HttpMethod.PUT, - HttpMethod.PATCH -> true - else -> false - } - private fun HttpRequest.resolveUrl(): HttpRequest { return toBuilder().baseUrl(toUrl()).build() } @@ -182,41 +180,6 @@ internal constructor( return builder.toString() } - private fun HttpRequestBody.toRequestBody(): RequestBody { - val mediaType = contentType()?.toMediaType() - val length = contentLength() - - return object : RequestBody() { - override fun contentType(): MediaType? = mediaType - - override fun contentLength(): Long = length - - override fun isOneShot(): Boolean = !repeatable() - - override fun writeTo(sink: BufferedSink) = writeTo(sink.outputStream()) - } - } - - private fun Response.toResponse(): HttpResponse { - val headers = headers.toHeaders() - - return object : HttpResponse { - override fun statusCode(): Int = code - - override fun headers(): Headers = headers - - override fun body(): InputStream = body!!.byteStream() - - override fun close() = body!!.close() - } - } - - private fun okhttp3.Headers.toHeaders(): Headers { - val headersBuilder = Headers.builder() - forEach { (name, value) -> headersBuilder.put(name, value) } - return headersBuilder.build() - } - companion object { @JvmStatic fun builder() = Builder() } @@ -226,6 +189,8 @@ internal constructor( private var timeout: Timeout = Timeout.default() private var proxy: Proxy? = null private var backend: Backend? = null + + private var proxyAuthenticator: ProxyAuthenticator? = null private var maxIdleConnections: Int? = null private var keepAliveDuration: Duration? = null private var dispatcherExecutorService: ExecutorService? = null @@ -241,6 +206,10 @@ internal constructor( fun backend(backend: Backend) = apply { this.backend = backend } + fun proxyAuthenticator(proxyAuthenticator: ProxyAuthenticator?) = apply { + this.proxyAuthenticator = proxyAuthenticator + } + /** * Sets the maximum number of idle connections kept by the underlying [ConnectionPool]. * @@ -291,6 +260,19 @@ internal constructor( .callTimeout(timeout.request()) .proxy(proxy) .apply { + proxyAuthenticator?.let { auth -> + proxyAuthenticator { route, response -> + auth + .authenticate( + route?.proxy ?: Proxy.NO_PROXY, + response.request.toHttpRequest(), + response.toHttpResponse(), + ) + .getOrNull() + ?.toRequest(client = null) + } + } + dispatcherExecutorService?.let { dispatcher(Dispatcher(it)) } val maxIdleConnections = maxIdleConnections @@ -331,3 +313,126 @@ internal constructor( ) } } + +private fun HttpRequest.toRequest(client: okhttp3.OkHttpClient?): Request { + var body: RequestBody? = body?.toRequestBody() + if (body == null && requiresBody(method)) { + body = "".toRequestBody() + } + + val builder = Request.Builder().url(toUrl()).method(method.name, body) + headers.names().forEach { name -> headers.values(name).forEach { builder.addHeader(name, it) } } + + if (client != null) { + if ( + !headers.names().contains("X-Stainless-Read-Timeout") && client.readTimeoutMillis != 0 + ) { + builder.addHeader( + "X-Stainless-Read-Timeout", + Duration.ofMillis(client.readTimeoutMillis.toLong()).seconds.toString(), + ) + } + if (!headers.names().contains("X-Stainless-Timeout") && client.callTimeoutMillis != 0) { + builder.addHeader( + "X-Stainless-Timeout", + Duration.ofMillis(client.callTimeoutMillis.toLong()).seconds.toString(), + ) + } + } + + return builder.build() +} + +/** `OkHttpClient` always requires a request body for some methods. */ +private fun requiresBody(method: HttpMethod): Boolean = + when (method) { + HttpMethod.POST, + HttpMethod.PUT, + HttpMethod.PATCH -> true + else -> false + } + +private fun HttpRequest.toUrl(): String { + val builder = baseUrl.toHttpUrl().newBuilder() + pathSegments.forEach(builder::addPathSegment) + queryParams.keys().forEach { key -> + queryParams.values(key).forEach { builder.addQueryParameter(key, it) } + } + + return builder.toString() +} + +private fun HttpRequestBody.toRequestBody(): RequestBody { + val mediaType = contentType()?.toMediaType() + val length = contentLength() + + return object : RequestBody() { + override fun contentType(): MediaType? = mediaType + + override fun contentLength(): Long = length + + override fun isOneShot(): Boolean = !repeatable() + + override fun writeTo(sink: BufferedSink) = writeTo(sink.outputStream()) + } +} + +private fun Request.toHttpRequest(): HttpRequest { + val builder = HttpRequest.builder().method(HttpMethod.valueOf(method)).baseUrl(url.toBaseUrl()) + url.pathSegments.forEach(builder::addPathSegment) + url.queryParameterNames.forEach { name -> + url.queryParameterValues(name).filterNotNull().forEach { builder.putQueryParam(name, it) } + } + headers.forEach { (name, value) -> builder.putHeader(name, value) } + body?.let { builder.body(it.toHttpRequestBody()) } + return builder.build() +} + +private fun HttpUrl.toBaseUrl(): String = buildString { + append(scheme).append("://").append(host) + if (port != HttpUrl.defaultPort(scheme)) { + append(":").append(port) + } +} + +private fun RequestBody.toHttpRequestBody(): HttpRequestBody { + val mediaType = contentType()?.toString() + val length = contentLength() + val isOneShot = isOneShot() + val source = this + return object : HttpRequestBody { + override fun contentType(): String? = mediaType + + override fun contentLength(): Long = length + + override fun repeatable(): Boolean = !isOneShot + + override fun writeTo(outputStream: OutputStream) { + val sink = outputStream.sink().buffer() + source.writeTo(sink) + sink.flush() + } + + override fun close() {} + } +} + +private fun Response.toHttpResponse(): HttpResponse { + val headers = headers.toHeaders() + + return object : HttpResponse { + override fun statusCode(): Int = code + + override fun headers(): Headers = headers + + override fun body(): InputStream = body!!.byteStream() + + override fun close() = body!!.close() + } +} + +private fun okhttp3.Headers.toHeaders(): Headers { + val headersBuilder = Headers.builder() + forEach { (name, value) -> headersBuilder.put(name, value) } + return headersBuilder.build() +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/core/http/ProxyAuthenticator.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/core/http/ProxyAuthenticator.kt new file mode 100644 index 000000000..8376c20ce --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/core/http/ProxyAuthenticator.kt @@ -0,0 +1,59 @@ +package com.anthropic.core.http + +import java.net.Proxy +import java.nio.charset.Charset +import java.nio.charset.StandardCharsets +import java.util.Base64 +import java.util.Optional + +/** + * Provides credentials when an HTTP proxy responds with `407 Proxy Authentication Required`. + * + * Implementations inspect the 407 [response] (typically its `Proxy-Authenticate` header) and return + * the request to retry with a `Proxy-Authorization` header set, or [Optional.empty] to abandon + * authentication and surface the 407 to the caller. + * + * Implementations must be thread-safe; they may be invoked concurrently from multiple HTTP calls. + */ +fun interface ProxyAuthenticator { + + /** + * @param proxy the proxy that produced the challenge, or [Proxy.NO_PROXY] if the route is not + * yet established + * @param request the request that produced [response] + * @param response the 407 challenge response + * @return the retry request to send (typically [request] with a `Proxy-Authorization` header + * added), or [Optional.empty] to abandon authentication + */ + fun authenticate( + proxy: Proxy, + request: HttpRequest, + response: HttpResponse, + ): Optional + + companion object { + + /** + * A [ProxyAuthenticator] that uses RFC 7617 Basic authentication with the ISO-8859-1 + * charset. + */ + @JvmStatic + fun basic(username: String, password: String): ProxyAuthenticator = + basic(username, password, StandardCharsets.ISO_8859_1) + + /** + * A [ProxyAuthenticator] that uses RFC 7617 Basic authentication with the given [charset]. + */ + @JvmStatic + fun basic(username: String, password: String, charset: Charset): ProxyAuthenticator { + val token = + Base64.getEncoder().encodeToString("$username:$password".toByteArray(charset)) + val headerValue = "Basic $token" + return ProxyAuthenticator { _, request, _ -> + Optional.of( + request.toBuilder().putHeader("Proxy-Authorization", headerValue).build() + ) + } + } + } +} From 60675993a7c520e7fb74d02dc797d64e854d58e8 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 5 May 2026 19:17:18 +0000 Subject: [PATCH 2/6] feat(api): add support for Managed Agents multiagents and outcomes, webhooks, vault validation --- .stats.yml | 8 +- .../client/okhttp/AnthropicOkHttpClient.kt | 5 + .../okhttp/AnthropicOkHttpClientAsync.kt | 5 + .../com/anthropic/core/ClientOptions.kt | 9 + .../com/anthropic/core/UnwrapWebhookParams.kt | 102 + .../anthropic/core/handlers/EmptyHandler.kt | 12 + .../com/anthropic/core/handlers/SseHandler.kt | 16 +- .../com/anthropic/core/http/QueryParams.kt | 22 +- .../errors/AnthropicWebhookException.kt | 5 + .../anthropic/models/beta/AnthropicBeta.kt | 6 + .../models/beta/agents/AgentCreateParams.kt | 127 +- .../models/beta/agents/AgentUpdateParams.kt | 127 +- .../beta/agents/BetaManagedAgentsAgent.kt | 70 +- .../agents/BetaManagedAgentsAgentReference.kt | 382 +++ .../BetaManagedAgentsMultiagentCoordinator.kt | 376 +++ ...anagedAgentsMultiagentCoordinatorParams.kt | 413 +++ .../BetaManagedAgentsMultiagentSelfParams.kt | 318 ++ .../BetaCitationContentBlockLocation.kt | 29 + .../BetaCitationContentBlockLocationParam.kt | 29 + .../BetaCitationSearchResultLocation.kt | 42 + .../BetaCitationSearchResultLocationParam.kt | 42 + .../sessions/BetaManagedAgentsMultiagent.kt | 373 +++ .../BetaManagedAgentsMultiagentParams.kt | 410 +++ ...anagedAgentsMultiagentRosterEntryParams.kt | 314 ++ ...aManagedAgentsOutcomeEvaluationResource.kt | 588 ++++ .../beta/sessions/BetaManagedAgentsSession.kt | 69 +- .../sessions/BetaManagedAgentsSessionAgent.kt | 72 +- ...nagedAgentsSessionMultiagentCoordinator.kt | 376 +++ .../models/beta/sessions/SessionListParams.kt | 176 +- ...etaManagedAgentsAgentCustomToolUseEvent.kt | 61 +- .../BetaManagedAgentsAgentMcpToolUseEvent.kt | 69 +- ...edAgentsAgentThreadMessageReceivedEvent.kt | 1010 +++++++ ...anagedAgentsAgentThreadMessageSentEvent.kt | 1003 +++++++ .../BetaManagedAgentsAgentToolUseEvent.kt | 78 +- .../events/BetaManagedAgentsEventParams.kt | 66 +- .../events/BetaManagedAgentsFileRubric.kt | 348 +++ .../BetaManagedAgentsFileRubricParams.kt | 351 +++ .../BetaManagedAgentsSendSessionEvents.kt | 70 +- .../events/BetaManagedAgentsSessionEvent.kt | 715 ++++- ...aManagedAgentsSessionThreadCreatedEvent.kt | 483 +++ ...nagedAgentsSessionThreadStatusIdleEvent.kt | 873 ++++++ ...entsSessionThreadStatusRescheduledEvent.kt | 486 +++ ...edAgentsSessionThreadStatusRunningEvent.kt | 484 +++ ...gentsSessionThreadStatusTerminatedEvent.kt | 485 +++ ...agedAgentsSpanOutcomeEvaluationEndEvent.kt | 679 +++++ ...AgentsSpanOutcomeEvaluationOngoingEvent.kt | 478 +++ ...edAgentsSpanOutcomeEvaluationStartEvent.kt | 477 +++ .../BetaManagedAgentsStreamSessionEvents.kt | 736 ++++- .../events/BetaManagedAgentsTextRubric.kt | 348 +++ .../BetaManagedAgentsTextRubricParams.kt | 355 +++ ...aManagedAgentsUserCustomToolResultEvent.kt | 76 +- ...BetaManagedAgentsUserDefineOutcomeEvent.kt | 840 ++++++ ...nagedAgentsUserDefineOutcomeEventParams.kt | 717 +++++ .../BetaManagedAgentsUserInterruptEvent.kt | 60 +- ...taManagedAgentsUserInterruptEventParams.kt | 63 +- ...aManagedAgentsUserToolConfirmationEvent.kt | 69 +- .../sessions/events/EventListPageResponse.kt | 111 + .../beta/sessions/events/EventListParams.kt | 119 +- .../beta/sessions/events/EventSendParams.kt | 15 + .../threads/BetaManagedAgentsSessionThread.kt | 780 +++++ .../BetaManagedAgentsSessionThreadAgent.kt | 1217 ++++++++ .../BetaManagedAgentsSessionThreadStats.kt | 276 ++ .../BetaManagedAgentsSessionThreadStatus.kt | 161 + .../BetaManagedAgentsSessionThreadUsage.kt | 314 ++ ...aManagedAgentsStreamSessionThreadEvents.kt | 1973 +++++++++++++ .../sessions/threads/ThreadArchiveParams.kt | 298 ++ .../beta/sessions/threads/ThreadListPage.kt | 132 + .../sessions/threads/ThreadListPageAsync.kt | 147 + .../threads/ThreadListPageResponse.kt | 229 ++ .../beta/sessions/threads/ThreadListParams.kt | 276 ++ .../sessions/threads/ThreadRetrieveParams.kt | 257 ++ .../sessions/threads/events/EventListPage.kt | 133 + .../threads/events/EventListPageAsync.kt | 148 + .../threads/events/EventListPageResponse.kt | 539 ++++ .../threads/events/EventListParams.kt | 307 ++ .../threads/events/EventStreamParams.kt | 257 ++ .../beta/userprofiles/BetaUserProfile.kt | 259 +- .../userprofiles/UserProfileCreateParams.kt | 320 +- .../userprofiles/UserProfileUpdateParams.kt | 326 ++- .../BetaManagedAgentsCredentialValidation.kt | 646 ++++ ...ManagedAgentsCredentialValidationStatus.kt | 156 + .../credentials/BetaManagedAgentsMcpProbe.kt | 235 ++ .../BetaManagedAgentsRefreshHttpResponse.kt | 310 ++ .../BetaManagedAgentsRefreshObject.kt | 387 +++ .../CredentialMcpOAuthValidateParams.kt | 302 ++ .../models/beta/webhooks/BetaWebhookEvent.kt | 442 +++ .../beta/webhooks/BetaWebhookEventData.kt | 1055 +++++++ .../BetaWebhookSessionArchivedEventData.kt | 304 ++ .../BetaWebhookSessionCreatedEventData.kt | 303 ++ .../BetaWebhookSessionDeletedEventData.kt | 303 ++ .../BetaWebhookSessionIdledEventData.kt | 303 ++ ...kSessionOutcomeEvaluationEndedEventData.kt | 306 ++ .../BetaWebhookSessionPendingEventData.kt | 303 ++ ...taWebhookSessionRequiresActionEventData.kt | 304 ++ .../BetaWebhookSessionRunningEventData.kt | 303 ++ .../BetaWebhookSessionStatusIdledEventData.kt | 304 ++ ...WebhookSessionStatusRunStartedEventData.kt | 304 ++ ...aWebhookSessionStatusScheduledEventData.kt | 304 ++ ...WebhookSessionStatusTerminatedEventData.kt | 304 ++ ...etaWebhookSessionThreadCreatedEventData.kt | 304 ++ .../BetaWebhookSessionThreadIdledEventData.kt | 304 ++ ...WebhookSessionThreadTerminatedEventData.kt | 304 ++ .../BetaWebhookVaultArchivedEventData.kt | 303 ++ .../BetaWebhookVaultCreatedEventData.kt | 303 ++ ...WebhookVaultCredentialArchivedEventData.kt | 340 +++ ...aWebhookVaultCredentialCreatedEventData.kt | 340 +++ ...aWebhookVaultCredentialDeletedEventData.kt | 340 +++ ...okVaultCredentialRefreshFailedEventData.kt | 341 +++ .../BetaWebhookVaultDeletedEventData.kt | 303 ++ .../beta/webhooks/UnwrapWebhookEvent.kt | 442 +++ .../messages/CitationContentBlockLocation.kt | 29 + .../CitationContentBlockLocationParam.kt | 29 + .../CitationSearchResultLocationParam.kt | 42 + .../messages/CitationsSearchResultLocation.kt | 42 + .../services/async/BetaServiceAsync.kt | 5 + .../services/async/BetaServiceAsyncImpl.kt | 12 + .../async/beta/SessionServiceAsync.kt | 5 + .../async/beta/SessionServiceAsyncImpl.kt | 12 + .../async/beta/WebhookServiceAsync.kt | 55 + .../async/beta/WebhookServiceAsyncImpl.kt | 39 + .../async/beta/sessions/ThreadServiceAsync.kt | 237 ++ .../beta/sessions/ThreadServiceAsyncImpl.kt | 221 ++ .../sessions/threads/EventServiceAsync.kt | 162 + .../sessions/threads/EventServiceAsyncImpl.kt | 181 ++ .../beta/vaults/CredentialServiceAsync.kt | 60 + .../beta/vaults/CredentialServiceAsyncImpl.kt | 52 + .../services/blocking/BetaService.kt | 5 + .../services/blocking/BetaServiceImpl.kt | 12 + .../services/blocking/beta/SessionService.kt | 5 + .../blocking/beta/SessionServiceImpl.kt | 12 + .../services/blocking/beta/WebhookService.kt | 51 + .../blocking/beta/WebhookServiceImpl.kt | 68 + .../blocking/beta/sessions/ThreadService.kt | 229 ++ .../beta/sessions/ThreadServiceImpl.kt | 207 ++ .../beta/sessions/threads/EventService.kt | 156 + .../beta/sessions/threads/EventServiceImpl.kt | 163 ++ .../blocking/beta/vaults/CredentialService.kt | 63 + .../beta/vaults/CredentialServiceImpl.kt | 49 + .../beta/agents/AgentCreateParamsTest.kt | 46 + .../beta/agents/AgentListPageResponseTest.kt | 37 + .../beta/agents/AgentUpdateParamsTest.kt | 46 + .../BetaManagedAgentsAgentReferenceTest.kt | 46 + .../beta/agents/BetaManagedAgentsAgentTest.kt | 38 + ...edAgentsMultiagentCoordinatorParamsTest.kt | 64 + ...aManagedAgentsMultiagentCoordinatorTest.kt | 62 + ...taManagedAgentsMultiagentSelfParamsTest.kt | 40 + .../versions/VersionListPageResponseTest.kt | 38 + .../BetaManagedAgentsMultiagentParamsTest.kt | 64 + ...edAgentsMultiagentRosterEntryParamsTest.kt | 143 + .../BetaManagedAgentsMultiagentTest.kt | 62 + ...agedAgentsOutcomeEvaluationResourceTest.kt | 63 + .../BetaManagedAgentsSessionAgentTest.kt | 218 ++ ...dAgentsSessionMultiagentCoordinatorTest.kt | 243 ++ .../sessions/BetaManagedAgentsSessionTest.kt | 289 ++ .../sessions/SessionListPageResponseTest.kt | 342 +++ .../beta/sessions/SessionListParamsTest.kt | 4 + ...anagedAgentsAgentCustomToolUseEventTest.kt | 4 + ...taManagedAgentsAgentMcpToolUseEventTest.kt | 4 + ...entsAgentThreadMessageReceivedEventTest.kt | 75 + ...edAgentsAgentThreadMessageSentEventTest.kt | 67 + .../BetaManagedAgentsAgentToolUseEventTest.kt | 4 + .../BetaManagedAgentsEventParamsTest.kt | 48 + .../BetaManagedAgentsFileRubricParamsTest.kt | 44 + .../events/BetaManagedAgentsFileRubricTest.kt | 42 + .../BetaManagedAgentsSessionEventTest.kt | 1123 ++++++- ...agedAgentsSessionThreadCreatedEventTest.kt | 56 + ...dAgentsSessionThreadStatusIdleEventTest.kt | 77 + ...SessionThreadStatusRescheduledEventTest.kt | 65 + ...entsSessionThreadStatusRunningEventTest.kt | 64 + ...sSessionThreadStatusTerminatedEventTest.kt | 65 + ...AgentsSpanOutcomeEvaluationEndEventTest.kt | 101 + ...tsSpanOutcomeEvaluationOngoingEventTest.kt | 65 + ...entsSpanOutcomeEvaluationStartEventTest.kt | 64 + ...etaManagedAgentsStreamSessionEventsTest.kt | 1126 +++++++ .../BetaManagedAgentsTextRubricParamsTest.kt | 44 + .../events/BetaManagedAgentsTextRubricTest.kt | 42 + ...agedAgentsUserCustomToolResultEventTest.kt | 4 + ...dAgentsUserDefineOutcomeEventParamsTest.kt | 58 + ...ManagedAgentsUserDefineOutcomeEventTest.kt | 71 + ...nagedAgentsUserInterruptEventParamsTest.kt | 4 + ...BetaManagedAgentsUserInterruptEventTest.kt | 4 + ...agedAgentsUserToolConfirmationEventTest.kt | 4 + .../sessions/events/EventListParamsTest.kt | 21 + ...BetaManagedAgentsSessionThreadAgentTest.kt | 219 ++ ...BetaManagedAgentsSessionThreadStatsTest.kt | 45 + .../BetaManagedAgentsSessionThreadTest.kt | 331 +++ ...BetaManagedAgentsSessionThreadUsageTest.kt | 65 + ...agedAgentsStreamSessionThreadEventsTest.kt | 2595 +++++++++++++++++ .../threads/ThreadArchiveParamsTest.kt | 64 + .../threads/ThreadListPageResponseTest.kt | 348 +++ .../sessions/threads/ThreadListParamsTest.kt | 83 + .../threads/ThreadRetrieveParamsTest.kt | 64 + .../events/EventListPageResponseTest.kt | 69 + .../threads/events/EventListParamsTest.kt | 99 + .../threads/events/EventStreamParamsTest.kt | 64 + .../beta/userprofiles/BetaUserProfileTest.kt | 6 + .../UserProfileCreateParamsTest.kt | 8 + .../UserProfileListPageResponseTest.kt | 6 + .../UserProfileUpdateParamsTest.kt | 8 + ...taManagedAgentsCredentialValidationTest.kt | 140 + .../BetaManagedAgentsMcpProbeTest.kt | 63 + ...etaManagedAgentsRefreshHttpResponseTest.kt | 48 + .../BetaManagedAgentsRefreshObjectTest.kt | 65 + .../CredentialMcpOAuthValidateParamsTest.kt | 64 + .../beta/webhooks/BetaWebhookEventDataTest.kt | 1286 ++++++++ .../beta/webhooks/BetaWebhookEventTest.kt | 67 + ...BetaWebhookSessionArchivedEventDataTest.kt | 46 + .../BetaWebhookSessionCreatedEventDataTest.kt | 45 + .../BetaWebhookSessionDeletedEventDataTest.kt | 45 + .../BetaWebhookSessionIdledEventDataTest.kt | 45 + ...sionOutcomeEvaluationEndedEventDataTest.kt | 48 + .../BetaWebhookSessionPendingEventDataTest.kt | 45 + ...bhookSessionRequiresActionEventDataTest.kt | 47 + .../BetaWebhookSessionRunningEventDataTest.kt | 45 + ...aWebhookSessionStatusIdledEventDataTest.kt | 48 + ...ookSessionStatusRunStartedEventDataTest.kt | 47 + ...hookSessionStatusScheduledEventDataTest.kt | 47 + ...ookSessionStatusTerminatedEventDataTest.kt | 47 + ...ebhookSessionThreadCreatedEventDataTest.kt | 46 + ...aWebhookSessionThreadIdledEventDataTest.kt | 46 + ...ookSessionThreadTerminatedEventDataTest.kt | 47 + .../BetaWebhookVaultArchivedEventDataTest.kt | 45 + .../BetaWebhookVaultCreatedEventDataTest.kt | 45 + ...ookVaultCredentialArchivedEventDataTest.kt | 50 + ...hookVaultCredentialCreatedEventDataTest.kt | 50 + ...hookVaultCredentialDeletedEventDataTest.kt | 50 + ...ultCredentialRefreshFailedEventDataTest.kt | 50 + .../BetaWebhookVaultDeletedEventDataTest.kt | 45 + .../beta/webhooks/UnwrapWebhookEventTest.kt | 67 + .../async/beta/AgentServiceAsyncTest.kt | 24 + .../async/beta/UserProfileServiceAsyncTest.kt | 4 + .../async/beta/WebhookServiceAsyncTest.kt | 159 + .../beta/sessions/ThreadServiceAsyncTest.kt | 76 + .../sessions/threads/EventServiceAsyncTest.kt | 65 + .../beta/vaults/CredentialServiceAsyncTest.kt | 25 + .../blocking/beta/AgentServiceTest.kt | 24 + .../blocking/beta/UserProfileServiceTest.kt | 4 + .../blocking/beta/WebhookServiceTest.kt | 159 + .../beta/sessions/ThreadServiceTest.kt | 73 + .../beta/sessions/threads/EventServiceTest.kt | 63 + .../beta/vaults/CredentialServiceTest.kt | 23 + scripts/mock | 4 +- scripts/test | 2 +- 243 files changed, 50314 insertions(+), 87 deletions(-) create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/core/UnwrapWebhookParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/core/handlers/EmptyHandler.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/errors/AnthropicWebhookException.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgentReference.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinator.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinatorParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentSelfParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentRosterEntryParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsOutcomeEvaluationResource.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionMultiagentCoordinator.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageReceivedEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageSentEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubric.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubricParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadCreatedEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusIdleEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRescheduledEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRunningEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusTerminatedEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationEndEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationStartEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubric.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubricParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEventParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThread.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadAgent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadStats.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadStatus.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadUsage.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsStreamSessionThreadEvents.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadArchiveParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPage.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPageAsync.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPageResponse.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadRetrieveParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPage.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPageAsync.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPageResponse.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventStreamParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsCredentialValidation.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsCredentialValidationStatus.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsMcpProbe.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshHttpResponse.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshObject.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/CredentialMcpOAuthValidateParams.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionArchivedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionCreatedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionDeletedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionIdledEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionOutcomeEvaluationEndedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionPendingEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRequiresActionEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRunningEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusIdledEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRunStartedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusTerminatedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadCreatedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadIdledEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadTerminatedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultArchivedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCreatedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialArchivedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialCreatedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialDeletedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialRefreshFailedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultDeletedEventData.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/UnwrapWebhookEvent.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/WebhookServiceAsync.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/WebhookServiceAsyncImpl.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/ThreadServiceAsync.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/ThreadServiceAsyncImpl.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/threads/EventServiceAsync.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/threads/EventServiceAsyncImpl.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/WebhookService.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/WebhookServiceImpl.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/ThreadService.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/ThreadServiceImpl.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/threads/EventService.kt create mode 100644 anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/threads/EventServiceImpl.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgentReferenceTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinatorParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinatorTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentSelfParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentRosterEntryParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsOutcomeEvaluationResourceTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionMultiagentCoordinatorTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageReceivedEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageSentEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubricParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubricTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadCreatedEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusIdleEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRescheduledEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRunningEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusTerminatedEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationEndEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationOngoingEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationStartEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubricParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubricTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEventParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadAgentTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadStatsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadUsageTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsStreamSessionThreadEventsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadArchiveParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPageResponseTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadRetrieveParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPageResponseTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/events/EventStreamParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsCredentialValidationTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsMcpProbeTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshHttpResponseTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshObjectTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/CredentialMcpOAuthValidateParamsTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionArchivedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionCreatedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionDeletedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionIdledEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionOutcomeEvaluationEndedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionPendingEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRequiresActionEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRunningEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusIdledEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRunStartedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusTerminatedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadCreatedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadIdledEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadTerminatedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultArchivedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCreatedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialArchivedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialCreatedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialDeletedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialRefreshFailedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultDeletedEventDataTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/UnwrapWebhookEventTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/WebhookServiceAsyncTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/sessions/ThreadServiceAsyncTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/sessions/threads/EventServiceAsyncTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/WebhookServiceTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/sessions/ThreadServiceTest.kt create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/sessions/threads/EventServiceTest.kt diff --git a/.stats.yml b/.stats.yml index 7027e4e50..89ca80542 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 91 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic/anthropic-ad9228826393d94e86ecf4c22853ae51b1d4094960c836238b3ab79a1044be32.yml -openapi_spec_hash: dc43ed54947d427a084a891b7c4a783a -config_hash: bbf09e23cb2e12b5bb8cbcee3044ceec +configured_endpoints: 97 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic/anthropic-9f858907356014087c51d59846cd158425826fc558a1683e6ebf49483503cd5e.yml +openapi_spec_hash: 87cd38428be2fb157f6d79b50c00f573 +config_hash: 0ed9b1770bb175fa6bdc1e4d41afb180 diff --git a/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClient.kt b/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClient.kt index 1134ca0a5..4afb293ca 100644 --- a/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClient.kt +++ b/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClient.kt @@ -308,6 +308,11 @@ class AnthropicOkHttpClient private constructor() { /** Alias for calling [Builder.authToken] with `authToken.orElse(null)`. */ fun authToken(authToken: Optional) = authToken(authToken.getOrNull()) + fun webhookKey(webhookKey: String?) = apply { clientOptions.webhookKey(webhookKey) } + + /** Alias for calling [Builder.webhookKey] with `webhookKey.orElse(null)`. */ + fun webhookKey(webhookKey: Optional) = webhookKey(webhookKey.getOrNull()) + fun headers(headers: Headers) = apply { clientOptions.headers(headers) } fun headers(headers: Map>) = apply { diff --git a/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClientAsync.kt b/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClientAsync.kt index 04f58d8bd..c3a156c80 100644 --- a/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClientAsync.kt +++ b/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/AnthropicOkHttpClientAsync.kt @@ -308,6 +308,11 @@ class AnthropicOkHttpClientAsync private constructor() { /** Alias for calling [Builder.authToken] with `authToken.orElse(null)`. */ fun authToken(authToken: Optional) = authToken(authToken.getOrNull()) + fun webhookKey(webhookKey: String?) = apply { clientOptions.webhookKey(webhookKey) } + + /** Alias for calling [Builder.webhookKey] with `webhookKey.orElse(null)`. */ + fun webhookKey(webhookKey: Optional) = webhookKey(webhookKey.getOrNull()) + fun headers(headers: Headers) = apply { clientOptions.headers(headers) } fun headers(headers: Map>) = apply { diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/core/ClientOptions.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/core/ClientOptions.kt index 7cf748315..742fb5e1a 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/core/ClientOptions.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/core/ClientOptions.kt @@ -128,6 +128,8 @@ private constructor( */ fun baseUrl(): String? = baseUrl + fun webhookKey(): Optional = Optional.ofNullable(webhookKey) + fun toBuilder() = Builder().from(this) companion object { @@ -159,6 +161,7 @@ private constructor( private var timeout: Timeout = Timeout.default() private var maxRetries: Int = 2 private var credentialResult: CredentialResult? = null + private var webhookKey: String? = null @JvmSynthetic internal fun from(clientOptions: ClientOptions) = apply { @@ -303,6 +306,11 @@ private constructor( this.credentialResult = credentials } + fun webhookKey(webhookKey: String?) = apply { this.webhookKey = webhookKey } + + /** Alias for calling [Builder.webhookKey] with `webhookKey.orElse(null)`. */ + fun webhookKey(webhookKey: Optional) = webhookKey(webhookKey.getOrNull()) + fun headers(headers: Headers) = apply { this.headers.clear() putAllHeaders(headers) @@ -475,6 +483,7 @@ private constructor( timeout, maxRetries, credentialResult, + webhookKey, ) } } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/core/UnwrapWebhookParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/core/UnwrapWebhookParams.kt new file mode 100644 index 000000000..c99374247 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/core/UnwrapWebhookParams.kt @@ -0,0 +1,102 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.core + +import com.anthropic.core.http.Headers +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class UnwrapWebhookParams +private constructor( + private val body: String, + private val headers: Headers?, + private val secret: String?, +) { + + /** The raw JSON body of the webhook request. */ + fun body(): String = body + + /** The headers from the webhook request. */ + fun headers(): Optional = Optional.ofNullable(headers) + + /** The secret used to verify the webhook signature. */ + fun secret(): Optional = Optional.ofNullable(secret) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [UnwrapWebhookParams]. + * + * The following fields are required: + * ```java + * .body() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UnwrapWebhookParams]. */ + class Builder internal constructor() { + + private var body: String? = null + private var headers: Headers? = null + private var secret: String? = null + + @JvmSynthetic + internal fun from(unwrapWebhookParams: UnwrapWebhookParams) = apply { + body = unwrapWebhookParams.body + headers = unwrapWebhookParams.headers + secret = unwrapWebhookParams.secret + } + + /** The raw JSON body of the webhook request. */ + fun body(body: String) = apply { this.body = body } + + /** The headers from the webhook request. */ + fun headers(headers: Headers?) = apply { this.headers = headers } + + /** Alias for calling [Builder.headers] with `headers.orElse(null)`. */ + fun headers(headers: Optional) = headers(headers.getOrNull()) + + /** The secret used to verify the webhook signature. */ + fun secret(secret: String?) = apply { this.secret = secret } + + /** Alias for calling [Builder.secret] with `secret.orElse(null)`. */ + fun secret(secret: Optional) = secret(secret.getOrNull()) + + /** + * Returns an immutable instance of [UnwrapWebhookParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .body() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnwrapWebhookParams = + UnwrapWebhookParams(checkRequired("body", body), headers, secret) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnwrapWebhookParams && + body == other.body && + headers == other.headers && + secret == other.secret + } + + private val hashCode: Int by lazy { Objects.hash(body, headers, secret) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "UnwrapWebhookParams{body=$body, headers=$headers, secret=$secret}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/core/handlers/EmptyHandler.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/core/handlers/EmptyHandler.kt new file mode 100644 index 000000000..14eb80bc7 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/core/handlers/EmptyHandler.kt @@ -0,0 +1,12 @@ +@file:JvmName("EmptyHandler") + +package com.anthropic.core.handlers + +import com.anthropic.core.http.HttpResponse +import com.anthropic.core.http.HttpResponse.Handler + +@JvmSynthetic internal fun emptyHandler(): Handler = EmptyHandlerInternal + +private object EmptyHandlerInternal : Handler { + override fun handle(response: HttpResponse): Void? = null +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/core/handlers/SseHandler.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/core/handlers/SseHandler.kt index 3e8b91ec9..dae5c33ca 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/core/handlers/SseHandler.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/core/handlers/SseHandler.kt @@ -49,7 +49,21 @@ internal fun sseHandler(jsonMapper: JsonMapper): Handler yield(message) + "span.model_request_end", + "span.outcome_evaluation_start", + "span.outcome_evaluation_ongoing", + "span.outcome_evaluation_end", + "user.define_outcome", + "agent.thread_message_received", + "agent.thread_message_sent", + "agent.session_thread_message_received", + "agent.session_thread_message_sent", + "session.thread_created", + "session.thread_status_created", + "session.thread_status_running", + "session.thread_status_idle", + "session.thread_status_rescheduled", + "session.thread_status_terminated" -> yield(message) "ping" -> continue "error" -> { throw SseException.builder() diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/core/http/QueryParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/core/http/QueryParams.kt index 8fcc04414..3b6af1127 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/core/http/QueryParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/core/http/QueryParams.kt @@ -43,27 +43,7 @@ private constructor( is JsonBoolean -> put(key, value.value.toString()) is JsonNumber -> put(key, value.value.toString()) is JsonString -> put(key, value.value) - is JsonArray -> - put( - key, - value.values - .asSequence() - .mapNotNull { - when (it) { - is JsonMissing, - is JsonNull -> null - is JsonBoolean -> it.value.toString() - is JsonNumber -> it.value.toString() - is JsonString -> it.value - is JsonArray, - is JsonObject -> - throw IllegalArgumentException( - "Cannot comma separate non-primitives in query params" - ) - } - } - .joinToString(","), - ) + is JsonArray -> value.values.forEach { put("$key[]", it) } is JsonObject -> value.values.forEach { (nestedKey, value) -> put("$key[$nestedKey]", value) } } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/errors/AnthropicWebhookException.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/errors/AnthropicWebhookException.kt new file mode 100644 index 000000000..aa1c7b3f6 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/errors/AnthropicWebhookException.kt @@ -0,0 +1,5 @@ +package com.anthropic.errors + +class AnthropicWebhookException +@JvmOverloads +constructor(message: String? = null, cause: Throwable? = null) : AnthropicException(message, cause) diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/AnthropicBeta.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/AnthropicBeta.kt index 5551e8ad5..de6524b3c 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/AnthropicBeta.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/AnthropicBeta.kt @@ -68,6 +68,8 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel @JvmField val ADVISOR_TOOL_2026_03_01 = of("advisor-tool-2026-03-01") + @JvmField val MANAGED_AGENTS_2026_04_01 = of("managed-agents-2026-04-01") + @JvmStatic fun of(value: String) = AnthropicBeta(JsonField.of(value)) } @@ -96,6 +98,7 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel OUTPUT_300K_2026_03_24, USER_PROFILES_2026_03_24, ADVISOR_TOOL_2026_03_01, + MANAGED_AGENTS_2026_04_01, } /** @@ -131,6 +134,7 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel OUTPUT_300K_2026_03_24, USER_PROFILES_2026_03_24, ADVISOR_TOOL_2026_03_01, + MANAGED_AGENTS_2026_04_01, /** * An enum member indicating that [AnthropicBeta] was instantiated with an unknown value. */ @@ -170,6 +174,7 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel OUTPUT_300K_2026_03_24 -> Value.OUTPUT_300K_2026_03_24 USER_PROFILES_2026_03_24 -> Value.USER_PROFILES_2026_03_24 ADVISOR_TOOL_2026_03_01 -> Value.ADVISOR_TOOL_2026_03_01 + MANAGED_AGENTS_2026_04_01 -> Value.MANAGED_AGENTS_2026_04_01 else -> Value._UNKNOWN } @@ -207,6 +212,7 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel OUTPUT_300K_2026_03_24 -> Known.OUTPUT_300K_2026_03_24 USER_PROFILES_2026_03_24 -> Known.USER_PROFILES_2026_03_24 ADVISOR_TOOL_2026_03_01 -> Known.ADVISOR_TOOL_2026_03_01 + MANAGED_AGENTS_2026_04_01 -> Known.MANAGED_AGENTS_2026_04_01 else -> throw AnthropicInvalidDataException("Unknown AnthropicBeta: $value") } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/AgentCreateParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/AgentCreateParams.kt index 4e8f381ce..67e5248de 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/AgentCreateParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/AgentCreateParams.kt @@ -18,6 +18,8 @@ import com.anthropic.core.http.QueryParams import com.anthropic.core.toImmutable import com.anthropic.errors.AnthropicInvalidDataException import com.anthropic.models.beta.AnthropicBeta +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagentParams +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagentRosterEntryParams import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator @@ -88,6 +90,15 @@ private constructor( */ fun metadata(): Optional = body.metadata() + /** + * A coordinator topology: the session's primary thread orchestrates work by spawning session + * threads, each running an agent drawn from the `agents` roster. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun multiagent(): Optional = body.multiagent() + /** * Skills available to the agent. Maximum 20. * @@ -147,6 +158,13 @@ private constructor( */ fun _metadata(): JsonField = body._metadata() + /** + * Returns the raw JSON value of [multiagent]. + * + * Unlike [multiagent], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _multiagent(): JsonField = body._multiagent() + /** * Returns the raw JSON value of [skills]. * @@ -342,6 +360,43 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + /** + * A coordinator topology: the session's primary thread orchestrates work by spawning + * session threads, each running an agent drawn from the `agents` roster. + */ + fun multiagent(multiagent: BetaManagedAgentsMultiagentParams?) = apply { + body.multiagent(multiagent) + } + + /** Alias for calling [Builder.multiagent] with `multiagent.orElse(null)`. */ + fun multiagent(multiagent: Optional) = + multiagent(multiagent.getOrNull()) + + /** + * Sets [Builder.multiagent] to an arbitrary JSON value. + * + * You should usually call [Builder.multiagent] with a well-typed + * [BetaManagedAgentsMultiagentParams] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun multiagent(multiagent: JsonField) = apply { + body.multiagent(multiagent) + } + + /** + * Alias for calling [multiagent] with the following: + * ```java + * BetaManagedAgentsMultiagentParams.builder() + * .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + * .agents(agents) + * .build() + * ``` + */ + fun coordinatorMultiagent(agents: List) = + apply { + body.coordinatorMultiagent(agents) + } + /** Skills available to the agent. Maximum 20. */ fun skills(skills: List) = apply { body.skills(skills) } @@ -617,6 +672,7 @@ private constructor( private val description: JsonField, private val mcpServers: JsonField>, private val metadata: JsonField, + private val multiagent: JsonField, private val skills: JsonField>, private val system: JsonField, private val tools: JsonField>, @@ -636,6 +692,9 @@ private constructor( @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("multiagent") + @ExcludeMissing + multiagent: JsonField = JsonMissing.of(), @JsonProperty("skills") @ExcludeMissing skills: JsonField> = JsonMissing.of(), @@ -647,6 +706,7 @@ private constructor( description, mcpServers, metadata, + multiagent, skills, system, tools, @@ -697,6 +757,16 @@ private constructor( */ fun metadata(): Optional = metadata.getOptional("metadata") + /** + * A coordinator topology: the session's primary thread orchestrates work by spawning + * session threads, each running an agent drawn from the `agents` roster. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun multiagent(): Optional = + multiagent.getOptional("multiagent") + /** * Skills available to the agent. Maximum 20. * @@ -761,6 +831,15 @@ private constructor( */ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + /** + * Returns the raw JSON value of [multiagent]. + * + * Unlike [multiagent], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("multiagent") + @ExcludeMissing + fun _multiagent(): JsonField = multiagent + /** * Returns the raw JSON value of [skills]. * @@ -819,6 +898,7 @@ private constructor( private var mcpServers: JsonField>? = null private var metadata: JsonField = JsonMissing.of() + private var multiagent: JsonField = JsonMissing.of() private var skills: JsonField>? = null private var system: JsonField = JsonMissing.of() private var tools: JsonField>? = null @@ -831,6 +911,7 @@ private constructor( description = body.description mcpServers = body.mcpServers.map { it.toMutableList() } metadata = body.metadata + multiagent = body.multiagent skills = body.skills.map { it.toMutableList() } system = body.system tools = body.tools.map { it.toMutableList() } @@ -942,6 +1023,45 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + /** + * A coordinator topology: the session's primary thread orchestrates work by spawning + * session threads, each running an agent drawn from the `agents` roster. + */ + fun multiagent(multiagent: BetaManagedAgentsMultiagentParams?) = + multiagent(JsonField.ofNullable(multiagent)) + + /** Alias for calling [Builder.multiagent] with `multiagent.orElse(null)`. */ + fun multiagent(multiagent: Optional) = + multiagent(multiagent.getOrNull()) + + /** + * Sets [Builder.multiagent] to an arbitrary JSON value. + * + * You should usually call [Builder.multiagent] with a well-typed + * [BetaManagedAgentsMultiagentParams] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun multiagent(multiagent: JsonField) = apply { + this.multiagent = multiagent + } + + /** + * Alias for calling [multiagent] with the following: + * ```java + * BetaManagedAgentsMultiagentParams.builder() + * .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + * .agents(agents) + * .build() + * ``` + */ + fun coordinatorMultiagent(agents: List) = + multiagent( + BetaManagedAgentsMultiagentParams.builder() + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .agents(agents) + .build() + ) + /** Skills available to the agent. Maximum 20. */ fun skills(skills: List) = skills(JsonField.of(skills)) @@ -1128,6 +1248,7 @@ private constructor( description, (mcpServers ?: JsonMissing.of()).map { it.toImmutable() }, metadata, + multiagent, (skills ?: JsonMissing.of()).map { it.toImmutable() }, system, (tools ?: JsonMissing.of()).map { it.toImmutable() }, @@ -1156,6 +1277,7 @@ private constructor( description() mcpServers().ifPresent { it.forEach { it.validate() } } metadata().ifPresent { it.validate() } + multiagent().ifPresent { it.validate() } skills().ifPresent { it.forEach { it.validate() } } system() tools().ifPresent { it.forEach { it.validate() } } @@ -1183,6 +1305,7 @@ private constructor( (if (description.asKnown().isPresent) 1 else 0) + (mcpServers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (multiagent.asKnown().getOrNull()?.validity() ?: 0) + (skills.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (system.asKnown().isPresent) 1 else 0) + (tools.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) @@ -1198,6 +1321,7 @@ private constructor( description == other.description && mcpServers == other.mcpServers && metadata == other.metadata && + multiagent == other.multiagent && skills == other.skills && system == other.system && tools == other.tools && @@ -1211,6 +1335,7 @@ private constructor( description, mcpServers, metadata, + multiagent, skills, system, tools, @@ -1221,7 +1346,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Body{model=$model, name=$name, description=$description, mcpServers=$mcpServers, metadata=$metadata, skills=$skills, system=$system, tools=$tools, additionalProperties=$additionalProperties}" + "Body{model=$model, name=$name, description=$description, mcpServers=$mcpServers, metadata=$metadata, multiagent=$multiagent, skills=$skills, system=$system, tools=$tools, additionalProperties=$additionalProperties}" } /** diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/AgentUpdateParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/AgentUpdateParams.kt index b16410f60..e76aeb19e 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/AgentUpdateParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/AgentUpdateParams.kt @@ -18,6 +18,8 @@ import com.anthropic.core.http.QueryParams import com.anthropic.core.toImmutable import com.anthropic.errors.AnthropicInvalidDataException import com.anthropic.models.beta.AnthropicBeta +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagentParams +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagentRosterEntryParams import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator @@ -97,6 +99,15 @@ private constructor( */ fun model(): Optional = body.model() + /** + * A coordinator topology: the session's primary thread orchestrates work by spawning session + * threads, each running an agent drawn from the `agents` roster. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun multiagent(): Optional = body.multiagent() + /** * Human-readable name. 1-256 characters. Omit to preserve. Cannot be cleared. * @@ -166,6 +177,13 @@ private constructor( */ fun _model(): JsonField = body._model() + /** + * Returns the raw JSON value of [multiagent]. + * + * Unlike [multiagent], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _multiagent(): JsonField = body._multiagent() + /** * Returns the raw JSON value of [name]. * @@ -390,6 +408,43 @@ private constructor( body.model(betaManagedAgentsModelConfigParams) } + /** + * A coordinator topology: the session's primary thread orchestrates work by spawning + * session threads, each running an agent drawn from the `agents` roster. + */ + fun multiagent(multiagent: BetaManagedAgentsMultiagentParams?) = apply { + body.multiagent(multiagent) + } + + /** Alias for calling [Builder.multiagent] with `multiagent.orElse(null)`. */ + fun multiagent(multiagent: Optional) = + multiagent(multiagent.getOrNull()) + + /** + * Sets [Builder.multiagent] to an arbitrary JSON value. + * + * You should usually call [Builder.multiagent] with a well-typed + * [BetaManagedAgentsMultiagentParams] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun multiagent(multiagent: JsonField) = apply { + body.multiagent(multiagent) + } + + /** + * Alias for calling [multiagent] with the following: + * ```java + * BetaManagedAgentsMultiagentParams.builder() + * .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + * .agents(agents) + * .build() + * ``` + */ + fun coordinatorMultiagent(agents: List) = + apply { + body.coordinatorMultiagent(agents) + } + /** Human-readable name. 1-256 characters. Omit to preserve. Cannot be cleared. */ fun name(name: String) = apply { body.name(name) } @@ -695,6 +750,7 @@ private constructor( private val mcpServers: JsonField>, private val metadata: JsonField, private val model: JsonField, + private val multiagent: JsonField, private val name: JsonField, private val skills: JsonField>, private val system: JsonField, @@ -715,6 +771,9 @@ private constructor( @ExcludeMissing metadata: JsonField = JsonMissing.of(), @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of(), + @JsonProperty("multiagent") + @ExcludeMissing + multiagent: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("skills") @ExcludeMissing @@ -727,6 +786,7 @@ private constructor( mcpServers, metadata, model, + multiagent, name, skills, system, @@ -783,6 +843,16 @@ private constructor( */ fun model(): Optional = model.getOptional("model") + /** + * A coordinator topology: the session's primary thread orchestrates work by spawning + * session threads, each running an agent drawn from the `agents` roster. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun multiagent(): Optional = + multiagent.getOptional("multiagent") + /** * Human-readable name. 1-256 characters. Omit to preserve. Cannot be cleared. * @@ -857,6 +927,15 @@ private constructor( */ @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + /** + * Returns the raw JSON value of [multiagent]. + * + * Unlike [multiagent], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("multiagent") + @ExcludeMissing + fun _multiagent(): JsonField = multiagent + /** * Returns the raw JSON value of [name]. * @@ -921,6 +1000,7 @@ private constructor( null private var metadata: JsonField = JsonMissing.of() private var model: JsonField = JsonMissing.of() + private var multiagent: JsonField = JsonMissing.of() private var name: JsonField = JsonMissing.of() private var skills: JsonField>? = null private var system: JsonField = JsonMissing.of() @@ -934,6 +1014,7 @@ private constructor( mcpServers = body.mcpServers.map { it.toMutableList() } metadata = body.metadata model = body.model + multiagent = body.multiagent name = body.name skills = body.skills.map { it.toMutableList() } system = body.system @@ -1061,6 +1142,45 @@ private constructor( Model.ofBetaManagedAgentsModelConfigParams(betaManagedAgentsModelConfigParams) ) + /** + * A coordinator topology: the session's primary thread orchestrates work by spawning + * session threads, each running an agent drawn from the `agents` roster. + */ + fun multiagent(multiagent: BetaManagedAgentsMultiagentParams?) = + multiagent(JsonField.ofNullable(multiagent)) + + /** Alias for calling [Builder.multiagent] with `multiagent.orElse(null)`. */ + fun multiagent(multiagent: Optional) = + multiagent(multiagent.getOrNull()) + + /** + * Sets [Builder.multiagent] to an arbitrary JSON value. + * + * You should usually call [Builder.multiagent] with a well-typed + * [BetaManagedAgentsMultiagentParams] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun multiagent(multiagent: JsonField) = apply { + this.multiagent = multiagent + } + + /** + * Alias for calling [multiagent] with the following: + * ```java + * BetaManagedAgentsMultiagentParams.builder() + * .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + * .agents(agents) + * .build() + * ``` + */ + fun coordinatorMultiagent(agents: List) = + multiagent( + BetaManagedAgentsMultiagentParams.builder() + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .agents(agents) + .build() + ) + /** Human-readable name. 1-256 characters. Omit to preserve. Cannot be cleared. */ fun name(name: String) = name(JsonField.of(name)) @@ -1272,6 +1392,7 @@ private constructor( (mcpServers ?: JsonMissing.of()).map { it.toImmutable() }, metadata, model, + multiagent, name, (skills ?: JsonMissing.of()).map { it.toImmutable() }, system, @@ -1301,6 +1422,7 @@ private constructor( mcpServers().ifPresent { it.forEach { it.validate() } } metadata().ifPresent { it.validate() } model().ifPresent { it.validate() } + multiagent().ifPresent { it.validate() } name() skills().ifPresent { it.forEach { it.validate() } } system() @@ -1329,6 +1451,7 @@ private constructor( (mcpServers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (metadata.asKnown().getOrNull()?.validity() ?: 0) + (model.asKnown().getOrNull()?.validity() ?: 0) + + (multiagent.asKnown().getOrNull()?.validity() ?: 0) + (if (name.asKnown().isPresent) 1 else 0) + (skills.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (system.asKnown().isPresent) 1 else 0) + @@ -1345,6 +1468,7 @@ private constructor( mcpServers == other.mcpServers && metadata == other.metadata && model == other.model && + multiagent == other.multiagent && name == other.name && skills == other.skills && system == other.system && @@ -1359,6 +1483,7 @@ private constructor( mcpServers, metadata, model, + multiagent, name, skills, system, @@ -1370,7 +1495,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Body{version=$version, description=$description, mcpServers=$mcpServers, metadata=$metadata, model=$model, name=$name, skills=$skills, system=$system, tools=$tools, additionalProperties=$additionalProperties}" + "Body{version=$version, description=$description, mcpServers=$mcpServers, metadata=$metadata, model=$model, multiagent=$multiagent, name=$name, skills=$skills, system=$system, tools=$tools, additionalProperties=$additionalProperties}" } /** diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgent.kt index f3c48ef7f..3552445a4 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgent.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgent.kt @@ -14,6 +14,7 @@ import com.anthropic.core.checkRequired import com.anthropic.core.getOrThrow import com.anthropic.core.toImmutable import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagent import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator @@ -42,6 +43,7 @@ private constructor( private val mcpServers: JsonField>, private val metadata: JsonField, private val model: JsonField, + private val multiagent: JsonField, private val name: JsonField, private val skills: JsonField>, private val system: JsonField, @@ -71,6 +73,9 @@ private constructor( @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of(), + @JsonProperty("multiagent") + @ExcludeMissing + multiagent: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("skills") @ExcludeMissing skills: JsonField> = JsonMissing.of(), @JsonProperty("system") @ExcludeMissing system: JsonField = JsonMissing.of(), @@ -88,6 +93,7 @@ private constructor( mcpServers, metadata, model, + multiagent, name, skills, system, @@ -147,6 +153,14 @@ private constructor( */ fun model(): BetaManagedAgentsModelConfig = model.getRequired("model") + /** + * Resolved coordinator topology with a concrete agent roster. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun multiagent(): Optional = multiagent.getOptional("multiagent") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -250,6 +264,15 @@ private constructor( @ExcludeMissing fun _model(): JsonField = model + /** + * Returns the raw JSON value of [multiagent]. + * + * Unlike [multiagent], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("multiagent") + @ExcludeMissing + fun _multiagent(): JsonField = multiagent + /** * Returns the raw JSON value of [name]. * @@ -327,6 +350,7 @@ private constructor( * .mcpServers() * .metadata() * .model() + * .multiagent() * .name() * .skills() * .system() @@ -350,6 +374,7 @@ private constructor( null private var metadata: JsonField? = null private var model: JsonField? = null + private var multiagent: JsonField? = null private var name: JsonField? = null private var skills: JsonField>? = null private var system: JsonField? = null @@ -368,6 +393,7 @@ private constructor( mcpServers = betaManagedAgentsAgent.mcpServers.map { it.toMutableList() } metadata = betaManagedAgentsAgent.metadata model = betaManagedAgentsAgent.model + multiagent = betaManagedAgentsAgent.multiagent name = betaManagedAgentsAgent.name skills = betaManagedAgentsAgent.skills.map { it.toMutableList() } system = betaManagedAgentsAgent.system @@ -481,6 +507,42 @@ private constructor( */ fun model(model: JsonField) = apply { this.model = model } + /** Resolved coordinator topology with a concrete agent roster. */ + fun multiagent(multiagent: BetaManagedAgentsMultiagent?) = + multiagent(JsonField.ofNullable(multiagent)) + + /** Alias for calling [Builder.multiagent] with `multiagent.orElse(null)`. */ + fun multiagent(multiagent: Optional) = + multiagent(multiagent.getOrNull()) + + /** + * Sets [Builder.multiagent] to an arbitrary JSON value. + * + * You should usually call [Builder.multiagent] with a well-typed + * [BetaManagedAgentsMultiagent] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun multiagent(multiagent: JsonField) = apply { + this.multiagent = multiagent + } + + /** + * Alias for calling [multiagent] with the following: + * ```java + * BetaManagedAgentsMultiagent.builder() + * .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + * .agents(agents) + * .build() + * ``` + */ + fun coordinatorMultiagent(agents: List) = + multiagent( + BetaManagedAgentsMultiagent.builder() + .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + .agents(agents) + .build() + ) + fun name(name: String) = name(JsonField.of(name)) /** @@ -636,6 +698,7 @@ private constructor( * .mcpServers() * .metadata() * .model() + * .multiagent() * .name() * .skills() * .system() @@ -656,6 +719,7 @@ private constructor( checkRequired("mcpServers", mcpServers).map { it.toImmutable() }, checkRequired("metadata", metadata), checkRequired("model", model), + checkRequired("multiagent", multiagent), checkRequired("name", name), checkRequired("skills", skills).map { it.toImmutable() }, checkRequired("system", system), @@ -689,6 +753,7 @@ private constructor( mcpServers().forEach { it.validate() } metadata().validate() model().validate() + multiagent().ifPresent { it.validate() } name() skills().forEach { it.validate() } system() @@ -721,6 +786,7 @@ private constructor( (mcpServers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (metadata.asKnown().getOrNull()?.validity() ?: 0) + (model.asKnown().getOrNull()?.validity() ?: 0) + + (multiagent.asKnown().getOrNull()?.validity() ?: 0) + (if (name.asKnown().isPresent) 1 else 0) + (skills.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (system.asKnown().isPresent) 1 else 0) + @@ -1448,6 +1514,7 @@ private constructor( mcpServers == other.mcpServers && metadata == other.metadata && model == other.model && + multiagent == other.multiagent && name == other.name && skills == other.skills && system == other.system && @@ -1467,6 +1534,7 @@ private constructor( mcpServers, metadata, model, + multiagent, name, skills, system, @@ -1481,5 +1549,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "BetaManagedAgentsAgent{id=$id, archivedAt=$archivedAt, createdAt=$createdAt, description=$description, mcpServers=$mcpServers, metadata=$metadata, model=$model, name=$name, skills=$skills, system=$system, tools=$tools, type=$type, updatedAt=$updatedAt, version=$version, additionalProperties=$additionalProperties}" + "BetaManagedAgentsAgent{id=$id, archivedAt=$archivedAt, createdAt=$createdAt, description=$description, mcpServers=$mcpServers, metadata=$metadata, model=$model, multiagent=$multiagent, name=$name, skills=$skills, system=$system, tools=$tools, type=$type, updatedAt=$updatedAt, version=$version, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgentReference.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgentReference.kt new file mode 100644 index 000000000..6f16c3379 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgentReference.kt @@ -0,0 +1,382 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.agents + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** A resolved agent reference with a concrete version. */ +class BetaManagedAgentsAgentReference +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val type: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(id, type, version, mutableMapOf()) + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun version(): Int = version.getRequired("version") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BetaManagedAgentsAgentReference]. + * + * The following fields are required: + * ```java + * .id() + * .type() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsAgentReference]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var type: JsonField? = null + private var version: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaManagedAgentsAgentReference: BetaManagedAgentsAgentReference) = + apply { + id = betaManagedAgentsAgentReference.id + type = betaManagedAgentsAgentReference.type + version = betaManagedAgentsAgentReference.version + additionalProperties = + betaManagedAgentsAgentReference.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun 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 version(version: Int) = version(JsonField.of(version)) + + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [Int] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun version(version: JsonField) = apply { this.version = version } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaManagedAgentsAgentReference]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .type() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsAgentReference = + BetaManagedAgentsAgentReference( + checkRequired("id", id), + checkRequired("type", type), + checkRequired("version", version), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsAgentReference = apply { + if (validated) { + return@apply + } + + id() + type().validate() + version() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) + + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val AGENT = of("agent") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + AGENT + } + + /** + * 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 { + AGENT, + /** 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) { + AGENT -> Value.AGENT + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + AGENT -> Known.AGENT + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsAgentReference && + id == other.id && + type == other.type && + version == other.version && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(id, type, version, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsAgentReference{id=$id, type=$type, version=$version, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinator.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinator.kt new file mode 100644 index 000000000..b85311282 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinator.kt @@ -0,0 +1,376 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.agents + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkKnown +import com.anthropic.core.checkRequired +import com.anthropic.core.toImmutable +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** Resolved coordinator topology with a concrete agent roster. */ +class BetaManagedAgentsMultiagentCoordinator +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val agents: JsonField>, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("agents") + @ExcludeMissing + agents: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(agents, type, mutableMapOf()) + + /** + * Agents the coordinator may spawn as session threads, each resolved to a specific version. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun agents(): List = agents.getRequired("agents") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [agents]. + * + * Unlike [agents], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("agents") + @ExcludeMissing + fun _agents(): JsonField> = agents + + /** + * 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 + * [BetaManagedAgentsMultiagentCoordinator]. + * + * The following fields are required: + * ```java + * .agents() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsMultiagentCoordinator]. */ + class Builder internal constructor() { + + private var agents: JsonField>? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsMultiagentCoordinator: BetaManagedAgentsMultiagentCoordinator + ) = apply { + agents = betaManagedAgentsMultiagentCoordinator.agents.map { it.toMutableList() } + type = betaManagedAgentsMultiagentCoordinator.type + additionalProperties = + betaManagedAgentsMultiagentCoordinator.additionalProperties.toMutableMap() + } + + /** + * Agents the coordinator may spawn as session threads, each resolved to a specific version. + */ + fun agents(agents: List) = agents(JsonField.of(agents)) + + /** + * Sets [Builder.agents] to an arbitrary JSON value. + * + * You should usually call [Builder.agents] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun agents(agents: JsonField>) = apply { + this.agents = agents.map { it.toMutableList() } + } + + /** + * Adds a single [BetaManagedAgentsAgentReference] to [agents]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAgent(agent: BetaManagedAgentsAgentReference) = apply { + agents = + (agents ?: JsonField.of(mutableListOf())).also { + checkKnown("agents", it).add(agent) + } + } + + 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 [BetaManagedAgentsMultiagentCoordinator]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .agents() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsMultiagentCoordinator = + BetaManagedAgentsMultiagentCoordinator( + checkRequired("agents", agents).map { it.toImmutable() }, + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsMultiagentCoordinator = apply { + if (validated) { + return@apply + } + + agents().forEach { it.validate() } + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (agents.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 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 COORDINATOR = of("coordinator") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + COORDINATOR + } + + /** + * 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 { + COORDINATOR, + /** 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) { + COORDINATOR -> Value.COORDINATOR + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + COORDINATOR -> Known.COORDINATOR + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsMultiagentCoordinator && + agents == other.agents && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(agents, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsMultiagentCoordinator{agents=$agents, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinatorParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinatorParams.kt new file mode 100644 index 000000000..997a71416 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinatorParams.kt @@ -0,0 +1,413 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.agents + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkKnown +import com.anthropic.core.checkRequired +import com.anthropic.core.toImmutable +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.models.beta.sessions.BetaManagedAgentsAgentParams +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagentRosterEntryParams +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 kotlin.jvm.optionals.getOrNull + +/** + * A coordinator topology: the session's primary thread orchestrates work by spawning session + * threads, each running an agent drawn from the `agents` roster. + */ +class BetaManagedAgentsMultiagentCoordinatorParams +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val agents: JsonField>, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("agents") + @ExcludeMissing + agents: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(agents, type, mutableMapOf()) + + /** + * Agents the coordinator may spawn as session threads. 1–20 entries. Each entry is an agent ID + * string, a versioned `{"type":"agent","id","version"}` reference, or `{"type":"self"}` to + * allow recursive self-invocation. Entries must reference distinct agents (after resolving + * `self` and string forms); at most one `self`. Referenced agents must exist, must not be + * archived, and must not themselves have `multiagent` set (depth limit 1). + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun agents(): List = agents.getRequired("agents") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [agents]. + * + * Unlike [agents], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("agents") + @ExcludeMissing + fun _agents(): JsonField> = agents + + /** + * 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 + * [BetaManagedAgentsMultiagentCoordinatorParams]. + * + * The following fields are required: + * ```java + * .agents() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsMultiagentCoordinatorParams]. */ + class Builder internal constructor() { + + private var agents: JsonField>? = + null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsMultiagentCoordinatorParams: + BetaManagedAgentsMultiagentCoordinatorParams + ) = apply { + agents = betaManagedAgentsMultiagentCoordinatorParams.agents.map { it.toMutableList() } + type = betaManagedAgentsMultiagentCoordinatorParams.type + additionalProperties = + betaManagedAgentsMultiagentCoordinatorParams.additionalProperties.toMutableMap() + } + + /** + * Agents the coordinator may spawn as session threads. 1–20 entries. Each entry is an agent + * ID string, a versioned `{"type":"agent","id","version"}` reference, or `{"type":"self"}` + * to allow recursive self-invocation. Entries must reference distinct agents (after + * resolving `self` and string forms); at most one `self`. Referenced agents must exist, + * must not be archived, and must not themselves have `multiagent` set (depth limit 1). + */ + fun agents(agents: List) = + agents(JsonField.of(agents)) + + /** + * Sets [Builder.agents] to an arbitrary JSON value. + * + * You should usually call [Builder.agents] with a well-typed + * `List` value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun agents(agents: JsonField>) = apply { + this.agents = agents.map { it.toMutableList() } + } + + /** + * Adds a single [BetaManagedAgentsMultiagentRosterEntryParams] to [agents]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAgent(agent: BetaManagedAgentsMultiagentRosterEntryParams) = apply { + agents = + (agents ?: JsonField.of(mutableListOf())).also { + checkKnown("agents", it).add(agent) + } + } + + /** + * Alias for calling [addAgent] with + * `BetaManagedAgentsMultiagentRosterEntryParams.ofString(string)`. + */ + fun addAgent(string: String) = + addAgent(BetaManagedAgentsMultiagentRosterEntryParams.ofString(string)) + + /** + * Alias for calling [addAgent] with + * `BetaManagedAgentsMultiagentRosterEntryParams.ofAgent(agent)`. + */ + fun addAgent(agent: BetaManagedAgentsAgentParams) = + addAgent(BetaManagedAgentsMultiagentRosterEntryParams.ofAgent(agent)) + + /** + * Alias for calling [addAgent] with + * `BetaManagedAgentsMultiagentRosterEntryParams.ofSelf(self)`. + */ + fun addAgent(self: BetaManagedAgentsMultiagentSelfParams) = + addAgent(BetaManagedAgentsMultiagentRosterEntryParams.ofSelf(self)) + + 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 [BetaManagedAgentsMultiagentCoordinatorParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .agents() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsMultiagentCoordinatorParams = + BetaManagedAgentsMultiagentCoordinatorParams( + checkRequired("agents", agents).map { it.toImmutable() }, + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsMultiagentCoordinatorParams = apply { + if (validated) { + return@apply + } + + agents().forEach { it.validate() } + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (agents.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 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 COORDINATOR = of("coordinator") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + COORDINATOR + } + + /** + * 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 { + COORDINATOR, + /** 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) { + COORDINATOR -> Value.COORDINATOR + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + COORDINATOR -> Known.COORDINATOR + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsMultiagentCoordinatorParams && + agents == other.agents && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(agents, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsMultiagentCoordinatorParams{agents=$agents, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentSelfParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentSelfParams.kt new file mode 100644 index 000000000..d2aff641d --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentSelfParams.kt @@ -0,0 +1,318 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.agents + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** + * Sentinel roster entry meaning "the agent that owns this configuration". Resolved server-side to a + * concrete agent reference. + */ +class BetaManagedAgentsMultiagentSelfParams +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of() + ) : this(type, mutableMapOf()) + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [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 + * [BetaManagedAgentsMultiagentSelfParams]. + * + * The following fields are required: + * ```java + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsMultiagentSelfParams]. */ + class Builder internal constructor() { + + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsMultiagentSelfParams: BetaManagedAgentsMultiagentSelfParams + ) = apply { + type = betaManagedAgentsMultiagentSelfParams.type + additionalProperties = + betaManagedAgentsMultiagentSelfParams.additionalProperties.toMutableMap() + } + + 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 [BetaManagedAgentsMultiagentSelfParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsMultiagentSelfParams = + BetaManagedAgentsMultiagentSelfParams( + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsMultiagentSelfParams = apply { + if (validated) { + return@apply + } + + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (type.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 SELF = of("self") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SELF + } + + /** + * 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 { + SELF, + /** 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) { + SELF -> Value.SELF + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SELF -> Known.SELF + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsMultiagentSelfParams && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsMultiagentSelfParams{type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationContentBlockLocation.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationContentBlockLocation.kt index f973bf2ee..2951d2942 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationContentBlockLocation.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationContentBlockLocation.kt @@ -68,6 +68,13 @@ private constructor( .build() /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined together. + * The text block is the minimal citable unit; this field is never a substring of a single + * block. Not counted toward output tokens, and not counted toward input tokens when sent back + * in subsequent turns. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -86,6 +93,11 @@ private constructor( fun documentTitle(): Optional = documentTitle.getOptional("document_title") /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -98,6 +110,8 @@ private constructor( fun fileId(): Optional = fileId.getOptional("file_id") /** + * 0-based index of the first cited block in the source's `content` array. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -221,6 +235,14 @@ private constructor( betaCitationContentBlockLocation.additionalProperties.toMutableMap() } + /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined + * together. The text block is the minimal citable unit; this field is never a substring of + * a single block. Not counted toward output tokens, and not counted toward input tokens + * when sent back in subsequent turns. + */ fun citedText(citedText: String) = citedText(JsonField.of(citedText)) /** @@ -263,6 +285,12 @@ private constructor( this.documentTitle = documentTitle } + /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + */ fun endBlockIndex(endBlockIndex: Long) = endBlockIndex(JsonField.of(endBlockIndex)) /** @@ -289,6 +317,7 @@ private constructor( */ fun fileId(fileId: JsonField) = apply { this.fileId = fileId } + /** 0-based index of the first cited block in the source's `content` array. */ fun startBlockIndex(startBlockIndex: Long) = startBlockIndex(JsonField.of(startBlockIndex)) /** diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationContentBlockLocationParam.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationContentBlockLocationParam.kt index 2ffb3366c..f6d734ac7 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationContentBlockLocationParam.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationContentBlockLocationParam.kt @@ -56,6 +56,13 @@ private constructor( ) /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined together. + * The text block is the minimal citable unit; this field is never a substring of a single + * block. Not counted toward output tokens, and not counted toward input tokens when sent back + * in subsequent turns. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -74,12 +81,19 @@ private constructor( fun documentTitle(): Optional = documentTitle.getOptional("document_title") /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun endBlockIndex(): Long = endBlockIndex.getRequired("end_block_index") /** + * 0-based index of the first cited block in the source's `content` array. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -194,6 +208,14 @@ private constructor( betaCitationContentBlockLocationParam.additionalProperties.toMutableMap() } + /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined + * together. The text block is the minimal citable unit; this field is never a substring of + * a single block. Not counted toward output tokens, and not counted toward input tokens + * when sent back in subsequent turns. + */ fun citedText(citedText: String) = citedText(JsonField.of(citedText)) /** @@ -236,6 +258,12 @@ private constructor( this.documentTitle = documentTitle } + /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + */ fun endBlockIndex(endBlockIndex: Long) = endBlockIndex(JsonField.of(endBlockIndex)) /** @@ -249,6 +277,7 @@ private constructor( this.endBlockIndex = endBlockIndex } + /** 0-based index of the first cited block in the source's `content` array. */ fun startBlockIndex(startBlockIndex: Long) = startBlockIndex(JsonField.of(startBlockIndex)) /** diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationSearchResultLocation.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationSearchResultLocation.kt index 9ca339d76..d4749f54c 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationSearchResultLocation.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationSearchResultLocation.kt @@ -67,18 +67,36 @@ private constructor( .build() /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined together. + * The text block is the minimal citable unit; this field is never a substring of a single + * block. Not counted toward output tokens, and not counted toward input tokens when sent back + * in subsequent turns. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun citedText(): String = citedText.getRequired("cited_text") /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun endBlockIndex(): Long = endBlockIndex.getRequired("end_block_index") /** + * 0-based index of the cited search result among all `search_result` content blocks in the + * request, in the order they appear across messages and tool results. + * + * Counted separately from `document_index`; server-side web search results are not included in + * this count. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -91,6 +109,8 @@ private constructor( fun source(): String = source.getRequired("source") /** + * 0-based index of the first cited block in the source's `content` array. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -219,6 +239,14 @@ private constructor( betaCitationSearchResultLocation.additionalProperties.toMutableMap() } + /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined + * together. The text block is the minimal citable unit; this field is never a substring of + * a single block. Not counted toward output tokens, and not counted toward input tokens + * when sent back in subsequent turns. + */ fun citedText(citedText: String) = citedText(JsonField.of(citedText)) /** @@ -230,6 +258,12 @@ private constructor( */ fun citedText(citedText: JsonField) = apply { this.citedText = citedText } + /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + */ fun endBlockIndex(endBlockIndex: Long) = endBlockIndex(JsonField.of(endBlockIndex)) /** @@ -243,6 +277,13 @@ private constructor( this.endBlockIndex = endBlockIndex } + /** + * 0-based index of the cited search result among all `search_result` content blocks in the + * request, in the order they appear across messages and tool results. + * + * Counted separately from `document_index`; server-side web search results are not included + * in this count. + */ fun searchResultIndex(searchResultIndex: Long) = searchResultIndex(JsonField.of(searchResultIndex)) @@ -267,6 +308,7 @@ private constructor( */ fun source(source: JsonField) = apply { this.source = source } + /** 0-based index of the first cited block in the source's `content` array. */ fun startBlockIndex(startBlockIndex: Long) = startBlockIndex(JsonField.of(startBlockIndex)) /** diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationSearchResultLocationParam.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationSearchResultLocationParam.kt index 8aed61987..4641eac37 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationSearchResultLocationParam.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCitationSearchResultLocationParam.kt @@ -57,18 +57,36 @@ private constructor( ) /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined together. + * The text block is the minimal citable unit; this field is never a substring of a single + * block. Not counted toward output tokens, and not counted toward input tokens when sent back + * in subsequent turns. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun citedText(): String = citedText.getRequired("cited_text") /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun endBlockIndex(): Long = endBlockIndex.getRequired("end_block_index") /** + * 0-based index of the cited search result among all `search_result` content blocks in the + * request, in the order they appear across messages and tool results. + * + * Counted separately from `document_index`; server-side web search results are not included in + * this count. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -81,6 +99,8 @@ private constructor( fun source(): String = source.getRequired("source") /** + * 0-based index of the first cited block in the source's `content` array. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -210,6 +230,14 @@ private constructor( betaCitationSearchResultLocationParam.additionalProperties.toMutableMap() } + /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined + * together. The text block is the minimal citable unit; this field is never a substring of + * a single block. Not counted toward output tokens, and not counted toward input tokens + * when sent back in subsequent turns. + */ fun citedText(citedText: String) = citedText(JsonField.of(citedText)) /** @@ -221,6 +249,12 @@ private constructor( */ fun citedText(citedText: JsonField) = apply { this.citedText = citedText } + /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + */ fun endBlockIndex(endBlockIndex: Long) = endBlockIndex(JsonField.of(endBlockIndex)) /** @@ -234,6 +268,13 @@ private constructor( this.endBlockIndex = endBlockIndex } + /** + * 0-based index of the cited search result among all `search_result` content blocks in the + * request, in the order they appear across messages and tool results. + * + * Counted separately from `document_index`; server-side web search results are not included + * in this count. + */ fun searchResultIndex(searchResultIndex: Long) = searchResultIndex(JsonField.of(searchResultIndex)) @@ -258,6 +299,7 @@ private constructor( */ fun source(source: JsonField) = apply { this.source = source } + /** 0-based index of the first cited block in the source's `content` array. */ fun startBlockIndex(startBlockIndex: Long) = startBlockIndex(JsonField.of(startBlockIndex)) /** diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagent.kt new file mode 100644 index 000000000..ec44e8602 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagent.kt @@ -0,0 +1,373 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkKnown +import com.anthropic.core.checkRequired +import com.anthropic.core.toImmutable +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentReference +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 kotlin.jvm.optionals.getOrNull + +/** Resolved coordinator topology with a concrete agent roster. */ +class BetaManagedAgentsMultiagent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val agents: JsonField>, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("agents") + @ExcludeMissing + agents: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(agents, type, mutableMapOf()) + + /** + * Agents the coordinator may spawn as session threads, each resolved to a specific version. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun agents(): List = agents.getRequired("agents") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [agents]. + * + * Unlike [agents], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("agents") + @ExcludeMissing + fun _agents(): JsonField> = agents + + /** + * 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 [BetaManagedAgentsMultiagent]. + * + * The following fields are required: + * ```java + * .agents() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsMultiagent]. */ + class Builder internal constructor() { + + private var agents: JsonField>? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaManagedAgentsMultiagent: BetaManagedAgentsMultiagent) = apply { + agents = betaManagedAgentsMultiagent.agents.map { it.toMutableList() } + type = betaManagedAgentsMultiagent.type + additionalProperties = betaManagedAgentsMultiagent.additionalProperties.toMutableMap() + } + + /** + * Agents the coordinator may spawn as session threads, each resolved to a specific version. + */ + fun agents(agents: List) = agents(JsonField.of(agents)) + + /** + * Sets [Builder.agents] to an arbitrary JSON value. + * + * You should usually call [Builder.agents] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun agents(agents: JsonField>) = apply { + this.agents = agents.map { it.toMutableList() } + } + + /** + * Adds a single [BetaManagedAgentsAgentReference] to [agents]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAgent(agent: BetaManagedAgentsAgentReference) = apply { + agents = + (agents ?: JsonField.of(mutableListOf())).also { + checkKnown("agents", it).add(agent) + } + } + + 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 [BetaManagedAgentsMultiagent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .agents() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsMultiagent = + BetaManagedAgentsMultiagent( + checkRequired("agents", agents).map { it.toImmutable() }, + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsMultiagent = apply { + if (validated) { + return@apply + } + + agents().forEach { it.validate() } + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (agents.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 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 COORDINATOR = of("coordinator") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + COORDINATOR + } + + /** + * 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 { + COORDINATOR, + /** 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) { + COORDINATOR -> Value.COORDINATOR + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + COORDINATOR -> Known.COORDINATOR + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsMultiagent && + agents == other.agents && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(agents, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsMultiagent{agents=$agents, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentParams.kt new file mode 100644 index 000000000..c34398cfe --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentParams.kt @@ -0,0 +1,410 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkKnown +import com.anthropic.core.checkRequired +import com.anthropic.core.toImmutable +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.models.beta.agents.BetaManagedAgentsMultiagentSelfParams +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 kotlin.jvm.optionals.getOrNull + +/** + * A coordinator topology: the session's primary thread orchestrates work by spawning session + * threads, each running an agent drawn from the `agents` roster. + */ +class BetaManagedAgentsMultiagentParams +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val agents: JsonField>, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("agents") + @ExcludeMissing + agents: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(agents, type, mutableMapOf()) + + /** + * Agents the coordinator may spawn as session threads. 1–20 entries. Each entry is an agent ID + * string, a versioned `{"type":"agent","id","version"}` reference, or `{"type":"self"}` to + * allow recursive self-invocation. Entries must reference distinct agents (after resolving + * `self` and string forms); at most one `self`. Referenced agents must exist, must not be + * archived, and must not themselves have `multiagent` set (depth limit 1). + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun agents(): List = agents.getRequired("agents") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [agents]. + * + * Unlike [agents], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("agents") + @ExcludeMissing + fun _agents(): JsonField> = agents + + /** + * 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 + * [BetaManagedAgentsMultiagentParams]. + * + * The following fields are required: + * ```java + * .agents() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsMultiagentParams]. */ + class Builder internal constructor() { + + private var agents: JsonField>? = + null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaManagedAgentsMultiagentParams: BetaManagedAgentsMultiagentParams) = + apply { + agents = betaManagedAgentsMultiagentParams.agents.map { it.toMutableList() } + type = betaManagedAgentsMultiagentParams.type + additionalProperties = + betaManagedAgentsMultiagentParams.additionalProperties.toMutableMap() + } + + /** + * Agents the coordinator may spawn as session threads. 1–20 entries. Each entry is an agent + * ID string, a versioned `{"type":"agent","id","version"}` reference, or `{"type":"self"}` + * to allow recursive self-invocation. Entries must reference distinct agents (after + * resolving `self` and string forms); at most one `self`. Referenced agents must exist, + * must not be archived, and must not themselves have `multiagent` set (depth limit 1). + */ + fun agents(agents: List) = + agents(JsonField.of(agents)) + + /** + * Sets [Builder.agents] to an arbitrary JSON value. + * + * You should usually call [Builder.agents] with a well-typed + * `List` value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun agents(agents: JsonField>) = apply { + this.agents = agents.map { it.toMutableList() } + } + + /** + * Adds a single [BetaManagedAgentsMultiagentRosterEntryParams] to [agents]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAgent(agent: BetaManagedAgentsMultiagentRosterEntryParams) = apply { + agents = + (agents ?: JsonField.of(mutableListOf())).also { + checkKnown("agents", it).add(agent) + } + } + + /** + * Alias for calling [addAgent] with + * `BetaManagedAgentsMultiagentRosterEntryParams.ofString(string)`. + */ + fun addAgent(string: String) = + addAgent(BetaManagedAgentsMultiagentRosterEntryParams.ofString(string)) + + /** + * Alias for calling [addAgent] with + * `BetaManagedAgentsMultiagentRosterEntryParams.ofAgent(agent)`. + */ + fun addAgent(agent: BetaManagedAgentsAgentParams) = + addAgent(BetaManagedAgentsMultiagentRosterEntryParams.ofAgent(agent)) + + /** + * Alias for calling [addAgent] with + * `BetaManagedAgentsMultiagentRosterEntryParams.ofSelf(self)`. + */ + fun addAgent(self: BetaManagedAgentsMultiagentSelfParams) = + addAgent(BetaManagedAgentsMultiagentRosterEntryParams.ofSelf(self)) + + 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 [BetaManagedAgentsMultiagentParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .agents() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsMultiagentParams = + BetaManagedAgentsMultiagentParams( + checkRequired("agents", agents).map { it.toImmutable() }, + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsMultiagentParams = apply { + if (validated) { + return@apply + } + + agents().forEach { it.validate() } + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (agents.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 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 COORDINATOR = of("coordinator") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + COORDINATOR + } + + /** + * 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 { + COORDINATOR, + /** 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) { + COORDINATOR -> Value.COORDINATOR + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + COORDINATOR -> Known.COORDINATOR + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsMultiagentParams && + agents == other.agents && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(agents, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsMultiagentParams{agents=$agents, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentRosterEntryParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentRosterEntryParams.kt new file mode 100644 index 000000000..7eaadaa6d --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentRosterEntryParams.kt @@ -0,0 +1,314 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions + +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer +import com.anthropic.core.JsonValue +import com.anthropic.core.allMaxBy +import com.anthropic.core.getOrThrow +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.models.beta.agents.BetaManagedAgentsMultiagentSelfParams +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.Objects +import java.util.Optional + +/** An entry in a multiagent roster: an agent ID string, a versioned agent reference, or `self`. */ +@JsonDeserialize(using = BetaManagedAgentsMultiagentRosterEntryParams.Deserializer::class) +@JsonSerialize(using = BetaManagedAgentsMultiagentRosterEntryParams.Serializer::class) +class BetaManagedAgentsMultiagentRosterEntryParams +private constructor( + private val string: String? = null, + private val agent: BetaManagedAgentsAgentParams? = null, + private val self: BetaManagedAgentsMultiagentSelfParams? = null, + private val _json: JsonValue? = null, +) { + + fun string(): Optional = Optional.ofNullable(string) + + /** + * Specification for an Agent. Provide a specific `version` or use the short-form + * `agent="agent_id"` for the most recent version + */ + fun agent(): Optional = Optional.ofNullable(agent) + + /** + * Sentinel roster entry meaning "the agent that owns this configuration". Resolved server-side + * to a concrete agent reference. + */ + fun self(): Optional = Optional.ofNullable(self) + + fun isString(): Boolean = string != null + + fun isAgent(): Boolean = agent != null + + fun isSelf(): Boolean = self != null + + fun asString(): String = string.getOrThrow("string") + + /** + * Specification for an Agent. Provide a specific `version` or use the short-form + * `agent="agent_id"` for the most recent version + */ + fun asAgent(): BetaManagedAgentsAgentParams = agent.getOrThrow("agent") + + /** + * Sentinel roster entry meaning "the agent that owns this configuration". Resolved server-side + * to a concrete agent reference. + */ + fun asSelf(): BetaManagedAgentsMultiagentSelfParams = self.getOrThrow("self") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, unless + * [visitor] overrides [Visitor.unknown]. To handle variants not known to this version of the + * SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.anthropic.core.JsonValue; + * import java.util.Optional; + * + * Optional result = betaManagedAgentsMultiagentRosterEntryParams.accept(new BetaManagedAgentsMultiagentRosterEntryParams.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 AnthropicInvalidDataException 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) + agent != null -> visitor.visitAgent(agent) + self != null -> visitor.visitSelf(self) + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsMultiagentRosterEntryParams = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitString(string: String) {} + + override fun visitAgent(agent: BetaManagedAgentsAgentParams) { + agent.validate() + } + + override fun visitSelf(self: BetaManagedAgentsMultiagentSelfParams) { + self.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 visitAgent(agent: BetaManagedAgentsAgentParams) = agent.validity() + + override fun visitSelf(self: BetaManagedAgentsMultiagentSelfParams) = + self.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaManagedAgentsMultiagentRosterEntryParams && + string == other.string && + agent == other.agent && + self == other.self + } + + override fun hashCode(): Int = Objects.hash(string, agent, self) + + override fun toString(): String = + when { + string != null -> "BetaManagedAgentsMultiagentRosterEntryParams{string=$string}" + agent != null -> "BetaManagedAgentsMultiagentRosterEntryParams{agent=$agent}" + self != null -> "BetaManagedAgentsMultiagentRosterEntryParams{self=$self}" + _json != null -> "BetaManagedAgentsMultiagentRosterEntryParams{_unknown=$_json}" + else -> + throw IllegalStateException("Invalid BetaManagedAgentsMultiagentRosterEntryParams") + } + + companion object { + + @JvmStatic + fun ofString(string: String) = BetaManagedAgentsMultiagentRosterEntryParams(string = string) + + /** + * Specification for an Agent. Provide a specific `version` or use the short-form + * `agent="agent_id"` for the most recent version + */ + @JvmStatic + fun ofAgent(agent: BetaManagedAgentsAgentParams) = + BetaManagedAgentsMultiagentRosterEntryParams(agent = agent) + + /** + * Sentinel roster entry meaning "the agent that owns this configuration". Resolved + * server-side to a concrete agent reference. + */ + @JvmStatic + fun ofSelf(self: BetaManagedAgentsMultiagentSelfParams) = + BetaManagedAgentsMultiagentRosterEntryParams(self = self) + } + + /** + * An interface that defines how to map each variant of + * [BetaManagedAgentsMultiagentRosterEntryParams] to a value of type [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + /** + * Specification for an Agent. Provide a specific `version` or use the short-form + * `agent="agent_id"` for the most recent version + */ + fun visitAgent(agent: BetaManagedAgentsAgentParams): T + + /** + * Sentinel roster entry meaning "the agent that owns this configuration". Resolved + * server-side to a concrete agent reference. + */ + fun visitSelf(self: BetaManagedAgentsMultiagentSelfParams): T + + /** + * Maps an unknown variant of [BetaManagedAgentsMultiagentRosterEntryParams] to a value of + * type [T]. + * + * An instance of [BetaManagedAgentsMultiagentRosterEntryParams] 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 AnthropicInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw AnthropicInvalidDataException( + "Unknown BetaManagedAgentsMultiagentRosterEntryParams: $json" + ) + } + } + + internal class Deserializer : + BaseDeserializer( + BetaManagedAgentsMultiagentRosterEntryParams::class + ) { + + override fun ObjectCodec.deserialize( + node: JsonNode + ): BetaManagedAgentsMultiagentRosterEntryParams { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + BetaManagedAgentsMultiagentRosterEntryParams(agent = it, _json = json) + }, + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsMultiagentRosterEntryParams( + self = it, + _json = json, + ) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + BetaManagedAgentsMultiagentRosterEntryParams(string = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with all + // the possible variants (e.g. deserializing from boolean). + 0 -> BetaManagedAgentsMultiagentRosterEntryParams(_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( + BetaManagedAgentsMultiagentRosterEntryParams::class + ) { + + override fun serialize( + value: BetaManagedAgentsMultiagentRosterEntryParams, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.agent != null -> generator.writeObject(value.agent) + value.self != null -> generator.writeObject(value.self) + value._json != null -> generator.writeObject(value._json) + else -> + throw IllegalStateException( + "Invalid BetaManagedAgentsMultiagentRosterEntryParams" + ) + } + } + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsOutcomeEvaluationResource.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsOutcomeEvaluationResource.kt new file mode 100644 index 000000000..160c975e0 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsOutcomeEvaluationResource.kt @@ -0,0 +1,588 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +/** Evaluation state for a single outcome defined via a define_outcome event. */ +class BetaManagedAgentsOutcomeEvaluationResource +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val completedAt: JsonField, + private val description: JsonField, + private val explanation: JsonField, + private val iteration: JsonField, + private val outcomeId: JsonField, + private val result: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("completed_at") + @ExcludeMissing + completedAt: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("explanation") + @ExcludeMissing + explanation: JsonField = JsonMissing.of(), + @JsonProperty("iteration") @ExcludeMissing iteration: JsonField = JsonMissing.of(), + @JsonProperty("outcome_id") @ExcludeMissing outcomeId: JsonField = JsonMissing.of(), + @JsonProperty("result") @ExcludeMissing result: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this( + completedAt, + description, + explanation, + iteration, + outcomeId, + result, + type, + mutableMapOf(), + ) + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun completedAt(): Optional = completedAt.getOptional("completed_at") + + /** + * What the agent should produce. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun description(): String = description.getRequired("description") + + /** + * Grader's verdict text from the most recent evaluation. For satisfied, explains why criteria + * are met; for needs_revision (intermediate), what's missing; for failed, why unrecoverable. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun explanation(): Optional = explanation.getOptional("explanation") + + /** + * 0-indexed revision cycle the outcome is currently on. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun iteration(): Int = iteration.getRequired("iteration") + + /** + * Server-generated outc_ ID for this outcome. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun outcomeId(): String = outcomeId.getRequired("outcome_id") + + /** + * Current evaluation state. 'pending' before the agent begins work; 'running' while producing + * or revising; 'evaluating' while the grader scores; + * 'satisfied'/'max_iterations_reached'/'failed'/'interrupted' are terminal. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun result(): String = result.getRequired("result") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [completedAt]. + * + * Unlike [completedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("completed_at") + @ExcludeMissing + fun _completedAt(): JsonField = completedAt + + /** + * Returns the raw JSON value of [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 [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 [iteration]. + * + * Unlike [iteration], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("iteration") @ExcludeMissing fun _iteration(): JsonField = iteration + + /** + * Returns the raw JSON value of [outcomeId]. + * + * Unlike [outcomeId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("outcome_id") @ExcludeMissing fun _outcomeId(): JsonField = outcomeId + + /** + * 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 [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 + * [BetaManagedAgentsOutcomeEvaluationResource]. + * + * The following fields are required: + * ```java + * .completedAt() + * .description() + * .explanation() + * .iteration() + * .outcomeId() + * .result() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsOutcomeEvaluationResource]. */ + class Builder internal constructor() { + + private var completedAt: JsonField? = null + private var description: JsonField? = null + private var explanation: JsonField? = null + private var iteration: JsonField? = null + private var outcomeId: JsonField? = null + private var result: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsOutcomeEvaluationResource: BetaManagedAgentsOutcomeEvaluationResource + ) = apply { + completedAt = betaManagedAgentsOutcomeEvaluationResource.completedAt + description = betaManagedAgentsOutcomeEvaluationResource.description + explanation = betaManagedAgentsOutcomeEvaluationResource.explanation + iteration = betaManagedAgentsOutcomeEvaluationResource.iteration + outcomeId = betaManagedAgentsOutcomeEvaluationResource.outcomeId + result = betaManagedAgentsOutcomeEvaluationResource.result + type = betaManagedAgentsOutcomeEvaluationResource.type + additionalProperties = + betaManagedAgentsOutcomeEvaluationResource.additionalProperties.toMutableMap() + } + + /** A timestamp in RFC 3339 format */ + fun completedAt(completedAt: OffsetDateTime?) = + completedAt(JsonField.ofNullable(completedAt)) + + /** Alias for calling [Builder.completedAt] with `completedAt.orElse(null)`. */ + fun completedAt(completedAt: Optional) = + completedAt(completedAt.getOrNull()) + + /** + * Sets [Builder.completedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.completedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun completedAt(completedAt: JsonField) = apply { + this.completedAt = completedAt + } + + /** What the agent should produce. */ + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** + * Grader's verdict text from the most recent evaluation. For satisfied, explains why + * criteria are met; for needs_revision (intermediate), what's missing; for failed, why + * unrecoverable. + */ + fun explanation(explanation: String?) = explanation(JsonField.ofNullable(explanation)) + + /** Alias for calling [Builder.explanation] with `explanation.orElse(null)`. */ + fun explanation(explanation: Optional) = explanation(explanation.getOrNull()) + + /** + * 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 } + + /** 0-indexed revision cycle the outcome is currently on. */ + fun iteration(iteration: Int) = iteration(JsonField.of(iteration)) + + /** + * Sets [Builder.iteration] to an arbitrary JSON value. + * + * You should usually call [Builder.iteration] with a well-typed [Int] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun iteration(iteration: JsonField) = apply { this.iteration = iteration } + + /** Server-generated outc_ ID for this outcome. */ + fun outcomeId(outcomeId: String) = outcomeId(JsonField.of(outcomeId)) + + /** + * Sets [Builder.outcomeId] to an arbitrary JSON value. + * + * You should usually call [Builder.outcomeId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun outcomeId(outcomeId: JsonField) = apply { this.outcomeId = outcomeId } + + /** + * Current evaluation state. 'pending' before the agent begins work; 'running' while + * producing or revising; 'evaluating' while the grader scores; + * 'satisfied'/'max_iterations_reached'/'failed'/'interrupted' are terminal. + */ + fun result(result: String) = result(JsonField.of(result)) + + /** + * Sets [Builder.result] to an arbitrary JSON value. + * + * You should usually call [Builder.result] with a well-typed [String] 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 } + + 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 [BetaManagedAgentsOutcomeEvaluationResource]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .completedAt() + * .description() + * .explanation() + * .iteration() + * .outcomeId() + * .result() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsOutcomeEvaluationResource = + BetaManagedAgentsOutcomeEvaluationResource( + checkRequired("completedAt", completedAt), + checkRequired("description", description), + checkRequired("explanation", explanation), + checkRequired("iteration", iteration), + checkRequired("outcomeId", outcomeId), + checkRequired("result", result), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsOutcomeEvaluationResource = apply { + if (validated) { + return@apply + } + + completedAt() + description() + explanation() + iteration() + outcomeId() + result() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (completedAt.asKnown().isPresent) 1 else 0) + + (if (description.asKnown().isPresent) 1 else 0) + + (if (explanation.asKnown().isPresent) 1 else 0) + + (if (iteration.asKnown().isPresent) 1 else 0) + + (if (outcomeId.asKnown().isPresent) 1 else 0) + + (if (result.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 OUTCOME_EVALUATION = of("outcome_evaluation") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + OUTCOME_EVALUATION + } + + /** + * 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 { + OUTCOME_EVALUATION, + /** 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) { + OUTCOME_EVALUATION -> Value.OUTCOME_EVALUATION + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + OUTCOME_EVALUATION -> Known.OUTCOME_EVALUATION + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsOutcomeEvaluationResource && + completedAt == other.completedAt && + description == other.description && + explanation == other.explanation && + iteration == other.iteration && + outcomeId == other.outcomeId && + result == other.result && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + completedAt, + description, + explanation, + iteration, + outcomeId, + result, + type, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsOutcomeEvaluationResource{completedAt=$completedAt, description=$description, explanation=$explanation, iteration=$iteration, outcomeId=$outcomeId, result=$result, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSession.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSession.kt index 62065176c..6808cf5f3 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSession.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSession.kt @@ -35,6 +35,7 @@ private constructor( private val createdAt: JsonField, private val environmentId: JsonField, private val metadata: JsonField, + private val outcomeEvaluations: JsonField>, private val resources: JsonField>, private val stats: JsonField, private val status: JsonField, @@ -62,6 +63,10 @@ private constructor( @ExcludeMissing environmentId: JsonField = JsonMissing.of(), @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("outcome_evaluations") + @ExcludeMissing + outcomeEvaluations: JsonField> = + JsonMissing.of(), @JsonProperty("resources") @ExcludeMissing resources: JsonField> = JsonMissing.of(), @@ -87,6 +92,7 @@ private constructor( createdAt, environmentId, metadata, + outcomeEvaluations, resources, stats, status, @@ -141,6 +147,15 @@ private constructor( */ fun metadata(): Metadata = metadata.getRequired("metadata") + /** + * Per-outcome evaluation state. One entry per define_outcome event sent to the session. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun outcomeEvaluations(): List = + outcomeEvaluations.getRequired("outcome_evaluations") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -249,6 +264,17 @@ private constructor( */ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + /** + * Returns the raw JSON value of [outcomeEvaluations]. + * + * Unlike [outcomeEvaluations], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("outcome_evaluations") + @ExcludeMissing + fun _outcomeEvaluations(): JsonField> = + outcomeEvaluations + /** * Returns the raw JSON value of [resources]. * @@ -338,6 +364,7 @@ private constructor( * .createdAt() * .environmentId() * .metadata() + * .outcomeEvaluations() * .resources() * .stats() * .status() @@ -360,6 +387,9 @@ private constructor( private var createdAt: JsonField? = null private var environmentId: JsonField? = null private var metadata: JsonField? = null + private var outcomeEvaluations: + JsonField>? = + null private var resources: JsonField>? = null private var stats: JsonField? = null private var status: JsonField? = null @@ -378,6 +408,8 @@ private constructor( createdAt = betaManagedAgentsSession.createdAt environmentId = betaManagedAgentsSession.environmentId metadata = betaManagedAgentsSession.metadata + outcomeEvaluations = + betaManagedAgentsSession.outcomeEvaluations.map { it.toMutableList() } resources = betaManagedAgentsSession.resources.map { it.toMutableList() } stats = betaManagedAgentsSession.stats status = betaManagedAgentsSession.status @@ -467,6 +499,35 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + /** Per-outcome evaluation state. One entry per define_outcome event sent to the session. */ + fun outcomeEvaluations( + outcomeEvaluations: List + ) = outcomeEvaluations(JsonField.of(outcomeEvaluations)) + + /** + * Sets [Builder.outcomeEvaluations] to an arbitrary JSON value. + * + * You should usually call [Builder.outcomeEvaluations] with a well-typed + * `List` value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun outcomeEvaluations( + outcomeEvaluations: JsonField> + ) = apply { this.outcomeEvaluations = outcomeEvaluations.map { it.toMutableList() } } + + /** + * Adds a single [BetaManagedAgentsOutcomeEvaluationResource] to [outcomeEvaluations]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addOutcomeEvaluation(outcomeEvaluation: BetaManagedAgentsOutcomeEvaluationResource) = + apply { + outcomeEvaluations = + (outcomeEvaluations ?: JsonField.of(mutableListOf())).also { + checkKnown("outcomeEvaluations", it).add(outcomeEvaluation) + } + } + fun resources(resources: List) = resources(JsonField.of(resources)) @@ -656,6 +717,7 @@ private constructor( * .createdAt() * .environmentId() * .metadata() + * .outcomeEvaluations() * .resources() * .stats() * .status() @@ -676,6 +738,7 @@ private constructor( checkRequired("createdAt", createdAt), checkRequired("environmentId", environmentId), checkRequired("metadata", metadata), + checkRequired("outcomeEvaluations", outcomeEvaluations).map { it.toImmutable() }, checkRequired("resources", resources).map { it.toImmutable() }, checkRequired("stats", stats), checkRequired("status", status), @@ -709,6 +772,7 @@ private constructor( createdAt() environmentId() metadata().validate() + outcomeEvaluations().forEach { it.validate() } resources().forEach { it.validate() } stats().validate() status().validate() @@ -741,6 +805,7 @@ private constructor( (if (createdAt.asKnown().isPresent) 1 else 0) + (if (environmentId.asKnown().isPresent) 1 else 0) + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (outcomeEvaluations.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (resources.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (stats.asKnown().getOrNull()?.validity() ?: 0) + (status.asKnown().getOrNull()?.validity() ?: 0) + @@ -1149,6 +1214,7 @@ private constructor( createdAt == other.createdAt && environmentId == other.environmentId && metadata == other.metadata && + outcomeEvaluations == other.outcomeEvaluations && resources == other.resources && stats == other.stats && status == other.status && @@ -1168,6 +1234,7 @@ private constructor( createdAt, environmentId, metadata, + outcomeEvaluations, resources, stats, status, @@ -1183,5 +1250,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "BetaManagedAgentsSession{id=$id, agent=$agent, archivedAt=$archivedAt, createdAt=$createdAt, environmentId=$environmentId, metadata=$metadata, resources=$resources, stats=$stats, status=$status, title=$title, type=$type, updatedAt=$updatedAt, usage=$usage, vaultIds=$vaultIds, additionalProperties=$additionalProperties}" + "BetaManagedAgentsSession{id=$id, agent=$agent, archivedAt=$archivedAt, createdAt=$createdAt, environmentId=$environmentId, metadata=$metadata, outcomeEvaluations=$outcomeEvaluations, resources=$resources, stats=$stats, status=$status, title=$title, type=$type, updatedAt=$updatedAt, usage=$usage, vaultIds=$vaultIds, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionAgent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionAgent.kt index e42b5d440..778899ed7 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionAgent.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionAgent.kt @@ -21,6 +21,7 @@ import com.anthropic.models.beta.agents.BetaManagedAgentsCustomTool import com.anthropic.models.beta.agents.BetaManagedAgentsMcpServerUrlDefinition import com.anthropic.models.beta.agents.BetaManagedAgentsMcpToolset import com.anthropic.models.beta.agents.BetaManagedAgentsModelConfig +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsSessionThreadAgent import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator @@ -47,6 +48,7 @@ private constructor( private val description: JsonField, private val mcpServers: JsonField>, private val model: JsonField, + private val multiagent: JsonField, private val name: JsonField, private val skills: JsonField>, private val system: JsonField, @@ -68,6 +70,9 @@ private constructor( @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of(), + @JsonProperty("multiagent") + @ExcludeMissing + multiagent: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("skills") @ExcludeMissing skills: JsonField> = JsonMissing.of(), @JsonProperty("system") @ExcludeMissing system: JsonField = JsonMissing.of(), @@ -79,6 +84,7 @@ private constructor( description, mcpServers, model, + multiagent, name, skills, system, @@ -115,6 +121,15 @@ private constructor( */ fun model(): BetaManagedAgentsModelConfig = model.getRequired("model") + /** + * Resolved coordinator topology with full agent definitions for each roster member. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun multiagent(): Optional = + multiagent.getOptional("multiagent") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). @@ -183,6 +198,15 @@ private constructor( @ExcludeMissing fun _model(): JsonField = model + /** + * Returns the raw JSON value of [multiagent]. + * + * Unlike [multiagent], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("multiagent") + @ExcludeMissing + fun _multiagent(): JsonField = multiagent + /** * Returns the raw JSON value of [name]. * @@ -249,6 +273,7 @@ private constructor( * .description() * .mcpServers() * .model() + * .multiagent() * .name() * .skills() * .system() @@ -268,6 +293,7 @@ private constructor( private var mcpServers: JsonField>? = null private var model: JsonField? = null + private var multiagent: JsonField? = null private var name: JsonField? = null private var skills: JsonField>? = null private var system: JsonField? = null @@ -282,6 +308,7 @@ private constructor( description = betaManagedAgentsSessionAgent.description mcpServers = betaManagedAgentsSessionAgent.mcpServers.map { it.toMutableList() } model = betaManagedAgentsSessionAgent.model + multiagent = betaManagedAgentsSessionAgent.multiagent name = betaManagedAgentsSessionAgent.name skills = betaManagedAgentsSessionAgent.skills.map { it.toMutableList() } system = betaManagedAgentsSessionAgent.system @@ -354,6 +381,43 @@ private constructor( */ fun model(model: JsonField) = apply { this.model = model } + /** Resolved coordinator topology with full agent definitions for each roster member. */ + fun multiagent(multiagent: BetaManagedAgentsSessionMultiagentCoordinator?) = + multiagent(JsonField.ofNullable(multiagent)) + + /** Alias for calling [Builder.multiagent] with `multiagent.orElse(null)`. */ + fun multiagent(multiagent: Optional) = + multiagent(multiagent.getOrNull()) + + /** + * Sets [Builder.multiagent] to an arbitrary JSON value. + * + * You should usually call [Builder.multiagent] with a well-typed + * [BetaManagedAgentsSessionMultiagentCoordinator] value instead. This method is primarily + * for setting the field to an undocumented or not yet supported value. + */ + fun multiagent(multiagent: JsonField) = + apply { + this.multiagent = multiagent + } + + /** + * Alias for calling [multiagent] with the following: + * ```java + * BetaManagedAgentsSessionMultiagentCoordinator.builder() + * .type(BetaManagedAgentsSessionMultiagentCoordinator.Type.COORDINATOR) + * .agents(agents) + * .build() + * ``` + */ + fun coordinatorMultiagent(agents: List) = + multiagent( + BetaManagedAgentsSessionMultiagentCoordinator.builder() + .type(BetaManagedAgentsSessionMultiagentCoordinator.Type.COORDINATOR) + .agents(agents) + .build() + ) + fun name(name: String) = name(JsonField.of(name)) /** @@ -493,6 +557,7 @@ private constructor( * .description() * .mcpServers() * .model() + * .multiagent() * .name() * .skills() * .system() @@ -509,6 +574,7 @@ private constructor( checkRequired("description", description), checkRequired("mcpServers", mcpServers).map { it.toImmutable() }, checkRequired("model", model), + checkRequired("multiagent", multiagent), checkRequired("name", name), checkRequired("skills", skills).map { it.toImmutable() }, checkRequired("system", system), @@ -538,6 +604,7 @@ private constructor( description() mcpServers().forEach { it.validate() } model().validate() + multiagent().ifPresent { it.validate() } name() skills().forEach { it.validate() } system() @@ -566,6 +633,7 @@ private constructor( (if (description.asKnown().isPresent) 1 else 0) + (mcpServers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (model.asKnown().getOrNull()?.validity() ?: 0) + + (multiagent.asKnown().getOrNull()?.validity() ?: 0) + (if (name.asKnown().isPresent) 1 else 0) + (skills.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (system.asKnown().isPresent) 1 else 0) + @@ -1181,6 +1249,7 @@ private constructor( description == other.description && mcpServers == other.mcpServers && model == other.model && + multiagent == other.multiagent && name == other.name && skills == other.skills && system == other.system && @@ -1196,6 +1265,7 @@ private constructor( description, mcpServers, model, + multiagent, name, skills, system, @@ -1209,5 +1279,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "BetaManagedAgentsSessionAgent{id=$id, description=$description, mcpServers=$mcpServers, model=$model, name=$name, skills=$skills, system=$system, tools=$tools, type=$type, version=$version, additionalProperties=$additionalProperties}" + "BetaManagedAgentsSessionAgent{id=$id, description=$description, mcpServers=$mcpServers, model=$model, multiagent=$multiagent, name=$name, skills=$skills, system=$system, tools=$tools, type=$type, version=$version, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionMultiagentCoordinator.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionMultiagentCoordinator.kt new file mode 100644 index 000000000..bab050a98 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionMultiagentCoordinator.kt @@ -0,0 +1,376 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkKnown +import com.anthropic.core.checkRequired +import com.anthropic.core.toImmutable +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsSessionThreadAgent +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 kotlin.jvm.optionals.getOrNull + +/** Resolved coordinator topology with full agent definitions for each roster member. */ +class BetaManagedAgentsSessionMultiagentCoordinator +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val agents: JsonField>, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("agents") + @ExcludeMissing + agents: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(agents, type, mutableMapOf()) + + /** + * Full `agent` definitions the coordinator may spawn as session threads. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun agents(): List = agents.getRequired("agents") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [agents]. + * + * Unlike [agents], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("agents") + @ExcludeMissing + fun _agents(): JsonField> = agents + + /** + * 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 + * [BetaManagedAgentsSessionMultiagentCoordinator]. + * + * The following fields are required: + * ```java + * .agents() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSessionMultiagentCoordinator]. */ + class Builder internal constructor() { + + private var agents: JsonField>? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsSessionMultiagentCoordinator: + BetaManagedAgentsSessionMultiagentCoordinator + ) = apply { + agents = betaManagedAgentsSessionMultiagentCoordinator.agents.map { it.toMutableList() } + type = betaManagedAgentsSessionMultiagentCoordinator.type + additionalProperties = + betaManagedAgentsSessionMultiagentCoordinator.additionalProperties.toMutableMap() + } + + /** Full `agent` definitions the coordinator may spawn as session threads. */ + fun agents(agents: List) = agents(JsonField.of(agents)) + + /** + * Sets [Builder.agents] to an arbitrary JSON value. + * + * You should usually call [Builder.agents] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun agents(agents: JsonField>) = apply { + this.agents = agents.map { it.toMutableList() } + } + + /** + * Adds a single [BetaManagedAgentsSessionThreadAgent] to [agents]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAgent(agent: BetaManagedAgentsSessionThreadAgent) = apply { + agents = + (agents ?: JsonField.of(mutableListOf())).also { + checkKnown("agents", it).add(agent) + } + } + + 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 [BetaManagedAgentsSessionMultiagentCoordinator]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .agents() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsSessionMultiagentCoordinator = + BetaManagedAgentsSessionMultiagentCoordinator( + checkRequired("agents", agents).map { it.toImmutable() }, + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSessionMultiagentCoordinator = apply { + if (validated) { + return@apply + } + + agents().forEach { it.validate() } + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (agents.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 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 COORDINATOR = of("coordinator") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + COORDINATOR + } + + /** + * 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 { + COORDINATOR, + /** 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) { + COORDINATOR -> Value.COORDINATOR + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + COORDINATOR -> Known.COORDINATOR + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsSessionMultiagentCoordinator && + agents == other.agents && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(agents, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSessionMultiagentCoordinator{agents=$agents, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/SessionListParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/SessionListParams.kt index f3e416ead..071224316 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/SessionListParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/SessionListParams.kt @@ -31,6 +31,7 @@ private constructor( private val memoryStoreId: String?, private val order: Order?, private val page: String?, + private val statuses: List?, private val betas: List?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, @@ -69,6 +70,9 @@ private constructor( /** Opaque pagination cursor from a previous response's next_page. */ fun page(): Optional = Optional.ofNullable(page) + /** Filter by session status. Repeat the parameter to match any of multiple statuses. */ + fun statuses(): Optional> = Optional.ofNullable(statuses) + /** Optional header to specify the beta version(s) you want to use. */ fun betas(): Optional> = Optional.ofNullable(betas) @@ -102,6 +106,7 @@ private constructor( private var memoryStoreId: String? = null private var order: Order? = null private var page: String? = null + private var statuses: MutableList? = null private var betas: MutableList? = null private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @@ -119,6 +124,7 @@ private constructor( memoryStoreId = sessionListParams.memoryStoreId order = sessionListParams.order page = sessionListParams.page + statuses = sessionListParams.statuses?.toMutableList() betas = sessionListParams.betas?.toMutableList() additionalHeaders = sessionListParams.additionalHeaders.toBuilder() additionalQueryParams = sessionListParams.additionalQueryParams.toBuilder() @@ -219,6 +225,21 @@ private constructor( /** Alias for calling [Builder.page] with `page.orElse(null)`. */ fun page(page: Optional) = page(page.getOrNull()) + /** Filter by session status. Repeat the parameter to match any of multiple statuses. */ + fun statuses(statuses: List?) = apply { this.statuses = statuses?.toMutableList() } + + /** Alias for calling [Builder.statuses] with `statuses.orElse(null)`. */ + fun statuses(statuses: Optional>) = statuses(statuses.getOrNull()) + + /** + * Adds a single [Status] to [statuses]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addStatus(status: Status) = apply { + statuses = (statuses ?: mutableListOf()).apply { add(status) } + } + /** Optional header to specify the beta version(s) you want to use. */ fun betas(betas: List?) = apply { this.betas = betas?.toMutableList() } @@ -359,6 +380,7 @@ private constructor( memoryStoreId, order, page, + statuses?.toImmutable(), betas?.toImmutable(), additionalHeaders.build(), additionalQueryParams.build(), @@ -395,6 +417,7 @@ private constructor( memoryStoreId?.let { put("memory_store_id", it) } order?.let { put("order", it.toString()) } page?.let { put("page", it) } + statuses?.forEach { put("statuses[]", it.toString()) } putAll(additionalQueryParams) } .build() @@ -536,6 +559,155 @@ private constructor( override fun toString() = value.toString() } + /** SessionStatus enum */ + 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 RESCHEDULING = of("rescheduling") + + @JvmField val RUNNING = of("running") + + @JvmField val IDLE = of("idle") + + @JvmField val TERMINATED = of("terminated") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + RESCHEDULING, + RUNNING, + IDLE, + TERMINATED, + } + + /** + * 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 { + RESCHEDULING, + RUNNING, + IDLE, + TERMINATED, + /** 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) { + RESCHEDULING -> Value.RESCHEDULING + RUNNING -> Value.RUNNING + IDLE -> Value.IDLE + TERMINATED -> Value.TERMINATED + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + RESCHEDULING -> Known.RESCHEDULING + RUNNING -> Known.RUNNING + IDLE -> Known.IDLE + TERMINATED -> Known.TERMINATED + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 @@ -553,6 +725,7 @@ private constructor( memoryStoreId == other.memoryStoreId && order == other.order && page == other.page && + statuses == other.statuses && betas == other.betas && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams @@ -571,11 +744,12 @@ private constructor( memoryStoreId, order, page, + statuses, betas, additionalHeaders, additionalQueryParams, ) override fun toString() = - "SessionListParams{agentId=$agentId, agentVersion=$agentVersion, createdAtGt=$createdAtGt, createdAtGte=$createdAtGte, createdAtLt=$createdAtLt, createdAtLte=$createdAtLte, includeArchived=$includeArchived, limit=$limit, memoryStoreId=$memoryStoreId, order=$order, page=$page, betas=$betas, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "SessionListParams{agentId=$agentId, agentVersion=$agentVersion, createdAtGt=$createdAtGt, createdAtGte=$createdAtGte, createdAtLt=$createdAtLt, createdAtLte=$createdAtLte, includeArchived=$includeArchived, limit=$limit, memoryStoreId=$memoryStoreId, order=$order, page=$page, statuses=$statuses, betas=$betas, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentCustomToolUseEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentCustomToolUseEvent.kt index 24c58c87a..4532522f5 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentCustomToolUseEvent.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentCustomToolUseEvent.kt @@ -17,6 +17,7 @@ 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 /** @@ -31,6 +32,7 @@ private constructor( private val name: JsonField, private val processedAt: JsonField, private val type: JsonField, + private val sessionThreadId: JsonField, private val additionalProperties: MutableMap, ) { @@ -43,7 +45,10 @@ private constructor( @ExcludeMissing processedAt: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(id, input, name, processedAt, type, mutableMapOf()) + @JsonProperty("session_thread_id") + @ExcludeMissing + sessionThreadId: JsonField = JsonMissing.of(), + ) : this(id, input, name, processedAt, type, sessionThreadId, mutableMapOf()) /** * Unique identifier for this event. @@ -83,6 +88,16 @@ private constructor( */ fun type(): Type = type.getRequired("type") + /** + * When set, this event was cross-posted from a subagent's thread to surface its custom tool use + * on the primary thread's stream. Empty on the thread's own events. Echo this on a + * `user.custom_tool_result` event to route the result back. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun sessionThreadId(): Optional = sessionThreadId.getOptional("session_thread_id") + /** * Returns the raw JSON value of [id]. * @@ -120,6 +135,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** + * Returns the raw JSON value of [sessionThreadId]. + * + * Unlike [sessionThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_thread_id") + @ExcludeMissing + fun _sessionThreadId(): JsonField = sessionThreadId + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -158,6 +182,7 @@ private constructor( private var name: JsonField? = null private var processedAt: JsonField? = null private var type: JsonField? = null + private var sessionThreadId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -169,6 +194,7 @@ private constructor( name = betaManagedAgentsAgentCustomToolUseEvent.name processedAt = betaManagedAgentsAgentCustomToolUseEvent.processedAt type = betaManagedAgentsAgentCustomToolUseEvent.type + sessionThreadId = betaManagedAgentsAgentCustomToolUseEvent.sessionThreadId additionalProperties = betaManagedAgentsAgentCustomToolUseEvent.additionalProperties.toMutableMap() } @@ -230,6 +256,29 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } + /** + * When set, this event was cross-posted from a subagent's thread to surface its custom tool + * use on the primary thread's stream. Empty on the thread's own events. Echo this on a + * `user.custom_tool_result` event to route the result back. + */ + fun sessionThreadId(sessionThreadId: String?) = + sessionThreadId(JsonField.ofNullable(sessionThreadId)) + + /** Alias for calling [Builder.sessionThreadId] with `sessionThreadId.orElse(null)`. */ + fun sessionThreadId(sessionThreadId: Optional) = + sessionThreadId(sessionThreadId.getOrNull()) + + /** + * Sets [Builder.sessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sessionThreadId(sessionThreadId: JsonField) = apply { + this.sessionThreadId = sessionThreadId + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -272,6 +321,7 @@ private constructor( checkRequired("name", name), checkRequired("processedAt", processedAt), checkRequired("type", type), + sessionThreadId, additionalProperties.toMutableMap(), ) } @@ -296,6 +346,7 @@ private constructor( name() processedAt() type().validate() + sessionThreadId() validated = true } @@ -318,7 +369,8 @@ private constructor( (input.asKnown().getOrNull()?.validity() ?: 0) + (if (name.asKnown().isPresent) 1 else 0) + (if (processedAt.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (sessionThreadId.asKnown().isPresent) 1 else 0) /** Input parameters for the tool call. */ class Input @@ -570,15 +622,16 @@ private constructor( name == other.name && processedAt == other.processedAt && type == other.type && + sessionThreadId == other.sessionThreadId && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(id, input, name, processedAt, type, additionalProperties) + Objects.hash(id, input, name, processedAt, type, sessionThreadId, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaManagedAgentsAgentCustomToolUseEvent{id=$id, input=$input, name=$name, processedAt=$processedAt, type=$type, additionalProperties=$additionalProperties}" + "BetaManagedAgentsAgentCustomToolUseEvent{id=$id, input=$input, name=$name, processedAt=$processedAt, type=$type, sessionThreadId=$sessionThreadId, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentMcpToolUseEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentMcpToolUseEvent.kt index 6c6707590..962c399dc 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentMcpToolUseEvent.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentMcpToolUseEvent.kt @@ -31,6 +31,7 @@ private constructor( private val processedAt: JsonField, private val type: JsonField, private val evaluatedPermission: JsonField, + private val sessionThreadId: JsonField, private val additionalProperties: MutableMap, ) { @@ -49,7 +50,20 @@ private constructor( @JsonProperty("evaluated_permission") @ExcludeMissing evaluatedPermission: JsonField = JsonMissing.of(), - ) : this(id, input, mcpServerName, name, processedAt, type, evaluatedPermission, mutableMapOf()) + @JsonProperty("session_thread_id") + @ExcludeMissing + sessionThreadId: JsonField = JsonMissing.of(), + ) : this( + id, + input, + mcpServerName, + name, + processedAt, + type, + evaluatedPermission, + sessionThreadId, + mutableMapOf(), + ) /** * Unique identifier for this event. @@ -106,6 +120,16 @@ private constructor( fun evaluatedPermission(): Optional = evaluatedPermission.getOptional("evaluated_permission") + /** + * When set, this event was cross-posted from a subagent's thread to surface its permission + * request on the primary thread's stream. Empty on the thread's own events. Echo this on a + * `user.tool_confirmation` event to route the approval back. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun sessionThreadId(): Optional = sessionThreadId.getOptional("session_thread_id") + /** * Returns the raw JSON value of [id]. * @@ -162,6 +186,15 @@ private constructor( @ExcludeMissing fun _evaluatedPermission(): JsonField = evaluatedPermission + /** + * Returns the raw JSON value of [sessionThreadId]. + * + * Unlike [sessionThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_thread_id") + @ExcludeMissing + fun _sessionThreadId(): JsonField = sessionThreadId + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -203,6 +236,7 @@ private constructor( private var processedAt: JsonField? = null private var type: JsonField? = null private var evaluatedPermission: JsonField = JsonMissing.of() + private var sessionThreadId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -216,6 +250,7 @@ private constructor( processedAt = betaManagedAgentsAgentMcpToolUseEvent.processedAt type = betaManagedAgentsAgentMcpToolUseEvent.type evaluatedPermission = betaManagedAgentsAgentMcpToolUseEvent.evaluatedPermission + sessionThreadId = betaManagedAgentsAgentMcpToolUseEvent.sessionThreadId additionalProperties = betaManagedAgentsAgentMcpToolUseEvent.additionalProperties.toMutableMap() } @@ -306,6 +341,29 @@ private constructor( this.evaluatedPermission = evaluatedPermission } + /** + * When set, this event was cross-posted from a subagent's thread to surface its permission + * request on the primary thread's stream. Empty on the thread's own events. Echo this on a + * `user.tool_confirmation` event to route the approval back. + */ + fun sessionThreadId(sessionThreadId: String?) = + sessionThreadId(JsonField.ofNullable(sessionThreadId)) + + /** Alias for calling [Builder.sessionThreadId] with `sessionThreadId.orElse(null)`. */ + fun sessionThreadId(sessionThreadId: Optional) = + sessionThreadId(sessionThreadId.getOrNull()) + + /** + * Sets [Builder.sessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sessionThreadId(sessionThreadId: JsonField) = apply { + this.sessionThreadId = sessionThreadId + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -351,6 +409,7 @@ private constructor( checkRequired("processedAt", processedAt), checkRequired("type", type), evaluatedPermission, + sessionThreadId, additionalProperties.toMutableMap(), ) } @@ -377,6 +436,7 @@ private constructor( processedAt() type().validate() evaluatedPermission().ifPresent { it.validate() } + sessionThreadId() validated = true } @@ -401,7 +461,8 @@ private constructor( (if (name.asKnown().isPresent) 1 else 0) + (if (processedAt.asKnown().isPresent) 1 else 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + - (evaluatedPermission.asKnown().getOrNull()?.validity() ?: 0) + (evaluatedPermission.asKnown().getOrNull()?.validity() ?: 0) + + (if (sessionThreadId.asKnown().isPresent) 1 else 0) /** Input parameters for the tool call. */ class Input @@ -803,6 +864,7 @@ private constructor( processedAt == other.processedAt && type == other.type && evaluatedPermission == other.evaluatedPermission && + sessionThreadId == other.sessionThreadId && additionalProperties == other.additionalProperties } @@ -815,6 +877,7 @@ private constructor( processedAt, type, evaluatedPermission, + sessionThreadId, additionalProperties, ) } @@ -822,5 +885,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "BetaManagedAgentsAgentMcpToolUseEvent{id=$id, input=$input, mcpServerName=$mcpServerName, name=$name, processedAt=$processedAt, type=$type, evaluatedPermission=$evaluatedPermission, additionalProperties=$additionalProperties}" + "BetaManagedAgentsAgentMcpToolUseEvent{id=$id, input=$input, mcpServerName=$mcpServerName, name=$name, processedAt=$processedAt, type=$type, evaluatedPermission=$evaluatedPermission, sessionThreadId=$sessionThreadId, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageReceivedEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageReceivedEvent.kt new file mode 100644 index 000000000..6bc253e88 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageReceivedEvent.kt @@ -0,0 +1,1010 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkKnown +import com.anthropic.core.checkRequired +import com.anthropic.core.getOrThrow +import com.anthropic.core.toImmutable +import com.anthropic.errors.AnthropicInvalidDataException +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.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ +class BetaManagedAgentsAgentThreadMessageReceivedEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val content: JsonField>, + private val fromSessionThreadId: JsonField, + private val processedAt: JsonField, + private val type: JsonField, + private val fromAgentName: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField> = JsonMissing.of(), + @JsonProperty("from_session_thread_id") + @ExcludeMissing + fromSessionThreadId: JsonField = JsonMissing.of(), + @JsonProperty("processed_at") + @ExcludeMissing + processedAt: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("from_agent_name") + @ExcludeMissing + fromAgentName: JsonField = JsonMissing.of(), + ) : this(id, content, fromSessionThreadId, processedAt, type, fromAgentName, mutableMapOf()) + + /** + * Unique identifier for this event. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * Message content blocks. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun content(): List = content.getRequired("content") + + /** + * Public `sthr_` ID of the thread that sent the message. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun fromSessionThreadId(): String = fromSessionThreadId.getRequired("from_session_thread_id") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun processedAt(): OffsetDateTime = processedAt.getRequired("processed_at") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Name of the callable agent this message came from. Absent when received from the primary + * agent. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun fromAgentName(): Optional = fromAgentName.getOptional("from_agent_name") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField> = content + + /** + * Returns the raw JSON value of [fromSessionThreadId]. + * + * Unlike [fromSessionThreadId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("from_session_thread_id") + @ExcludeMissing + fun _fromSessionThreadId(): JsonField = fromSessionThreadId + + /** + * Returns the raw JSON value of [processedAt]. + * + * Unlike [processedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processed_at") + @ExcludeMissing + fun _processedAt(): JsonField = processedAt + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [fromAgentName]. + * + * Unlike [fromAgentName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("from_agent_name") + @ExcludeMissing + fun _fromAgentName(): JsonField = fromAgentName + + @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 + * [BetaManagedAgentsAgentThreadMessageReceivedEvent]. + * + * The following fields are required: + * ```java + * .id() + * .content() + * .fromSessionThreadId() + * .processedAt() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsAgentThreadMessageReceivedEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var content: JsonField>? = null + private var fromSessionThreadId: JsonField? = null + private var processedAt: JsonField? = null + private var type: JsonField? = null + private var fromAgentName: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsAgentThreadMessageReceivedEvent: + BetaManagedAgentsAgentThreadMessageReceivedEvent + ) = apply { + id = betaManagedAgentsAgentThreadMessageReceivedEvent.id + content = + betaManagedAgentsAgentThreadMessageReceivedEvent.content.map { it.toMutableList() } + fromSessionThreadId = + betaManagedAgentsAgentThreadMessageReceivedEvent.fromSessionThreadId + processedAt = betaManagedAgentsAgentThreadMessageReceivedEvent.processedAt + type = betaManagedAgentsAgentThreadMessageReceivedEvent.type + fromAgentName = betaManagedAgentsAgentThreadMessageReceivedEvent.fromAgentName + additionalProperties = + betaManagedAgentsAgentThreadMessageReceivedEvent.additionalProperties.toMutableMap() + } + + /** Unique identifier for this event. */ + 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 } + + /** Message content blocks. */ + fun content(content: List) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun content(content: JsonField>) = apply { + this.content = content.map { it.toMutableList() } + } + + /** + * Adds a single [Content] to [Builder.content]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addContent(content: Content) = apply { + this.content = + (this.content ?: JsonField.of(mutableListOf())).also { + checkKnown("content", it).add(content) + } + } + + /** Alias for calling [addContent] with `Content.ofText(text)`. */ + fun addContent(text: BetaManagedAgentsTextBlock) = addContent(Content.ofText(text)) + + /** + * Alias for calling [addContent] with the following: + * ```java + * BetaManagedAgentsTextBlock.builder() + * .type(BetaManagedAgentsTextBlock.Type.TEXT) + * .text(text) + * .build() + * ``` + */ + fun addTextContent(text: String) = + addContent( + BetaManagedAgentsTextBlock.builder() + .type(BetaManagedAgentsTextBlock.Type.TEXT) + .text(text) + .build() + ) + + /** Alias for calling [addContent] with `Content.ofImage(image)`. */ + fun addContent(image: BetaManagedAgentsImageBlock) = addContent(Content.ofImage(image)) + + /** + * Alias for calling [addContent] with the following: + * ```java + * BetaManagedAgentsImageBlock.builder() + * .type(BetaManagedAgentsImageBlock.Type.IMAGE) + * .source(source) + * .build() + * ``` + */ + fun addImageContent(source: BetaManagedAgentsImageBlock.Source) = + addContent( + BetaManagedAgentsImageBlock.builder() + .type(BetaManagedAgentsImageBlock.Type.IMAGE) + .source(source) + .build() + ) + + /** + * Alias for calling [addImageContent] with + * `BetaManagedAgentsImageBlock.Source.ofBase64(base64)`. + */ + fun addImageContent(base64: BetaManagedAgentsBase64ImageSource) = + addImageContent(BetaManagedAgentsImageBlock.Source.ofBase64(base64)) + + /** + * Alias for calling [addImageContent] with `BetaManagedAgentsImageBlock.Source.ofUrl(url)`. + */ + fun addImageContent(url: BetaManagedAgentsUrlImageSource) = + addImageContent(BetaManagedAgentsImageBlock.Source.ofUrl(url)) + + /** + * Alias for calling [addImageContent] with the following: + * ```java + * BetaManagedAgentsUrlImageSource.builder() + * .type(BetaManagedAgentsUrlImageSource.Type.URL) + * .url(url) + * .build() + * ``` + */ + fun addUrlImageContent(url: String) = + addImageContent( + BetaManagedAgentsUrlImageSource.builder() + .type(BetaManagedAgentsUrlImageSource.Type.URL) + .url(url) + .build() + ) + + /** + * Alias for calling [addImageContent] with + * `BetaManagedAgentsImageBlock.Source.ofFile(file)`. + */ + fun addImageContent(file: BetaManagedAgentsFileImageSource) = + addImageContent(BetaManagedAgentsImageBlock.Source.ofFile(file)) + + /** + * Alias for calling [addImageContent] with the following: + * ```java + * BetaManagedAgentsFileImageSource.builder() + * .type(BetaManagedAgentsFileImageSource.Type.FILE) + * .fileId(fileId) + * .build() + * ``` + */ + fun addFileImageContent(fileId: String) = + addImageContent( + BetaManagedAgentsFileImageSource.builder() + .type(BetaManagedAgentsFileImageSource.Type.FILE) + .fileId(fileId) + .build() + ) + + /** Alias for calling [addContent] with `Content.ofDocument(document)`. */ + fun addContent(document: BetaManagedAgentsDocumentBlock) = + addContent(Content.ofDocument(document)) + + /** + * Alias for calling [addContent] with the following: + * ```java + * BetaManagedAgentsDocumentBlock.builder() + * .type(BetaManagedAgentsDocumentBlock.Type.DOCUMENT) + * .source(source) + * .build() + * ``` + */ + fun addDocumentContent(source: BetaManagedAgentsDocumentBlock.Source) = + addContent( + BetaManagedAgentsDocumentBlock.builder() + .type(BetaManagedAgentsDocumentBlock.Type.DOCUMENT) + .source(source) + .build() + ) + + /** + * Alias for calling [addDocumentContent] with + * `BetaManagedAgentsDocumentBlock.Source.ofBase64(base64)`. + */ + fun addDocumentContent(base64: BetaManagedAgentsBase64DocumentSource) = + addDocumentContent(BetaManagedAgentsDocumentBlock.Source.ofBase64(base64)) + + /** + * Alias for calling [addDocumentContent] with + * `BetaManagedAgentsDocumentBlock.Source.ofText(text)`. + */ + fun addDocumentContent(text: BetaManagedAgentsPlainTextDocumentSource) = + addDocumentContent(BetaManagedAgentsDocumentBlock.Source.ofText(text)) + + /** + * Alias for calling [addDocumentContent] with + * `BetaManagedAgentsDocumentBlock.Source.ofUrl(url)`. + */ + fun addDocumentContent(url: BetaManagedAgentsUrlDocumentSource) = + addDocumentContent(BetaManagedAgentsDocumentBlock.Source.ofUrl(url)) + + /** + * Alias for calling [addDocumentContent] with the following: + * ```java + * BetaManagedAgentsUrlDocumentSource.builder() + * .type(BetaManagedAgentsUrlDocumentSource.Type.URL) + * .url(url) + * .build() + * ``` + */ + fun addUrlDocumentContent(url: String) = + addDocumentContent( + BetaManagedAgentsUrlDocumentSource.builder() + .type(BetaManagedAgentsUrlDocumentSource.Type.URL) + .url(url) + .build() + ) + + /** + * Alias for calling [addDocumentContent] with + * `BetaManagedAgentsDocumentBlock.Source.ofFile(file)`. + */ + fun addDocumentContent(file: BetaManagedAgentsFileDocumentSource) = + addDocumentContent(BetaManagedAgentsDocumentBlock.Source.ofFile(file)) + + /** + * Alias for calling [addDocumentContent] with the following: + * ```java + * BetaManagedAgentsFileDocumentSource.builder() + * .type(BetaManagedAgentsFileDocumentSource.Type.FILE) + * .fileId(fileId) + * .build() + * ``` + */ + fun addFileDocumentContent(fileId: String) = + addDocumentContent( + BetaManagedAgentsFileDocumentSource.builder() + .type(BetaManagedAgentsFileDocumentSource.Type.FILE) + .fileId(fileId) + .build() + ) + + /** Public `sthr_` ID of the thread that sent the message. */ + fun fromSessionThreadId(fromSessionThreadId: String) = + fromSessionThreadId(JsonField.of(fromSessionThreadId)) + + /** + * Sets [Builder.fromSessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.fromSessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fromSessionThreadId(fromSessionThreadId: JsonField) = apply { + this.fromSessionThreadId = fromSessionThreadId + } + + /** A timestamp in RFC 3339 format */ + fun processedAt(processedAt: OffsetDateTime) = processedAt(JsonField.of(processedAt)) + + /** + * Sets [Builder.processedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.processedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedAt(processedAt: JsonField) = apply { + this.processedAt = processedAt + } + + 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 } + + /** + * Name of the callable agent this message came from. Absent when received from the primary + * agent. + */ + fun fromAgentName(fromAgentName: String?) = + fromAgentName(JsonField.ofNullable(fromAgentName)) + + /** Alias for calling [Builder.fromAgentName] with `fromAgentName.orElse(null)`. */ + fun fromAgentName(fromAgentName: Optional) = + fromAgentName(fromAgentName.getOrNull()) + + /** + * Sets [Builder.fromAgentName] to an arbitrary JSON value. + * + * You should usually call [Builder.fromAgentName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun fromAgentName(fromAgentName: JsonField) = apply { + this.fromAgentName = fromAgentName + } + + 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 [BetaManagedAgentsAgentThreadMessageReceivedEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .content() + * .fromSessionThreadId() + * .processedAt() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsAgentThreadMessageReceivedEvent = + BetaManagedAgentsAgentThreadMessageReceivedEvent( + checkRequired("id", id), + checkRequired("content", content).map { it.toImmutable() }, + checkRequired("fromSessionThreadId", fromSessionThreadId), + checkRequired("processedAt", processedAt), + checkRequired("type", type), + fromAgentName, + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsAgentThreadMessageReceivedEvent = apply { + if (validated) { + return@apply + } + + id() + content().forEach { it.validate() } + fromSessionThreadId() + processedAt() + type().validate() + fromAgentName() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (content.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (fromSessionThreadId.asKnown().isPresent) 1 else 0) + + (if (processedAt.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (fromAgentName.asKnown().isPresent) 1 else 0) + + /** Content block in a user message. Can be `text`, `image`, or `document`. */ + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val text: BetaManagedAgentsTextBlock? = null, + private val image: BetaManagedAgentsImageBlock? = null, + private val document: BetaManagedAgentsDocumentBlock? = null, + private val _json: JsonValue? = null, + ) { + + /** Regular text content. */ + fun text(): Optional = Optional.ofNullable(text) + + /** Image content specified directly as base64 data or as a reference via a URL. */ + fun image(): Optional = Optional.ofNullable(image) + + /** + * Document content, either specified directly as base64 data, as text, or as a reference + * via a URL. + */ + fun document(): Optional = Optional.ofNullable(document) + + fun isText(): Boolean = text != null + + fun isImage(): Boolean = image != null + + fun isDocument(): Boolean = document != null + + /** Regular text content. */ + fun asText(): BetaManagedAgentsTextBlock = text.getOrThrow("text") + + /** Image content specified directly as base64 data or as a reference via a URL. */ + fun asImage(): BetaManagedAgentsImageBlock = image.getOrThrow("image") + + /** + * Document content, either specified directly as base64 data, as text, or as a reference + * via a URL. + */ + fun asDocument(): BetaManagedAgentsDocumentBlock = document.getOrThrow("document") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, unless + * [visitor] overrides [Visitor.unknown]. To handle variants not known to this version of + * the SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.anthropic.core.JsonValue; + * import java.util.Optional; + * + * Optional result = content.accept(new Content.Visitor>() { + * @Override + * public Optional visitText(BetaManagedAgentsTextBlock text) { + * return Optional.of(text.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws AnthropicInvalidDataException if [Visitor.unknown] is not overridden in [visitor] + * and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + text != null -> visitor.visitText(text) + image != null -> visitor.visitImage(image) + document != null -> visitor.visitDocument(document) + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Content = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitText(text: BetaManagedAgentsTextBlock) { + text.validate() + } + + override fun visitImage(image: BetaManagedAgentsImageBlock) { + image.validate() + } + + override fun visitDocument(document: BetaManagedAgentsDocumentBlock) { + document.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 visitText(text: BetaManagedAgentsTextBlock) = text.validity() + + override fun visitImage(image: BetaManagedAgentsImageBlock) = image.validity() + + override fun visitDocument(document: BetaManagedAgentsDocumentBlock) = + document.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + text == other.text && + image == other.image && + document == other.document + } + + override fun hashCode(): Int = Objects.hash(text, image, document) + + override fun toString(): String = + when { + text != null -> "Content{text=$text}" + image != null -> "Content{image=$image}" + document != null -> "Content{document=$document}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + + companion object { + + /** Regular text content. */ + @JvmStatic fun ofText(text: BetaManagedAgentsTextBlock) = Content(text = text) + + /** Image content specified directly as base64 data or as a reference via a URL. */ + @JvmStatic fun ofImage(image: BetaManagedAgentsImageBlock) = Content(image = image) + + /** + * Document content, either specified directly as base64 data, as text, or as a + * reference via a URL. + */ + @JvmStatic + fun ofDocument(document: BetaManagedAgentsDocumentBlock) = Content(document = document) + } + + /** + * An interface that defines how to map each variant of [Content] to a value of type [T]. + */ + interface Visitor { + + /** Regular text content. */ + fun visitText(text: BetaManagedAgentsTextBlock): T + + /** Image content specified directly as base64 data or as a reference via a URL. */ + fun visitImage(image: BetaManagedAgentsImageBlock): T + + /** + * Document content, either specified directly as base64 data, as text, or as a + * reference via a URL. + */ + fun visitDocument(document: BetaManagedAgentsDocumentBlock): T + + /** + * Maps an unknown variant of [Content] to a value of type [T]. + * + * An instance of [Content] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws AnthropicInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw AnthropicInvalidDataException("Unknown Content: $json") + } + } + + internal class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "text" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Content(text = it, _json = json) } ?: Content(_json = json) + } + "image" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Content(image = it, _json = json) } ?: Content(_json = json) + } + "document" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Content(document = it, _json = json) } ?: Content(_json = json) + } + } + + return Content(_json = json) + } + } + + internal class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.text != null -> generator.writeObject(value.text) + value.image != null -> generator.writeObject(value.image) + value.document != null -> generator.writeObject(value.document) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + } + + 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 AGENT_THREAD_MESSAGE_RECEIVED = of("agent.thread_message_received") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + AGENT_THREAD_MESSAGE_RECEIVED + } + + /** + * 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 { + AGENT_THREAD_MESSAGE_RECEIVED, + /** 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) { + AGENT_THREAD_MESSAGE_RECEIVED -> Value.AGENT_THREAD_MESSAGE_RECEIVED + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + AGENT_THREAD_MESSAGE_RECEIVED -> Known.AGENT_THREAD_MESSAGE_RECEIVED + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsAgentThreadMessageReceivedEvent && + id == other.id && + content == other.content && + fromSessionThreadId == other.fromSessionThreadId && + processedAt == other.processedAt && + type == other.type && + fromAgentName == other.fromAgentName && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + content, + fromSessionThreadId, + processedAt, + type, + fromAgentName, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsAgentThreadMessageReceivedEvent{id=$id, content=$content, fromSessionThreadId=$fromSessionThreadId, processedAt=$processedAt, type=$type, fromAgentName=$fromAgentName, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageSentEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageSentEvent.kt new file mode 100644 index 000000000..85b239288 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageSentEvent.kt @@ -0,0 +1,1003 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkKnown +import com.anthropic.core.checkRequired +import com.anthropic.core.getOrThrow +import com.anthropic.core.toImmutable +import com.anthropic.errors.AnthropicInvalidDataException +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.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Observability event emitted to the sender's output stream when an agent-to-agent message is sent. + */ +class BetaManagedAgentsAgentThreadMessageSentEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val content: JsonField>, + private val processedAt: JsonField, + private val toSessionThreadId: JsonField, + private val type: JsonField, + private val toAgentName: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("content") + @ExcludeMissing + content: JsonField> = JsonMissing.of(), + @JsonProperty("processed_at") + @ExcludeMissing + processedAt: JsonField = JsonMissing.of(), + @JsonProperty("to_session_thread_id") + @ExcludeMissing + toSessionThreadId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("to_agent_name") + @ExcludeMissing + toAgentName: JsonField = JsonMissing.of(), + ) : this(id, content, processedAt, toSessionThreadId, type, toAgentName, mutableMapOf()) + + /** + * Unique identifier for this event. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * Message content blocks. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun content(): List = content.getRequired("content") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun processedAt(): OffsetDateTime = processedAt.getRequired("processed_at") + + /** + * Public `sthr_` ID of the thread the message was sent to. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun toSessionThreadId(): String = toSessionThreadId.getRequired("to_session_thread_id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Name of the callable agent this message was sent to. Absent when sent to the primary agent. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun toAgentName(): Optional = toAgentName.getOptional("to_agent_name") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField> = content + + /** + * Returns the raw JSON value of [processedAt]. + * + * Unlike [processedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processed_at") + @ExcludeMissing + fun _processedAt(): JsonField = processedAt + + /** + * Returns the raw JSON value of [toSessionThreadId]. + * + * Unlike [toSessionThreadId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("to_session_thread_id") + @ExcludeMissing + fun _toSessionThreadId(): JsonField = toSessionThreadId + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [toAgentName]. + * + * Unlike [toAgentName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("to_agent_name") + @ExcludeMissing + fun _toAgentName(): JsonField = toAgentName + + @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 + * [BetaManagedAgentsAgentThreadMessageSentEvent]. + * + * The following fields are required: + * ```java + * .id() + * .content() + * .processedAt() + * .toSessionThreadId() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsAgentThreadMessageSentEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var content: JsonField>? = null + private var processedAt: JsonField? = null + private var toSessionThreadId: JsonField? = null + private var type: JsonField? = null + private var toAgentName: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsAgentThreadMessageSentEvent: + BetaManagedAgentsAgentThreadMessageSentEvent + ) = apply { + id = betaManagedAgentsAgentThreadMessageSentEvent.id + content = + betaManagedAgentsAgentThreadMessageSentEvent.content.map { it.toMutableList() } + processedAt = betaManagedAgentsAgentThreadMessageSentEvent.processedAt + toSessionThreadId = betaManagedAgentsAgentThreadMessageSentEvent.toSessionThreadId + type = betaManagedAgentsAgentThreadMessageSentEvent.type + toAgentName = betaManagedAgentsAgentThreadMessageSentEvent.toAgentName + additionalProperties = + betaManagedAgentsAgentThreadMessageSentEvent.additionalProperties.toMutableMap() + } + + /** Unique identifier for this event. */ + 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 } + + /** Message content blocks. */ + fun content(content: List) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun content(content: JsonField>) = apply { + this.content = content.map { it.toMutableList() } + } + + /** + * Adds a single [Content] to [Builder.content]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addContent(content: Content) = apply { + this.content = + (this.content ?: JsonField.of(mutableListOf())).also { + checkKnown("content", it).add(content) + } + } + + /** Alias for calling [addContent] with `Content.ofText(text)`. */ + fun addContent(text: BetaManagedAgentsTextBlock) = addContent(Content.ofText(text)) + + /** + * Alias for calling [addContent] with the following: + * ```java + * BetaManagedAgentsTextBlock.builder() + * .type(BetaManagedAgentsTextBlock.Type.TEXT) + * .text(text) + * .build() + * ``` + */ + fun addTextContent(text: String) = + addContent( + BetaManagedAgentsTextBlock.builder() + .type(BetaManagedAgentsTextBlock.Type.TEXT) + .text(text) + .build() + ) + + /** Alias for calling [addContent] with `Content.ofImage(image)`. */ + fun addContent(image: BetaManagedAgentsImageBlock) = addContent(Content.ofImage(image)) + + /** + * Alias for calling [addContent] with the following: + * ```java + * BetaManagedAgentsImageBlock.builder() + * .type(BetaManagedAgentsImageBlock.Type.IMAGE) + * .source(source) + * .build() + * ``` + */ + fun addImageContent(source: BetaManagedAgentsImageBlock.Source) = + addContent( + BetaManagedAgentsImageBlock.builder() + .type(BetaManagedAgentsImageBlock.Type.IMAGE) + .source(source) + .build() + ) + + /** + * Alias for calling [addImageContent] with + * `BetaManagedAgentsImageBlock.Source.ofBase64(base64)`. + */ + fun addImageContent(base64: BetaManagedAgentsBase64ImageSource) = + addImageContent(BetaManagedAgentsImageBlock.Source.ofBase64(base64)) + + /** + * Alias for calling [addImageContent] with `BetaManagedAgentsImageBlock.Source.ofUrl(url)`. + */ + fun addImageContent(url: BetaManagedAgentsUrlImageSource) = + addImageContent(BetaManagedAgentsImageBlock.Source.ofUrl(url)) + + /** + * Alias for calling [addImageContent] with the following: + * ```java + * BetaManagedAgentsUrlImageSource.builder() + * .type(BetaManagedAgentsUrlImageSource.Type.URL) + * .url(url) + * .build() + * ``` + */ + fun addUrlImageContent(url: String) = + addImageContent( + BetaManagedAgentsUrlImageSource.builder() + .type(BetaManagedAgentsUrlImageSource.Type.URL) + .url(url) + .build() + ) + + /** + * Alias for calling [addImageContent] with + * `BetaManagedAgentsImageBlock.Source.ofFile(file)`. + */ + fun addImageContent(file: BetaManagedAgentsFileImageSource) = + addImageContent(BetaManagedAgentsImageBlock.Source.ofFile(file)) + + /** + * Alias for calling [addImageContent] with the following: + * ```java + * BetaManagedAgentsFileImageSource.builder() + * .type(BetaManagedAgentsFileImageSource.Type.FILE) + * .fileId(fileId) + * .build() + * ``` + */ + fun addFileImageContent(fileId: String) = + addImageContent( + BetaManagedAgentsFileImageSource.builder() + .type(BetaManagedAgentsFileImageSource.Type.FILE) + .fileId(fileId) + .build() + ) + + /** Alias for calling [addContent] with `Content.ofDocument(document)`. */ + fun addContent(document: BetaManagedAgentsDocumentBlock) = + addContent(Content.ofDocument(document)) + + /** + * Alias for calling [addContent] with the following: + * ```java + * BetaManagedAgentsDocumentBlock.builder() + * .type(BetaManagedAgentsDocumentBlock.Type.DOCUMENT) + * .source(source) + * .build() + * ``` + */ + fun addDocumentContent(source: BetaManagedAgentsDocumentBlock.Source) = + addContent( + BetaManagedAgentsDocumentBlock.builder() + .type(BetaManagedAgentsDocumentBlock.Type.DOCUMENT) + .source(source) + .build() + ) + + /** + * Alias for calling [addDocumentContent] with + * `BetaManagedAgentsDocumentBlock.Source.ofBase64(base64)`. + */ + fun addDocumentContent(base64: BetaManagedAgentsBase64DocumentSource) = + addDocumentContent(BetaManagedAgentsDocumentBlock.Source.ofBase64(base64)) + + /** + * Alias for calling [addDocumentContent] with + * `BetaManagedAgentsDocumentBlock.Source.ofText(text)`. + */ + fun addDocumentContent(text: BetaManagedAgentsPlainTextDocumentSource) = + addDocumentContent(BetaManagedAgentsDocumentBlock.Source.ofText(text)) + + /** + * Alias for calling [addDocumentContent] with + * `BetaManagedAgentsDocumentBlock.Source.ofUrl(url)`. + */ + fun addDocumentContent(url: BetaManagedAgentsUrlDocumentSource) = + addDocumentContent(BetaManagedAgentsDocumentBlock.Source.ofUrl(url)) + + /** + * Alias for calling [addDocumentContent] with the following: + * ```java + * BetaManagedAgentsUrlDocumentSource.builder() + * .type(BetaManagedAgentsUrlDocumentSource.Type.URL) + * .url(url) + * .build() + * ``` + */ + fun addUrlDocumentContent(url: String) = + addDocumentContent( + BetaManagedAgentsUrlDocumentSource.builder() + .type(BetaManagedAgentsUrlDocumentSource.Type.URL) + .url(url) + .build() + ) + + /** + * Alias for calling [addDocumentContent] with + * `BetaManagedAgentsDocumentBlock.Source.ofFile(file)`. + */ + fun addDocumentContent(file: BetaManagedAgentsFileDocumentSource) = + addDocumentContent(BetaManagedAgentsDocumentBlock.Source.ofFile(file)) + + /** + * Alias for calling [addDocumentContent] with the following: + * ```java + * BetaManagedAgentsFileDocumentSource.builder() + * .type(BetaManagedAgentsFileDocumentSource.Type.FILE) + * .fileId(fileId) + * .build() + * ``` + */ + fun addFileDocumentContent(fileId: String) = + addDocumentContent( + BetaManagedAgentsFileDocumentSource.builder() + .type(BetaManagedAgentsFileDocumentSource.Type.FILE) + .fileId(fileId) + .build() + ) + + /** A timestamp in RFC 3339 format */ + fun processedAt(processedAt: OffsetDateTime) = processedAt(JsonField.of(processedAt)) + + /** + * Sets [Builder.processedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.processedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedAt(processedAt: JsonField) = apply { + this.processedAt = processedAt + } + + /** Public `sthr_` ID of the thread the message was sent to. */ + fun toSessionThreadId(toSessionThreadId: String) = + toSessionThreadId(JsonField.of(toSessionThreadId)) + + /** + * Sets [Builder.toSessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.toSessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun toSessionThreadId(toSessionThreadId: JsonField) = apply { + this.toSessionThreadId = toSessionThreadId + } + + 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 } + + /** + * Name of the callable agent this message was sent to. Absent when sent to the primary + * agent. + */ + fun toAgentName(toAgentName: String?) = toAgentName(JsonField.ofNullable(toAgentName)) + + /** Alias for calling [Builder.toAgentName] with `toAgentName.orElse(null)`. */ + fun toAgentName(toAgentName: Optional) = toAgentName(toAgentName.getOrNull()) + + /** + * Sets [Builder.toAgentName] to an arbitrary JSON value. + * + * You should usually call [Builder.toAgentName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun toAgentName(toAgentName: JsonField) = apply { this.toAgentName = toAgentName } + + 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 [BetaManagedAgentsAgentThreadMessageSentEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .content() + * .processedAt() + * .toSessionThreadId() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsAgentThreadMessageSentEvent = + BetaManagedAgentsAgentThreadMessageSentEvent( + checkRequired("id", id), + checkRequired("content", content).map { it.toImmutable() }, + checkRequired("processedAt", processedAt), + checkRequired("toSessionThreadId", toSessionThreadId), + checkRequired("type", type), + toAgentName, + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsAgentThreadMessageSentEvent = apply { + if (validated) { + return@apply + } + + id() + content().forEach { it.validate() } + processedAt() + toSessionThreadId() + type().validate() + toAgentName() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (content.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (processedAt.asKnown().isPresent) 1 else 0) + + (if (toSessionThreadId.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (toAgentName.asKnown().isPresent) 1 else 0) + + /** Content block in a user message. Can be `text`, `image`, or `document`. */ + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val text: BetaManagedAgentsTextBlock? = null, + private val image: BetaManagedAgentsImageBlock? = null, + private val document: BetaManagedAgentsDocumentBlock? = null, + private val _json: JsonValue? = null, + ) { + + /** Regular text content. */ + fun text(): Optional = Optional.ofNullable(text) + + /** Image content specified directly as base64 data or as a reference via a URL. */ + fun image(): Optional = Optional.ofNullable(image) + + /** + * Document content, either specified directly as base64 data, as text, or as a reference + * via a URL. + */ + fun document(): Optional = Optional.ofNullable(document) + + fun isText(): Boolean = text != null + + fun isImage(): Boolean = image != null + + fun isDocument(): Boolean = document != null + + /** Regular text content. */ + fun asText(): BetaManagedAgentsTextBlock = text.getOrThrow("text") + + /** Image content specified directly as base64 data or as a reference via a URL. */ + fun asImage(): BetaManagedAgentsImageBlock = image.getOrThrow("image") + + /** + * Document content, either specified directly as base64 data, as text, or as a reference + * via a URL. + */ + fun asDocument(): BetaManagedAgentsDocumentBlock = document.getOrThrow("document") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, unless + * [visitor] overrides [Visitor.unknown]. To handle variants not known to this version of + * the SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.anthropic.core.JsonValue; + * import java.util.Optional; + * + * Optional result = content.accept(new Content.Visitor>() { + * @Override + * public Optional visitText(BetaManagedAgentsTextBlock text) { + * return Optional.of(text.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws AnthropicInvalidDataException if [Visitor.unknown] is not overridden in [visitor] + * and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + text != null -> visitor.visitText(text) + image != null -> visitor.visitImage(image) + document != null -> visitor.visitDocument(document) + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Content = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitText(text: BetaManagedAgentsTextBlock) { + text.validate() + } + + override fun visitImage(image: BetaManagedAgentsImageBlock) { + image.validate() + } + + override fun visitDocument(document: BetaManagedAgentsDocumentBlock) { + document.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 visitText(text: BetaManagedAgentsTextBlock) = text.validity() + + override fun visitImage(image: BetaManagedAgentsImageBlock) = image.validity() + + override fun visitDocument(document: BetaManagedAgentsDocumentBlock) = + document.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + text == other.text && + image == other.image && + document == other.document + } + + override fun hashCode(): Int = Objects.hash(text, image, document) + + override fun toString(): String = + when { + text != null -> "Content{text=$text}" + image != null -> "Content{image=$image}" + document != null -> "Content{document=$document}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + + companion object { + + /** Regular text content. */ + @JvmStatic fun ofText(text: BetaManagedAgentsTextBlock) = Content(text = text) + + /** Image content specified directly as base64 data or as a reference via a URL. */ + @JvmStatic fun ofImage(image: BetaManagedAgentsImageBlock) = Content(image = image) + + /** + * Document content, either specified directly as base64 data, as text, or as a + * reference via a URL. + */ + @JvmStatic + fun ofDocument(document: BetaManagedAgentsDocumentBlock) = Content(document = document) + } + + /** + * An interface that defines how to map each variant of [Content] to a value of type [T]. + */ + interface Visitor { + + /** Regular text content. */ + fun visitText(text: BetaManagedAgentsTextBlock): T + + /** Image content specified directly as base64 data or as a reference via a URL. */ + fun visitImage(image: BetaManagedAgentsImageBlock): T + + /** + * Document content, either specified directly as base64 data, as text, or as a + * reference via a URL. + */ + fun visitDocument(document: BetaManagedAgentsDocumentBlock): T + + /** + * Maps an unknown variant of [Content] to a value of type [T]. + * + * An instance of [Content] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws AnthropicInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw AnthropicInvalidDataException("Unknown Content: $json") + } + } + + internal class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "text" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Content(text = it, _json = json) } ?: Content(_json = json) + } + "image" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Content(image = it, _json = json) } ?: Content(_json = json) + } + "document" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Content(document = it, _json = json) } ?: Content(_json = json) + } + } + + return Content(_json = json) + } + } + + internal class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.text != null -> generator.writeObject(value.text) + value.image != null -> generator.writeObject(value.image) + value.document != null -> generator.writeObject(value.document) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + } + + 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 AGENT_THREAD_MESSAGE_SENT = of("agent.thread_message_sent") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + AGENT_THREAD_MESSAGE_SENT + } + + /** + * 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 { + AGENT_THREAD_MESSAGE_SENT, + /** 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) { + AGENT_THREAD_MESSAGE_SENT -> Value.AGENT_THREAD_MESSAGE_SENT + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + AGENT_THREAD_MESSAGE_SENT -> Known.AGENT_THREAD_MESSAGE_SENT + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsAgentThreadMessageSentEvent && + id == other.id && + content == other.content && + processedAt == other.processedAt && + toSessionThreadId == other.toSessionThreadId && + type == other.type && + toAgentName == other.toAgentName && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + content, + processedAt, + toSessionThreadId, + type, + toAgentName, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsAgentThreadMessageSentEvent{id=$id, content=$content, processedAt=$processedAt, toSessionThreadId=$toSessionThreadId, type=$type, toAgentName=$toAgentName, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentToolUseEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentToolUseEvent.kt index de950120f..dc975f7e0 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentToolUseEvent.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentToolUseEvent.kt @@ -30,6 +30,7 @@ private constructor( private val processedAt: JsonField, private val type: JsonField, private val evaluatedPermission: JsonField, + private val sessionThreadId: JsonField, private val additionalProperties: MutableMap, ) { @@ -45,7 +46,19 @@ private constructor( @JsonProperty("evaluated_permission") @ExcludeMissing evaluatedPermission: JsonField = JsonMissing.of(), - ) : this(id, input, name, processedAt, type, evaluatedPermission, mutableMapOf()) + @JsonProperty("session_thread_id") + @ExcludeMissing + sessionThreadId: JsonField = JsonMissing.of(), + ) : this( + id, + input, + name, + processedAt, + type, + evaluatedPermission, + sessionThreadId, + mutableMapOf(), + ) /** * Unique identifier for this event. @@ -94,6 +107,16 @@ private constructor( fun evaluatedPermission(): Optional = evaluatedPermission.getOptional("evaluated_permission") + /** + * When set, this event was cross-posted from a subagent's thread to surface its permission + * request on the primary thread's stream. Empty on the thread's own events. Echo this on a + * `user.tool_confirmation` event to route the approval back. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun sessionThreadId(): Optional = sessionThreadId.getOptional("session_thread_id") + /** * Returns the raw JSON value of [id]. * @@ -141,6 +164,15 @@ private constructor( @ExcludeMissing fun _evaluatedPermission(): JsonField = evaluatedPermission + /** + * Returns the raw JSON value of [sessionThreadId]. + * + * Unlike [sessionThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_thread_id") + @ExcludeMissing + fun _sessionThreadId(): JsonField = sessionThreadId + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -180,6 +212,7 @@ private constructor( private var processedAt: JsonField? = null private var type: JsonField? = null private var evaluatedPermission: JsonField = JsonMissing.of() + private var sessionThreadId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -191,6 +224,7 @@ private constructor( processedAt = betaManagedAgentsAgentToolUseEvent.processedAt type = betaManagedAgentsAgentToolUseEvent.type evaluatedPermission = betaManagedAgentsAgentToolUseEvent.evaluatedPermission + sessionThreadId = betaManagedAgentsAgentToolUseEvent.sessionThreadId additionalProperties = betaManagedAgentsAgentToolUseEvent.additionalProperties.toMutableMap() } @@ -267,6 +301,29 @@ private constructor( this.evaluatedPermission = evaluatedPermission } + /** + * When set, this event was cross-posted from a subagent's thread to surface its permission + * request on the primary thread's stream. Empty on the thread's own events. Echo this on a + * `user.tool_confirmation` event to route the approval back. + */ + fun sessionThreadId(sessionThreadId: String?) = + sessionThreadId(JsonField.ofNullable(sessionThreadId)) + + /** Alias for calling [Builder.sessionThreadId] with `sessionThreadId.orElse(null)`. */ + fun sessionThreadId(sessionThreadId: Optional) = + sessionThreadId(sessionThreadId.getOrNull()) + + /** + * Sets [Builder.sessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sessionThreadId(sessionThreadId: JsonField) = apply { + this.sessionThreadId = sessionThreadId + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -310,6 +367,7 @@ private constructor( checkRequired("processedAt", processedAt), checkRequired("type", type), evaluatedPermission, + sessionThreadId, additionalProperties.toMutableMap(), ) } @@ -335,6 +393,7 @@ private constructor( processedAt() type().validate() evaluatedPermission().ifPresent { it.validate() } + sessionThreadId() validated = true } @@ -358,7 +417,8 @@ private constructor( (if (name.asKnown().isPresent) 1 else 0) + (if (processedAt.asKnown().isPresent) 1 else 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + - (evaluatedPermission.asKnown().getOrNull()?.validity() ?: 0) + (evaluatedPermission.asKnown().getOrNull()?.validity() ?: 0) + + (if (sessionThreadId.asKnown().isPresent) 1 else 0) /** Input parameters for the tool call. */ class Input @@ -759,15 +819,25 @@ private constructor( processedAt == other.processedAt && type == other.type && evaluatedPermission == other.evaluatedPermission && + sessionThreadId == other.sessionThreadId && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(id, input, name, processedAt, type, evaluatedPermission, additionalProperties) + Objects.hash( + id, + input, + name, + processedAt, + type, + evaluatedPermission, + sessionThreadId, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaManagedAgentsAgentToolUseEvent{id=$id, input=$input, name=$name, processedAt=$processedAt, type=$type, evaluatedPermission=$evaluatedPermission, additionalProperties=$additionalProperties}" + "BetaManagedAgentsAgentToolUseEvent{id=$id, input=$input, name=$name, processedAt=$processedAt, type=$type, evaluatedPermission=$evaluatedPermission, sessionThreadId=$sessionThreadId, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsEventParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsEventParams.kt index 30dc818c7..59d4fb19e 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsEventParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsEventParams.kt @@ -27,6 +27,7 @@ private constructor( private val userInterrupt: BetaManagedAgentsUserInterruptEventParams? = null, private val userToolConfirmation: BetaManagedAgentsUserToolConfirmationEventParams? = null, private val userCustomToolResult: BetaManagedAgentsUserCustomToolResultEventParams? = null, + private val userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEventParams? = null, private val _json: JsonValue? = null, ) { @@ -46,6 +47,13 @@ private constructor( fun userCustomToolResult(): Optional = Optional.ofNullable(userCustomToolResult) + /** + * Parameters for defining an outcome the agent should work toward. The agent begins work on + * receipt. + */ + fun userDefineOutcome(): Optional = + Optional.ofNullable(userDefineOutcome) + fun isUserMessage(): Boolean = userMessage != null fun isUserInterrupt(): Boolean = userInterrupt != null @@ -54,6 +62,8 @@ private constructor( fun isUserCustomToolResult(): Boolean = userCustomToolResult != null + fun isUserDefineOutcome(): Boolean = userDefineOutcome != null + /** Parameters for sending a user message to the session. */ fun asUserMessage(): BetaManagedAgentsUserMessageEventParams = userMessage.getOrThrow("userMessage") @@ -70,6 +80,13 @@ private constructor( fun asUserCustomToolResult(): BetaManagedAgentsUserCustomToolResultEventParams = userCustomToolResult.getOrThrow("userCustomToolResult") + /** + * Parameters for defining an outcome the agent should work toward. The agent begins work on + * receipt. + */ + fun asUserDefineOutcome(): BetaManagedAgentsUserDefineOutcomeEventParams = + userDefineOutcome.getOrThrow("userDefineOutcome") + fun _json(): Optional = Optional.ofNullable(_json) /** @@ -107,6 +124,7 @@ private constructor( userInterrupt != null -> visitor.visitUserInterrupt(userInterrupt) userToolConfirmation != null -> visitor.visitUserToolConfirmation(userToolConfirmation) userCustomToolResult != null -> visitor.visitUserCustomToolResult(userCustomToolResult) + userDefineOutcome != null -> visitor.visitUserDefineOutcome(userDefineOutcome) else -> visitor.unknown(_json) } @@ -150,6 +168,12 @@ private constructor( ) { userCustomToolResult.validate() } + + override fun visitUserDefineOutcome( + userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEventParams + ) { + userDefineOutcome.validate() + } } ) validated = true @@ -188,6 +212,10 @@ private constructor( userCustomToolResult: BetaManagedAgentsUserCustomToolResultEventParams ) = userCustomToolResult.validity() + override fun visitUserDefineOutcome( + userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEventParams + ) = userDefineOutcome.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -201,11 +229,18 @@ private constructor( userMessage == other.userMessage && userInterrupt == other.userInterrupt && userToolConfirmation == other.userToolConfirmation && - userCustomToolResult == other.userCustomToolResult + userCustomToolResult == other.userCustomToolResult && + userDefineOutcome == other.userDefineOutcome } override fun hashCode(): Int = - Objects.hash(userMessage, userInterrupt, userToolConfirmation, userCustomToolResult) + Objects.hash( + userMessage, + userInterrupt, + userToolConfirmation, + userCustomToolResult, + userDefineOutcome, + ) override fun toString(): String = when { @@ -215,6 +250,8 @@ private constructor( "BetaManagedAgentsEventParams{userToolConfirmation=$userToolConfirmation}" userCustomToolResult != null -> "BetaManagedAgentsEventParams{userCustomToolResult=$userCustomToolResult}" + userDefineOutcome != null -> + "BetaManagedAgentsEventParams{userDefineOutcome=$userDefineOutcome}" _json != null -> "BetaManagedAgentsEventParams{_unknown=$_json}" else -> throw IllegalStateException("Invalid BetaManagedAgentsEventParams") } @@ -242,6 +279,14 @@ private constructor( fun ofUserCustomToolResult( userCustomToolResult: BetaManagedAgentsUserCustomToolResultEventParams ) = BetaManagedAgentsEventParams(userCustomToolResult = userCustomToolResult) + + /** + * Parameters for defining an outcome the agent should work toward. The agent begins work on + * receipt. + */ + @JvmStatic + fun ofUserDefineOutcome(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEventParams) = + BetaManagedAgentsEventParams(userDefineOutcome = userDefineOutcome) } /** @@ -266,6 +311,14 @@ private constructor( userCustomToolResult: BetaManagedAgentsUserCustomToolResultEventParams ): T + /** + * Parameters for defining an outcome the agent should work toward. The agent begins work on + * receipt. + */ + fun visitUserDefineOutcome( + userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEventParams + ): T + /** * Maps an unknown variant of [BetaManagedAgentsEventParams] to a value of type [T]. * @@ -323,6 +376,14 @@ private constructor( BetaManagedAgentsEventParams(userCustomToolResult = it, _json = json) } ?: BetaManagedAgentsEventParams(_json = json) } + "user.define_outcome" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaManagedAgentsEventParams(userDefineOutcome = it, _json = json) } + ?: BetaManagedAgentsEventParams(_json = json) + } } return BetaManagedAgentsEventParams(_json = json) @@ -344,6 +405,7 @@ private constructor( generator.writeObject(value.userToolConfirmation) value.userCustomToolResult != null -> generator.writeObject(value.userCustomToolResult) + value.userDefineOutcome != null -> generator.writeObject(value.userDefineOutcome) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid BetaManagedAgentsEventParams") } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubric.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubric.kt new file mode 100644 index 000000000..20fc327e3 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubric.kt @@ -0,0 +1,348 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** Rubric referenced by a file uploaded via the Files API. */ +class BetaManagedAgentsFileRubric +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val fileId: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("file_id") @ExcludeMissing fileId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(fileId, type, mutableMapOf()) + + /** + * ID of the rubric file. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [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 [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 [BetaManagedAgentsFileRubric]. + * + * The following fields are required: + * ```java + * .fileId() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsFileRubric]. */ + class Builder internal constructor() { + + private var fileId: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaManagedAgentsFileRubric: BetaManagedAgentsFileRubric) = apply { + fileId = betaManagedAgentsFileRubric.fileId + type = betaManagedAgentsFileRubric.type + additionalProperties = betaManagedAgentsFileRubric.additionalProperties.toMutableMap() + } + + /** ID of the rubric 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 } + + 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 [BetaManagedAgentsFileRubric]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fileId() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsFileRubric = + BetaManagedAgentsFileRubric( + checkRequired("fileId", fileId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsFileRubric = apply { + if (validated) { + return@apply + } + + fileId() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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) + (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 FILE = of("file") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + FILE + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + FILE, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + FILE -> Value.FILE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + FILE -> Known.FILE + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsFileRubric && + fileId == other.fileId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(fileId, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsFileRubric{fileId=$fileId, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubricParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubricParams.kt new file mode 100644 index 000000000..46ed323bd --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubricParams.kt @@ -0,0 +1,351 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** Rubric referenced by a file uploaded via the Files API. */ +class BetaManagedAgentsFileRubricParams +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val fileId: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("file_id") @ExcludeMissing fileId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(fileId, type, mutableMapOf()) + + /** + * ID of the rubric file. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [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 [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 + * [BetaManagedAgentsFileRubricParams]. + * + * The following fields are required: + * ```java + * .fileId() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsFileRubricParams]. */ + class Builder internal constructor() { + + private var fileId: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaManagedAgentsFileRubricParams: BetaManagedAgentsFileRubricParams) = + apply { + fileId = betaManagedAgentsFileRubricParams.fileId + type = betaManagedAgentsFileRubricParams.type + additionalProperties = + betaManagedAgentsFileRubricParams.additionalProperties.toMutableMap() + } + + /** ID of the rubric 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 } + + 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 [BetaManagedAgentsFileRubricParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fileId() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsFileRubricParams = + BetaManagedAgentsFileRubricParams( + checkRequired("fileId", fileId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsFileRubricParams = apply { + if (validated) { + return@apply + } + + fileId() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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) + (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 FILE = of("file") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + FILE + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + FILE, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + FILE -> Value.FILE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + FILE -> Known.FILE + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsFileRubricParams && + fileId == other.fileId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(fileId, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsFileRubricParams{fileId=$fileId, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSendSessionEvents.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSendSessionEvents.kt index 7dd82a5e0..58a250808 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSendSessionEvents.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSendSessionEvents.kt @@ -149,6 +149,10 @@ private constructor( fun addData(userCustomToolResult: BetaManagedAgentsUserCustomToolResultEvent) = addData(Data.ofUserCustomToolResult(userCustomToolResult)) + /** Alias for calling [addData] with `Data.ofUserDefineOutcome(userDefineOutcome)`. */ + fun addData(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent) = + addData(Data.ofUserDefineOutcome(userDefineOutcome)) + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -225,6 +229,7 @@ private constructor( private val userInterrupt: BetaManagedAgentsUserInterruptEvent? = null, private val userToolConfirmation: BetaManagedAgentsUserToolConfirmationEvent? = null, private val userCustomToolResult: BetaManagedAgentsUserCustomToolResultEvent? = null, + private val userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent? = null, private val _json: JsonValue? = null, ) { @@ -244,6 +249,13 @@ private constructor( fun userCustomToolResult(): Optional = Optional.ofNullable(userCustomToolResult) + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` + * that subsequent `span.outcome_evaluation_*` events reference. + */ + fun userDefineOutcome(): Optional = + Optional.ofNullable(userDefineOutcome) + fun isUserMessage(): Boolean = userMessage != null fun isUserInterrupt(): Boolean = userInterrupt != null @@ -252,6 +264,8 @@ private constructor( fun isUserCustomToolResult(): Boolean = userCustomToolResult != null + fun isUserDefineOutcome(): Boolean = userDefineOutcome != null + /** A user message event in the session conversation. */ fun asUserMessage(): BetaManagedAgentsUserMessageEvent = userMessage.getOrThrow("userMessage") @@ -268,6 +282,13 @@ private constructor( fun asUserCustomToolResult(): BetaManagedAgentsUserCustomToolResultEvent = userCustomToolResult.getOrThrow("userCustomToolResult") + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` + * that subsequent `span.outcome_evaluation_*` events reference. + */ + fun asUserDefineOutcome(): BetaManagedAgentsUserDefineOutcomeEvent = + userDefineOutcome.getOrThrow("userDefineOutcome") + fun _json(): Optional = Optional.ofNullable(_json) /** @@ -307,6 +328,7 @@ private constructor( visitor.visitUserToolConfirmation(userToolConfirmation) userCustomToolResult != null -> visitor.visitUserCustomToolResult(userCustomToolResult) + userDefineOutcome != null -> visitor.visitUserDefineOutcome(userDefineOutcome) else -> visitor.unknown(_json) } @@ -349,6 +371,12 @@ private constructor( ) { userCustomToolResult.validate() } + + override fun visitUserDefineOutcome( + userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent + ) { + userDefineOutcome.validate() + } } ) validated = true @@ -387,6 +415,10 @@ private constructor( userCustomToolResult: BetaManagedAgentsUserCustomToolResultEvent ) = userCustomToolResult.validity() + override fun visitUserDefineOutcome( + userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent + ) = userDefineOutcome.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -400,11 +432,18 @@ private constructor( userMessage == other.userMessage && userInterrupt == other.userInterrupt && userToolConfirmation == other.userToolConfirmation && - userCustomToolResult == other.userCustomToolResult + userCustomToolResult == other.userCustomToolResult && + userDefineOutcome == other.userDefineOutcome } override fun hashCode(): Int = - Objects.hash(userMessage, userInterrupt, userToolConfirmation, userCustomToolResult) + Objects.hash( + userMessage, + userInterrupt, + userToolConfirmation, + userCustomToolResult, + userDefineOutcome, + ) override fun toString(): String = when { @@ -412,6 +451,7 @@ private constructor( userInterrupt != null -> "Data{userInterrupt=$userInterrupt}" userToolConfirmation != null -> "Data{userToolConfirmation=$userToolConfirmation}" userCustomToolResult != null -> "Data{userCustomToolResult=$userCustomToolResult}" + userDefineOutcome != null -> "Data{userDefineOutcome=$userDefineOutcome}" _json != null -> "Data{_unknown=$_json}" else -> throw IllegalStateException("Invalid Data") } @@ -439,6 +479,14 @@ private constructor( fun ofUserCustomToolResult( userCustomToolResult: BetaManagedAgentsUserCustomToolResultEvent ) = Data(userCustomToolResult = userCustomToolResult) + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated + * `outcome_id` that subsequent `span.outcome_evaluation_*` events reference. + */ + @JvmStatic + fun ofUserDefineOutcome(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent) = + Data(userDefineOutcome = userDefineOutcome) } /** An interface that defines how to map each variant of [Data] to a value of type [T]. */ @@ -460,6 +508,14 @@ private constructor( userCustomToolResult: BetaManagedAgentsUserCustomToolResultEvent ): T + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated + * `outcome_id` that subsequent `span.outcome_evaluation_*` events reference. + */ + fun visitUserDefineOutcome( + userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent + ): T + /** * Maps an unknown variant of [Data] to a value of type [T]. * @@ -511,6 +567,14 @@ private constructor( ?.let { Data(userCustomToolResult = it, _json = json) } ?: Data(_json = json) } + "user.define_outcome" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Data(userDefineOutcome = it, _json = json) } + ?: Data(_json = json) + } } return Data(_json = json) @@ -531,6 +595,8 @@ private constructor( generator.writeObject(value.userToolConfirmation) value.userCustomToolResult != null -> generator.writeObject(value.userCustomToolResult) + value.userDefineOutcome != null -> + generator.writeObject(value.userDefineOutcome) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Data") } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionEvent.kt index 3b05ba9de..4c66b9387 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionEvent.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionEvent.kt @@ -34,6 +34,9 @@ private constructor( private val agentMcpToolResult: BetaManagedAgentsAgentMcpToolResultEvent? = null, private val agentToolUse: BetaManagedAgentsAgentToolUseEvent? = null, private val agentToolResult: BetaManagedAgentsAgentToolResultEvent? = null, + private val agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent? = + null, + private val agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent? = null, private val agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent? = null, private val sessionError: BetaManagedAgentsSessionErrorEvent? = null, @@ -41,9 +44,25 @@ private constructor( private val sessionStatusRunning: BetaManagedAgentsSessionStatusRunningEvent? = null, private val sessionStatusIdle: BetaManagedAgentsSessionStatusIdleEvent? = null, private val sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent? = null, + private val sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent? = null, + private val spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent? = + null, + private val spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent? = null, private val spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent? = null, private val spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent? = null, + private val spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent? = + null, + private val userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent? = null, private val sessionDeleted: BetaManagedAgentsSessionDeletedEvent? = null, + private val sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent? = + null, + private val sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent? = null, + private val sessionThreadStatusTerminated: + BetaManagedAgentsSessionThreadStatusTerminatedEvent? = + null, + private val sessionThreadStatusRescheduled: + BetaManagedAgentsSessionThreadStatusRescheduledEvent? = + null, private val _json: JsonValue? = null, ) { @@ -97,6 +116,20 @@ private constructor( fun agentToolResult(): Optional = Optional.ofNullable(agentToolResult) + /** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ + fun agentThreadMessageReceived(): Optional = + Optional.ofNullable(agentThreadMessageReceived) + + /** + * Observability event emitted to the sender's output stream when an agent-to-agent message is + * sent. + */ + fun agentThreadMessageSent(): Optional = + Optional.ofNullable(agentThreadMessageSent) + /** Indicates that context compaction (summarization) occurred during the session. */ fun agentThreadContextCompacted(): Optional = Optional.ofNullable(agentThreadContextCompacted) @@ -121,6 +154,26 @@ private constructor( fun sessionStatusTerminated(): Optional = Optional.ofNullable(sessionStatusTerminated) + /** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output + * stream so clients observing the session see child creation. + */ + fun sessionThreadCreated(): Optional = + Optional.ofNullable(sessionThreadCreated) + + /** Emitted when an outcome evaluation cycle begins. */ + fun spanOutcomeEvaluationStart(): Optional = + Optional.ofNullable(spanOutcomeEvaluationStart) + + /** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate token + * usage. A verdict of `needs_revision` means another evaluation cycle follows; `satisfied`, + * `max_iterations_reached`, `failed`, or `interrupted` are terminal — no further evaluation + * cycles follow. + */ + fun spanOutcomeEvaluationEnd(): Optional = + Optional.ofNullable(spanOutcomeEvaluationEnd) + /** Emitted when a model request is initiated by the agent. */ fun spanModelRequestStart(): Optional = Optional.ofNullable(spanModelRequestStart) @@ -129,6 +182,22 @@ private constructor( fun spanModelRequestEnd(): Optional = Optional.ofNullable(spanModelRequestEnd) + /** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. Distinguishes + * 'evaluation is actively running' from 'evaluation is stuck' between the corresponding + * `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ + fun spanOutcomeEvaluationOngoing(): + Optional = + Optional.ofNullable(spanOutcomeEvaluationOngoing) + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` that + * subsequent `span.outcome_evaluation_*` events reference. + */ + fun userDefineOutcome(): Optional = + Optional.ofNullable(userDefineOutcome) + /** * Emitted when a session has been deleted. Terminates any active event stream — no further * events will be emitted for this session. @@ -136,6 +205,36 @@ private constructor( fun sessionDeleted(): Optional = Optional.ofNullable(sessionDeleted) + /** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted to + * the primary stream for child threads. + */ + fun sessionThreadStatusRunning(): Optional = + Optional.ofNullable(sessionThreadStatusRunning) + + /** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream and + * cross-posted to the primary stream for child threads. + */ + fun sessionThreadStatusIdle(): Optional = + Optional.ofNullable(sessionThreadStatusIdle) + + /** + * A session thread has terminated and will accept no further input. Emitted on the thread's own + * stream and cross-posted to the primary stream for child threads. + */ + fun sessionThreadStatusTerminated(): + Optional = + Optional.ofNullable(sessionThreadStatusTerminated) + + /** + * A session thread hit a transient error and is retrying automatically. Emitted on the thread's + * own stream and cross-posted to the primary stream for child threads. + */ + fun sessionThreadStatusRescheduled(): + Optional = + Optional.ofNullable(sessionThreadStatusRescheduled) + fun isUserMessage(): Boolean = userMessage != null fun isUserInterrupt(): Boolean = userInterrupt != null @@ -158,6 +257,10 @@ private constructor( fun isAgentToolResult(): Boolean = agentToolResult != null + fun isAgentThreadMessageReceived(): Boolean = agentThreadMessageReceived != null + + fun isAgentThreadMessageSent(): Boolean = agentThreadMessageSent != null + fun isAgentThreadContextCompacted(): Boolean = agentThreadContextCompacted != null fun isSessionError(): Boolean = sessionError != null @@ -170,12 +273,30 @@ private constructor( fun isSessionStatusTerminated(): Boolean = sessionStatusTerminated != null + fun isSessionThreadCreated(): Boolean = sessionThreadCreated != null + + fun isSpanOutcomeEvaluationStart(): Boolean = spanOutcomeEvaluationStart != null + + fun isSpanOutcomeEvaluationEnd(): Boolean = spanOutcomeEvaluationEnd != null + fun isSpanModelRequestStart(): Boolean = spanModelRequestStart != null fun isSpanModelRequestEnd(): Boolean = spanModelRequestEnd != null + fun isSpanOutcomeEvaluationOngoing(): Boolean = spanOutcomeEvaluationOngoing != null + + fun isUserDefineOutcome(): Boolean = userDefineOutcome != null + fun isSessionDeleted(): Boolean = sessionDeleted != null + fun isSessionThreadStatusRunning(): Boolean = sessionThreadStatusRunning != null + + fun isSessionThreadStatusIdle(): Boolean = sessionThreadStatusIdle != null + + fun isSessionThreadStatusTerminated(): Boolean = sessionThreadStatusTerminated != null + + fun isSessionThreadStatusRescheduled(): Boolean = sessionThreadStatusRescheduled != null + /** A user message event in the session conversation. */ fun asUserMessage(): BetaManagedAgentsUserMessageEvent = userMessage.getOrThrow("userMessage") @@ -225,6 +346,20 @@ private constructor( fun asAgentToolResult(): BetaManagedAgentsAgentToolResultEvent = agentToolResult.getOrThrow("agentToolResult") + /** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ + fun asAgentThreadMessageReceived(): BetaManagedAgentsAgentThreadMessageReceivedEvent = + agentThreadMessageReceived.getOrThrow("agentThreadMessageReceived") + + /** + * Observability event emitted to the sender's output stream when an agent-to-agent message is + * sent. + */ + fun asAgentThreadMessageSent(): BetaManagedAgentsAgentThreadMessageSentEvent = + agentThreadMessageSent.getOrThrow("agentThreadMessageSent") + /** Indicates that context compaction (summarization) occurred during the session. */ fun asAgentThreadContextCompacted(): BetaManagedAgentsAgentThreadContextCompactedEvent = agentThreadContextCompacted.getOrThrow("agentThreadContextCompacted") @@ -249,6 +384,26 @@ private constructor( fun asSessionStatusTerminated(): BetaManagedAgentsSessionStatusTerminatedEvent = sessionStatusTerminated.getOrThrow("sessionStatusTerminated") + /** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output + * stream so clients observing the session see child creation. + */ + fun asSessionThreadCreated(): BetaManagedAgentsSessionThreadCreatedEvent = + sessionThreadCreated.getOrThrow("sessionThreadCreated") + + /** Emitted when an outcome evaluation cycle begins. */ + fun asSpanOutcomeEvaluationStart(): BetaManagedAgentsSpanOutcomeEvaluationStartEvent = + spanOutcomeEvaluationStart.getOrThrow("spanOutcomeEvaluationStart") + + /** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate token + * usage. A verdict of `needs_revision` means another evaluation cycle follows; `satisfied`, + * `max_iterations_reached`, `failed`, or `interrupted` are terminal — no further evaluation + * cycles follow. + */ + fun asSpanOutcomeEvaluationEnd(): BetaManagedAgentsSpanOutcomeEvaluationEndEvent = + spanOutcomeEvaluationEnd.getOrThrow("spanOutcomeEvaluationEnd") + /** Emitted when a model request is initiated by the agent. */ fun asSpanModelRequestStart(): BetaManagedAgentsSpanModelRequestStartEvent = spanModelRequestStart.getOrThrow("spanModelRequestStart") @@ -257,6 +412,21 @@ private constructor( fun asSpanModelRequestEnd(): BetaManagedAgentsSpanModelRequestEndEvent = spanModelRequestEnd.getOrThrow("spanModelRequestEnd") + /** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. Distinguishes + * 'evaluation is actively running' from 'evaluation is stuck' between the corresponding + * `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ + fun asSpanOutcomeEvaluationOngoing(): BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent = + spanOutcomeEvaluationOngoing.getOrThrow("spanOutcomeEvaluationOngoing") + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` that + * subsequent `span.outcome_evaluation_*` events reference. + */ + fun asUserDefineOutcome(): BetaManagedAgentsUserDefineOutcomeEvent = + userDefineOutcome.getOrThrow("userDefineOutcome") + /** * Emitted when a session has been deleted. Terminates any active event stream — no further * events will be emitted for this session. @@ -264,6 +434,34 @@ private constructor( fun asSessionDeleted(): BetaManagedAgentsSessionDeletedEvent = sessionDeleted.getOrThrow("sessionDeleted") + /** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted to + * the primary stream for child threads. + */ + fun asSessionThreadStatusRunning(): BetaManagedAgentsSessionThreadStatusRunningEvent = + sessionThreadStatusRunning.getOrThrow("sessionThreadStatusRunning") + + /** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream and + * cross-posted to the primary stream for child threads. + */ + fun asSessionThreadStatusIdle(): BetaManagedAgentsSessionThreadStatusIdleEvent = + sessionThreadStatusIdle.getOrThrow("sessionThreadStatusIdle") + + /** + * A session thread has terminated and will accept no further input. Emitted on the thread's own + * stream and cross-posted to the primary stream for child threads. + */ + fun asSessionThreadStatusTerminated(): BetaManagedAgentsSessionThreadStatusTerminatedEvent = + sessionThreadStatusTerminated.getOrThrow("sessionThreadStatusTerminated") + + /** + * A session thread hit a transient error and is retrying automatically. Emitted on the thread's + * own stream and cross-posted to the primary stream for child threads. + */ + fun asSessionThreadStatusRescheduled(): BetaManagedAgentsSessionThreadStatusRescheduledEvent = + sessionThreadStatusRescheduled.getOrThrow("sessionThreadStatusRescheduled") + fun _json(): Optional = Optional.ofNullable(_json) /** @@ -308,6 +506,10 @@ private constructor( agentMcpToolResult != null -> visitor.visitAgentMcpToolResult(agentMcpToolResult) agentToolUse != null -> visitor.visitAgentToolUse(agentToolUse) agentToolResult != null -> visitor.visitAgentToolResult(agentToolResult) + agentThreadMessageReceived != null -> + visitor.visitAgentThreadMessageReceived(agentThreadMessageReceived) + agentThreadMessageSent != null -> + visitor.visitAgentThreadMessageSent(agentThreadMessageSent) agentThreadContextCompacted != null -> visitor.visitAgentThreadContextCompacted(agentThreadContextCompacted) sessionError != null -> visitor.visitSessionError(sessionError) @@ -317,10 +519,26 @@ private constructor( sessionStatusIdle != null -> visitor.visitSessionStatusIdle(sessionStatusIdle) sessionStatusTerminated != null -> visitor.visitSessionStatusTerminated(sessionStatusTerminated) + sessionThreadCreated != null -> visitor.visitSessionThreadCreated(sessionThreadCreated) + spanOutcomeEvaluationStart != null -> + visitor.visitSpanOutcomeEvaluationStart(spanOutcomeEvaluationStart) + spanOutcomeEvaluationEnd != null -> + visitor.visitSpanOutcomeEvaluationEnd(spanOutcomeEvaluationEnd) spanModelRequestStart != null -> visitor.visitSpanModelRequestStart(spanModelRequestStart) spanModelRequestEnd != null -> visitor.visitSpanModelRequestEnd(spanModelRequestEnd) + spanOutcomeEvaluationOngoing != null -> + visitor.visitSpanOutcomeEvaluationOngoing(spanOutcomeEvaluationOngoing) + userDefineOutcome != null -> visitor.visitUserDefineOutcome(userDefineOutcome) sessionDeleted != null -> visitor.visitSessionDeleted(sessionDeleted) + sessionThreadStatusRunning != null -> + visitor.visitSessionThreadStatusRunning(sessionThreadStatusRunning) + sessionThreadStatusIdle != null -> + visitor.visitSessionThreadStatusIdle(sessionThreadStatusIdle) + sessionThreadStatusTerminated != null -> + visitor.visitSessionThreadStatusTerminated(sessionThreadStatusTerminated) + sessionThreadStatusRescheduled != null -> + visitor.visitSessionThreadStatusRescheduled(sessionThreadStatusRescheduled) else -> visitor.unknown(_json) } @@ -401,6 +619,18 @@ private constructor( agentToolResult.validate() } + override fun visitAgentThreadMessageReceived( + agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent + ) { + agentThreadMessageReceived.validate() + } + + override fun visitAgentThreadMessageSent( + agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent + ) { + agentThreadMessageSent.validate() + } + override fun visitAgentThreadContextCompacted( agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent ) { @@ -435,6 +665,24 @@ private constructor( sessionStatusTerminated.validate() } + override fun visitSessionThreadCreated( + sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent + ) { + sessionThreadCreated.validate() + } + + override fun visitSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ) { + spanOutcomeEvaluationStart.validate() + } + + override fun visitSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ) { + spanOutcomeEvaluationEnd.validate() + } + override fun visitSpanModelRequestStart( spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent ) { @@ -447,11 +695,49 @@ private constructor( spanModelRequestEnd.validate() } + override fun visitSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ) { + spanOutcomeEvaluationOngoing.validate() + } + + override fun visitUserDefineOutcome( + userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent + ) { + userDefineOutcome.validate() + } + override fun visitSessionDeleted( sessionDeleted: BetaManagedAgentsSessionDeletedEvent ) { sessionDeleted.validate() } + + override fun visitSessionThreadStatusRunning( + sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent + ) { + sessionThreadStatusRunning.validate() + } + + override fun visitSessionThreadStatusIdle( + sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent + ) { + sessionThreadStatusIdle.validate() + } + + override fun visitSessionThreadStatusTerminated( + sessionThreadStatusTerminated: + BetaManagedAgentsSessionThreadStatusTerminatedEvent + ) { + sessionThreadStatusTerminated.validate() + } + + override fun visitSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled: + BetaManagedAgentsSessionThreadStatusRescheduledEvent + ) { + sessionThreadStatusRescheduled.validate() + } } ) validated = true @@ -515,6 +801,14 @@ private constructor( agentToolResult: BetaManagedAgentsAgentToolResultEvent ) = agentToolResult.validity() + override fun visitAgentThreadMessageReceived( + agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent + ) = agentThreadMessageReceived.validity() + + override fun visitAgentThreadMessageSent( + agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent + ) = agentThreadMessageSent.validity() + override fun visitAgentThreadContextCompacted( agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent ) = agentThreadContextCompacted.validity() @@ -538,6 +832,18 @@ private constructor( sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent ) = sessionStatusTerminated.validity() + override fun visitSessionThreadCreated( + sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent + ) = sessionThreadCreated.validity() + + override fun visitSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ) = spanOutcomeEvaluationStart.validity() + + override fun visitSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ) = spanOutcomeEvaluationEnd.validity() + override fun visitSpanModelRequestStart( spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent ) = spanModelRequestStart.validity() @@ -546,10 +852,36 @@ private constructor( spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent ) = spanModelRequestEnd.validity() + override fun visitSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ) = spanOutcomeEvaluationOngoing.validity() + + override fun visitUserDefineOutcome( + userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent + ) = userDefineOutcome.validity() + override fun visitSessionDeleted( sessionDeleted: BetaManagedAgentsSessionDeletedEvent ) = sessionDeleted.validity() + override fun visitSessionThreadStatusRunning( + sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent + ) = sessionThreadStatusRunning.validity() + + override fun visitSessionThreadStatusIdle( + sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent + ) = sessionThreadStatusIdle.validity() + + override fun visitSessionThreadStatusTerminated( + sessionThreadStatusTerminated: + BetaManagedAgentsSessionThreadStatusTerminatedEvent + ) = sessionThreadStatusTerminated.validity() + + override fun visitSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled: + BetaManagedAgentsSessionThreadStatusRescheduledEvent + ) = sessionThreadStatusRescheduled.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -571,15 +903,26 @@ private constructor( agentMcpToolResult == other.agentMcpToolResult && agentToolUse == other.agentToolUse && agentToolResult == other.agentToolResult && + agentThreadMessageReceived == other.agentThreadMessageReceived && + agentThreadMessageSent == other.agentThreadMessageSent && agentThreadContextCompacted == other.agentThreadContextCompacted && sessionError == other.sessionError && sessionStatusRescheduled == other.sessionStatusRescheduled && sessionStatusRunning == other.sessionStatusRunning && sessionStatusIdle == other.sessionStatusIdle && sessionStatusTerminated == other.sessionStatusTerminated && + sessionThreadCreated == other.sessionThreadCreated && + spanOutcomeEvaluationStart == other.spanOutcomeEvaluationStart && + spanOutcomeEvaluationEnd == other.spanOutcomeEvaluationEnd && spanModelRequestStart == other.spanModelRequestStart && spanModelRequestEnd == other.spanModelRequestEnd && - sessionDeleted == other.sessionDeleted + spanOutcomeEvaluationOngoing == other.spanOutcomeEvaluationOngoing && + userDefineOutcome == other.userDefineOutcome && + sessionDeleted == other.sessionDeleted && + sessionThreadStatusRunning == other.sessionThreadStatusRunning && + sessionThreadStatusIdle == other.sessionThreadStatusIdle && + sessionThreadStatusTerminated == other.sessionThreadStatusTerminated && + sessionThreadStatusRescheduled == other.sessionThreadStatusRescheduled } override fun hashCode(): Int = @@ -595,15 +938,26 @@ private constructor( agentMcpToolResult, agentToolUse, agentToolResult, + agentThreadMessageReceived, + agentThreadMessageSent, agentThreadContextCompacted, sessionError, sessionStatusRescheduled, sessionStatusRunning, sessionStatusIdle, sessionStatusTerminated, + sessionThreadCreated, + spanOutcomeEvaluationStart, + spanOutcomeEvaluationEnd, spanModelRequestStart, spanModelRequestEnd, + spanOutcomeEvaluationOngoing, + userDefineOutcome, sessionDeleted, + sessionThreadStatusRunning, + sessionThreadStatusIdle, + sessionThreadStatusTerminated, + sessionThreadStatusRescheduled, ) override fun toString(): String = @@ -625,6 +979,10 @@ private constructor( agentToolUse != null -> "BetaManagedAgentsSessionEvent{agentToolUse=$agentToolUse}" agentToolResult != null -> "BetaManagedAgentsSessionEvent{agentToolResult=$agentToolResult}" + agentThreadMessageReceived != null -> + "BetaManagedAgentsSessionEvent{agentThreadMessageReceived=$agentThreadMessageReceived}" + agentThreadMessageSent != null -> + "BetaManagedAgentsSessionEvent{agentThreadMessageSent=$agentThreadMessageSent}" agentThreadContextCompacted != null -> "BetaManagedAgentsSessionEvent{agentThreadContextCompacted=$agentThreadContextCompacted}" sessionError != null -> "BetaManagedAgentsSessionEvent{sessionError=$sessionError}" @@ -636,12 +994,30 @@ private constructor( "BetaManagedAgentsSessionEvent{sessionStatusIdle=$sessionStatusIdle}" sessionStatusTerminated != null -> "BetaManagedAgentsSessionEvent{sessionStatusTerminated=$sessionStatusTerminated}" + sessionThreadCreated != null -> + "BetaManagedAgentsSessionEvent{sessionThreadCreated=$sessionThreadCreated}" + spanOutcomeEvaluationStart != null -> + "BetaManagedAgentsSessionEvent{spanOutcomeEvaluationStart=$spanOutcomeEvaluationStart}" + spanOutcomeEvaluationEnd != null -> + "BetaManagedAgentsSessionEvent{spanOutcomeEvaluationEnd=$spanOutcomeEvaluationEnd}" spanModelRequestStart != null -> "BetaManagedAgentsSessionEvent{spanModelRequestStart=$spanModelRequestStart}" spanModelRequestEnd != null -> "BetaManagedAgentsSessionEvent{spanModelRequestEnd=$spanModelRequestEnd}" + spanOutcomeEvaluationOngoing != null -> + "BetaManagedAgentsSessionEvent{spanOutcomeEvaluationOngoing=$spanOutcomeEvaluationOngoing}" + userDefineOutcome != null -> + "BetaManagedAgentsSessionEvent{userDefineOutcome=$userDefineOutcome}" sessionDeleted != null -> "BetaManagedAgentsSessionEvent{sessionDeleted=$sessionDeleted}" + sessionThreadStatusRunning != null -> + "BetaManagedAgentsSessionEvent{sessionThreadStatusRunning=$sessionThreadStatusRunning}" + sessionThreadStatusIdle != null -> + "BetaManagedAgentsSessionEvent{sessionThreadStatusIdle=$sessionThreadStatusIdle}" + sessionThreadStatusTerminated != null -> + "BetaManagedAgentsSessionEvent{sessionThreadStatusTerminated=$sessionThreadStatusTerminated}" + sessionThreadStatusRescheduled != null -> + "BetaManagedAgentsSessionEvent{sessionThreadStatusRescheduled=$sessionThreadStatusRescheduled}" _json != null -> "BetaManagedAgentsSessionEvent{_unknown=$_json}" else -> throw IllegalStateException("Invalid BetaManagedAgentsSessionEvent") } @@ -711,6 +1087,24 @@ private constructor( fun ofAgentToolResult(agentToolResult: BetaManagedAgentsAgentToolResultEvent) = BetaManagedAgentsSessionEvent(agentToolResult = agentToolResult) + /** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ + @JvmStatic + fun ofAgentThreadMessageReceived( + agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent + ) = BetaManagedAgentsSessionEvent(agentThreadMessageReceived = agentThreadMessageReceived) + + /** + * Observability event emitted to the sender's output stream when an agent-to-agent message + * is sent. + */ + @JvmStatic + fun ofAgentThreadMessageSent( + agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent + ) = BetaManagedAgentsSessionEvent(agentThreadMessageSent = agentThreadMessageSent) + /** Indicates that context compaction (summarization) occurred during the session. */ @JvmStatic fun ofAgentThreadContextCompacted( @@ -747,6 +1141,32 @@ private constructor( sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent ) = BetaManagedAgentsSessionEvent(sessionStatusTerminated = sessionStatusTerminated) + /** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output + * stream so clients observing the session see child creation. + */ + @JvmStatic + fun ofSessionThreadCreated( + sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent + ) = BetaManagedAgentsSessionEvent(sessionThreadCreated = sessionThreadCreated) + + /** Emitted when an outcome evaluation cycle begins. */ + @JvmStatic + fun ofSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ) = BetaManagedAgentsSessionEvent(spanOutcomeEvaluationStart = spanOutcomeEvaluationStart) + + /** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate + * token usage. A verdict of `needs_revision` means another evaluation cycle follows; + * `satisfied`, `max_iterations_reached`, `failed`, or `interrupted` are terminal — no + * further evaluation cycles follow. + */ + @JvmStatic + fun ofSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ) = BetaManagedAgentsSessionEvent(spanOutcomeEvaluationEnd = spanOutcomeEvaluationEnd) + /** Emitted when a model request is initiated by the agent. */ @JvmStatic fun ofSpanModelRequestStart( @@ -758,6 +1178,27 @@ private constructor( fun ofSpanModelRequestEnd(spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent) = BetaManagedAgentsSessionEvent(spanModelRequestEnd = spanModelRequestEnd) + /** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. + * Distinguishes 'evaluation is actively running' from 'evaluation is stuck' between the + * corresponding `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ + @JvmStatic + fun ofSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ) = + BetaManagedAgentsSessionEvent( + spanOutcomeEvaluationOngoing = spanOutcomeEvaluationOngoing + ) + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` + * that subsequent `span.outcome_evaluation_*` events reference. + */ + @JvmStatic + fun ofUserDefineOutcome(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent) = + BetaManagedAgentsSessionEvent(userDefineOutcome = userDefineOutcome) + /** * Emitted when a session has been deleted. Terminates any active event stream — no further * events will be emitted for this session. @@ -765,6 +1206,48 @@ private constructor( @JvmStatic fun ofSessionDeleted(sessionDeleted: BetaManagedAgentsSessionDeletedEvent) = BetaManagedAgentsSessionEvent(sessionDeleted = sessionDeleted) + + /** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted + * to the primary stream for child threads. + */ + @JvmStatic + fun ofSessionThreadStatusRunning( + sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent + ) = BetaManagedAgentsSessionEvent(sessionThreadStatusRunning = sessionThreadStatusRunning) + + /** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream + * and cross-posted to the primary stream for child threads. + */ + @JvmStatic + fun ofSessionThreadStatusIdle( + sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent + ) = BetaManagedAgentsSessionEvent(sessionThreadStatusIdle = sessionThreadStatusIdle) + + /** + * A session thread has terminated and will accept no further input. Emitted on the thread's + * own stream and cross-posted to the primary stream for child threads. + */ + @JvmStatic + fun ofSessionThreadStatusTerminated( + sessionThreadStatusTerminated: BetaManagedAgentsSessionThreadStatusTerminatedEvent + ) = + BetaManagedAgentsSessionEvent( + sessionThreadStatusTerminated = sessionThreadStatusTerminated + ) + + /** + * A session thread hit a transient error and is retrying automatically. Emitted on the + * thread's own stream and cross-posted to the primary stream for child threads. + */ + @JvmStatic + fun ofSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled: BetaManagedAgentsSessionThreadStatusRescheduledEvent + ) = + BetaManagedAgentsSessionEvent( + sessionThreadStatusRescheduled = sessionThreadStatusRescheduled + ) } /** @@ -816,6 +1299,22 @@ private constructor( /** Event representing the result of an agent tool execution. */ fun visitAgentToolResult(agentToolResult: BetaManagedAgentsAgentToolResultEvent): T + /** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ + fun visitAgentThreadMessageReceived( + agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent + ): T + + /** + * Observability event emitted to the sender's output stream when an agent-to-agent message + * is sent. + */ + fun visitAgentThreadMessageSent( + agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent + ): T + /** Indicates that context compaction (summarization) occurred during the session. */ fun visitAgentThreadContextCompacted( agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent @@ -844,6 +1343,29 @@ private constructor( sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent ): T + /** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output + * stream so clients observing the session see child creation. + */ + fun visitSessionThreadCreated( + sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent + ): T + + /** Emitted when an outcome evaluation cycle begins. */ + fun visitSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ): T + + /** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate + * token usage. A verdict of `needs_revision` means another evaluation cycle follows; + * `satisfied`, `max_iterations_reached`, `failed`, or `interrupted` are terminal — no + * further evaluation cycles follow. + */ + fun visitSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ): T + /** Emitted when a model request is initiated by the agent. */ fun visitSpanModelRequestStart( spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent @@ -854,12 +1376,59 @@ private constructor( spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent ): T + /** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. + * Distinguishes 'evaluation is actively running' from 'evaluation is stuck' between the + * corresponding `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ + fun visitSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ): T + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` + * that subsequent `span.outcome_evaluation_*` events reference. + */ + fun visitUserDefineOutcome(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent): T + /** * Emitted when a session has been deleted. Terminates any active event stream — no further * events will be emitted for this session. */ fun visitSessionDeleted(sessionDeleted: BetaManagedAgentsSessionDeletedEvent): T + /** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted + * to the primary stream for child threads. + */ + fun visitSessionThreadStatusRunning( + sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent + ): T + + /** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream + * and cross-posted to the primary stream for child threads. + */ + fun visitSessionThreadStatusIdle( + sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent + ): T + + /** + * A session thread has terminated and will accept no further input. Emitted on the thread's + * own stream and cross-posted to the primary stream for child threads. + */ + fun visitSessionThreadStatusTerminated( + sessionThreadStatusTerminated: BetaManagedAgentsSessionThreadStatusTerminatedEvent + ): T + + /** + * A session thread hit a transient error and is retrying automatically. Emitted on the + * thread's own stream and cross-posted to the primary stream for child threads. + */ + fun visitSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled: BetaManagedAgentsSessionThreadStatusRescheduledEvent + ): T + /** * Maps an unknown variant of [BetaManagedAgentsSessionEvent] to a value of type [T]. * @@ -972,6 +1541,27 @@ private constructor( ?.let { BetaManagedAgentsSessionEvent(agentToolResult = it, _json = json) } ?: BetaManagedAgentsSessionEvent(_json = json) } + "agent.thread_message_received" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsSessionEvent( + agentThreadMessageReceived = it, + _json = json, + ) + } ?: BetaManagedAgentsSessionEvent(_json = json) + } + "agent.thread_message_sent" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsSessionEvent(agentThreadMessageSent = it, _json = json) + } ?: BetaManagedAgentsSessionEvent(_json = json) + } "agent.thread_context_compacted" -> { return tryDeserialize( node, @@ -1034,6 +1624,39 @@ private constructor( ) } ?: BetaManagedAgentsSessionEvent(_json = json) } + "session.thread_created" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsSessionEvent(sessionThreadCreated = it, _json = json) + } ?: BetaManagedAgentsSessionEvent(_json = json) + } + "span.outcome_evaluation_start" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsSessionEvent( + spanOutcomeEvaluationStart = it, + _json = json, + ) + } ?: BetaManagedAgentsSessionEvent(_json = json) + } + "span.outcome_evaluation_end" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsSessionEvent( + spanOutcomeEvaluationEnd = it, + _json = json, + ) + } ?: BetaManagedAgentsSessionEvent(_json = json) + } "span.model_request_start" -> { return tryDeserialize( node, @@ -1052,6 +1675,27 @@ private constructor( BetaManagedAgentsSessionEvent(spanModelRequestEnd = it, _json = json) } ?: BetaManagedAgentsSessionEvent(_json = json) } + "span.outcome_evaluation_ongoing" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsSessionEvent( + spanOutcomeEvaluationOngoing = it, + _json = json, + ) + } ?: BetaManagedAgentsSessionEvent(_json = json) + } + "user.define_outcome" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsSessionEvent(userDefineOutcome = it, _json = json) + } ?: BetaManagedAgentsSessionEvent(_json = json) + } "session.deleted" -> { return tryDeserialize( node, @@ -1060,6 +1704,54 @@ private constructor( ?.let { BetaManagedAgentsSessionEvent(sessionDeleted = it, _json = json) } ?: BetaManagedAgentsSessionEvent(_json = json) } + "session.thread_status_running" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsSessionEvent( + sessionThreadStatusRunning = it, + _json = json, + ) + } ?: BetaManagedAgentsSessionEvent(_json = json) + } + "session.thread_status_idle" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsSessionEvent( + sessionThreadStatusIdle = it, + _json = json, + ) + } ?: BetaManagedAgentsSessionEvent(_json = json) + } + "session.thread_status_terminated" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsSessionEvent( + sessionThreadStatusTerminated = it, + _json = json, + ) + } ?: BetaManagedAgentsSessionEvent(_json = json) + } + "session.thread_status_rescheduled" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsSessionEvent( + sessionThreadStatusRescheduled = it, + _json = json, + ) + } ?: BetaManagedAgentsSessionEvent(_json = json) + } } return BetaManagedAgentsSessionEvent(_json = json) @@ -1088,6 +1780,10 @@ private constructor( value.agentMcpToolResult != null -> generator.writeObject(value.agentMcpToolResult) value.agentToolUse != null -> generator.writeObject(value.agentToolUse) value.agentToolResult != null -> generator.writeObject(value.agentToolResult) + value.agentThreadMessageReceived != null -> + generator.writeObject(value.agentThreadMessageReceived) + value.agentThreadMessageSent != null -> + generator.writeObject(value.agentThreadMessageSent) value.agentThreadContextCompacted != null -> generator.writeObject(value.agentThreadContextCompacted) value.sessionError != null -> generator.writeObject(value.sessionError) @@ -1098,11 +1794,28 @@ private constructor( value.sessionStatusIdle != null -> generator.writeObject(value.sessionStatusIdle) value.sessionStatusTerminated != null -> generator.writeObject(value.sessionStatusTerminated) + value.sessionThreadCreated != null -> + generator.writeObject(value.sessionThreadCreated) + value.spanOutcomeEvaluationStart != null -> + generator.writeObject(value.spanOutcomeEvaluationStart) + value.spanOutcomeEvaluationEnd != null -> + generator.writeObject(value.spanOutcomeEvaluationEnd) value.spanModelRequestStart != null -> generator.writeObject(value.spanModelRequestStart) value.spanModelRequestEnd != null -> generator.writeObject(value.spanModelRequestEnd) + value.spanOutcomeEvaluationOngoing != null -> + generator.writeObject(value.spanOutcomeEvaluationOngoing) + value.userDefineOutcome != null -> generator.writeObject(value.userDefineOutcome) value.sessionDeleted != null -> generator.writeObject(value.sessionDeleted) + value.sessionThreadStatusRunning != null -> + generator.writeObject(value.sessionThreadStatusRunning) + value.sessionThreadStatusIdle != null -> + generator.writeObject(value.sessionThreadStatusIdle) + value.sessionThreadStatusTerminated != null -> + generator.writeObject(value.sessionThreadStatusTerminated) + value.sessionThreadStatusRescheduled != null -> + generator.writeObject(value.sessionThreadStatusRescheduled) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid BetaManagedAgentsSessionEvent") } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadCreatedEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadCreatedEvent.kt new file mode 100644 index 000000000..701f8522c --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadCreatedEvent.kt @@ -0,0 +1,483 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output stream + * so clients observing the session see child creation. + */ +class BetaManagedAgentsSessionThreadCreatedEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val agentName: JsonField, + private val processedAt: JsonField, + private val sessionThreadId: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("agent_name") @ExcludeMissing agentName: JsonField = JsonMissing.of(), + @JsonProperty("processed_at") + @ExcludeMissing + processedAt: JsonField = JsonMissing.of(), + @JsonProperty("session_thread_id") + @ExcludeMissing + sessionThreadId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(id, agentName, processedAt, sessionThreadId, type, mutableMapOf()) + + /** + * Unique identifier for this event. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * Name of the callable agent the thread runs. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun agentName(): String = agentName.getRequired("agent_name") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun processedAt(): OffsetDateTime = processedAt.getRequired("processed_at") + + /** + * Public `sthr_` ID of the newly created thread. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun sessionThreadId(): String = sessionThreadId.getRequired("session_thread_id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [agentName]. + * + * Unlike [agentName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("agent_name") @ExcludeMissing fun _agentName(): JsonField = agentName + + /** + * Returns the raw JSON value of [processedAt]. + * + * Unlike [processedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processed_at") + @ExcludeMissing + fun _processedAt(): JsonField = processedAt + + /** + * Returns the raw JSON value of [sessionThreadId]. + * + * Unlike [sessionThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_thread_id") + @ExcludeMissing + fun _sessionThreadId(): JsonField = sessionThreadId + + /** + * 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 + * [BetaManagedAgentsSessionThreadCreatedEvent]. + * + * The following fields are required: + * ```java + * .id() + * .agentName() + * .processedAt() + * .sessionThreadId() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSessionThreadCreatedEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var agentName: JsonField? = null + private var processedAt: JsonField? = null + private var sessionThreadId: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsSessionThreadCreatedEvent: BetaManagedAgentsSessionThreadCreatedEvent + ) = apply { + id = betaManagedAgentsSessionThreadCreatedEvent.id + agentName = betaManagedAgentsSessionThreadCreatedEvent.agentName + processedAt = betaManagedAgentsSessionThreadCreatedEvent.processedAt + sessionThreadId = betaManagedAgentsSessionThreadCreatedEvent.sessionThreadId + type = betaManagedAgentsSessionThreadCreatedEvent.type + additionalProperties = + betaManagedAgentsSessionThreadCreatedEvent.additionalProperties.toMutableMap() + } + + /** Unique identifier for this event. */ + 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 } + + /** Name of the callable agent the thread runs. */ + fun agentName(agentName: String) = agentName(JsonField.of(agentName)) + + /** + * Sets [Builder.agentName] to an arbitrary JSON value. + * + * You should usually call [Builder.agentName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun agentName(agentName: JsonField) = apply { this.agentName = agentName } + + /** A timestamp in RFC 3339 format */ + fun processedAt(processedAt: OffsetDateTime) = processedAt(JsonField.of(processedAt)) + + /** + * Sets [Builder.processedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.processedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedAt(processedAt: JsonField) = apply { + this.processedAt = processedAt + } + + /** Public `sthr_` ID of the newly created thread. */ + fun sessionThreadId(sessionThreadId: String) = + sessionThreadId(JsonField.of(sessionThreadId)) + + /** + * Sets [Builder.sessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sessionThreadId(sessionThreadId: JsonField) = apply { + this.sessionThreadId = sessionThreadId + } + + 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 [BetaManagedAgentsSessionThreadCreatedEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .agentName() + * .processedAt() + * .sessionThreadId() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsSessionThreadCreatedEvent = + BetaManagedAgentsSessionThreadCreatedEvent( + checkRequired("id", id), + checkRequired("agentName", agentName), + checkRequired("processedAt", processedAt), + checkRequired("sessionThreadId", sessionThreadId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSessionThreadCreatedEvent = apply { + if (validated) { + return@apply + } + + id() + agentName() + processedAt() + sessionThreadId() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (agentName.asKnown().isPresent) 1 else 0) + + (if (processedAt.asKnown().isPresent) 1 else 0) + + (if (sessionThreadId.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 SESSION_THREAD_CREATED = of("session.thread_created") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SESSION_THREAD_CREATED + } + + /** + * 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 { + SESSION_THREAD_CREATED, + /** 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) { + SESSION_THREAD_CREATED -> Value.SESSION_THREAD_CREATED + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SESSION_THREAD_CREATED -> Known.SESSION_THREAD_CREATED + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsSessionThreadCreatedEvent && + id == other.id && + agentName == other.agentName && + processedAt == other.processedAt && + sessionThreadId == other.sessionThreadId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, agentName, processedAt, sessionThreadId, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSessionThreadCreatedEvent{id=$id, agentName=$agentName, processedAt=$processedAt, sessionThreadId=$sessionThreadId, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusIdleEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusIdleEvent.kt new file mode 100644 index 000000000..0d75e4514 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusIdleEvent.kt @@ -0,0 +1,873 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.core.getOrThrow +import com.anthropic.errors.AnthropicInvalidDataException +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.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream and + * cross-posted to the primary stream for child threads. + */ +class BetaManagedAgentsSessionThreadStatusIdleEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val agentName: JsonField, + private val processedAt: JsonField, + private val sessionThreadId: JsonField, + private val stopReason: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("agent_name") @ExcludeMissing agentName: JsonField = JsonMissing.of(), + @JsonProperty("processed_at") + @ExcludeMissing + processedAt: JsonField = JsonMissing.of(), + @JsonProperty("session_thread_id") + @ExcludeMissing + sessionThreadId: JsonField = JsonMissing.of(), + @JsonProperty("stop_reason") + @ExcludeMissing + stopReason: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(id, agentName, processedAt, sessionThreadId, stopReason, type, mutableMapOf()) + + /** + * Unique identifier for this event. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * Name of the agent the thread runs. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun agentName(): String = agentName.getRequired("agent_name") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun processedAt(): OffsetDateTime = processedAt.getRequired("processed_at") + + /** + * Public sthr_ ID of the thread that went idle. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun sessionThreadId(): String = sessionThreadId.getRequired("session_thread_id") + + /** + * The agent completed its turn naturally and is ready for the next user message. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun stopReason(): StopReason = stopReason.getRequired("stop_reason") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [agentName]. + * + * Unlike [agentName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("agent_name") @ExcludeMissing fun _agentName(): JsonField = agentName + + /** + * Returns the raw JSON value of [processedAt]. + * + * Unlike [processedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processed_at") + @ExcludeMissing + fun _processedAt(): JsonField = processedAt + + /** + * Returns the raw JSON value of [sessionThreadId]. + * + * Unlike [sessionThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_thread_id") + @ExcludeMissing + fun _sessionThreadId(): JsonField = sessionThreadId + + /** + * Returns the raw JSON value of [stopReason]. + * + * Unlike [stopReason], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("stop_reason") + @ExcludeMissing + fun _stopReason(): JsonField = stopReason + + /** + * 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 + * [BetaManagedAgentsSessionThreadStatusIdleEvent]. + * + * The following fields are required: + * ```java + * .id() + * .agentName() + * .processedAt() + * .sessionThreadId() + * .stopReason() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSessionThreadStatusIdleEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var agentName: JsonField? = null + private var processedAt: JsonField? = null + private var sessionThreadId: JsonField? = null + private var stopReason: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsSessionThreadStatusIdleEvent: + BetaManagedAgentsSessionThreadStatusIdleEvent + ) = apply { + id = betaManagedAgentsSessionThreadStatusIdleEvent.id + agentName = betaManagedAgentsSessionThreadStatusIdleEvent.agentName + processedAt = betaManagedAgentsSessionThreadStatusIdleEvent.processedAt + sessionThreadId = betaManagedAgentsSessionThreadStatusIdleEvent.sessionThreadId + stopReason = betaManagedAgentsSessionThreadStatusIdleEvent.stopReason + type = betaManagedAgentsSessionThreadStatusIdleEvent.type + additionalProperties = + betaManagedAgentsSessionThreadStatusIdleEvent.additionalProperties.toMutableMap() + } + + /** Unique identifier for this event. */ + 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 } + + /** Name of the agent the thread runs. */ + fun agentName(agentName: String) = agentName(JsonField.of(agentName)) + + /** + * Sets [Builder.agentName] to an arbitrary JSON value. + * + * You should usually call [Builder.agentName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun agentName(agentName: JsonField) = apply { this.agentName = agentName } + + /** A timestamp in RFC 3339 format */ + fun processedAt(processedAt: OffsetDateTime) = processedAt(JsonField.of(processedAt)) + + /** + * Sets [Builder.processedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.processedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedAt(processedAt: JsonField) = apply { + this.processedAt = processedAt + } + + /** Public sthr_ ID of the thread that went idle. */ + fun sessionThreadId(sessionThreadId: String) = + sessionThreadId(JsonField.of(sessionThreadId)) + + /** + * Sets [Builder.sessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sessionThreadId(sessionThreadId: JsonField) = apply { + this.sessionThreadId = sessionThreadId + } + + /** The agent completed its turn naturally and is ready for the next user message. */ + fun stopReason(stopReason: StopReason) = stopReason(JsonField.of(stopReason)) + + /** + * Sets [Builder.stopReason] to an arbitrary JSON value. + * + * You should usually call [Builder.stopReason] with a well-typed [StopReason] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun stopReason(stopReason: JsonField) = apply { this.stopReason = stopReason } + + /** Alias for calling [stopReason] with `StopReason.ofEndTurn(endTurn)`. */ + fun stopReason(endTurn: BetaManagedAgentsSessionEndTurn) = + stopReason(StopReason.ofEndTurn(endTurn)) + + /** Alias for calling [stopReason] with `StopReason.ofRequiresAction(requiresAction)`. */ + fun stopReason(requiresAction: BetaManagedAgentsSessionRequiresAction) = + stopReason(StopReason.ofRequiresAction(requiresAction)) + + /** + * Alias for calling [stopReason] with the following: + * ```java + * BetaManagedAgentsSessionRequiresAction.builder() + * .type(BetaManagedAgentsSessionRequiresAction.Type.REQUIRES_ACTION) + * .eventIds(eventIds) + * .build() + * ``` + */ + fun requiresActionStopReason(eventIds: List) = + stopReason( + BetaManagedAgentsSessionRequiresAction.builder() + .type(BetaManagedAgentsSessionRequiresAction.Type.REQUIRES_ACTION) + .eventIds(eventIds) + .build() + ) + + /** + * Alias for calling [stopReason] with `StopReason.ofRetriesExhausted(retriesExhausted)`. + */ + fun stopReason(retriesExhausted: BetaManagedAgentsSessionRetriesExhausted) = + stopReason(StopReason.ofRetriesExhausted(retriesExhausted)) + + 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 [BetaManagedAgentsSessionThreadStatusIdleEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .agentName() + * .processedAt() + * .sessionThreadId() + * .stopReason() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsSessionThreadStatusIdleEvent = + BetaManagedAgentsSessionThreadStatusIdleEvent( + checkRequired("id", id), + checkRequired("agentName", agentName), + checkRequired("processedAt", processedAt), + checkRequired("sessionThreadId", sessionThreadId), + checkRequired("stopReason", stopReason), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSessionThreadStatusIdleEvent = apply { + if (validated) { + return@apply + } + + id() + agentName() + processedAt() + sessionThreadId() + stopReason().validate() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (agentName.asKnown().isPresent) 1 else 0) + + (if (processedAt.asKnown().isPresent) 1 else 0) + + (if (sessionThreadId.asKnown().isPresent) 1 else 0) + + (stopReason.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + /** The agent completed its turn naturally and is ready for the next user message. */ + @JsonDeserialize(using = StopReason.Deserializer::class) + @JsonSerialize(using = StopReason.Serializer::class) + class StopReason + private constructor( + private val endTurn: BetaManagedAgentsSessionEndTurn? = null, + private val requiresAction: BetaManagedAgentsSessionRequiresAction? = null, + private val retriesExhausted: BetaManagedAgentsSessionRetriesExhausted? = null, + private val _json: JsonValue? = null, + ) { + + /** The agent completed its turn naturally and is ready for the next user message. */ + fun endTurn(): Optional = Optional.ofNullable(endTurn) + + /** + * The agent is idle waiting on one or more blocking user-input events (tool confirmation, + * custom tool result, etc.). Resolving all of them transitions the session back to running. + */ + fun requiresAction(): Optional = + Optional.ofNullable(requiresAction) + + /** + * The turn ended because the retry budget was exhausted (`max_iterations` hit or an error + * escalated to `retry_status: 'exhausted'`). + */ + fun retriesExhausted(): Optional = + Optional.ofNullable(retriesExhausted) + + fun isEndTurn(): Boolean = endTurn != null + + fun isRequiresAction(): Boolean = requiresAction != null + + fun isRetriesExhausted(): Boolean = retriesExhausted != null + + /** The agent completed its turn naturally and is ready for the next user message. */ + fun asEndTurn(): BetaManagedAgentsSessionEndTurn = endTurn.getOrThrow("endTurn") + + /** + * The agent is idle waiting on one or more blocking user-input events (tool confirmation, + * custom tool result, etc.). Resolving all of them transitions the session back to running. + */ + fun asRequiresAction(): BetaManagedAgentsSessionRequiresAction = + requiresAction.getOrThrow("requiresAction") + + /** + * The turn ended because the retry budget was exhausted (`max_iterations` hit or an error + * escalated to `retry_status: 'exhausted'`). + */ + fun asRetriesExhausted(): BetaManagedAgentsSessionRetriesExhausted = + retriesExhausted.getOrThrow("retriesExhausted") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, unless + * [visitor] overrides [Visitor.unknown]. To handle variants not known to this version of + * the SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.anthropic.core.JsonValue; + * import java.util.Optional; + * + * Optional result = stopReason.accept(new StopReason.Visitor>() { + * @Override + * public Optional visitEndTurn(BetaManagedAgentsSessionEndTurn endTurn) { + * return Optional.of(endTurn.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws AnthropicInvalidDataException if [Visitor.unknown] is not overridden in [visitor] + * and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + endTurn != null -> visitor.visitEndTurn(endTurn) + requiresAction != null -> visitor.visitRequiresAction(requiresAction) + retriesExhausted != null -> visitor.visitRetriesExhausted(retriesExhausted) + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): StopReason = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitEndTurn(endTurn: BetaManagedAgentsSessionEndTurn) { + endTurn.validate() + } + + override fun visitRequiresAction( + requiresAction: BetaManagedAgentsSessionRequiresAction + ) { + requiresAction.validate() + } + + override fun visitRetriesExhausted( + retriesExhausted: BetaManagedAgentsSessionRetriesExhausted + ) { + retriesExhausted.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 visitEndTurn(endTurn: BetaManagedAgentsSessionEndTurn) = + endTurn.validity() + + override fun visitRequiresAction( + requiresAction: BetaManagedAgentsSessionRequiresAction + ) = requiresAction.validity() + + override fun visitRetriesExhausted( + retriesExhausted: BetaManagedAgentsSessionRetriesExhausted + ) = retriesExhausted.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StopReason && + endTurn == other.endTurn && + requiresAction == other.requiresAction && + retriesExhausted == other.retriesExhausted + } + + override fun hashCode(): Int = Objects.hash(endTurn, requiresAction, retriesExhausted) + + override fun toString(): String = + when { + endTurn != null -> "StopReason{endTurn=$endTurn}" + requiresAction != null -> "StopReason{requiresAction=$requiresAction}" + retriesExhausted != null -> "StopReason{retriesExhausted=$retriesExhausted}" + _json != null -> "StopReason{_unknown=$_json}" + else -> throw IllegalStateException("Invalid StopReason") + } + + companion object { + + /** The agent completed its turn naturally and is ready for the next user message. */ + @JvmStatic + fun ofEndTurn(endTurn: BetaManagedAgentsSessionEndTurn) = StopReason(endTurn = endTurn) + + /** + * The agent is idle waiting on one or more blocking user-input events (tool + * confirmation, custom tool result, etc.). Resolving all of them transitions the + * session back to running. + */ + @JvmStatic + fun ofRequiresAction(requiresAction: BetaManagedAgentsSessionRequiresAction) = + StopReason(requiresAction = requiresAction) + + /** + * The turn ended because the retry budget was exhausted (`max_iterations` hit or an + * error escalated to `retry_status: 'exhausted'`). + */ + @JvmStatic + fun ofRetriesExhausted(retriesExhausted: BetaManagedAgentsSessionRetriesExhausted) = + StopReason(retriesExhausted = retriesExhausted) + } + + /** + * An interface that defines how to map each variant of [StopReason] to a value of type [T]. + */ + interface Visitor { + + /** The agent completed its turn naturally and is ready for the next user message. */ + fun visitEndTurn(endTurn: BetaManagedAgentsSessionEndTurn): T + + /** + * The agent is idle waiting on one or more blocking user-input events (tool + * confirmation, custom tool result, etc.). Resolving all of them transitions the + * session back to running. + */ + fun visitRequiresAction(requiresAction: BetaManagedAgentsSessionRequiresAction): T + + /** + * The turn ended because the retry budget was exhausted (`max_iterations` hit or an + * error escalated to `retry_status: 'exhausted'`). + */ + fun visitRetriesExhausted(retriesExhausted: BetaManagedAgentsSessionRetriesExhausted): T + + /** + * Maps an unknown variant of [StopReason] to a value of type [T]. + * + * An instance of [StopReason] 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 AnthropicInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw AnthropicInvalidDataException("Unknown StopReason: $json") + } + } + + internal class Deserializer : BaseDeserializer(StopReason::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): StopReason { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "end_turn" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { StopReason(endTurn = it, _json = json) } + ?: StopReason(_json = json) + } + "requires_action" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { StopReason(requiresAction = it, _json = json) } + ?: StopReason(_json = json) + } + "retries_exhausted" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { StopReason(retriesExhausted = it, _json = json) } + ?: StopReason(_json = json) + } + } + + return StopReason(_json = json) + } + } + + internal class Serializer : BaseSerializer(StopReason::class) { + + override fun serialize( + value: StopReason, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.endTurn != null -> generator.writeObject(value.endTurn) + value.requiresAction != null -> generator.writeObject(value.requiresAction) + value.retriesExhausted != null -> generator.writeObject(value.retriesExhausted) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid StopReason") + } + } + } + } + + 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 SESSION_THREAD_STATUS_IDLE = of("session.thread_status_idle") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SESSION_THREAD_STATUS_IDLE + } + + /** + * 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 { + SESSION_THREAD_STATUS_IDLE, + /** 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) { + SESSION_THREAD_STATUS_IDLE -> Value.SESSION_THREAD_STATUS_IDLE + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SESSION_THREAD_STATUS_IDLE -> Known.SESSION_THREAD_STATUS_IDLE + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsSessionThreadStatusIdleEvent && + id == other.id && + agentName == other.agentName && + processedAt == other.processedAt && + sessionThreadId == other.sessionThreadId && + stopReason == other.stopReason && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + agentName, + processedAt, + sessionThreadId, + stopReason, + type, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSessionThreadStatusIdleEvent{id=$id, agentName=$agentName, processedAt=$processedAt, sessionThreadId=$sessionThreadId, stopReason=$stopReason, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRescheduledEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRescheduledEvent.kt new file mode 100644 index 000000000..302e98231 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRescheduledEvent.kt @@ -0,0 +1,486 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** + * A session thread hit a transient error and is retrying automatically. Emitted on the thread's own + * stream and cross-posted to the primary stream for child threads. + */ +class BetaManagedAgentsSessionThreadStatusRescheduledEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val agentName: JsonField, + private val processedAt: JsonField, + private val sessionThreadId: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("agent_name") @ExcludeMissing agentName: JsonField = JsonMissing.of(), + @JsonProperty("processed_at") + @ExcludeMissing + processedAt: JsonField = JsonMissing.of(), + @JsonProperty("session_thread_id") + @ExcludeMissing + sessionThreadId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(id, agentName, processedAt, sessionThreadId, type, mutableMapOf()) + + /** + * Unique identifier for this event. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * Name of the agent the thread runs. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun agentName(): String = agentName.getRequired("agent_name") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun processedAt(): OffsetDateTime = processedAt.getRequired("processed_at") + + /** + * Public sthr_ ID of the thread that is retrying. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun sessionThreadId(): String = sessionThreadId.getRequired("session_thread_id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [agentName]. + * + * Unlike [agentName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("agent_name") @ExcludeMissing fun _agentName(): JsonField = agentName + + /** + * Returns the raw JSON value of [processedAt]. + * + * Unlike [processedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processed_at") + @ExcludeMissing + fun _processedAt(): JsonField = processedAt + + /** + * Returns the raw JSON value of [sessionThreadId]. + * + * Unlike [sessionThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_thread_id") + @ExcludeMissing + fun _sessionThreadId(): JsonField = sessionThreadId + + /** + * 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 + * [BetaManagedAgentsSessionThreadStatusRescheduledEvent]. + * + * The following fields are required: + * ```java + * .id() + * .agentName() + * .processedAt() + * .sessionThreadId() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSessionThreadStatusRescheduledEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var agentName: JsonField? = null + private var processedAt: JsonField? = null + private var sessionThreadId: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsSessionThreadStatusRescheduledEvent: + BetaManagedAgentsSessionThreadStatusRescheduledEvent + ) = apply { + id = betaManagedAgentsSessionThreadStatusRescheduledEvent.id + agentName = betaManagedAgentsSessionThreadStatusRescheduledEvent.agentName + processedAt = betaManagedAgentsSessionThreadStatusRescheduledEvent.processedAt + sessionThreadId = betaManagedAgentsSessionThreadStatusRescheduledEvent.sessionThreadId + type = betaManagedAgentsSessionThreadStatusRescheduledEvent.type + additionalProperties = + betaManagedAgentsSessionThreadStatusRescheduledEvent.additionalProperties + .toMutableMap() + } + + /** Unique identifier for this event. */ + 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 } + + /** Name of the agent the thread runs. */ + fun agentName(agentName: String) = agentName(JsonField.of(agentName)) + + /** + * Sets [Builder.agentName] to an arbitrary JSON value. + * + * You should usually call [Builder.agentName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun agentName(agentName: JsonField) = apply { this.agentName = agentName } + + /** A timestamp in RFC 3339 format */ + fun processedAt(processedAt: OffsetDateTime) = processedAt(JsonField.of(processedAt)) + + /** + * Sets [Builder.processedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.processedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedAt(processedAt: JsonField) = apply { + this.processedAt = processedAt + } + + /** Public sthr_ ID of the thread that is retrying. */ + fun sessionThreadId(sessionThreadId: String) = + sessionThreadId(JsonField.of(sessionThreadId)) + + /** + * Sets [Builder.sessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sessionThreadId(sessionThreadId: JsonField) = apply { + this.sessionThreadId = sessionThreadId + } + + 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 [BetaManagedAgentsSessionThreadStatusRescheduledEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .agentName() + * .processedAt() + * .sessionThreadId() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsSessionThreadStatusRescheduledEvent = + BetaManagedAgentsSessionThreadStatusRescheduledEvent( + checkRequired("id", id), + checkRequired("agentName", agentName), + checkRequired("processedAt", processedAt), + checkRequired("sessionThreadId", sessionThreadId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSessionThreadStatusRescheduledEvent = apply { + if (validated) { + return@apply + } + + id() + agentName() + processedAt() + sessionThreadId() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (agentName.asKnown().isPresent) 1 else 0) + + (if (processedAt.asKnown().isPresent) 1 else 0) + + (if (sessionThreadId.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 SESSION_THREAD_STATUS_RESCHEDULED = of("session.thread_status_rescheduled") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SESSION_THREAD_STATUS_RESCHEDULED + } + + /** + * 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 { + SESSION_THREAD_STATUS_RESCHEDULED, + /** 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) { + SESSION_THREAD_STATUS_RESCHEDULED -> Value.SESSION_THREAD_STATUS_RESCHEDULED + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SESSION_THREAD_STATUS_RESCHEDULED -> Known.SESSION_THREAD_STATUS_RESCHEDULED + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsSessionThreadStatusRescheduledEvent && + id == other.id && + agentName == other.agentName && + processedAt == other.processedAt && + sessionThreadId == other.sessionThreadId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, agentName, processedAt, sessionThreadId, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSessionThreadStatusRescheduledEvent{id=$id, agentName=$agentName, processedAt=$processedAt, sessionThreadId=$sessionThreadId, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRunningEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRunningEvent.kt new file mode 100644 index 000000000..bbb246795 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRunningEvent.kt @@ -0,0 +1,484 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted to the + * primary stream for child threads. + */ +class BetaManagedAgentsSessionThreadStatusRunningEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val agentName: JsonField, + private val processedAt: JsonField, + private val sessionThreadId: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("agent_name") @ExcludeMissing agentName: JsonField = JsonMissing.of(), + @JsonProperty("processed_at") + @ExcludeMissing + processedAt: JsonField = JsonMissing.of(), + @JsonProperty("session_thread_id") + @ExcludeMissing + sessionThreadId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(id, agentName, processedAt, sessionThreadId, type, mutableMapOf()) + + /** + * Unique identifier for this event. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * Name of the agent the thread runs. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun agentName(): String = agentName.getRequired("agent_name") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun processedAt(): OffsetDateTime = processedAt.getRequired("processed_at") + + /** + * Public sthr_ ID of the thread that started running. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun sessionThreadId(): String = sessionThreadId.getRequired("session_thread_id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [agentName]. + * + * Unlike [agentName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("agent_name") @ExcludeMissing fun _agentName(): JsonField = agentName + + /** + * Returns the raw JSON value of [processedAt]. + * + * Unlike [processedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processed_at") + @ExcludeMissing + fun _processedAt(): JsonField = processedAt + + /** + * Returns the raw JSON value of [sessionThreadId]. + * + * Unlike [sessionThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_thread_id") + @ExcludeMissing + fun _sessionThreadId(): JsonField = sessionThreadId + + /** + * 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 + * [BetaManagedAgentsSessionThreadStatusRunningEvent]. + * + * The following fields are required: + * ```java + * .id() + * .agentName() + * .processedAt() + * .sessionThreadId() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSessionThreadStatusRunningEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var agentName: JsonField? = null + private var processedAt: JsonField? = null + private var sessionThreadId: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsSessionThreadStatusRunningEvent: + BetaManagedAgentsSessionThreadStatusRunningEvent + ) = apply { + id = betaManagedAgentsSessionThreadStatusRunningEvent.id + agentName = betaManagedAgentsSessionThreadStatusRunningEvent.agentName + processedAt = betaManagedAgentsSessionThreadStatusRunningEvent.processedAt + sessionThreadId = betaManagedAgentsSessionThreadStatusRunningEvent.sessionThreadId + type = betaManagedAgentsSessionThreadStatusRunningEvent.type + additionalProperties = + betaManagedAgentsSessionThreadStatusRunningEvent.additionalProperties.toMutableMap() + } + + /** Unique identifier for this event. */ + 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 } + + /** Name of the agent the thread runs. */ + fun agentName(agentName: String) = agentName(JsonField.of(agentName)) + + /** + * Sets [Builder.agentName] to an arbitrary JSON value. + * + * You should usually call [Builder.agentName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun agentName(agentName: JsonField) = apply { this.agentName = agentName } + + /** A timestamp in RFC 3339 format */ + fun processedAt(processedAt: OffsetDateTime) = processedAt(JsonField.of(processedAt)) + + /** + * Sets [Builder.processedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.processedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedAt(processedAt: JsonField) = apply { + this.processedAt = processedAt + } + + /** Public sthr_ ID of the thread that started running. */ + fun sessionThreadId(sessionThreadId: String) = + sessionThreadId(JsonField.of(sessionThreadId)) + + /** + * Sets [Builder.sessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sessionThreadId(sessionThreadId: JsonField) = apply { + this.sessionThreadId = sessionThreadId + } + + 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 [BetaManagedAgentsSessionThreadStatusRunningEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .agentName() + * .processedAt() + * .sessionThreadId() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsSessionThreadStatusRunningEvent = + BetaManagedAgentsSessionThreadStatusRunningEvent( + checkRequired("id", id), + checkRequired("agentName", agentName), + checkRequired("processedAt", processedAt), + checkRequired("sessionThreadId", sessionThreadId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSessionThreadStatusRunningEvent = apply { + if (validated) { + return@apply + } + + id() + agentName() + processedAt() + sessionThreadId() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (agentName.asKnown().isPresent) 1 else 0) + + (if (processedAt.asKnown().isPresent) 1 else 0) + + (if (sessionThreadId.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 SESSION_THREAD_STATUS_RUNNING = of("session.thread_status_running") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SESSION_THREAD_STATUS_RUNNING + } + + /** + * 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 { + SESSION_THREAD_STATUS_RUNNING, + /** 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) { + SESSION_THREAD_STATUS_RUNNING -> Value.SESSION_THREAD_STATUS_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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SESSION_THREAD_STATUS_RUNNING -> Known.SESSION_THREAD_STATUS_RUNNING + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsSessionThreadStatusRunningEvent && + id == other.id && + agentName == other.agentName && + processedAt == other.processedAt && + sessionThreadId == other.sessionThreadId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, agentName, processedAt, sessionThreadId, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSessionThreadStatusRunningEvent{id=$id, agentName=$agentName, processedAt=$processedAt, sessionThreadId=$sessionThreadId, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusTerminatedEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusTerminatedEvent.kt new file mode 100644 index 000000000..f99439cd4 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusTerminatedEvent.kt @@ -0,0 +1,485 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** + * A session thread has terminated and will accept no further input. Emitted on the thread's own + * stream and cross-posted to the primary stream for child threads. + */ +class BetaManagedAgentsSessionThreadStatusTerminatedEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val agentName: JsonField, + private val processedAt: JsonField, + private val sessionThreadId: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("agent_name") @ExcludeMissing agentName: JsonField = JsonMissing.of(), + @JsonProperty("processed_at") + @ExcludeMissing + processedAt: JsonField = JsonMissing.of(), + @JsonProperty("session_thread_id") + @ExcludeMissing + sessionThreadId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(id, agentName, processedAt, sessionThreadId, type, mutableMapOf()) + + /** + * Unique identifier for this event. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * Name of the agent the thread runs. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun agentName(): String = agentName.getRequired("agent_name") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun processedAt(): OffsetDateTime = processedAt.getRequired("processed_at") + + /** + * Public sthr_ ID of the thread that terminated. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun sessionThreadId(): String = sessionThreadId.getRequired("session_thread_id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [agentName]. + * + * Unlike [agentName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("agent_name") @ExcludeMissing fun _agentName(): JsonField = agentName + + /** + * Returns the raw JSON value of [processedAt]. + * + * Unlike [processedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processed_at") + @ExcludeMissing + fun _processedAt(): JsonField = processedAt + + /** + * Returns the raw JSON value of [sessionThreadId]. + * + * Unlike [sessionThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_thread_id") + @ExcludeMissing + fun _sessionThreadId(): JsonField = sessionThreadId + + /** + * 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 + * [BetaManagedAgentsSessionThreadStatusTerminatedEvent]. + * + * The following fields are required: + * ```java + * .id() + * .agentName() + * .processedAt() + * .sessionThreadId() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSessionThreadStatusTerminatedEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var agentName: JsonField? = null + private var processedAt: JsonField? = null + private var sessionThreadId: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsSessionThreadStatusTerminatedEvent: + BetaManagedAgentsSessionThreadStatusTerminatedEvent + ) = apply { + id = betaManagedAgentsSessionThreadStatusTerminatedEvent.id + agentName = betaManagedAgentsSessionThreadStatusTerminatedEvent.agentName + processedAt = betaManagedAgentsSessionThreadStatusTerminatedEvent.processedAt + sessionThreadId = betaManagedAgentsSessionThreadStatusTerminatedEvent.sessionThreadId + type = betaManagedAgentsSessionThreadStatusTerminatedEvent.type + additionalProperties = + betaManagedAgentsSessionThreadStatusTerminatedEvent.additionalProperties + .toMutableMap() + } + + /** Unique identifier for this event. */ + 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 } + + /** Name of the agent the thread runs. */ + fun agentName(agentName: String) = agentName(JsonField.of(agentName)) + + /** + * Sets [Builder.agentName] to an arbitrary JSON value. + * + * You should usually call [Builder.agentName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun agentName(agentName: JsonField) = apply { this.agentName = agentName } + + /** A timestamp in RFC 3339 format */ + fun processedAt(processedAt: OffsetDateTime) = processedAt(JsonField.of(processedAt)) + + /** + * Sets [Builder.processedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.processedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedAt(processedAt: JsonField) = apply { + this.processedAt = processedAt + } + + /** Public sthr_ ID of the thread that terminated. */ + fun sessionThreadId(sessionThreadId: String) = + sessionThreadId(JsonField.of(sessionThreadId)) + + /** + * Sets [Builder.sessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sessionThreadId(sessionThreadId: JsonField) = apply { + this.sessionThreadId = sessionThreadId + } + + 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 [BetaManagedAgentsSessionThreadStatusTerminatedEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .agentName() + * .processedAt() + * .sessionThreadId() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsSessionThreadStatusTerminatedEvent = + BetaManagedAgentsSessionThreadStatusTerminatedEvent( + checkRequired("id", id), + checkRequired("agentName", agentName), + checkRequired("processedAt", processedAt), + checkRequired("sessionThreadId", sessionThreadId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSessionThreadStatusTerminatedEvent = apply { + if (validated) { + return@apply + } + + id() + agentName() + processedAt() + sessionThreadId() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (agentName.asKnown().isPresent) 1 else 0) + + (if (processedAt.asKnown().isPresent) 1 else 0) + + (if (sessionThreadId.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 SESSION_THREAD_STATUS_TERMINATED = of("session.thread_status_terminated") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SESSION_THREAD_STATUS_TERMINATED + } + + /** + * 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 { + SESSION_THREAD_STATUS_TERMINATED, + /** 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) { + SESSION_THREAD_STATUS_TERMINATED -> Value.SESSION_THREAD_STATUS_TERMINATED + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SESSION_THREAD_STATUS_TERMINATED -> Known.SESSION_THREAD_STATUS_TERMINATED + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsSessionThreadStatusTerminatedEvent && + id == other.id && + agentName == other.agentName && + processedAt == other.processedAt && + sessionThreadId == other.sessionThreadId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, agentName, processedAt, sessionThreadId, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSessionThreadStatusTerminatedEvent{id=$id, agentName=$agentName, processedAt=$processedAt, sessionThreadId=$sessionThreadId, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationEndEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationEndEvent.kt new file mode 100644 index 000000000..ac4ee95ca --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationEndEvent.kt @@ -0,0 +1,679 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate token + * usage. A verdict of `needs_revision` means another evaluation cycle follows; `satisfied`, + * `max_iterations_reached`, `failed`, or `interrupted` are terminal — no further evaluation cycles + * follow. + */ +class BetaManagedAgentsSpanOutcomeEvaluationEndEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val explanation: JsonField, + private val iteration: JsonField, + private val outcomeEvaluationStartId: JsonField, + private val outcomeId: JsonField, + private val processedAt: JsonField, + private val result: JsonField, + private val type: JsonField, + private val usage: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("explanation") + @ExcludeMissing + explanation: JsonField = JsonMissing.of(), + @JsonProperty("iteration") @ExcludeMissing iteration: JsonField = JsonMissing.of(), + @JsonProperty("outcome_evaluation_start_id") + @ExcludeMissing + outcomeEvaluationStartId: JsonField = JsonMissing.of(), + @JsonProperty("outcome_id") @ExcludeMissing outcomeId: JsonField = JsonMissing.of(), + @JsonProperty("processed_at") + @ExcludeMissing + processedAt: JsonField = JsonMissing.of(), + @JsonProperty("result") @ExcludeMissing result: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("usage") + @ExcludeMissing + usage: JsonField = JsonMissing.of(), + ) : this( + id, + explanation, + iteration, + outcomeEvaluationStartId, + outcomeId, + processedAt, + result, + type, + usage, + mutableMapOf(), + ) + + /** + * Unique identifier for this event. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * Human-readable explanation of the verdict. For `needs_revision`, describes which criteria + * failed and why. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * 0-indexed revision cycle, matching the corresponding `span.outcome_evaluation_start`. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun iteration(): Int = iteration.getRequired("iteration") + + /** + * The id of the corresponding `span.outcome_evaluation_start` event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun outcomeEvaluationStartId(): String = + outcomeEvaluationStartId.getRequired("outcome_evaluation_start_id") + + /** + * The `outc_` ID of the outcome being evaluated. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun outcomeId(): String = outcomeId.getRequired("outcome_id") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun processedAt(): OffsetDateTime = processedAt.getRequired("processed_at") + + /** + * Evaluation verdict. 'satisfied': criteria met, session goes idle. 'needs_revision': criteria + * not met, another revision cycle follows. 'max_iterations_reached': evaluation budget + * exhausted with criteria still unmet — one final acknowledgment turn follows before the + * session goes idle, but no further evaluation runs. 'failed': grader determined the rubric + * does not apply to the deliverables. 'interrupted': user sent an interrupt while evaluation + * was in progress. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun result(): String = result.getRequired("result") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Token usage for a single model request. + * + * @throws AnthropicInvalidDataException if 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(): BetaManagedAgentsSpanModelUsage = usage.getRequired("usage") + + /** + * 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 [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 [iteration]. + * + * Unlike [iteration], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("iteration") @ExcludeMissing fun _iteration(): JsonField = iteration + + /** + * Returns the raw JSON value of [outcomeEvaluationStartId]. + * + * Unlike [outcomeEvaluationStartId], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("outcome_evaluation_start_id") + @ExcludeMissing + fun _outcomeEvaluationStartId(): JsonField = outcomeEvaluationStartId + + /** + * Returns the raw JSON value of [outcomeId]. + * + * Unlike [outcomeId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("outcome_id") @ExcludeMissing fun _outcomeId(): JsonField = outcomeId + + /** + * Returns the raw JSON value of [processedAt]. + * + * Unlike [processedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processed_at") + @ExcludeMissing + fun _processedAt(): JsonField = processedAt + + /** + * 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 [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [usage]. + * + * Unlike [usage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("usage") + @ExcludeMissing + fun _usage(): JsonField = usage + + @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 + * [BetaManagedAgentsSpanOutcomeEvaluationEndEvent]. + * + * The following fields are required: + * ```java + * .id() + * .explanation() + * .iteration() + * .outcomeEvaluationStartId() + * .outcomeId() + * .processedAt() + * .result() + * .type() + * .usage() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSpanOutcomeEvaluationEndEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var explanation: JsonField? = null + private var iteration: JsonField? = null + private var outcomeEvaluationStartId: JsonField? = null + private var outcomeId: JsonField? = null + private var processedAt: JsonField? = null + private var result: JsonField? = null + private var type: JsonField? = null + private var usage: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsSpanOutcomeEvaluationEndEvent: + BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ) = apply { + id = betaManagedAgentsSpanOutcomeEvaluationEndEvent.id + explanation = betaManagedAgentsSpanOutcomeEvaluationEndEvent.explanation + iteration = betaManagedAgentsSpanOutcomeEvaluationEndEvent.iteration + outcomeEvaluationStartId = + betaManagedAgentsSpanOutcomeEvaluationEndEvent.outcomeEvaluationStartId + outcomeId = betaManagedAgentsSpanOutcomeEvaluationEndEvent.outcomeId + processedAt = betaManagedAgentsSpanOutcomeEvaluationEndEvent.processedAt + result = betaManagedAgentsSpanOutcomeEvaluationEndEvent.result + type = betaManagedAgentsSpanOutcomeEvaluationEndEvent.type + usage = betaManagedAgentsSpanOutcomeEvaluationEndEvent.usage + additionalProperties = + betaManagedAgentsSpanOutcomeEvaluationEndEvent.additionalProperties.toMutableMap() + } + + /** Unique identifier for this event. */ + 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 } + + /** + * Human-readable explanation of the verdict. For `needs_revision`, describes which criteria + * failed and why. + */ + 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 } + + /** 0-indexed revision cycle, matching the corresponding `span.outcome_evaluation_start`. */ + fun iteration(iteration: Int) = iteration(JsonField.of(iteration)) + + /** + * Sets [Builder.iteration] to an arbitrary JSON value. + * + * You should usually call [Builder.iteration] with a well-typed [Int] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun iteration(iteration: JsonField) = apply { this.iteration = iteration } + + /** The id of the corresponding `span.outcome_evaluation_start` event. */ + fun outcomeEvaluationStartId(outcomeEvaluationStartId: String) = + outcomeEvaluationStartId(JsonField.of(outcomeEvaluationStartId)) + + /** + * Sets [Builder.outcomeEvaluationStartId] to an arbitrary JSON value. + * + * You should usually call [Builder.outcomeEvaluationStartId] with a well-typed [String] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun outcomeEvaluationStartId(outcomeEvaluationStartId: JsonField) = apply { + this.outcomeEvaluationStartId = outcomeEvaluationStartId + } + + /** The `outc_` ID of the outcome being evaluated. */ + fun outcomeId(outcomeId: String) = outcomeId(JsonField.of(outcomeId)) + + /** + * Sets [Builder.outcomeId] to an arbitrary JSON value. + * + * You should usually call [Builder.outcomeId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun outcomeId(outcomeId: JsonField) = apply { this.outcomeId = outcomeId } + + /** A timestamp in RFC 3339 format */ + fun processedAt(processedAt: OffsetDateTime) = processedAt(JsonField.of(processedAt)) + + /** + * Sets [Builder.processedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.processedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedAt(processedAt: JsonField) = apply { + this.processedAt = processedAt + } + + /** + * Evaluation verdict. 'satisfied': criteria met, session goes idle. 'needs_revision': + * criteria not met, another revision cycle follows. 'max_iterations_reached': evaluation + * budget exhausted with criteria still unmet — one final acknowledgment turn follows before + * the session goes idle, but no further evaluation runs. 'failed': grader determined the + * rubric does not apply to the deliverables. 'interrupted': user sent an interrupt while + * evaluation was in progress. + */ + fun result(result: String) = result(JsonField.of(result)) + + /** + * Sets [Builder.result] to an arbitrary JSON value. + * + * You should usually call [Builder.result] with a well-typed [String] 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 } + + 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 } + + /** Token usage for a single model request. */ + fun usage(usage: BetaManagedAgentsSpanModelUsage) = usage(JsonField.of(usage)) + + /** + * Sets [Builder.usage] to an arbitrary JSON value. + * + * You should usually call [Builder.usage] with a well-typed + * [BetaManagedAgentsSpanModelUsage] 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 } + + 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 [BetaManagedAgentsSpanOutcomeEvaluationEndEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .explanation() + * .iteration() + * .outcomeEvaluationStartId() + * .outcomeId() + * .processedAt() + * .result() + * .type() + * .usage() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsSpanOutcomeEvaluationEndEvent = + BetaManagedAgentsSpanOutcomeEvaluationEndEvent( + checkRequired("id", id), + checkRequired("explanation", explanation), + checkRequired("iteration", iteration), + checkRequired("outcomeEvaluationStartId", outcomeEvaluationStartId), + checkRequired("outcomeId", outcomeId), + checkRequired("processedAt", processedAt), + checkRequired("result", result), + checkRequired("type", type), + checkRequired("usage", usage), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSpanOutcomeEvaluationEndEvent = apply { + if (validated) { + return@apply + } + + id() + explanation() + iteration() + outcomeEvaluationStartId() + outcomeId() + processedAt() + result() + type().validate() + usage().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (explanation.asKnown().isPresent) 1 else 0) + + (if (iteration.asKnown().isPresent) 1 else 0) + + (if (outcomeEvaluationStartId.asKnown().isPresent) 1 else 0) + + (if (outcomeId.asKnown().isPresent) 1 else 0) + + (if (processedAt.asKnown().isPresent) 1 else 0) + + (if (result.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (usage.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 SPAN_OUTCOME_EVALUATION_END = of("span.outcome_evaluation_end") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SPAN_OUTCOME_EVALUATION_END + } + + /** + * 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 { + SPAN_OUTCOME_EVALUATION_END, + /** 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) { + SPAN_OUTCOME_EVALUATION_END -> Value.SPAN_OUTCOME_EVALUATION_END + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SPAN_OUTCOME_EVALUATION_END -> Known.SPAN_OUTCOME_EVALUATION_END + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsSpanOutcomeEvaluationEndEvent && + id == other.id && + explanation == other.explanation && + iteration == other.iteration && + outcomeEvaluationStartId == other.outcomeEvaluationStartId && + outcomeId == other.outcomeId && + processedAt == other.processedAt && + result == other.result && + type == other.type && + usage == other.usage && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + explanation, + iteration, + outcomeEvaluationStartId, + outcomeId, + processedAt, + result, + type, + usage, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSpanOutcomeEvaluationEndEvent{id=$id, explanation=$explanation, iteration=$iteration, outcomeEvaluationStartId=$outcomeEvaluationStartId, outcomeId=$outcomeId, processedAt=$processedAt, result=$result, type=$type, usage=$usage, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.kt new file mode 100644 index 000000000..d950621d5 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.kt @@ -0,0 +1,478 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. Distinguishes + * 'evaluation is actively running' from 'evaluation is stuck' between the corresponding + * `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ +class BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val iteration: JsonField, + private val outcomeId: JsonField, + private val processedAt: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("iteration") @ExcludeMissing iteration: JsonField = JsonMissing.of(), + @JsonProperty("outcome_id") @ExcludeMissing outcomeId: JsonField = JsonMissing.of(), + @JsonProperty("processed_at") + @ExcludeMissing + processedAt: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(id, iteration, outcomeId, processedAt, type, mutableMapOf()) + + /** + * Unique identifier for this event. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * 0-indexed revision cycle, matching the corresponding `span.outcome_evaluation_start`. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun iteration(): Int = iteration.getRequired("iteration") + + /** + * The `outc_` ID of the outcome being evaluated. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun outcomeId(): String = outcomeId.getRequired("outcome_id") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun processedAt(): OffsetDateTime = processedAt.getRequired("processed_at") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [iteration]. + * + * Unlike [iteration], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("iteration") @ExcludeMissing fun _iteration(): JsonField = iteration + + /** + * Returns the raw JSON value of [outcomeId]. + * + * Unlike [outcomeId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("outcome_id") @ExcludeMissing fun _outcomeId(): JsonField = outcomeId + + /** + * Returns the raw JSON value of [processedAt]. + * + * Unlike [processedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processed_at") + @ExcludeMissing + fun _processedAt(): JsonField = processedAt + + /** + * 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 + * [BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent]. + * + * The following fields are required: + * ```java + * .id() + * .iteration() + * .outcomeId() + * .processedAt() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var iteration: JsonField? = null + private var outcomeId: JsonField? = null + private var processedAt: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsSpanOutcomeEvaluationOngoingEvent: + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ) = apply { + id = betaManagedAgentsSpanOutcomeEvaluationOngoingEvent.id + iteration = betaManagedAgentsSpanOutcomeEvaluationOngoingEvent.iteration + outcomeId = betaManagedAgentsSpanOutcomeEvaluationOngoingEvent.outcomeId + processedAt = betaManagedAgentsSpanOutcomeEvaluationOngoingEvent.processedAt + type = betaManagedAgentsSpanOutcomeEvaluationOngoingEvent.type + additionalProperties = + betaManagedAgentsSpanOutcomeEvaluationOngoingEvent.additionalProperties + .toMutableMap() + } + + /** Unique identifier for this event. */ + 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 } + + /** 0-indexed revision cycle, matching the corresponding `span.outcome_evaluation_start`. */ + fun iteration(iteration: Int) = iteration(JsonField.of(iteration)) + + /** + * Sets [Builder.iteration] to an arbitrary JSON value. + * + * You should usually call [Builder.iteration] with a well-typed [Int] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun iteration(iteration: JsonField) = apply { this.iteration = iteration } + + /** The `outc_` ID of the outcome being evaluated. */ + fun outcomeId(outcomeId: String) = outcomeId(JsonField.of(outcomeId)) + + /** + * Sets [Builder.outcomeId] to an arbitrary JSON value. + * + * You should usually call [Builder.outcomeId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun outcomeId(outcomeId: JsonField) = apply { this.outcomeId = outcomeId } + + /** A timestamp in RFC 3339 format */ + fun processedAt(processedAt: OffsetDateTime) = processedAt(JsonField.of(processedAt)) + + /** + * Sets [Builder.processedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.processedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedAt(processedAt: JsonField) = apply { + this.processedAt = processedAt + } + + 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 [BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .iteration() + * .outcomeId() + * .processedAt() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent = + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent( + checkRequired("id", id), + checkRequired("iteration", iteration), + checkRequired("outcomeId", outcomeId), + checkRequired("processedAt", processedAt), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent = apply { + if (validated) { + return@apply + } + + id() + iteration() + outcomeId() + processedAt() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (iteration.asKnown().isPresent) 1 else 0) + + (if (outcomeId.asKnown().isPresent) 1 else 0) + + (if (processedAt.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 SPAN_OUTCOME_EVALUATION_ONGOING = of("span.outcome_evaluation_ongoing") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SPAN_OUTCOME_EVALUATION_ONGOING + } + + /** + * 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 { + SPAN_OUTCOME_EVALUATION_ONGOING, + /** 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) { + SPAN_OUTCOME_EVALUATION_ONGOING -> Value.SPAN_OUTCOME_EVALUATION_ONGOING + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SPAN_OUTCOME_EVALUATION_ONGOING -> Known.SPAN_OUTCOME_EVALUATION_ONGOING + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent && + id == other.id && + iteration == other.iteration && + outcomeId == other.outcomeId && + processedAt == other.processedAt && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, iteration, outcomeId, processedAt, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent{id=$id, iteration=$iteration, outcomeId=$outcomeId, processedAt=$processedAt, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationStartEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationStartEvent.kt new file mode 100644 index 000000000..669c844f5 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationStartEvent.kt @@ -0,0 +1,477 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** Emitted when an outcome evaluation cycle begins. */ +class BetaManagedAgentsSpanOutcomeEvaluationStartEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val iteration: JsonField, + private val outcomeId: JsonField, + private val processedAt: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("iteration") @ExcludeMissing iteration: JsonField = JsonMissing.of(), + @JsonProperty("outcome_id") @ExcludeMissing outcomeId: JsonField = JsonMissing.of(), + @JsonProperty("processed_at") + @ExcludeMissing + processedAt: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(id, iteration, outcomeId, processedAt, type, mutableMapOf()) + + /** + * Unique identifier for this event. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * 0-indexed revision cycle. 0 is the first evaluation; 1 is the re-evaluation after the first + * revision; etc. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun iteration(): Int = iteration.getRequired("iteration") + + /** + * The `outc_` ID of the outcome being evaluated. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun outcomeId(): String = outcomeId.getRequired("outcome_id") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun processedAt(): OffsetDateTime = processedAt.getRequired("processed_at") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [iteration]. + * + * Unlike [iteration], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("iteration") @ExcludeMissing fun _iteration(): JsonField = iteration + + /** + * Returns the raw JSON value of [outcomeId]. + * + * Unlike [outcomeId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("outcome_id") @ExcludeMissing fun _outcomeId(): JsonField = outcomeId + + /** + * Returns the raw JSON value of [processedAt]. + * + * Unlike [processedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processed_at") + @ExcludeMissing + fun _processedAt(): JsonField = processedAt + + /** + * 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 + * [BetaManagedAgentsSpanOutcomeEvaluationStartEvent]. + * + * The following fields are required: + * ```java + * .id() + * .iteration() + * .outcomeId() + * .processedAt() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSpanOutcomeEvaluationStartEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var iteration: JsonField? = null + private var outcomeId: JsonField? = null + private var processedAt: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsSpanOutcomeEvaluationStartEvent: + BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ) = apply { + id = betaManagedAgentsSpanOutcomeEvaluationStartEvent.id + iteration = betaManagedAgentsSpanOutcomeEvaluationStartEvent.iteration + outcomeId = betaManagedAgentsSpanOutcomeEvaluationStartEvent.outcomeId + processedAt = betaManagedAgentsSpanOutcomeEvaluationStartEvent.processedAt + type = betaManagedAgentsSpanOutcomeEvaluationStartEvent.type + additionalProperties = + betaManagedAgentsSpanOutcomeEvaluationStartEvent.additionalProperties.toMutableMap() + } + + /** Unique identifier for this event. */ + 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 } + + /** + * 0-indexed revision cycle. 0 is the first evaluation; 1 is the re-evaluation after the + * first revision; etc. + */ + fun iteration(iteration: Int) = iteration(JsonField.of(iteration)) + + /** + * Sets [Builder.iteration] to an arbitrary JSON value. + * + * You should usually call [Builder.iteration] with a well-typed [Int] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun iteration(iteration: JsonField) = apply { this.iteration = iteration } + + /** The `outc_` ID of the outcome being evaluated. */ + fun outcomeId(outcomeId: String) = outcomeId(JsonField.of(outcomeId)) + + /** + * Sets [Builder.outcomeId] to an arbitrary JSON value. + * + * You should usually call [Builder.outcomeId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun outcomeId(outcomeId: JsonField) = apply { this.outcomeId = outcomeId } + + /** A timestamp in RFC 3339 format */ + fun processedAt(processedAt: OffsetDateTime) = processedAt(JsonField.of(processedAt)) + + /** + * Sets [Builder.processedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.processedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedAt(processedAt: JsonField) = apply { + this.processedAt = processedAt + } + + 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 [BetaManagedAgentsSpanOutcomeEvaluationStartEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .iteration() + * .outcomeId() + * .processedAt() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsSpanOutcomeEvaluationStartEvent = + BetaManagedAgentsSpanOutcomeEvaluationStartEvent( + checkRequired("id", id), + checkRequired("iteration", iteration), + checkRequired("outcomeId", outcomeId), + checkRequired("processedAt", processedAt), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSpanOutcomeEvaluationStartEvent = apply { + if (validated) { + return@apply + } + + id() + iteration() + outcomeId() + processedAt() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (iteration.asKnown().isPresent) 1 else 0) + + (if (outcomeId.asKnown().isPresent) 1 else 0) + + (if (processedAt.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 SPAN_OUTCOME_EVALUATION_START = of("span.outcome_evaluation_start") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SPAN_OUTCOME_EVALUATION_START + } + + /** + * 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 { + SPAN_OUTCOME_EVALUATION_START, + /** 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) { + SPAN_OUTCOME_EVALUATION_START -> Value.SPAN_OUTCOME_EVALUATION_START + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SPAN_OUTCOME_EVALUATION_START -> Known.SPAN_OUTCOME_EVALUATION_START + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsSpanOutcomeEvaluationStartEvent && + id == other.id && + iteration == other.iteration && + outcomeId == other.outcomeId && + processedAt == other.processedAt && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, iteration, outcomeId, processedAt, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSpanOutcomeEvaluationStartEvent{id=$id, iteration=$iteration, outcomeId=$outcomeId, processedAt=$processedAt, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsStreamSessionEvents.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsStreamSessionEvents.kt index e4788a61d..8b6426bf7 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsStreamSessionEvents.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsStreamSessionEvents.kt @@ -34,6 +34,9 @@ private constructor( private val agentMcpToolResult: BetaManagedAgentsAgentMcpToolResultEvent? = null, private val agentToolUse: BetaManagedAgentsAgentToolUseEvent? = null, private val agentToolResult: BetaManagedAgentsAgentToolResultEvent? = null, + private val agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent? = + null, + private val agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent? = null, private val agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent? = null, private val sessionError: BetaManagedAgentsSessionErrorEvent? = null, @@ -41,9 +44,25 @@ private constructor( private val sessionStatusRunning: BetaManagedAgentsSessionStatusRunningEvent? = null, private val sessionStatusIdle: BetaManagedAgentsSessionStatusIdleEvent? = null, private val sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent? = null, + private val sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent? = null, + private val spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent? = + null, + private val spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent? = null, private val spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent? = null, private val spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent? = null, + private val spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent? = + null, + private val userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent? = null, private val sessionDeleted: BetaManagedAgentsSessionDeletedEvent? = null, + private val sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent? = + null, + private val sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent? = null, + private val sessionThreadStatusTerminated: + BetaManagedAgentsSessionThreadStatusTerminatedEvent? = + null, + private val sessionThreadStatusRescheduled: + BetaManagedAgentsSessionThreadStatusRescheduledEvent? = + null, private val _json: JsonValue? = null, ) { @@ -97,6 +116,20 @@ private constructor( fun agentToolResult(): Optional = Optional.ofNullable(agentToolResult) + /** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ + fun agentThreadMessageReceived(): Optional = + Optional.ofNullable(agentThreadMessageReceived) + + /** + * Observability event emitted to the sender's output stream when an agent-to-agent message is + * sent. + */ + fun agentThreadMessageSent(): Optional = + Optional.ofNullable(agentThreadMessageSent) + /** Indicates that context compaction (summarization) occurred during the session. */ fun agentThreadContextCompacted(): Optional = Optional.ofNullable(agentThreadContextCompacted) @@ -121,6 +154,26 @@ private constructor( fun sessionStatusTerminated(): Optional = Optional.ofNullable(sessionStatusTerminated) + /** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output + * stream so clients observing the session see child creation. + */ + fun sessionThreadCreated(): Optional = + Optional.ofNullable(sessionThreadCreated) + + /** Emitted when an outcome evaluation cycle begins. */ + fun spanOutcomeEvaluationStart(): Optional = + Optional.ofNullable(spanOutcomeEvaluationStart) + + /** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate token + * usage. A verdict of `needs_revision` means another evaluation cycle follows; `satisfied`, + * `max_iterations_reached`, `failed`, or `interrupted` are terminal — no further evaluation + * cycles follow. + */ + fun spanOutcomeEvaluationEnd(): Optional = + Optional.ofNullable(spanOutcomeEvaluationEnd) + /** Emitted when a model request is initiated by the agent. */ fun spanModelRequestStart(): Optional = Optional.ofNullable(spanModelRequestStart) @@ -129,6 +182,22 @@ private constructor( fun spanModelRequestEnd(): Optional = Optional.ofNullable(spanModelRequestEnd) + /** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. Distinguishes + * 'evaluation is actively running' from 'evaluation is stuck' between the corresponding + * `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ + fun spanOutcomeEvaluationOngoing(): + Optional = + Optional.ofNullable(spanOutcomeEvaluationOngoing) + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` that + * subsequent `span.outcome_evaluation_*` events reference. + */ + fun userDefineOutcome(): Optional = + Optional.ofNullable(userDefineOutcome) + /** * Emitted when a session has been deleted. Terminates any active event stream — no further * events will be emitted for this session. @@ -136,6 +205,36 @@ private constructor( fun sessionDeleted(): Optional = Optional.ofNullable(sessionDeleted) + /** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted to + * the primary stream for child threads. + */ + fun sessionThreadStatusRunning(): Optional = + Optional.ofNullable(sessionThreadStatusRunning) + + /** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream and + * cross-posted to the primary stream for child threads. + */ + fun sessionThreadStatusIdle(): Optional = + Optional.ofNullable(sessionThreadStatusIdle) + + /** + * A session thread has terminated and will accept no further input. Emitted on the thread's own + * stream and cross-posted to the primary stream for child threads. + */ + fun sessionThreadStatusTerminated(): + Optional = + Optional.ofNullable(sessionThreadStatusTerminated) + + /** + * A session thread hit a transient error and is retrying automatically. Emitted on the thread's + * own stream and cross-posted to the primary stream for child threads. + */ + fun sessionThreadStatusRescheduled(): + Optional = + Optional.ofNullable(sessionThreadStatusRescheduled) + fun isUserMessage(): Boolean = userMessage != null fun isUserInterrupt(): Boolean = userInterrupt != null @@ -158,6 +257,10 @@ private constructor( fun isAgentToolResult(): Boolean = agentToolResult != null + fun isAgentThreadMessageReceived(): Boolean = agentThreadMessageReceived != null + + fun isAgentThreadMessageSent(): Boolean = agentThreadMessageSent != null + fun isAgentThreadContextCompacted(): Boolean = agentThreadContextCompacted != null fun isSessionError(): Boolean = sessionError != null @@ -170,12 +273,30 @@ private constructor( fun isSessionStatusTerminated(): Boolean = sessionStatusTerminated != null + fun isSessionThreadCreated(): Boolean = sessionThreadCreated != null + + fun isSpanOutcomeEvaluationStart(): Boolean = spanOutcomeEvaluationStart != null + + fun isSpanOutcomeEvaluationEnd(): Boolean = spanOutcomeEvaluationEnd != null + fun isSpanModelRequestStart(): Boolean = spanModelRequestStart != null fun isSpanModelRequestEnd(): Boolean = spanModelRequestEnd != null + fun isSpanOutcomeEvaluationOngoing(): Boolean = spanOutcomeEvaluationOngoing != null + + fun isUserDefineOutcome(): Boolean = userDefineOutcome != null + fun isSessionDeleted(): Boolean = sessionDeleted != null + fun isSessionThreadStatusRunning(): Boolean = sessionThreadStatusRunning != null + + fun isSessionThreadStatusIdle(): Boolean = sessionThreadStatusIdle != null + + fun isSessionThreadStatusTerminated(): Boolean = sessionThreadStatusTerminated != null + + fun isSessionThreadStatusRescheduled(): Boolean = sessionThreadStatusRescheduled != null + /** A user message event in the session conversation. */ fun asUserMessage(): BetaManagedAgentsUserMessageEvent = userMessage.getOrThrow("userMessage") @@ -225,6 +346,20 @@ private constructor( fun asAgentToolResult(): BetaManagedAgentsAgentToolResultEvent = agentToolResult.getOrThrow("agentToolResult") + /** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ + fun asAgentThreadMessageReceived(): BetaManagedAgentsAgentThreadMessageReceivedEvent = + agentThreadMessageReceived.getOrThrow("agentThreadMessageReceived") + + /** + * Observability event emitted to the sender's output stream when an agent-to-agent message is + * sent. + */ + fun asAgentThreadMessageSent(): BetaManagedAgentsAgentThreadMessageSentEvent = + agentThreadMessageSent.getOrThrow("agentThreadMessageSent") + /** Indicates that context compaction (summarization) occurred during the session. */ fun asAgentThreadContextCompacted(): BetaManagedAgentsAgentThreadContextCompactedEvent = agentThreadContextCompacted.getOrThrow("agentThreadContextCompacted") @@ -249,6 +384,26 @@ private constructor( fun asSessionStatusTerminated(): BetaManagedAgentsSessionStatusTerminatedEvent = sessionStatusTerminated.getOrThrow("sessionStatusTerminated") + /** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output + * stream so clients observing the session see child creation. + */ + fun asSessionThreadCreated(): BetaManagedAgentsSessionThreadCreatedEvent = + sessionThreadCreated.getOrThrow("sessionThreadCreated") + + /** Emitted when an outcome evaluation cycle begins. */ + fun asSpanOutcomeEvaluationStart(): BetaManagedAgentsSpanOutcomeEvaluationStartEvent = + spanOutcomeEvaluationStart.getOrThrow("spanOutcomeEvaluationStart") + + /** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate token + * usage. A verdict of `needs_revision` means another evaluation cycle follows; `satisfied`, + * `max_iterations_reached`, `failed`, or `interrupted` are terminal — no further evaluation + * cycles follow. + */ + fun asSpanOutcomeEvaluationEnd(): BetaManagedAgentsSpanOutcomeEvaluationEndEvent = + spanOutcomeEvaluationEnd.getOrThrow("spanOutcomeEvaluationEnd") + /** Emitted when a model request is initiated by the agent. */ fun asSpanModelRequestStart(): BetaManagedAgentsSpanModelRequestStartEvent = spanModelRequestStart.getOrThrow("spanModelRequestStart") @@ -257,6 +412,21 @@ private constructor( fun asSpanModelRequestEnd(): BetaManagedAgentsSpanModelRequestEndEvent = spanModelRequestEnd.getOrThrow("spanModelRequestEnd") + /** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. Distinguishes + * 'evaluation is actively running' from 'evaluation is stuck' between the corresponding + * `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ + fun asSpanOutcomeEvaluationOngoing(): BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent = + spanOutcomeEvaluationOngoing.getOrThrow("spanOutcomeEvaluationOngoing") + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` that + * subsequent `span.outcome_evaluation_*` events reference. + */ + fun asUserDefineOutcome(): BetaManagedAgentsUserDefineOutcomeEvent = + userDefineOutcome.getOrThrow("userDefineOutcome") + /** * Emitted when a session has been deleted. Terminates any active event stream — no further * events will be emitted for this session. @@ -264,6 +434,34 @@ private constructor( fun asSessionDeleted(): BetaManagedAgentsSessionDeletedEvent = sessionDeleted.getOrThrow("sessionDeleted") + /** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted to + * the primary stream for child threads. + */ + fun asSessionThreadStatusRunning(): BetaManagedAgentsSessionThreadStatusRunningEvent = + sessionThreadStatusRunning.getOrThrow("sessionThreadStatusRunning") + + /** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream and + * cross-posted to the primary stream for child threads. + */ + fun asSessionThreadStatusIdle(): BetaManagedAgentsSessionThreadStatusIdleEvent = + sessionThreadStatusIdle.getOrThrow("sessionThreadStatusIdle") + + /** + * A session thread has terminated and will accept no further input. Emitted on the thread's own + * stream and cross-posted to the primary stream for child threads. + */ + fun asSessionThreadStatusTerminated(): BetaManagedAgentsSessionThreadStatusTerminatedEvent = + sessionThreadStatusTerminated.getOrThrow("sessionThreadStatusTerminated") + + /** + * A session thread hit a transient error and is retrying automatically. Emitted on the thread's + * own stream and cross-posted to the primary stream for child threads. + */ + fun asSessionThreadStatusRescheduled(): BetaManagedAgentsSessionThreadStatusRescheduledEvent = + sessionThreadStatusRescheduled.getOrThrow("sessionThreadStatusRescheduled") + fun _json(): Optional = Optional.ofNullable(_json) /** @@ -308,6 +506,10 @@ private constructor( agentMcpToolResult != null -> visitor.visitAgentMcpToolResult(agentMcpToolResult) agentToolUse != null -> visitor.visitAgentToolUse(agentToolUse) agentToolResult != null -> visitor.visitAgentToolResult(agentToolResult) + agentThreadMessageReceived != null -> + visitor.visitAgentThreadMessageReceived(agentThreadMessageReceived) + agentThreadMessageSent != null -> + visitor.visitAgentThreadMessageSent(agentThreadMessageSent) agentThreadContextCompacted != null -> visitor.visitAgentThreadContextCompacted(agentThreadContextCompacted) sessionError != null -> visitor.visitSessionError(sessionError) @@ -317,10 +519,26 @@ private constructor( sessionStatusIdle != null -> visitor.visitSessionStatusIdle(sessionStatusIdle) sessionStatusTerminated != null -> visitor.visitSessionStatusTerminated(sessionStatusTerminated) + sessionThreadCreated != null -> visitor.visitSessionThreadCreated(sessionThreadCreated) + spanOutcomeEvaluationStart != null -> + visitor.visitSpanOutcomeEvaluationStart(spanOutcomeEvaluationStart) + spanOutcomeEvaluationEnd != null -> + visitor.visitSpanOutcomeEvaluationEnd(spanOutcomeEvaluationEnd) spanModelRequestStart != null -> visitor.visitSpanModelRequestStart(spanModelRequestStart) spanModelRequestEnd != null -> visitor.visitSpanModelRequestEnd(spanModelRequestEnd) + spanOutcomeEvaluationOngoing != null -> + visitor.visitSpanOutcomeEvaluationOngoing(spanOutcomeEvaluationOngoing) + userDefineOutcome != null -> visitor.visitUserDefineOutcome(userDefineOutcome) sessionDeleted != null -> visitor.visitSessionDeleted(sessionDeleted) + sessionThreadStatusRunning != null -> + visitor.visitSessionThreadStatusRunning(sessionThreadStatusRunning) + sessionThreadStatusIdle != null -> + visitor.visitSessionThreadStatusIdle(sessionThreadStatusIdle) + sessionThreadStatusTerminated != null -> + visitor.visitSessionThreadStatusTerminated(sessionThreadStatusTerminated) + sessionThreadStatusRescheduled != null -> + visitor.visitSessionThreadStatusRescheduled(sessionThreadStatusRescheduled) else -> visitor.unknown(_json) } @@ -401,6 +619,18 @@ private constructor( agentToolResult.validate() } + override fun visitAgentThreadMessageReceived( + agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent + ) { + agentThreadMessageReceived.validate() + } + + override fun visitAgentThreadMessageSent( + agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent + ) { + agentThreadMessageSent.validate() + } + override fun visitAgentThreadContextCompacted( agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent ) { @@ -435,6 +665,24 @@ private constructor( sessionStatusTerminated.validate() } + override fun visitSessionThreadCreated( + sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent + ) { + sessionThreadCreated.validate() + } + + override fun visitSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ) { + spanOutcomeEvaluationStart.validate() + } + + override fun visitSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ) { + spanOutcomeEvaluationEnd.validate() + } + override fun visitSpanModelRequestStart( spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent ) { @@ -447,11 +695,49 @@ private constructor( spanModelRequestEnd.validate() } + override fun visitSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ) { + spanOutcomeEvaluationOngoing.validate() + } + + override fun visitUserDefineOutcome( + userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent + ) { + userDefineOutcome.validate() + } + override fun visitSessionDeleted( sessionDeleted: BetaManagedAgentsSessionDeletedEvent ) { sessionDeleted.validate() } + + override fun visitSessionThreadStatusRunning( + sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent + ) { + sessionThreadStatusRunning.validate() + } + + override fun visitSessionThreadStatusIdle( + sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent + ) { + sessionThreadStatusIdle.validate() + } + + override fun visitSessionThreadStatusTerminated( + sessionThreadStatusTerminated: + BetaManagedAgentsSessionThreadStatusTerminatedEvent + ) { + sessionThreadStatusTerminated.validate() + } + + override fun visitSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled: + BetaManagedAgentsSessionThreadStatusRescheduledEvent + ) { + sessionThreadStatusRescheduled.validate() + } } ) validated = true @@ -515,6 +801,14 @@ private constructor( agentToolResult: BetaManagedAgentsAgentToolResultEvent ) = agentToolResult.validity() + override fun visitAgentThreadMessageReceived( + agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent + ) = agentThreadMessageReceived.validity() + + override fun visitAgentThreadMessageSent( + agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent + ) = agentThreadMessageSent.validity() + override fun visitAgentThreadContextCompacted( agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent ) = agentThreadContextCompacted.validity() @@ -538,6 +832,18 @@ private constructor( sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent ) = sessionStatusTerminated.validity() + override fun visitSessionThreadCreated( + sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent + ) = sessionThreadCreated.validity() + + override fun visitSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ) = spanOutcomeEvaluationStart.validity() + + override fun visitSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ) = spanOutcomeEvaluationEnd.validity() + override fun visitSpanModelRequestStart( spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent ) = spanModelRequestStart.validity() @@ -546,10 +852,36 @@ private constructor( spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent ) = spanModelRequestEnd.validity() + override fun visitSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ) = spanOutcomeEvaluationOngoing.validity() + + override fun visitUserDefineOutcome( + userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent + ) = userDefineOutcome.validity() + override fun visitSessionDeleted( sessionDeleted: BetaManagedAgentsSessionDeletedEvent ) = sessionDeleted.validity() + override fun visitSessionThreadStatusRunning( + sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent + ) = sessionThreadStatusRunning.validity() + + override fun visitSessionThreadStatusIdle( + sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent + ) = sessionThreadStatusIdle.validity() + + override fun visitSessionThreadStatusTerminated( + sessionThreadStatusTerminated: + BetaManagedAgentsSessionThreadStatusTerminatedEvent + ) = sessionThreadStatusTerminated.validity() + + override fun visitSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled: + BetaManagedAgentsSessionThreadStatusRescheduledEvent + ) = sessionThreadStatusRescheduled.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -571,15 +903,26 @@ private constructor( agentMcpToolResult == other.agentMcpToolResult && agentToolUse == other.agentToolUse && agentToolResult == other.agentToolResult && + agentThreadMessageReceived == other.agentThreadMessageReceived && + agentThreadMessageSent == other.agentThreadMessageSent && agentThreadContextCompacted == other.agentThreadContextCompacted && sessionError == other.sessionError && sessionStatusRescheduled == other.sessionStatusRescheduled && sessionStatusRunning == other.sessionStatusRunning && sessionStatusIdle == other.sessionStatusIdle && sessionStatusTerminated == other.sessionStatusTerminated && + sessionThreadCreated == other.sessionThreadCreated && + spanOutcomeEvaluationStart == other.spanOutcomeEvaluationStart && + spanOutcomeEvaluationEnd == other.spanOutcomeEvaluationEnd && spanModelRequestStart == other.spanModelRequestStart && spanModelRequestEnd == other.spanModelRequestEnd && - sessionDeleted == other.sessionDeleted + spanOutcomeEvaluationOngoing == other.spanOutcomeEvaluationOngoing && + userDefineOutcome == other.userDefineOutcome && + sessionDeleted == other.sessionDeleted && + sessionThreadStatusRunning == other.sessionThreadStatusRunning && + sessionThreadStatusIdle == other.sessionThreadStatusIdle && + sessionThreadStatusTerminated == other.sessionThreadStatusTerminated && + sessionThreadStatusRescheduled == other.sessionThreadStatusRescheduled } override fun hashCode(): Int = @@ -595,15 +938,26 @@ private constructor( agentMcpToolResult, agentToolUse, agentToolResult, + agentThreadMessageReceived, + agentThreadMessageSent, agentThreadContextCompacted, sessionError, sessionStatusRescheduled, sessionStatusRunning, sessionStatusIdle, sessionStatusTerminated, + sessionThreadCreated, + spanOutcomeEvaluationStart, + spanOutcomeEvaluationEnd, spanModelRequestStart, spanModelRequestEnd, + spanOutcomeEvaluationOngoing, + userDefineOutcome, sessionDeleted, + sessionThreadStatusRunning, + sessionThreadStatusIdle, + sessionThreadStatusTerminated, + sessionThreadStatusRescheduled, ) override fun toString(): String = @@ -629,6 +983,10 @@ private constructor( "BetaManagedAgentsStreamSessionEvents{agentToolUse=$agentToolUse}" agentToolResult != null -> "BetaManagedAgentsStreamSessionEvents{agentToolResult=$agentToolResult}" + agentThreadMessageReceived != null -> + "BetaManagedAgentsStreamSessionEvents{agentThreadMessageReceived=$agentThreadMessageReceived}" + agentThreadMessageSent != null -> + "BetaManagedAgentsStreamSessionEvents{agentThreadMessageSent=$agentThreadMessageSent}" agentThreadContextCompacted != null -> "BetaManagedAgentsStreamSessionEvents{agentThreadContextCompacted=$agentThreadContextCompacted}" sessionError != null -> @@ -641,12 +999,30 @@ private constructor( "BetaManagedAgentsStreamSessionEvents{sessionStatusIdle=$sessionStatusIdle}" sessionStatusTerminated != null -> "BetaManagedAgentsStreamSessionEvents{sessionStatusTerminated=$sessionStatusTerminated}" + sessionThreadCreated != null -> + "BetaManagedAgentsStreamSessionEvents{sessionThreadCreated=$sessionThreadCreated}" + spanOutcomeEvaluationStart != null -> + "BetaManagedAgentsStreamSessionEvents{spanOutcomeEvaluationStart=$spanOutcomeEvaluationStart}" + spanOutcomeEvaluationEnd != null -> + "BetaManagedAgentsStreamSessionEvents{spanOutcomeEvaluationEnd=$spanOutcomeEvaluationEnd}" spanModelRequestStart != null -> "BetaManagedAgentsStreamSessionEvents{spanModelRequestStart=$spanModelRequestStart}" spanModelRequestEnd != null -> "BetaManagedAgentsStreamSessionEvents{spanModelRequestEnd=$spanModelRequestEnd}" + spanOutcomeEvaluationOngoing != null -> + "BetaManagedAgentsStreamSessionEvents{spanOutcomeEvaluationOngoing=$spanOutcomeEvaluationOngoing}" + userDefineOutcome != null -> + "BetaManagedAgentsStreamSessionEvents{userDefineOutcome=$userDefineOutcome}" sessionDeleted != null -> "BetaManagedAgentsStreamSessionEvents{sessionDeleted=$sessionDeleted}" + sessionThreadStatusRunning != null -> + "BetaManagedAgentsStreamSessionEvents{sessionThreadStatusRunning=$sessionThreadStatusRunning}" + sessionThreadStatusIdle != null -> + "BetaManagedAgentsStreamSessionEvents{sessionThreadStatusIdle=$sessionThreadStatusIdle}" + sessionThreadStatusTerminated != null -> + "BetaManagedAgentsStreamSessionEvents{sessionThreadStatusTerminated=$sessionThreadStatusTerminated}" + sessionThreadStatusRescheduled != null -> + "BetaManagedAgentsStreamSessionEvents{sessionThreadStatusRescheduled=$sessionThreadStatusRescheduled}" _json != null -> "BetaManagedAgentsStreamSessionEvents{_unknown=$_json}" else -> throw IllegalStateException("Invalid BetaManagedAgentsStreamSessionEvents") } @@ -716,6 +1092,27 @@ private constructor( fun ofAgentToolResult(agentToolResult: BetaManagedAgentsAgentToolResultEvent) = BetaManagedAgentsStreamSessionEvents(agentToolResult = agentToolResult) + /** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ + @JvmStatic + fun ofAgentThreadMessageReceived( + agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent + ) = + BetaManagedAgentsStreamSessionEvents( + agentThreadMessageReceived = agentThreadMessageReceived + ) + + /** + * Observability event emitted to the sender's output stream when an agent-to-agent message + * is sent. + */ + @JvmStatic + fun ofAgentThreadMessageSent( + agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent + ) = BetaManagedAgentsStreamSessionEvents(agentThreadMessageSent = agentThreadMessageSent) + /** Indicates that context compaction (summarization) occurred during the session. */ @JvmStatic fun ofAgentThreadContextCompacted( @@ -758,6 +1155,38 @@ private constructor( sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent ) = BetaManagedAgentsStreamSessionEvents(sessionStatusTerminated = sessionStatusTerminated) + /** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output + * stream so clients observing the session see child creation. + */ + @JvmStatic + fun ofSessionThreadCreated( + sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent + ) = BetaManagedAgentsStreamSessionEvents(sessionThreadCreated = sessionThreadCreated) + + /** Emitted when an outcome evaluation cycle begins. */ + @JvmStatic + fun ofSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ) = + BetaManagedAgentsStreamSessionEvents( + spanOutcomeEvaluationStart = spanOutcomeEvaluationStart + ) + + /** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate + * token usage. A verdict of `needs_revision` means another evaluation cycle follows; + * `satisfied`, `max_iterations_reached`, `failed`, or `interrupted` are terminal — no + * further evaluation cycles follow. + */ + @JvmStatic + fun ofSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ) = + BetaManagedAgentsStreamSessionEvents( + spanOutcomeEvaluationEnd = spanOutcomeEvaluationEnd + ) + /** Emitted when a model request is initiated by the agent. */ @JvmStatic fun ofSpanModelRequestStart( @@ -769,6 +1198,27 @@ private constructor( fun ofSpanModelRequestEnd(spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent) = BetaManagedAgentsStreamSessionEvents(spanModelRequestEnd = spanModelRequestEnd) + /** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. + * Distinguishes 'evaluation is actively running' from 'evaluation is stuck' between the + * corresponding `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ + @JvmStatic + fun ofSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ) = + BetaManagedAgentsStreamSessionEvents( + spanOutcomeEvaluationOngoing = spanOutcomeEvaluationOngoing + ) + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` + * that subsequent `span.outcome_evaluation_*` events reference. + */ + @JvmStatic + fun ofUserDefineOutcome(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent) = + BetaManagedAgentsStreamSessionEvents(userDefineOutcome = userDefineOutcome) + /** * Emitted when a session has been deleted. Terminates any active event stream — no further * events will be emitted for this session. @@ -776,6 +1226,51 @@ private constructor( @JvmStatic fun ofSessionDeleted(sessionDeleted: BetaManagedAgentsSessionDeletedEvent) = BetaManagedAgentsStreamSessionEvents(sessionDeleted = sessionDeleted) + + /** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted + * to the primary stream for child threads. + */ + @JvmStatic + fun ofSessionThreadStatusRunning( + sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent + ) = + BetaManagedAgentsStreamSessionEvents( + sessionThreadStatusRunning = sessionThreadStatusRunning + ) + + /** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream + * and cross-posted to the primary stream for child threads. + */ + @JvmStatic + fun ofSessionThreadStatusIdle( + sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent + ) = BetaManagedAgentsStreamSessionEvents(sessionThreadStatusIdle = sessionThreadStatusIdle) + + /** + * A session thread has terminated and will accept no further input. Emitted on the thread's + * own stream and cross-posted to the primary stream for child threads. + */ + @JvmStatic + fun ofSessionThreadStatusTerminated( + sessionThreadStatusTerminated: BetaManagedAgentsSessionThreadStatusTerminatedEvent + ) = + BetaManagedAgentsStreamSessionEvents( + sessionThreadStatusTerminated = sessionThreadStatusTerminated + ) + + /** + * A session thread hit a transient error and is retrying automatically. Emitted on the + * thread's own stream and cross-posted to the primary stream for child threads. + */ + @JvmStatic + fun ofSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled: BetaManagedAgentsSessionThreadStatusRescheduledEvent + ) = + BetaManagedAgentsStreamSessionEvents( + sessionThreadStatusRescheduled = sessionThreadStatusRescheduled + ) } /** @@ -827,6 +1322,22 @@ private constructor( /** Event representing the result of an agent tool execution. */ fun visitAgentToolResult(agentToolResult: BetaManagedAgentsAgentToolResultEvent): T + /** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ + fun visitAgentThreadMessageReceived( + agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent + ): T + + /** + * Observability event emitted to the sender's output stream when an agent-to-agent message + * is sent. + */ + fun visitAgentThreadMessageSent( + agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent + ): T + /** Indicates that context compaction (summarization) occurred during the session. */ fun visitAgentThreadContextCompacted( agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent @@ -855,6 +1366,29 @@ private constructor( sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent ): T + /** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output + * stream so clients observing the session see child creation. + */ + fun visitSessionThreadCreated( + sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent + ): T + + /** Emitted when an outcome evaluation cycle begins. */ + fun visitSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ): T + + /** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate + * token usage. A verdict of `needs_revision` means another evaluation cycle follows; + * `satisfied`, `max_iterations_reached`, `failed`, or `interrupted` are terminal — no + * further evaluation cycles follow. + */ + fun visitSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ): T + /** Emitted when a model request is initiated by the agent. */ fun visitSpanModelRequestStart( spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent @@ -865,12 +1399,59 @@ private constructor( spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent ): T + /** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. + * Distinguishes 'evaluation is actively running' from 'evaluation is stuck' between the + * corresponding `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ + fun visitSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ): T + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` + * that subsequent `span.outcome_evaluation_*` events reference. + */ + fun visitUserDefineOutcome(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent): T + /** * Emitted when a session has been deleted. Terminates any active event stream — no further * events will be emitted for this session. */ fun visitSessionDeleted(sessionDeleted: BetaManagedAgentsSessionDeletedEvent): T + /** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted + * to the primary stream for child threads. + */ + fun visitSessionThreadStatusRunning( + sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent + ): T + + /** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream + * and cross-posted to the primary stream for child threads. + */ + fun visitSessionThreadStatusIdle( + sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent + ): T + + /** + * A session thread has terminated and will accept no further input. Emitted on the thread's + * own stream and cross-posted to the primary stream for child threads. + */ + fun visitSessionThreadStatusTerminated( + sessionThreadStatusTerminated: BetaManagedAgentsSessionThreadStatusTerminatedEvent + ): T + + /** + * A session thread hit a transient error and is retrying automatically. Emitted on the + * thread's own stream and cross-posted to the primary stream for child threads. + */ + fun visitSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled: BetaManagedAgentsSessionThreadStatusRescheduledEvent + ): T + /** * Maps an unknown variant of [BetaManagedAgentsStreamSessionEvents] to a value of type [T]. * @@ -1006,6 +1587,30 @@ private constructor( BetaManagedAgentsStreamSessionEvents(agentToolResult = it, _json = json) } ?: BetaManagedAgentsStreamSessionEvents(_json = json) } + "agent.thread_message_received" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionEvents( + agentThreadMessageReceived = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionEvents(_json = json) + } + "agent.thread_message_sent" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionEvents( + agentThreadMessageSent = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionEvents(_json = json) + } "agent.thread_context_compacted" -> { return tryDeserialize( node, @@ -1075,6 +1680,42 @@ private constructor( ) } ?: BetaManagedAgentsStreamSessionEvents(_json = json) } + "session.thread_created" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionEvents( + sessionThreadCreated = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionEvents(_json = json) + } + "span.outcome_evaluation_start" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionEvents( + spanOutcomeEvaluationStart = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionEvents(_json = json) + } + "span.outcome_evaluation_end" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionEvents( + spanOutcomeEvaluationEnd = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionEvents(_json = json) + } "span.model_request_start" -> { return tryDeserialize( node, @@ -1099,6 +1740,30 @@ private constructor( ) } ?: BetaManagedAgentsStreamSessionEvents(_json = json) } + "span.outcome_evaluation_ongoing" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionEvents( + spanOutcomeEvaluationOngoing = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionEvents(_json = json) + } + "user.define_outcome" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionEvents( + userDefineOutcome = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionEvents(_json = json) + } "session.deleted" -> { return tryDeserialize( node, @@ -1108,6 +1773,54 @@ private constructor( BetaManagedAgentsStreamSessionEvents(sessionDeleted = it, _json = json) } ?: BetaManagedAgentsStreamSessionEvents(_json = json) } + "session.thread_status_running" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionEvents( + sessionThreadStatusRunning = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionEvents(_json = json) + } + "session.thread_status_idle" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionEvents( + sessionThreadStatusIdle = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionEvents(_json = json) + } + "session.thread_status_terminated" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionEvents( + sessionThreadStatusTerminated = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionEvents(_json = json) + } + "session.thread_status_rescheduled" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionEvents( + sessionThreadStatusRescheduled = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionEvents(_json = json) + } } return BetaManagedAgentsStreamSessionEvents(_json = json) @@ -1138,6 +1851,10 @@ private constructor( value.agentMcpToolResult != null -> generator.writeObject(value.agentMcpToolResult) value.agentToolUse != null -> generator.writeObject(value.agentToolUse) value.agentToolResult != null -> generator.writeObject(value.agentToolResult) + value.agentThreadMessageReceived != null -> + generator.writeObject(value.agentThreadMessageReceived) + value.agentThreadMessageSent != null -> + generator.writeObject(value.agentThreadMessageSent) value.agentThreadContextCompacted != null -> generator.writeObject(value.agentThreadContextCompacted) value.sessionError != null -> generator.writeObject(value.sessionError) @@ -1148,11 +1865,28 @@ private constructor( value.sessionStatusIdle != null -> generator.writeObject(value.sessionStatusIdle) value.sessionStatusTerminated != null -> generator.writeObject(value.sessionStatusTerminated) + value.sessionThreadCreated != null -> + generator.writeObject(value.sessionThreadCreated) + value.spanOutcomeEvaluationStart != null -> + generator.writeObject(value.spanOutcomeEvaluationStart) + value.spanOutcomeEvaluationEnd != null -> + generator.writeObject(value.spanOutcomeEvaluationEnd) value.spanModelRequestStart != null -> generator.writeObject(value.spanModelRequestStart) value.spanModelRequestEnd != null -> generator.writeObject(value.spanModelRequestEnd) + value.spanOutcomeEvaluationOngoing != null -> + generator.writeObject(value.spanOutcomeEvaluationOngoing) + value.userDefineOutcome != null -> generator.writeObject(value.userDefineOutcome) value.sessionDeleted != null -> generator.writeObject(value.sessionDeleted) + value.sessionThreadStatusRunning != null -> + generator.writeObject(value.sessionThreadStatusRunning) + value.sessionThreadStatusIdle != null -> + generator.writeObject(value.sessionThreadStatusIdle) + value.sessionThreadStatusTerminated != null -> + generator.writeObject(value.sessionThreadStatusTerminated) + value.sessionThreadStatusRescheduled != null -> + generator.writeObject(value.sessionThreadStatusRescheduled) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid BetaManagedAgentsStreamSessionEvents") } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubric.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubric.kt new file mode 100644 index 000000000..db26e5ecb --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubric.kt @@ -0,0 +1,348 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** Rubric content provided inline as text. */ +class BetaManagedAgentsTextRubric +@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()) + + /** + * Rubric content. Plain text or markdown — the grader treats it as freeform text. + * + * @throws AnthropicInvalidDataException if 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 AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [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 [BetaManagedAgentsTextRubric]. + * + * The following fields are required: + * ```java + * .content() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsTextRubric]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaManagedAgentsTextRubric: BetaManagedAgentsTextRubric) = apply { + content = betaManagedAgentsTextRubric.content + type = betaManagedAgentsTextRubric.type + additionalProperties = betaManagedAgentsTextRubric.additionalProperties.toMutableMap() + } + + /** Rubric content. Plain text or markdown — the grader treats it as freeform text. */ + 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 [BetaManagedAgentsTextRubric]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsTextRubric = + BetaManagedAgentsTextRubric( + checkRequired("content", content), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsTextRubric = apply { + if (validated) { + return@apply + } + + content() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + TEXT -> Known.TEXT + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsTextRubric && + 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() = + "BetaManagedAgentsTextRubric{content=$content, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubricParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubricParams.kt new file mode 100644 index 000000000..b78c4206e --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubricParams.kt @@ -0,0 +1,355 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +/** Rubric content provided inline as text. */ +class BetaManagedAgentsTextRubricParams +@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()) + + /** + * Rubric content. Plain text or markdown — the grader treats it as freeform text. Maximum + * 262144 characters. + * + * @throws AnthropicInvalidDataException if 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 AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [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 + * [BetaManagedAgentsTextRubricParams]. + * + * The following fields are required: + * ```java + * .content() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsTextRubricParams]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaManagedAgentsTextRubricParams: BetaManagedAgentsTextRubricParams) = + apply { + content = betaManagedAgentsTextRubricParams.content + type = betaManagedAgentsTextRubricParams.type + additionalProperties = + betaManagedAgentsTextRubricParams.additionalProperties.toMutableMap() + } + + /** + * Rubric content. Plain text or markdown — the grader treats it as freeform text. Maximum + * 262144 characters. + */ + 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 [BetaManagedAgentsTextRubricParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsTextRubricParams = + BetaManagedAgentsTextRubricParams( + checkRequired("content", content), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsTextRubricParams = apply { + if (validated) { + return@apply + } + + content() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + TEXT -> Known.TEXT + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsTextRubricParams && + 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() = + "BetaManagedAgentsTextRubricParams{content=$content, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserCustomToolResultEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserCustomToolResultEvent.kt index 47277ebe9..3bed13a00 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserCustomToolResultEvent.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserCustomToolResultEvent.kt @@ -41,6 +41,7 @@ private constructor( private val content: JsonField>, private val isError: JsonField, private val processedAt: JsonField, + private val sessionThreadId: JsonField, private val additionalProperties: MutableMap, ) { @@ -58,7 +59,19 @@ private constructor( @JsonProperty("processed_at") @ExcludeMissing processedAt: JsonField = JsonMissing.of(), - ) : this(id, customToolUseId, type, content, isError, processedAt, mutableMapOf()) + @JsonProperty("session_thread_id") + @ExcludeMissing + sessionThreadId: JsonField = JsonMissing.of(), + ) : this( + id, + customToolUseId, + type, + content, + isError, + processedAt, + sessionThreadId, + mutableMapOf(), + ) /** * Unique identifier for this event. @@ -109,6 +122,15 @@ private constructor( */ fun processedAt(): Optional = processedAt.getOptional("processed_at") + /** + * Routes this result to a subagent thread. Copy from the `agent.custom_tool_use` event's + * `session_thread_id`. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun sessionThreadId(): Optional = sessionThreadId.getOptional("session_thread_id") + /** * Returns the raw JSON value of [id]. * @@ -155,6 +177,15 @@ private constructor( @ExcludeMissing fun _processedAt(): JsonField = processedAt + /** + * Returns the raw JSON value of [sessionThreadId]. + * + * Unlike [sessionThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_thread_id") + @ExcludeMissing + fun _sessionThreadId(): JsonField = sessionThreadId + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -192,6 +223,7 @@ private constructor( private var content: JsonField>? = null private var isError: JsonField = JsonMissing.of() private var processedAt: JsonField = JsonMissing.of() + private var sessionThreadId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -204,6 +236,7 @@ private constructor( content = betaManagedAgentsUserCustomToolResultEvent.content.map { it.toMutableList() } isError = betaManagedAgentsUserCustomToolResultEvent.isError processedAt = betaManagedAgentsUserCustomToolResultEvent.processedAt + sessionThreadId = betaManagedAgentsUserCustomToolResultEvent.sessionThreadId additionalProperties = betaManagedAgentsUserCustomToolResultEvent.additionalProperties.toMutableMap() } @@ -492,6 +525,28 @@ private constructor( this.processedAt = processedAt } + /** + * Routes this result to a subagent thread. Copy from the `agent.custom_tool_use` event's + * `session_thread_id`. + */ + fun sessionThreadId(sessionThreadId: String?) = + sessionThreadId(JsonField.ofNullable(sessionThreadId)) + + /** Alias for calling [Builder.sessionThreadId] with `sessionThreadId.orElse(null)`. */ + fun sessionThreadId(sessionThreadId: Optional) = + sessionThreadId(sessionThreadId.getOrNull()) + + /** + * Sets [Builder.sessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sessionThreadId(sessionThreadId: JsonField) = apply { + this.sessionThreadId = sessionThreadId + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -533,6 +588,7 @@ private constructor( (content ?: JsonMissing.of()).map { it.toImmutable() }, isError, processedAt, + sessionThreadId, additionalProperties.toMutableMap(), ) } @@ -558,6 +614,7 @@ private constructor( content().ifPresent { it.forEach { it.validate() } } isError() processedAt() + sessionThreadId() validated = true } @@ -581,7 +638,8 @@ private constructor( (type.asKnown().getOrNull()?.validity() ?: 0) + (content.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (isError.asKnown().isPresent) 1 else 0) + - (if (processedAt.asKnown().isPresent) 1 else 0) + (if (processedAt.asKnown().isPresent) 1 else 0) + + (if (sessionThreadId.asKnown().isPresent) 1 else 0) class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -984,15 +1042,25 @@ private constructor( content == other.content && isError == other.isError && processedAt == other.processedAt && + sessionThreadId == other.sessionThreadId && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(id, customToolUseId, type, content, isError, processedAt, additionalProperties) + Objects.hash( + id, + customToolUseId, + type, + content, + isError, + processedAt, + sessionThreadId, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaManagedAgentsUserCustomToolResultEvent{id=$id, customToolUseId=$customToolUseId, type=$type, content=$content, isError=$isError, processedAt=$processedAt, additionalProperties=$additionalProperties}" + "BetaManagedAgentsUserCustomToolResultEvent{id=$id, customToolUseId=$customToolUseId, type=$type, content=$content, isError=$isError, processedAt=$processedAt, sessionThreadId=$sessionThreadId, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEvent.kt new file mode 100644 index 000000000..a378d3bd3 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEvent.kt @@ -0,0 +1,840 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.core.getOrThrow +import com.anthropic.errors.AnthropicInvalidDataException +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.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` that + * subsequent `span.outcome_evaluation_*` events reference. + */ +class BetaManagedAgentsUserDefineOutcomeEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val description: JsonField, + private val maxIterations: JsonField, + private val outcomeId: JsonField, + private val processedAt: JsonField, + private val rubric: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("max_iterations") + @ExcludeMissing + maxIterations: JsonField = JsonMissing.of(), + @JsonProperty("outcome_id") @ExcludeMissing outcomeId: JsonField = JsonMissing.of(), + @JsonProperty("processed_at") + @ExcludeMissing + processedAt: JsonField = JsonMissing.of(), + @JsonProperty("rubric") @ExcludeMissing rubric: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(id, description, maxIterations, outcomeId, processedAt, rubric, type, mutableMapOf()) + + /** + * Unique identifier for this event. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * What the agent should produce. Copied from the input event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun description(): String = description.getRequired("description") + + /** + * Evaluate-then-revise cycles before giving up. Default 3, max 20. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun maxIterations(): Optional = maxIterations.getOptional("max_iterations") + + /** + * Server-generated `outc_` ID for this outcome. Referenced by `span.outcome_evaluation_*` + * events and the session's `outcome_evaluations` list. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun outcomeId(): String = outcomeId.getRequired("outcome_id") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun processedAt(): OffsetDateTime = processedAt.getRequired("processed_at") + + /** + * Rubric for grading the quality of an outcome. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun rubric(): Rubric = rubric.getRequired("rubric") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [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 [maxIterations]. + * + * Unlike [maxIterations], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("max_iterations") + @ExcludeMissing + fun _maxIterations(): JsonField = maxIterations + + /** + * Returns the raw JSON value of [outcomeId]. + * + * Unlike [outcomeId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("outcome_id") @ExcludeMissing fun _outcomeId(): JsonField = outcomeId + + /** + * Returns the raw JSON value of [processedAt]. + * + * Unlike [processedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processed_at") + @ExcludeMissing + fun _processedAt(): JsonField = processedAt + + /** + * Returns the raw JSON value of [rubric]. + * + * Unlike [rubric], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rubric") @ExcludeMissing fun _rubric(): JsonField = rubric + + /** + * 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 + * [BetaManagedAgentsUserDefineOutcomeEvent]. + * + * The following fields are required: + * ```java + * .id() + * .description() + * .maxIterations() + * .outcomeId() + * .processedAt() + * .rubric() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsUserDefineOutcomeEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var description: JsonField? = null + private var maxIterations: JsonField? = null + private var outcomeId: JsonField? = null + private var processedAt: JsonField? = null + private var rubric: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsUserDefineOutcomeEvent: BetaManagedAgentsUserDefineOutcomeEvent + ) = apply { + id = betaManagedAgentsUserDefineOutcomeEvent.id + description = betaManagedAgentsUserDefineOutcomeEvent.description + maxIterations = betaManagedAgentsUserDefineOutcomeEvent.maxIterations + outcomeId = betaManagedAgentsUserDefineOutcomeEvent.outcomeId + processedAt = betaManagedAgentsUserDefineOutcomeEvent.processedAt + rubric = betaManagedAgentsUserDefineOutcomeEvent.rubric + type = betaManagedAgentsUserDefineOutcomeEvent.type + additionalProperties = + betaManagedAgentsUserDefineOutcomeEvent.additionalProperties.toMutableMap() + } + + /** Unique identifier for this event. */ + 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 } + + /** What the agent should produce. Copied from the input event. */ + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** Evaluate-then-revise cycles before giving up. Default 3, max 20. */ + fun maxIterations(maxIterations: Int?) = maxIterations(JsonField.ofNullable(maxIterations)) + + /** + * Alias for [Builder.maxIterations]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun maxIterations(maxIterations: Int) = maxIterations(maxIterations as Int?) + + /** Alias for calling [Builder.maxIterations] with `maxIterations.orElse(null)`. */ + fun maxIterations(maxIterations: Optional) = maxIterations(maxIterations.getOrNull()) + + /** + * Sets [Builder.maxIterations] to an arbitrary JSON value. + * + * You should usually call [Builder.maxIterations] with a well-typed [Int] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun maxIterations(maxIterations: JsonField) = apply { + this.maxIterations = maxIterations + } + + /** + * Server-generated `outc_` ID for this outcome. Referenced by `span.outcome_evaluation_*` + * events and the session's `outcome_evaluations` list. + */ + fun outcomeId(outcomeId: String) = outcomeId(JsonField.of(outcomeId)) + + /** + * Sets [Builder.outcomeId] to an arbitrary JSON value. + * + * You should usually call [Builder.outcomeId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun outcomeId(outcomeId: JsonField) = apply { this.outcomeId = outcomeId } + + /** A timestamp in RFC 3339 format */ + fun processedAt(processedAt: OffsetDateTime) = processedAt(JsonField.of(processedAt)) + + /** + * Sets [Builder.processedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.processedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedAt(processedAt: JsonField) = apply { + this.processedAt = processedAt + } + + /** Rubric for grading the quality of an outcome. */ + fun rubric(rubric: Rubric) = rubric(JsonField.of(rubric)) + + /** + * Sets [Builder.rubric] to an arbitrary JSON value. + * + * You should usually call [Builder.rubric] with a well-typed [Rubric] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun rubric(rubric: JsonField) = apply { this.rubric = rubric } + + /** Alias for calling [rubric] with `Rubric.ofFile(file)`. */ + fun rubric(file: BetaManagedAgentsFileRubric) = rubric(Rubric.ofFile(file)) + + /** + * Alias for calling [rubric] with the following: + * ```java + * BetaManagedAgentsFileRubric.builder() + * .type(BetaManagedAgentsFileRubric.Type.FILE) + * .fileId(fileId) + * .build() + * ``` + */ + fun fileRubric(fileId: String) = + rubric( + BetaManagedAgentsFileRubric.builder() + .type(BetaManagedAgentsFileRubric.Type.FILE) + .fileId(fileId) + .build() + ) + + /** Alias for calling [rubric] with `Rubric.ofText(text)`. */ + fun rubric(text: BetaManagedAgentsTextRubric) = rubric(Rubric.ofText(text)) + + /** + * Alias for calling [rubric] with the following: + * ```java + * BetaManagedAgentsTextRubric.builder() + * .type(BetaManagedAgentsTextRubric.Type.TEXT) + * .content(content) + * .build() + * ``` + */ + fun textRubric(content: String) = + rubric( + BetaManagedAgentsTextRubric.builder() + .type(BetaManagedAgentsTextRubric.Type.TEXT) + .content(content) + .build() + ) + + 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 [BetaManagedAgentsUserDefineOutcomeEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .description() + * .maxIterations() + * .outcomeId() + * .processedAt() + * .rubric() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsUserDefineOutcomeEvent = + BetaManagedAgentsUserDefineOutcomeEvent( + checkRequired("id", id), + checkRequired("description", description), + checkRequired("maxIterations", maxIterations), + checkRequired("outcomeId", outcomeId), + checkRequired("processedAt", processedAt), + checkRequired("rubric", rubric), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsUserDefineOutcomeEvent = apply { + if (validated) { + return@apply + } + + id() + description() + maxIterations() + outcomeId() + processedAt() + rubric().validate() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (description.asKnown().isPresent) 1 else 0) + + (if (maxIterations.asKnown().isPresent) 1 else 0) + + (if (outcomeId.asKnown().isPresent) 1 else 0) + + (if (processedAt.asKnown().isPresent) 1 else 0) + + (rubric.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + /** Rubric for grading the quality of an outcome. */ + @JsonDeserialize(using = Rubric.Deserializer::class) + @JsonSerialize(using = Rubric.Serializer::class) + class Rubric + private constructor( + private val file: BetaManagedAgentsFileRubric? = null, + private val text: BetaManagedAgentsTextRubric? = null, + private val _json: JsonValue? = null, + ) { + + /** Rubric referenced by a file uploaded via the Files API. */ + fun file(): Optional = Optional.ofNullable(file) + + /** Rubric content provided inline as text. */ + fun text(): Optional = Optional.ofNullable(text) + + fun isFile(): Boolean = file != null + + fun isText(): Boolean = text != null + + /** Rubric referenced by a file uploaded via the Files API. */ + fun asFile(): BetaManagedAgentsFileRubric = file.getOrThrow("file") + + /** Rubric content provided inline as text. */ + fun asText(): BetaManagedAgentsTextRubric = text.getOrThrow("text") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, unless + * [visitor] overrides [Visitor.unknown]. To handle variants not known to this version of + * the SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.anthropic.core.JsonValue; + * import java.util.Optional; + * + * Optional result = rubric.accept(new Rubric.Visitor>() { + * @Override + * public Optional visitFile(BetaManagedAgentsFileRubric file) { + * return Optional.of(file.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws AnthropicInvalidDataException if [Visitor.unknown] is not overridden in [visitor] + * and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + file != null -> visitor.visitFile(file) + text != null -> visitor.visitText(text) + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Rubric = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitFile(file: BetaManagedAgentsFileRubric) { + file.validate() + } + + override fun visitText(text: BetaManagedAgentsTextRubric) { + text.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitFile(file: BetaManagedAgentsFileRubric) = file.validity() + + override fun visitText(text: BetaManagedAgentsTextRubric) = text.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Rubric && file == other.file && text == other.text + } + + override fun hashCode(): Int = Objects.hash(file, text) + + override fun toString(): String = + when { + file != null -> "Rubric{file=$file}" + text != null -> "Rubric{text=$text}" + _json != null -> "Rubric{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Rubric") + } + + companion object { + + /** Rubric referenced by a file uploaded via the Files API. */ + @JvmStatic fun ofFile(file: BetaManagedAgentsFileRubric) = Rubric(file = file) + + /** Rubric content provided inline as text. */ + @JvmStatic fun ofText(text: BetaManagedAgentsTextRubric) = Rubric(text = text) + } + + /** An interface that defines how to map each variant of [Rubric] to a value of type [T]. */ + interface Visitor { + + /** Rubric referenced by a file uploaded via the Files API. */ + fun visitFile(file: BetaManagedAgentsFileRubric): T + + /** Rubric content provided inline as text. */ + fun visitText(text: BetaManagedAgentsTextRubric): T + + /** + * Maps an unknown variant of [Rubric] to a value of type [T]. + * + * An instance of [Rubric] 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 AnthropicInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw AnthropicInvalidDataException("Unknown Rubric: $json") + } + } + + internal class Deserializer : BaseDeserializer(Rubric::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Rubric { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "file" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Rubric(file = it, _json = json) } ?: Rubric(_json = json) + } + "text" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Rubric(text = it, _json = json) } ?: Rubric(_json = json) + } + } + + return Rubric(_json = json) + } + } + + internal class Serializer : BaseSerializer(Rubric::class) { + + override fun serialize( + value: Rubric, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.file != null -> generator.writeObject(value.file) + value.text != null -> generator.writeObject(value.text) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Rubric") + } + } + } + } + + 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_DEFINE_OUTCOME = of("user.define_outcome") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + USER_DEFINE_OUTCOME + } + + /** + * 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_DEFINE_OUTCOME, + /** 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_DEFINE_OUTCOME -> Value.USER_DEFINE_OUTCOME + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USER_DEFINE_OUTCOME -> Known.USER_DEFINE_OUTCOME + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsUserDefineOutcomeEvent && + id == other.id && + description == other.description && + maxIterations == other.maxIterations && + outcomeId == other.outcomeId && + processedAt == other.processedAt && + rubric == other.rubric && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + description, + maxIterations, + outcomeId, + processedAt, + rubric, + type, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsUserDefineOutcomeEvent{id=$id, description=$description, maxIterations=$maxIterations, outcomeId=$outcomeId, processedAt=$processedAt, rubric=$rubric, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEventParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEventParams.kt new file mode 100644 index 000000000..e12c91d56 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEventParams.kt @@ -0,0 +1,717 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.core.getOrThrow +import com.anthropic.errors.AnthropicInvalidDataException +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 + +/** + * Parameters for defining an outcome the agent should work toward. The agent begins work on + * receipt. + */ +class BetaManagedAgentsUserDefineOutcomeEventParams +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val description: JsonField, + private val rubric: JsonField, + private val type: JsonField, + private val maxIterations: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("rubric") @ExcludeMissing rubric: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("max_iterations") + @ExcludeMissing + maxIterations: JsonField = JsonMissing.of(), + ) : this(description, rubric, type, maxIterations, mutableMapOf()) + + /** + * What the agent should produce. This is the task specification. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun description(): String = description.getRequired("description") + + /** + * Rubric for grading the quality of an outcome. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun rubric(): Rubric = rubric.getRequired("rubric") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Eval→revision cycles before giving up. Default 3, max 20. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun maxIterations(): Optional = maxIterations.getOptional("max_iterations") + + /** + * 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 [rubric]. + * + * Unlike [rubric], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rubric") @ExcludeMissing fun _rubric(): JsonField = rubric + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [maxIterations]. + * + * Unlike [maxIterations], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("max_iterations") + @ExcludeMissing + fun _maxIterations(): JsonField = maxIterations + + @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 + * [BetaManagedAgentsUserDefineOutcomeEventParams]. + * + * The following fields are required: + * ```java + * .description() + * .rubric() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsUserDefineOutcomeEventParams]. */ + class Builder internal constructor() { + + private var description: JsonField? = null + private var rubric: JsonField? = null + private var type: JsonField? = null + private var maxIterations: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsUserDefineOutcomeEventParams: + BetaManagedAgentsUserDefineOutcomeEventParams + ) = apply { + description = betaManagedAgentsUserDefineOutcomeEventParams.description + rubric = betaManagedAgentsUserDefineOutcomeEventParams.rubric + type = betaManagedAgentsUserDefineOutcomeEventParams.type + maxIterations = betaManagedAgentsUserDefineOutcomeEventParams.maxIterations + additionalProperties = + betaManagedAgentsUserDefineOutcomeEventParams.additionalProperties.toMutableMap() + } + + /** What the agent should produce. This is the task specification. */ + fun description(description: String) = description(JsonField.of(description)) + + /** + * Sets [Builder.description] to an arbitrary JSON value. + * + * You should usually call [Builder.description] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun description(description: JsonField) = apply { this.description = description } + + /** Rubric for grading the quality of an outcome. */ + fun rubric(rubric: Rubric) = rubric(JsonField.of(rubric)) + + /** + * Sets [Builder.rubric] to an arbitrary JSON value. + * + * You should usually call [Builder.rubric] with a well-typed [Rubric] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun rubric(rubric: JsonField) = apply { this.rubric = rubric } + + /** Alias for calling [rubric] with `Rubric.ofFile(file)`. */ + fun rubric(file: BetaManagedAgentsFileRubricParams) = rubric(Rubric.ofFile(file)) + + /** + * Alias for calling [rubric] with the following: + * ```java + * BetaManagedAgentsFileRubricParams.builder() + * .type(BetaManagedAgentsFileRubricParams.Type.FILE) + * .fileId(fileId) + * .build() + * ``` + */ + fun fileRubric(fileId: String) = + rubric( + BetaManagedAgentsFileRubricParams.builder() + .type(BetaManagedAgentsFileRubricParams.Type.FILE) + .fileId(fileId) + .build() + ) + + /** Alias for calling [rubric] with `Rubric.ofText(text)`. */ + fun rubric(text: BetaManagedAgentsTextRubricParams) = rubric(Rubric.ofText(text)) + + /** + * Alias for calling [rubric] with the following: + * ```java + * BetaManagedAgentsTextRubricParams.builder() + * .type(BetaManagedAgentsTextRubricParams.Type.TEXT) + * .content(content) + * .build() + * ``` + */ + fun textRubric(content: String) = + rubric( + BetaManagedAgentsTextRubricParams.builder() + .type(BetaManagedAgentsTextRubricParams.Type.TEXT) + .content(content) + .build() + ) + + 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 } + + /** Eval→revision cycles before giving up. Default 3, max 20. */ + fun maxIterations(maxIterations: Int?) = maxIterations(JsonField.ofNullable(maxIterations)) + + /** + * Alias for [Builder.maxIterations]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun maxIterations(maxIterations: Int) = maxIterations(maxIterations as Int?) + + /** Alias for calling [Builder.maxIterations] with `maxIterations.orElse(null)`. */ + fun maxIterations(maxIterations: Optional) = maxIterations(maxIterations.getOrNull()) + + /** + * Sets [Builder.maxIterations] to an arbitrary JSON value. + * + * You should usually call [Builder.maxIterations] with a well-typed [Int] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun maxIterations(maxIterations: JsonField) = apply { + this.maxIterations = maxIterations + } + + 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 [BetaManagedAgentsUserDefineOutcomeEventParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .description() + * .rubric() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsUserDefineOutcomeEventParams = + BetaManagedAgentsUserDefineOutcomeEventParams( + checkRequired("description", description), + checkRequired("rubric", rubric), + checkRequired("type", type), + maxIterations, + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsUserDefineOutcomeEventParams = apply { + if (validated) { + return@apply + } + + description() + rubric().validate() + type().validate() + maxIterations() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (description.asKnown().isPresent) 1 else 0) + + (rubric.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (maxIterations.asKnown().isPresent) 1 else 0) + + /** Rubric for grading the quality of an outcome. */ + @JsonDeserialize(using = Rubric.Deserializer::class) + @JsonSerialize(using = Rubric.Serializer::class) + class Rubric + private constructor( + private val file: BetaManagedAgentsFileRubricParams? = null, + private val text: BetaManagedAgentsTextRubricParams? = null, + private val _json: JsonValue? = null, + ) { + + /** Rubric referenced by a file uploaded via the Files API. */ + fun file(): Optional = Optional.ofNullable(file) + + /** Rubric content provided inline as text. */ + fun text(): Optional = Optional.ofNullable(text) + + fun isFile(): Boolean = file != null + + fun isText(): Boolean = text != null + + /** Rubric referenced by a file uploaded via the Files API. */ + fun asFile(): BetaManagedAgentsFileRubricParams = file.getOrThrow("file") + + /** Rubric content provided inline as text. */ + fun asText(): BetaManagedAgentsTextRubricParams = text.getOrThrow("text") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, unless + * [visitor] overrides [Visitor.unknown]. To handle variants not known to this version of + * the SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.anthropic.core.JsonValue; + * import java.util.Optional; + * + * Optional result = rubric.accept(new Rubric.Visitor>() { + * @Override + * public Optional visitFile(BetaManagedAgentsFileRubricParams file) { + * return Optional.of(file.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws AnthropicInvalidDataException if [Visitor.unknown] is not overridden in [visitor] + * and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + file != null -> visitor.visitFile(file) + text != null -> visitor.visitText(text) + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Rubric = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitFile(file: BetaManagedAgentsFileRubricParams) { + file.validate() + } + + override fun visitText(text: BetaManagedAgentsTextRubricParams) { + text.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitFile(file: BetaManagedAgentsFileRubricParams) = + file.validity() + + override fun visitText(text: BetaManagedAgentsTextRubricParams) = + text.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Rubric && file == other.file && text == other.text + } + + override fun hashCode(): Int = Objects.hash(file, text) + + override fun toString(): String = + when { + file != null -> "Rubric{file=$file}" + text != null -> "Rubric{text=$text}" + _json != null -> "Rubric{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Rubric") + } + + companion object { + + /** Rubric referenced by a file uploaded via the Files API. */ + @JvmStatic fun ofFile(file: BetaManagedAgentsFileRubricParams) = Rubric(file = file) + + /** Rubric content provided inline as text. */ + @JvmStatic fun ofText(text: BetaManagedAgentsTextRubricParams) = Rubric(text = text) + } + + /** An interface that defines how to map each variant of [Rubric] to a value of type [T]. */ + interface Visitor { + + /** Rubric referenced by a file uploaded via the Files API. */ + fun visitFile(file: BetaManagedAgentsFileRubricParams): T + + /** Rubric content provided inline as text. */ + fun visitText(text: BetaManagedAgentsTextRubricParams): T + + /** + * Maps an unknown variant of [Rubric] to a value of type [T]. + * + * An instance of [Rubric] 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 AnthropicInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw AnthropicInvalidDataException("Unknown Rubric: $json") + } + } + + internal class Deserializer : BaseDeserializer(Rubric::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Rubric { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "file" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Rubric(file = it, _json = json) } ?: Rubric(_json = json) + } + "text" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Rubric(text = it, _json = json) } ?: Rubric(_json = json) + } + } + + return Rubric(_json = json) + } + } + + internal class Serializer : BaseSerializer(Rubric::class) { + + override fun serialize( + value: Rubric, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.file != null -> generator.writeObject(value.file) + value.text != null -> generator.writeObject(value.text) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Rubric") + } + } + } + } + + 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_DEFINE_OUTCOME = of("user.define_outcome") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + USER_DEFINE_OUTCOME + } + + /** + * 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_DEFINE_OUTCOME, + /** 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_DEFINE_OUTCOME -> Value.USER_DEFINE_OUTCOME + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + USER_DEFINE_OUTCOME -> Known.USER_DEFINE_OUTCOME + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsUserDefineOutcomeEventParams && + description == other.description && + rubric == other.rubric && + type == other.type && + maxIterations == other.maxIterations && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(description, rubric, type, maxIterations, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsUserDefineOutcomeEventParams{description=$description, rubric=$rubric, type=$type, maxIterations=$maxIterations, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEvent.kt index 42feee8da..309792c6b 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEvent.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEvent.kt @@ -26,6 +26,7 @@ private constructor( private val id: JsonField, private val type: JsonField, private val processedAt: JsonField, + private val sessionThreadId: JsonField, private val additionalProperties: MutableMap, ) { @@ -36,7 +37,10 @@ private constructor( @JsonProperty("processed_at") @ExcludeMissing processedAt: JsonField = JsonMissing.of(), - ) : this(id, type, processedAt, mutableMapOf()) + @JsonProperty("session_thread_id") + @ExcludeMissing + sessionThreadId: JsonField = JsonMissing.of(), + ) : this(id, type, processedAt, sessionThreadId, mutableMapOf()) /** * Unique identifier for this event. @@ -60,6 +64,15 @@ private constructor( */ fun processedAt(): Optional = processedAt.getOptional("processed_at") + /** + * If absent, interrupts every non-archived thread in a multiagent session (or the primary alone + * in a single-agent session). If present, interrupts only the named thread. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun sessionThreadId(): Optional = sessionThreadId.getOptional("session_thread_id") + /** * Returns the raw JSON value of [id]. * @@ -83,6 +96,15 @@ private constructor( @ExcludeMissing fun _processedAt(): JsonField = processedAt + /** + * Returns the raw JSON value of [sessionThreadId]. + * + * Unlike [sessionThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_thread_id") + @ExcludeMissing + fun _sessionThreadId(): JsonField = sessionThreadId + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -116,6 +138,7 @@ private constructor( private var id: JsonField? = null private var type: JsonField? = null private var processedAt: JsonField = JsonMissing.of() + private var sessionThreadId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -125,6 +148,7 @@ private constructor( id = betaManagedAgentsUserInterruptEvent.id type = betaManagedAgentsUserInterruptEvent.type processedAt = betaManagedAgentsUserInterruptEvent.processedAt + sessionThreadId = betaManagedAgentsUserInterruptEvent.sessionThreadId additionalProperties = betaManagedAgentsUserInterruptEvent.additionalProperties.toMutableMap() } @@ -169,6 +193,28 @@ private constructor( this.processedAt = processedAt } + /** + * If absent, interrupts every non-archived thread in a multiagent session (or the primary + * alone in a single-agent session). If present, interrupts only the named thread. + */ + fun sessionThreadId(sessionThreadId: String?) = + sessionThreadId(JsonField.ofNullable(sessionThreadId)) + + /** Alias for calling [Builder.sessionThreadId] with `sessionThreadId.orElse(null)`. */ + fun sessionThreadId(sessionThreadId: Optional) = + sessionThreadId(sessionThreadId.getOrNull()) + + /** + * Sets [Builder.sessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sessionThreadId(sessionThreadId: JsonField) = apply { + this.sessionThreadId = sessionThreadId + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -206,6 +252,7 @@ private constructor( checkRequired("id", id), checkRequired("type", type), processedAt, + sessionThreadId, additionalProperties.toMutableMap(), ) } @@ -228,6 +275,7 @@ private constructor( id() type().validate() processedAt() + sessionThreadId() validated = true } @@ -248,7 +296,8 @@ private constructor( internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + - (if (processedAt.asKnown().isPresent) 1 else 0) + (if (processedAt.asKnown().isPresent) 1 else 0) + + (if (sessionThreadId.asKnown().isPresent) 1 else 0) class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -389,13 +438,16 @@ private constructor( id == other.id && type == other.type && processedAt == other.processedAt && + sessionThreadId == other.sessionThreadId && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(id, type, processedAt, additionalProperties) } + private val hashCode: Int by lazy { + Objects.hash(id, type, processedAt, sessionThreadId, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "BetaManagedAgentsUserInterruptEvent{id=$id, type=$type, processedAt=$processedAt, additionalProperties=$additionalProperties}" + "BetaManagedAgentsUserInterruptEvent{id=$id, type=$type, processedAt=$processedAt, sessionThreadId=$sessionThreadId, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEventParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEventParams.kt index 9a2188a6a..74c89ea36 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEventParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEventParams.kt @@ -15,6 +15,7 @@ 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 /** Parameters for sending an interrupt to pause the agent. */ @@ -22,13 +23,17 @@ class BetaManagedAgentsUserInterruptEventParams @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val type: JsonField, + private val sessionThreadId: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of() - ) : this(type, mutableMapOf()) + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("session_thread_id") + @ExcludeMissing + sessionThreadId: JsonField = JsonMissing.of(), + ) : this(type, sessionThreadId, mutableMapOf()) /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is @@ -36,6 +41,15 @@ private constructor( */ fun type(): Type = type.getRequired("type") + /** + * If absent, interrupts every non-archived thread in a multiagent session (or the primary alone + * in a single-agent session). If present, interrupts only the named thread. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun sessionThreadId(): Optional = sessionThreadId.getOptional("session_thread_id") + /** * Returns the raw JSON value of [type]. * @@ -43,6 +57,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** + * Returns the raw JSON value of [sessionThreadId]. + * + * Unlike [sessionThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_thread_id") + @ExcludeMissing + fun _sessionThreadId(): JsonField = sessionThreadId + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -73,6 +96,7 @@ private constructor( class Builder internal constructor() { private var type: JsonField? = null + private var sessionThreadId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -80,6 +104,7 @@ private constructor( betaManagedAgentsUserInterruptEventParams: BetaManagedAgentsUserInterruptEventParams ) = apply { type = betaManagedAgentsUserInterruptEventParams.type + sessionThreadId = betaManagedAgentsUserInterruptEventParams.sessionThreadId additionalProperties = betaManagedAgentsUserInterruptEventParams.additionalProperties.toMutableMap() } @@ -94,6 +119,28 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } + /** + * If absent, interrupts every non-archived thread in a multiagent session (or the primary + * alone in a single-agent session). If present, interrupts only the named thread. + */ + fun sessionThreadId(sessionThreadId: String?) = + sessionThreadId(JsonField.ofNullable(sessionThreadId)) + + /** Alias for calling [Builder.sessionThreadId] with `sessionThreadId.orElse(null)`. */ + fun sessionThreadId(sessionThreadId: Optional) = + sessionThreadId(sessionThreadId.getOrNull()) + + /** + * Sets [Builder.sessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sessionThreadId(sessionThreadId: JsonField) = apply { + this.sessionThreadId = sessionThreadId + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -128,6 +175,7 @@ private constructor( fun build(): BetaManagedAgentsUserInterruptEventParams = BetaManagedAgentsUserInterruptEventParams( checkRequired("type", type), + sessionThreadId, additionalProperties.toMutableMap(), ) } @@ -148,6 +196,7 @@ private constructor( } type().validate() + sessionThreadId() validated = true } @@ -164,7 +213,10 @@ private constructor( * * Used for best match union deserialization. */ - @JvmSynthetic internal fun validity(): Int = (type.asKnown().getOrNull()?.validity() ?: 0) + @JvmSynthetic + internal fun validity(): Int = + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (sessionThreadId.asKnown().isPresent) 1 else 0) class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -303,13 +355,14 @@ private constructor( return other is BetaManagedAgentsUserInterruptEventParams && type == other.type && + sessionThreadId == other.sessionThreadId && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(type, sessionThreadId, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaManagedAgentsUserInterruptEventParams{type=$type, additionalProperties=$additionalProperties}" + "BetaManagedAgentsUserInterruptEventParams{type=$type, sessionThreadId=$sessionThreadId, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserToolConfirmationEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserToolConfirmationEvent.kt index c65706b52..fedfb04b6 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserToolConfirmationEvent.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserToolConfirmationEvent.kt @@ -29,6 +29,7 @@ private constructor( private val type: JsonField, private val denyMessage: JsonField, private val processedAt: JsonField, + private val sessionThreadId: JsonField, private val additionalProperties: MutableMap, ) { @@ -46,7 +47,10 @@ private constructor( @JsonProperty("processed_at") @ExcludeMissing processedAt: JsonField = JsonMissing.of(), - ) : this(id, result, toolUseId, type, denyMessage, processedAt, mutableMapOf()) + @JsonProperty("session_thread_id") + @ExcludeMissing + sessionThreadId: JsonField = JsonMissing.of(), + ) : this(id, result, toolUseId, type, denyMessage, processedAt, sessionThreadId, mutableMapOf()) /** * Unique identifier for this event. @@ -97,6 +101,16 @@ private constructor( */ fun processedAt(): Optional = processedAt.getOptional("processed_at") + /** + * When set, the confirmation routes to this subagent's thread rather than the primary. Echo + * this from the `session_thread_id` on the `agent.tool_use` or `agent.mcp_tool_use` event that + * prompted the approval. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun sessionThreadId(): Optional = sessionThreadId.getOptional("session_thread_id") + /** * Returns the raw JSON value of [id]. * @@ -143,6 +157,15 @@ private constructor( @ExcludeMissing fun _processedAt(): JsonField = processedAt + /** + * Returns the raw JSON value of [sessionThreadId]. + * + * Unlike [sessionThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("session_thread_id") + @ExcludeMissing + fun _sessionThreadId(): JsonField = sessionThreadId + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -181,6 +204,7 @@ private constructor( private var type: JsonField? = null private var denyMessage: JsonField = JsonMissing.of() private var processedAt: JsonField = JsonMissing.of() + private var sessionThreadId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -193,6 +217,7 @@ private constructor( type = betaManagedAgentsUserToolConfirmationEvent.type denyMessage = betaManagedAgentsUserToolConfirmationEvent.denyMessage processedAt = betaManagedAgentsUserToolConfirmationEvent.processedAt + sessionThreadId = betaManagedAgentsUserToolConfirmationEvent.sessionThreadId additionalProperties = betaManagedAgentsUserToolConfirmationEvent.additionalProperties.toMutableMap() } @@ -283,6 +308,29 @@ private constructor( this.processedAt = processedAt } + /** + * When set, the confirmation routes to this subagent's thread rather than the primary. Echo + * this from the `session_thread_id` on the `agent.tool_use` or `agent.mcp_tool_use` event + * that prompted the approval. + */ + fun sessionThreadId(sessionThreadId: String?) = + sessionThreadId(JsonField.ofNullable(sessionThreadId)) + + /** Alias for calling [Builder.sessionThreadId] with `sessionThreadId.orElse(null)`. */ + fun sessionThreadId(sessionThreadId: Optional) = + sessionThreadId(sessionThreadId.getOrNull()) + + /** + * Sets [Builder.sessionThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.sessionThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sessionThreadId(sessionThreadId: JsonField) = apply { + this.sessionThreadId = sessionThreadId + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -325,6 +373,7 @@ private constructor( checkRequired("type", type), denyMessage, processedAt, + sessionThreadId, additionalProperties.toMutableMap(), ) } @@ -350,6 +399,7 @@ private constructor( type().validate() denyMessage() processedAt() + sessionThreadId() validated = true } @@ -373,7 +423,8 @@ private constructor( (if (toolUseId.asKnown().isPresent) 1 else 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + (if (denyMessage.asKnown().isPresent) 1 else 0) + - (if (processedAt.asKnown().isPresent) 1 else 0) + (if (processedAt.asKnown().isPresent) 1 else 0) + + (if (sessionThreadId.asKnown().isPresent) 1 else 0) /** UserToolConfirmationResult enum */ class Result @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -654,15 +705,25 @@ private constructor( type == other.type && denyMessage == other.denyMessage && processedAt == other.processedAt && + sessionThreadId == other.sessionThreadId && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(id, result, toolUseId, type, denyMessage, processedAt, additionalProperties) + Objects.hash( + id, + result, + toolUseId, + type, + denyMessage, + processedAt, + sessionThreadId, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaManagedAgentsUserToolConfirmationEvent{id=$id, result=$result, toolUseId=$toolUseId, type=$type, denyMessage=$denyMessage, processedAt=$processedAt, additionalProperties=$additionalProperties}" + "BetaManagedAgentsUserToolConfirmationEvent{id=$id, result=$result, toolUseId=$toolUseId, type=$type, denyMessage=$denyMessage, processedAt=$processedAt, sessionThreadId=$sessionThreadId, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/EventListPageResponse.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/EventListPageResponse.kt index 8530f02a2..7f56fd2e9 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/EventListPageResponse.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/EventListPageResponse.kt @@ -219,6 +219,24 @@ private constructor( fun addData(agentToolResult: BetaManagedAgentsAgentToolResultEvent) = addData(BetaManagedAgentsSessionEvent.ofAgentToolResult(agentToolResult)) + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofAgentThreadMessageReceived(agentThreadMessageReceived)`. + */ + fun addData(agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent) = + addData( + BetaManagedAgentsSessionEvent.ofAgentThreadMessageReceived( + agentThreadMessageReceived + ) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofAgentThreadMessageSent(agentThreadMessageSent)`. + */ + fun addData(agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent) = + addData(BetaManagedAgentsSessionEvent.ofAgentThreadMessageSent(agentThreadMessageSent)) + /** * Alias for calling [addData] with * `BetaManagedAgentsSessionEvent.ofAgentThreadContextCompacted(agentThreadContextCompacted)`. @@ -271,6 +289,33 @@ private constructor( BetaManagedAgentsSessionEvent.ofSessionStatusTerminated(sessionStatusTerminated) ) + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionThreadCreated(sessionThreadCreated)`. + */ + fun addData(sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent) = + addData(BetaManagedAgentsSessionEvent.ofSessionThreadCreated(sessionThreadCreated)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationStart(spanOutcomeEvaluationStart)`. + */ + fun addData(spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent) = + addData( + BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart + ) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationEnd(spanOutcomeEvaluationEnd)`. + */ + fun addData(spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent) = + addData( + BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationEnd(spanOutcomeEvaluationEnd) + ) + /** * Alias for calling [addData] with * `BetaManagedAgentsSessionEvent.ofSpanModelRequestStart(spanModelRequestStart)`. @@ -285,6 +330,26 @@ private constructor( fun addData(spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent) = addData(BetaManagedAgentsSessionEvent.ofSpanModelRequestEnd(spanModelRequestEnd)) + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationOngoing(spanOutcomeEvaluationOngoing)`. + */ + fun addData( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ) = + addData( + BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing + ) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofUserDefineOutcome(userDefineOutcome)`. + */ + fun addData(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent) = + addData(BetaManagedAgentsSessionEvent.ofUserDefineOutcome(userDefineOutcome)) + /** * Alias for calling [addData] with * `BetaManagedAgentsSessionEvent.ofSessionDeleted(sessionDeleted)`. @@ -292,6 +357,52 @@ private constructor( fun addData(sessionDeleted: BetaManagedAgentsSessionDeletedEvent) = addData(BetaManagedAgentsSessionEvent.ofSessionDeleted(sessionDeleted)) + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionThreadStatusRunning(sessionThreadStatusRunning)`. + */ + fun addData(sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent) = + addData( + BetaManagedAgentsSessionEvent.ofSessionThreadStatusRunning( + sessionThreadStatusRunning + ) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionThreadStatusIdle(sessionThreadStatusIdle)`. + */ + fun addData(sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent) = + addData( + BetaManagedAgentsSessionEvent.ofSessionThreadStatusIdle(sessionThreadStatusIdle) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionThreadStatusTerminated(sessionThreadStatusTerminated)`. + */ + fun addData( + sessionThreadStatusTerminated: BetaManagedAgentsSessionThreadStatusTerminatedEvent + ) = + addData( + BetaManagedAgentsSessionEvent.ofSessionThreadStatusTerminated( + sessionThreadStatusTerminated + ) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionThreadStatusRescheduled(sessionThreadStatusRescheduled)`. + */ + fun addData( + sessionThreadStatusRescheduled: BetaManagedAgentsSessionThreadStatusRescheduledEvent + ) = + addData( + BetaManagedAgentsSessionEvent.ofSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled + ) + ) + /** Opaque cursor for the next page. Null when no more results. */ fun nextPage(nextPage: String?) = nextPage(JsonField.ofNullable(nextPage)) diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/EventListParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/EventListParams.kt index 6bc894a71..a4b1a473f 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/EventListParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/EventListParams.kt @@ -11,6 +11,8 @@ import com.anthropic.core.toImmutable import com.anthropic.errors.AnthropicInvalidDataException import com.anthropic.models.beta.AnthropicBeta 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 @@ -19,9 +21,14 @@ import kotlin.jvm.optionals.getOrNull class EventListParams private constructor( private val sessionId: String?, + private val createdAtGt: OffsetDateTime?, + private val createdAtGte: OffsetDateTime?, + private val createdAtLt: OffsetDateTime?, + private val createdAtLte: OffsetDateTime?, private val limit: Int?, private val order: Order?, private val page: String?, + private val types: List?, private val betas: List?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, @@ -29,6 +36,18 @@ private constructor( fun sessionId(): Optional = Optional.ofNullable(sessionId) + /** Return events created after this time (exclusive). */ + fun createdAtGt(): Optional = Optional.ofNullable(createdAtGt) + + /** Return events created at or after this time (inclusive). */ + fun createdAtGte(): Optional = Optional.ofNullable(createdAtGte) + + /** Return events created before this time (exclusive). */ + fun createdAtLt(): Optional = Optional.ofNullable(createdAtLt) + + /** Return events created at or before this time (inclusive). */ + fun createdAtLte(): Optional = Optional.ofNullable(createdAtLte) + /** Query parameter for limit */ fun limit(): Optional = Optional.ofNullable(limit) @@ -38,6 +57,12 @@ private constructor( /** Opaque pagination cursor from a previous response's next_page. */ fun page(): Optional = Optional.ofNullable(page) + /** + * Filter by event type. Values match the `type` field on returned events (for example, + * `user.message` or `agent.tool_use`). Omit to return all event types. + */ + fun types(): Optional> = Optional.ofNullable(types) + /** Optional header to specify the beta version(s) you want to use. */ fun betas(): Optional> = Optional.ofNullable(betas) @@ -61,9 +86,14 @@ private constructor( class Builder internal constructor() { private var sessionId: String? = null + private var createdAtGt: OffsetDateTime? = null + private var createdAtGte: OffsetDateTime? = null + private var createdAtLt: OffsetDateTime? = null + private var createdAtLte: OffsetDateTime? = null private var limit: Int? = null private var order: Order? = null private var page: String? = null + private var types: MutableList? = null private var betas: MutableList? = null private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @@ -71,9 +101,14 @@ private constructor( @JvmSynthetic internal fun from(eventListParams: EventListParams) = apply { sessionId = eventListParams.sessionId + createdAtGt = eventListParams.createdAtGt + createdAtGte = eventListParams.createdAtGte + createdAtLt = eventListParams.createdAtLt + createdAtLte = eventListParams.createdAtLte limit = eventListParams.limit order = eventListParams.order page = eventListParams.page + types = eventListParams.types?.toMutableList() betas = eventListParams.betas?.toMutableList() additionalHeaders = eventListParams.additionalHeaders.toBuilder() additionalQueryParams = eventListParams.additionalQueryParams.toBuilder() @@ -84,6 +119,34 @@ private constructor( /** Alias for calling [Builder.sessionId] with `sessionId.orElse(null)`. */ fun sessionId(sessionId: Optional) = sessionId(sessionId.getOrNull()) + /** Return events created after this time (exclusive). */ + fun createdAtGt(createdAtGt: OffsetDateTime?) = apply { this.createdAtGt = createdAtGt } + + /** Alias for calling [Builder.createdAtGt] with `createdAtGt.orElse(null)`. */ + fun createdAtGt(createdAtGt: Optional) = + createdAtGt(createdAtGt.getOrNull()) + + /** Return events created at or after this time (inclusive). */ + fun createdAtGte(createdAtGte: OffsetDateTime?) = apply { this.createdAtGte = createdAtGte } + + /** Alias for calling [Builder.createdAtGte] with `createdAtGte.orElse(null)`. */ + fun createdAtGte(createdAtGte: Optional) = + createdAtGte(createdAtGte.getOrNull()) + + /** Return events created before this time (exclusive). */ + fun createdAtLt(createdAtLt: OffsetDateTime?) = apply { this.createdAtLt = createdAtLt } + + /** Alias for calling [Builder.createdAtLt] with `createdAtLt.orElse(null)`. */ + fun createdAtLt(createdAtLt: Optional) = + createdAtLt(createdAtLt.getOrNull()) + + /** Return events created at or before this time (inclusive). */ + fun createdAtLte(createdAtLte: OffsetDateTime?) = apply { this.createdAtLte = createdAtLte } + + /** Alias for calling [Builder.createdAtLte] with `createdAtLte.orElse(null)`. */ + fun createdAtLte(createdAtLte: Optional) = + createdAtLte(createdAtLte.getOrNull()) + /** Query parameter for limit */ fun limit(limit: Int?) = apply { this.limit = limit } @@ -109,6 +172,22 @@ private constructor( /** Alias for calling [Builder.page] with `page.orElse(null)`. */ fun page(page: Optional) = page(page.getOrNull()) + /** + * Filter by event type. Values match the `type` field on returned events (for example, + * `user.message` or `agent.tool_use`). Omit to return all event types. + */ + fun types(types: List?) = apply { this.types = types?.toMutableList() } + + /** Alias for calling [Builder.types] with `types.orElse(null)`. */ + fun types(types: Optional>) = types(types.getOrNull()) + + /** + * Adds a single [String] to [types]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addType(type: String) = apply { types = (types ?: mutableListOf()).apply { add(type) } } + /** Optional header to specify the beta version(s) you want to use. */ fun betas(betas: List?) = apply { this.betas = betas?.toMutableList() } @@ -239,9 +318,14 @@ private constructor( fun build(): EventListParams = EventListParams( sessionId, + createdAtGt, + createdAtGte, + createdAtLt, + createdAtLte, limit, order, page, + types?.toImmutable(), betas?.toImmutable(), additionalHeaders.build(), additionalQueryParams.build(), @@ -265,9 +349,22 @@ private constructor( override fun _queryParams(): QueryParams = QueryParams.builder() .apply { + createdAtGt?.let { + put("created_at[gt]", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(it)) + } + createdAtGte?.let { + put("created_at[gte]", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(it)) + } + createdAtLt?.let { + put("created_at[lt]", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(it)) + } + createdAtLte?.let { + put("created_at[lte]", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(it)) + } limit?.let { put("limit", it.toString()) } order?.let { put("order", it.toString()) } page?.let { put("page", it) } + types?.forEach { put("types[]", it) } putAll(additionalQueryParams) } .build() @@ -416,17 +513,35 @@ private constructor( return other is EventListParams && sessionId == other.sessionId && + createdAtGt == other.createdAtGt && + createdAtGte == other.createdAtGte && + createdAtLt == other.createdAtLt && + createdAtLte == other.createdAtLte && limit == other.limit && order == other.order && page == other.page && + types == other.types && betas == other.betas && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams } override fun hashCode(): Int = - Objects.hash(sessionId, limit, order, page, betas, additionalHeaders, additionalQueryParams) + Objects.hash( + sessionId, + createdAtGt, + createdAtGte, + createdAtLt, + createdAtLte, + limit, + order, + page, + types, + betas, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = - "EventListParams{sessionId=$sessionId, limit=$limit, order=$order, page=$page, betas=$betas, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "EventListParams{sessionId=$sessionId, createdAtGt=$createdAtGt, createdAtGte=$createdAtGte, createdAtLt=$createdAtLt, createdAtLte=$createdAtLte, limit=$limit, order=$order, page=$page, types=$types, betas=$betas, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/EventSendParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/EventSendParams.kt index 9e04a5d95..2fe5af3c7 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/EventSendParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/events/EventSendParams.kt @@ -214,6 +214,14 @@ private constructor( body.addUserCustomToolResultEvent(customToolUseId) } + /** + * Alias for calling [addEvent] with + * `BetaManagedAgentsEventParams.ofUserDefineOutcome(userDefineOutcome)`. + */ + fun addEvent(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEventParams) = apply { + body.addEvent(userDefineOutcome) + } + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { body.additionalProperties(additionalBodyProperties) } @@ -533,6 +541,13 @@ private constructor( .build() ) + /** + * Alias for calling [addEvent] with + * `BetaManagedAgentsEventParams.ofUserDefineOutcome(userDefineOutcome)`. + */ + fun addEvent(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEventParams) = + addEvent(BetaManagedAgentsEventParams.ofUserDefineOutcome(userDefineOutcome)) + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThread.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThread.kt new file mode 100644 index 000000000..ef60cb94e --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThread.kt @@ -0,0 +1,780 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +/** + * An execution thread within a `session`. Each session has one primary thread plus zero or more + * child threads spawned by the coordinator. + */ +class BetaManagedAgentsSessionThread +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val agent: JsonField, + private val archivedAt: JsonField, + private val createdAt: JsonField, + private val parentThreadId: JsonField, + private val sessionId: JsonField, + private val stats: JsonField, + private val status: JsonField, + private val type: JsonField, + private val updatedAt: JsonField, + private val usage: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("agent") + @ExcludeMissing + agent: JsonField = JsonMissing.of(), + @JsonProperty("archived_at") + @ExcludeMissing + archivedAt: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("parent_thread_id") + @ExcludeMissing + parentThreadId: JsonField = JsonMissing.of(), + @JsonProperty("session_id") @ExcludeMissing sessionId: JsonField = JsonMissing.of(), + @JsonProperty("stats") + @ExcludeMissing + stats: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + status: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + @JsonProperty("usage") + @ExcludeMissing + usage: JsonField = JsonMissing.of(), + ) : this( + id, + agent, + archivedAt, + createdAt, + parentThreadId, + sessionId, + stats, + status, + type, + updatedAt, + usage, + mutableMapOf(), + ) + + /** + * Unique identifier for this thread. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * Resolved `agent` definition for a single `session_thread`. Snapshot of the agent at thread + * creation time. The multiagent roster is not repeated here; read it from `Session.agent`. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun agent(): BetaManagedAgentsSessionThreadAgent = agent.getRequired("agent") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun archivedAt(): Optional = archivedAt.getOptional("archived_at") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("created_at") + + /** + * Parent thread that spawned this thread. Null for the primary thread. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun parentThreadId(): Optional = parentThreadId.getOptional("parent_thread_id") + + /** + * The session this thread belongs to. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * Timing statistics for a session thread. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun stats(): Optional = stats.getOptional("stats") + + /** + * SessionThreadStatus enum + * + * @throws AnthropicInvalidDataException if 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(): BetaManagedAgentsSessionThreadStatus = status.getRequired("status") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun updatedAt(): OffsetDateTime = updatedAt.getRequired("updated_at") + + /** + * Cumulative token usage for a session thread across all turns. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun usage(): Optional = usage.getOptional("usage") + + /** + * 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 [agent]. + * + * Unlike [agent], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("agent") + @ExcludeMissing + fun _agent(): JsonField = agent + + /** + * Returns the raw JSON value of [archivedAt]. + * + * Unlike [archivedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("archived_at") + @ExcludeMissing + fun _archivedAt(): JsonField = archivedAt + + /** + * 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 [parentThreadId]. + * + * Unlike [parentThreadId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("parent_thread_id") + @ExcludeMissing + fun _parentThreadId(): JsonField = parentThreadId + + /** + * 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 [stats]. + * + * Unlike [stats], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("stats") + @ExcludeMissing + fun _stats(): JsonField = stats + + /** + * 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 [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") + @ExcludeMissing + fun _updatedAt(): JsonField = updatedAt + + /** + * 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 + + @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 + * [BetaManagedAgentsSessionThread]. + * + * The following fields are required: + * ```java + * .id() + * .agent() + * .archivedAt() + * .createdAt() + * .parentThreadId() + * .sessionId() + * .stats() + * .status() + * .type() + * .updatedAt() + * .usage() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSessionThread]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var agent: JsonField? = null + private var archivedAt: JsonField? = null + private var createdAt: JsonField? = null + private var parentThreadId: JsonField? = null + private var sessionId: JsonField? = null + private var stats: JsonField? = null + private var status: JsonField? = null + private var type: JsonField? = null + private var updatedAt: JsonField? = null + private var usage: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaManagedAgentsSessionThread: BetaManagedAgentsSessionThread) = apply { + id = betaManagedAgentsSessionThread.id + agent = betaManagedAgentsSessionThread.agent + archivedAt = betaManagedAgentsSessionThread.archivedAt + createdAt = betaManagedAgentsSessionThread.createdAt + parentThreadId = betaManagedAgentsSessionThread.parentThreadId + sessionId = betaManagedAgentsSessionThread.sessionId + stats = betaManagedAgentsSessionThread.stats + status = betaManagedAgentsSessionThread.status + type = betaManagedAgentsSessionThread.type + updatedAt = betaManagedAgentsSessionThread.updatedAt + usage = betaManagedAgentsSessionThread.usage + additionalProperties = + betaManagedAgentsSessionThread.additionalProperties.toMutableMap() + } + + /** Unique identifier for this thread. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** + * Resolved `agent` definition for a single `session_thread`. Snapshot of the agent at + * thread creation time. The multiagent roster is not repeated here; read it from + * `Session.agent`. + */ + fun agent(agent: BetaManagedAgentsSessionThreadAgent) = agent(JsonField.of(agent)) + + /** + * Sets [Builder.agent] to an arbitrary JSON value. + * + * You should usually call [Builder.agent] with a well-typed + * [BetaManagedAgentsSessionThreadAgent] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun agent(agent: JsonField) = apply { + this.agent = agent + } + + /** A timestamp in RFC 3339 format */ + fun archivedAt(archivedAt: OffsetDateTime?) = archivedAt(JsonField.ofNullable(archivedAt)) + + /** Alias for calling [Builder.archivedAt] with `archivedAt.orElse(null)`. */ + fun archivedAt(archivedAt: Optional) = archivedAt(archivedAt.getOrNull()) + + /** + * Sets [Builder.archivedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.archivedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun archivedAt(archivedAt: JsonField) = apply { + this.archivedAt = archivedAt + } + + /** A timestamp in RFC 3339 format */ + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * 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 } + + /** Parent thread that spawned this thread. Null for the primary thread. */ + fun parentThreadId(parentThreadId: String?) = + parentThreadId(JsonField.ofNullable(parentThreadId)) + + /** Alias for calling [Builder.parentThreadId] with `parentThreadId.orElse(null)`. */ + fun parentThreadId(parentThreadId: Optional) = + parentThreadId(parentThreadId.getOrNull()) + + /** + * Sets [Builder.parentThreadId] to an arbitrary JSON value. + * + * You should usually call [Builder.parentThreadId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun parentThreadId(parentThreadId: JsonField) = apply { + this.parentThreadId = parentThreadId + } + + /** The session this thread belongs to. */ + 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 } + + /** Timing statistics for a session thread. */ + fun stats(stats: BetaManagedAgentsSessionThreadStats?) = stats(JsonField.ofNullable(stats)) + + /** Alias for calling [Builder.stats] with `stats.orElse(null)`. */ + fun stats(stats: Optional) = stats(stats.getOrNull()) + + /** + * Sets [Builder.stats] to an arbitrary JSON value. + * + * You should usually call [Builder.stats] with a well-typed + * [BetaManagedAgentsSessionThreadStats] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun stats(stats: JsonField) = apply { + this.stats = stats + } + + /** SessionThreadStatus enum */ + fun status(status: BetaManagedAgentsSessionThreadStatus) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed + * [BetaManagedAgentsSessionThreadStatus] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { + this.status = status + } + + fun 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 } + + /** A timestamp in RFC 3339 format */ + fun updatedAt(updatedAt: OffsetDateTime) = updatedAt(JsonField.of(updatedAt)) + + /** + * 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 } + + /** Cumulative token usage for a session thread across all turns. */ + fun usage(usage: BetaManagedAgentsSessionThreadUsage?) = usage(JsonField.ofNullable(usage)) + + /** Alias for calling [Builder.usage] with `usage.orElse(null)`. */ + fun usage(usage: Optional) = usage(usage.getOrNull()) + + /** + * Sets [Builder.usage] to an arbitrary JSON value. + * + * You should usually call [Builder.usage] with a well-typed + * [BetaManagedAgentsSessionThreadUsage] 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 + } + + 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 [BetaManagedAgentsSessionThread]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .agent() + * .archivedAt() + * .createdAt() + * .parentThreadId() + * .sessionId() + * .stats() + * .status() + * .type() + * .updatedAt() + * .usage() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsSessionThread = + BetaManagedAgentsSessionThread( + checkRequired("id", id), + checkRequired("agent", agent), + checkRequired("archivedAt", archivedAt), + checkRequired("createdAt", createdAt), + checkRequired("parentThreadId", parentThreadId), + checkRequired("sessionId", sessionId), + checkRequired("stats", stats), + checkRequired("status", status), + checkRequired("type", type), + checkRequired("updatedAt", updatedAt), + checkRequired("usage", usage), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSessionThread = apply { + if (validated) { + return@apply + } + + id() + agent().validate() + archivedAt() + createdAt() + parentThreadId() + sessionId() + stats().ifPresent { it.validate() } + status().validate() + type().validate() + updatedAt() + usage().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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) + + (agent.asKnown().getOrNull()?.validity() ?: 0) + + (if (archivedAt.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (parentThreadId.asKnown().isPresent) 1 else 0) + + (if (sessionId.asKnown().isPresent) 1 else 0) + + (stats.asKnown().getOrNull()?.validity() ?: 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + (usage.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 SESSION_THREAD = of("session_thread") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SESSION_THREAD + } + + /** + * 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 { + SESSION_THREAD, + /** 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) { + SESSION_THREAD -> Value.SESSION_THREAD + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SESSION_THREAD -> Known.SESSION_THREAD + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsSessionThread && + id == other.id && + agent == other.agent && + archivedAt == other.archivedAt && + createdAt == other.createdAt && + parentThreadId == other.parentThreadId && + sessionId == other.sessionId && + stats == other.stats && + status == other.status && + type == other.type && + updatedAt == other.updatedAt && + usage == other.usage && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + agent, + archivedAt, + createdAt, + parentThreadId, + sessionId, + stats, + status, + type, + updatedAt, + usage, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSessionThread{id=$id, agent=$agent, archivedAt=$archivedAt, createdAt=$createdAt, parentThreadId=$parentThreadId, sessionId=$sessionId, stats=$stats, status=$status, type=$type, updatedAt=$updatedAt, usage=$usage, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadAgent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadAgent.kt new file mode 100644 index 000000000..5d7d5a8e4 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadAgent.kt @@ -0,0 +1,1217 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkKnown +import com.anthropic.core.checkRequired +import com.anthropic.core.getOrThrow +import com.anthropic.core.toImmutable +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolset20260401 +import com.anthropic.models.beta.agents.BetaManagedAgentsAnthropicSkill +import com.anthropic.models.beta.agents.BetaManagedAgentsCustomSkill +import com.anthropic.models.beta.agents.BetaManagedAgentsCustomTool +import com.anthropic.models.beta.agents.BetaManagedAgentsMcpServerUrlDefinition +import com.anthropic.models.beta.agents.BetaManagedAgentsMcpToolset +import com.anthropic.models.beta.agents.BetaManagedAgentsModelConfig +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 + +/** + * Resolved `agent` definition for a single `session_thread`. Snapshot of the agent at thread + * creation time. The multiagent roster is not repeated here; read it from `Session.agent`. + */ +class BetaManagedAgentsSessionThreadAgent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val description: JsonField, + private val mcpServers: JsonField>, + private val model: JsonField, + private val name: JsonField, + private val skills: JsonField>, + private val system: JsonField, + private val tools: JsonField>, + private val type: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + description: JsonField = JsonMissing.of(), + @JsonProperty("mcp_servers") + @ExcludeMissing + mcpServers: JsonField> = JsonMissing.of(), + @JsonProperty("model") + @ExcludeMissing + model: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("skills") @ExcludeMissing skills: JsonField> = JsonMissing.of(), + @JsonProperty("system") @ExcludeMissing system: JsonField = JsonMissing.of(), + @JsonProperty("tools") @ExcludeMissing tools: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this( + id, + description, + mcpServers, + model, + name, + skills, + system, + tools, + type, + version, + mutableMapOf(), + ) + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun description(): Optional = description.getOptional("description") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun mcpServers(): List = + mcpServers.getRequired("mcp_servers") + + /** + * Model identifier and configuration. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun model(): BetaManagedAgentsModelConfig = model.getRequired("model") + + /** + * @throws AnthropicInvalidDataException if 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 AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun skills(): List = skills.getRequired("skills") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun system(): Optional = system.getOptional("system") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun tools(): List = tools.getRequired("tools") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun version(): Int = version.getRequired("version") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [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 [mcpServers]. + * + * Unlike [mcpServers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("mcp_servers") + @ExcludeMissing + fun _mcpServers(): JsonField> = mcpServers + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("model") + @ExcludeMissing + fun _model(): JsonField = model + + /** + * Returns the raw JSON value of [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 [skills]. + * + * Unlike [skills], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("skills") @ExcludeMissing fun _skills(): JsonField> = skills + + /** + * Returns the raw JSON value of [system]. + * + * Unlike [system], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("system") @ExcludeMissing fun _system(): JsonField = system + + /** + * Returns the raw JSON value of [tools]. + * + * Unlike [tools], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tools") @ExcludeMissing fun _tools(): JsonField> = tools + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BetaManagedAgentsSessionThreadAgent]. + * + * The following fields are required: + * ```java + * .id() + * .description() + * .mcpServers() + * .model() + * .name() + * .skills() + * .system() + * .tools() + * .type() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSessionThreadAgent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var description: JsonField? = null + private var mcpServers: JsonField>? = + null + private var model: JsonField? = null + private var name: JsonField? = null + private var skills: JsonField>? = null + private var system: JsonField? = null + private var tools: JsonField>? = null + private var type: JsonField? = null + private var version: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsSessionThreadAgent: BetaManagedAgentsSessionThreadAgent + ) = apply { + id = betaManagedAgentsSessionThreadAgent.id + description = betaManagedAgentsSessionThreadAgent.description + mcpServers = betaManagedAgentsSessionThreadAgent.mcpServers.map { it.toMutableList() } + model = betaManagedAgentsSessionThreadAgent.model + name = betaManagedAgentsSessionThreadAgent.name + skills = betaManagedAgentsSessionThreadAgent.skills.map { it.toMutableList() } + system = betaManagedAgentsSessionThreadAgent.system + tools = betaManagedAgentsSessionThreadAgent.tools.map { it.toMutableList() } + type = betaManagedAgentsSessionThreadAgent.type + version = betaManagedAgentsSessionThreadAgent.version + additionalProperties = + betaManagedAgentsSessionThreadAgent.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun 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 } + + fun mcpServers(mcpServers: List) = + mcpServers(JsonField.of(mcpServers)) + + /** + * Sets [Builder.mcpServers] to an arbitrary JSON value. + * + * You should usually call [Builder.mcpServers] with a well-typed + * `List` value instead. This method is primarily + * for setting the field to an undocumented or not yet supported value. + */ + fun mcpServers(mcpServers: JsonField>) = + apply { + this.mcpServers = mcpServers.map { it.toMutableList() } + } + + /** + * Adds a single [BetaManagedAgentsMcpServerUrlDefinition] to [mcpServers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMcpServer(mcpServer: BetaManagedAgentsMcpServerUrlDefinition) = apply { + mcpServers = + (mcpServers ?: JsonField.of(mutableListOf())).also { + checkKnown("mcpServers", it).add(mcpServer) + } + } + + /** Model identifier and configuration. */ + fun model(model: BetaManagedAgentsModelConfig) = model(JsonField.of(model)) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [BetaManagedAgentsModelConfig] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + 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 skills(skills: List) = skills(JsonField.of(skills)) + + /** + * Sets [Builder.skills] to an arbitrary JSON value. + * + * You should usually call [Builder.skills] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun skills(skills: JsonField>) = apply { + this.skills = skills.map { it.toMutableList() } + } + + /** + * Adds a single [Skill] to [skills]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSkill(skill: Skill) = apply { + skills = + (skills ?: JsonField.of(mutableListOf())).also { + checkKnown("skills", it).add(skill) + } + } + + /** Alias for calling [addSkill] with `Skill.ofAnthropic(anthropic)`. */ + fun addSkill(anthropic: BetaManagedAgentsAnthropicSkill) = + addSkill(Skill.ofAnthropic(anthropic)) + + /** Alias for calling [addSkill] with `Skill.ofCustom(custom)`. */ + fun addSkill(custom: BetaManagedAgentsCustomSkill) = addSkill(Skill.ofCustom(custom)) + + fun system(system: String?) = system(JsonField.ofNullable(system)) + + /** Alias for calling [Builder.system] with `system.orElse(null)`. */ + fun system(system: Optional) = system(system.getOrNull()) + + /** + * Sets [Builder.system] to an arbitrary JSON value. + * + * You should usually call [Builder.system] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun system(system: JsonField) = apply { this.system = system } + + fun tools(tools: List) = tools(JsonField.of(tools)) + + /** + * Sets [Builder.tools] to an arbitrary JSON value. + * + * You should usually call [Builder.tools] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun tools(tools: JsonField>) = apply { + this.tools = tools.map { it.toMutableList() } + } + + /** + * Adds a single [Tool] to [tools]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTool(tool: Tool) = apply { + tools = + (tools ?: JsonField.of(mutableListOf())).also { checkKnown("tools", it).add(tool) } + } + + /** Alias for calling [addTool] with `Tool.ofAgentToolset20260401(agentToolset20260401)`. */ + fun addTool(agentToolset20260401: BetaManagedAgentsAgentToolset20260401) = + addTool(Tool.ofAgentToolset20260401(agentToolset20260401)) + + /** Alias for calling [addTool] with `Tool.ofMcpToolset(mcpToolset)`. */ + fun addTool(mcpToolset: BetaManagedAgentsMcpToolset) = + addTool(Tool.ofMcpToolset(mcpToolset)) + + /** Alias for calling [addTool] with `Tool.ofCustom(custom)`. */ + fun addTool(custom: BetaManagedAgentsCustomTool) = addTool(Tool.ofCustom(custom)) + + 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 version(version: Int) = version(JsonField.of(version)) + + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [Int] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun version(version: JsonField) = apply { this.version = version } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaManagedAgentsSessionThreadAgent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .description() + * .mcpServers() + * .model() + * .name() + * .skills() + * .system() + * .tools() + * .type() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsSessionThreadAgent = + BetaManagedAgentsSessionThreadAgent( + checkRequired("id", id), + checkRequired("description", description), + checkRequired("mcpServers", mcpServers).map { it.toImmutable() }, + checkRequired("model", model), + checkRequired("name", name), + checkRequired("skills", skills).map { it.toImmutable() }, + checkRequired("system", system), + checkRequired("tools", tools).map { it.toImmutable() }, + checkRequired("type", type), + checkRequired("version", version), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSessionThreadAgent = apply { + if (validated) { + return@apply + } + + id() + description() + mcpServers().forEach { it.validate() } + model().validate() + name() + skills().forEach { it.validate() } + system() + tools().forEach { it.validate() } + type().validate() + version() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (description.asKnown().isPresent) 1 else 0) + + (mcpServers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (model.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (skills.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (system.asKnown().isPresent) 1 else 0) + + (tools.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) + + /** Resolved skill as returned in API responses. */ + @JsonDeserialize(using = Skill.Deserializer::class) + @JsonSerialize(using = Skill.Serializer::class) + class Skill + private constructor( + private val anthropic: BetaManagedAgentsAnthropicSkill? = null, + private val custom: BetaManagedAgentsCustomSkill? = null, + private val _json: JsonValue? = null, + ) { + + /** A resolved Anthropic-managed skill. */ + fun anthropic(): Optional = Optional.ofNullable(anthropic) + + /** A resolved user-created custom skill. */ + fun custom(): Optional = Optional.ofNullable(custom) + + fun isAnthropic(): Boolean = anthropic != null + + fun isCustom(): Boolean = custom != null + + /** A resolved Anthropic-managed skill. */ + fun asAnthropic(): BetaManagedAgentsAnthropicSkill = anthropic.getOrThrow("anthropic") + + /** A resolved user-created custom skill. */ + fun asCustom(): BetaManagedAgentsCustomSkill = custom.getOrThrow("custom") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, unless + * [visitor] overrides [Visitor.unknown]. To handle variants not known to this version of + * the SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.anthropic.core.JsonValue; + * import java.util.Optional; + * + * Optional result = skill.accept(new Skill.Visitor>() { + * @Override + * public Optional visitAnthropic(BetaManagedAgentsAnthropicSkill anthropic) { + * return Optional.of(anthropic.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws AnthropicInvalidDataException if [Visitor.unknown] is not overridden in [visitor] + * and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + anthropic != null -> visitor.visitAnthropic(anthropic) + custom != null -> visitor.visitCustom(custom) + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Skill = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitAnthropic(anthropic: BetaManagedAgentsAnthropicSkill) { + anthropic.validate() + } + + override fun visitCustom(custom: BetaManagedAgentsCustomSkill) { + custom.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 visitAnthropic(anthropic: BetaManagedAgentsAnthropicSkill) = + anthropic.validity() + + override fun visitCustom(custom: BetaManagedAgentsCustomSkill) = + custom.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Skill && anthropic == other.anthropic && custom == other.custom + } + + override fun hashCode(): Int = Objects.hash(anthropic, custom) + + override fun toString(): String = + when { + anthropic != null -> "Skill{anthropic=$anthropic}" + custom != null -> "Skill{custom=$custom}" + _json != null -> "Skill{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Skill") + } + + companion object { + + /** A resolved Anthropic-managed skill. */ + @JvmStatic + fun ofAnthropic(anthropic: BetaManagedAgentsAnthropicSkill) = + Skill(anthropic = anthropic) + + /** A resolved user-created custom skill. */ + @JvmStatic fun ofCustom(custom: BetaManagedAgentsCustomSkill) = Skill(custom = custom) + } + + /** An interface that defines how to map each variant of [Skill] to a value of type [T]. */ + interface Visitor { + + /** A resolved Anthropic-managed skill. */ + fun visitAnthropic(anthropic: BetaManagedAgentsAnthropicSkill): T + + /** A resolved user-created custom skill. */ + fun visitCustom(custom: BetaManagedAgentsCustomSkill): T + + /** + * Maps an unknown variant of [Skill] to a value of type [T]. + * + * An instance of [Skill] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws AnthropicInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw AnthropicInvalidDataException("Unknown Skill: $json") + } + } + + internal class Deserializer : BaseDeserializer(Skill::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Skill { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "anthropic" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Skill(anthropic = it, _json = json) } ?: Skill(_json = json) + } + "custom" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Skill(custom = it, _json = json) } ?: Skill(_json = json) + } + } + + return Skill(_json = json) + } + } + + internal class Serializer : BaseSerializer(Skill::class) { + + override fun serialize( + value: Skill, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.anthropic != null -> generator.writeObject(value.anthropic) + value.custom != null -> generator.writeObject(value.custom) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Skill") + } + } + } + } + + /** Union type for tool configurations returned in API responses. */ + @JsonDeserialize(using = Tool.Deserializer::class) + @JsonSerialize(using = Tool.Serializer::class) + class Tool + private constructor( + private val agentToolset20260401: BetaManagedAgentsAgentToolset20260401? = null, + private val mcpToolset: BetaManagedAgentsMcpToolset? = null, + private val custom: BetaManagedAgentsCustomTool? = null, + private val _json: JsonValue? = null, + ) { + + fun agentToolset20260401(): Optional = + Optional.ofNullable(agentToolset20260401) + + fun mcpToolset(): Optional = Optional.ofNullable(mcpToolset) + + /** A custom tool as returned in API responses. */ + fun custom(): Optional = Optional.ofNullable(custom) + + fun isAgentToolset20260401(): Boolean = agentToolset20260401 != null + + fun isMcpToolset(): Boolean = mcpToolset != null + + fun isCustom(): Boolean = custom != null + + fun asAgentToolset20260401(): BetaManagedAgentsAgentToolset20260401 = + agentToolset20260401.getOrThrow("agentToolset20260401") + + fun asMcpToolset(): BetaManagedAgentsMcpToolset = mcpToolset.getOrThrow("mcpToolset") + + /** A custom tool as returned in API responses. */ + fun asCustom(): BetaManagedAgentsCustomTool = custom.getOrThrow("custom") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, unless + * [visitor] overrides [Visitor.unknown]. To handle variants not known to this version of + * the SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.anthropic.core.JsonValue; + * import java.util.Optional; + * + * Optional result = tool.accept(new Tool.Visitor>() { + * @Override + * public Optional visitAgentToolset20260401(BetaManagedAgentsAgentToolset20260401 agentToolset20260401) { + * return Optional.of(agentToolset20260401.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws AnthropicInvalidDataException if [Visitor.unknown] is not overridden in [visitor] + * and the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + agentToolset20260401 != null -> + visitor.visitAgentToolset20260401(agentToolset20260401) + mcpToolset != null -> visitor.visitMcpToolset(mcpToolset) + custom != null -> visitor.visitCustom(custom) + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Tool = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitAgentToolset20260401( + agentToolset20260401: BetaManagedAgentsAgentToolset20260401 + ) { + agentToolset20260401.validate() + } + + override fun visitMcpToolset(mcpToolset: BetaManagedAgentsMcpToolset) { + mcpToolset.validate() + } + + override fun visitCustom(custom: BetaManagedAgentsCustomTool) { + custom.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 visitAgentToolset20260401( + agentToolset20260401: BetaManagedAgentsAgentToolset20260401 + ) = agentToolset20260401.validity() + + override fun visitMcpToolset(mcpToolset: BetaManagedAgentsMcpToolset) = + mcpToolset.validity() + + override fun visitCustom(custom: BetaManagedAgentsCustomTool) = + custom.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Tool && + agentToolset20260401 == other.agentToolset20260401 && + mcpToolset == other.mcpToolset && + custom == other.custom + } + + override fun hashCode(): Int = Objects.hash(agentToolset20260401, mcpToolset, custom) + + override fun toString(): String = + when { + agentToolset20260401 != null -> "Tool{agentToolset20260401=$agentToolset20260401}" + mcpToolset != null -> "Tool{mcpToolset=$mcpToolset}" + custom != null -> "Tool{custom=$custom}" + _json != null -> "Tool{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Tool") + } + + companion object { + + @JvmStatic + fun ofAgentToolset20260401( + agentToolset20260401: BetaManagedAgentsAgentToolset20260401 + ) = Tool(agentToolset20260401 = agentToolset20260401) + + @JvmStatic + fun ofMcpToolset(mcpToolset: BetaManagedAgentsMcpToolset) = + Tool(mcpToolset = mcpToolset) + + /** A custom tool as returned in API responses. */ + @JvmStatic fun ofCustom(custom: BetaManagedAgentsCustomTool) = Tool(custom = custom) + } + + /** An interface that defines how to map each variant of [Tool] to a value of type [T]. */ + interface Visitor { + + fun visitAgentToolset20260401( + agentToolset20260401: BetaManagedAgentsAgentToolset20260401 + ): T + + fun visitMcpToolset(mcpToolset: BetaManagedAgentsMcpToolset): T + + /** A custom tool as returned in API responses. */ + fun visitCustom(custom: BetaManagedAgentsCustomTool): T + + /** + * Maps an unknown variant of [Tool] to a value of type [T]. + * + * An instance of [Tool] 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 AnthropicInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw AnthropicInvalidDataException("Unknown Tool: $json") + } + } + + internal class Deserializer : BaseDeserializer(Tool::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Tool { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "agent_toolset_20260401" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Tool(agentToolset20260401 = it, _json = json) } + ?: Tool(_json = json) + } + "mcp_toolset" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Tool(mcpToolset = it, _json = json) } ?: Tool(_json = json) + } + "custom" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Tool(custom = it, _json = json) } ?: Tool(_json = json) + } + } + + return Tool(_json = json) + } + } + + internal class Serializer : BaseSerializer(Tool::class) { + + override fun serialize( + value: Tool, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.agentToolset20260401 != null -> + generator.writeObject(value.agentToolset20260401) + value.mcpToolset != null -> generator.writeObject(value.mcpToolset) + value.custom != null -> generator.writeObject(value.custom) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Tool") + } + } + } + } + + 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 AGENT = of("agent") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + AGENT + } + + /** + * 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 { + AGENT, + /** 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) { + AGENT -> Value.AGENT + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + AGENT -> Known.AGENT + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsSessionThreadAgent && + id == other.id && + description == other.description && + mcpServers == other.mcpServers && + model == other.model && + name == other.name && + skills == other.skills && + system == other.system && + tools == other.tools && + type == other.type && + version == other.version && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + description, + mcpServers, + model, + name, + skills, + system, + tools, + type, + version, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSessionThreadAgent{id=$id, description=$description, mcpServers=$mcpServers, model=$model, name=$name, skills=$skills, system=$system, tools=$tools, type=$type, version=$version, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadStats.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadStats.kt new file mode 100644 index 000000000..70feb5335 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadStats.kt @@ -0,0 +1,276 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.errors.AnthropicInvalidDataException +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 + +/** Timing statistics for a session thread. */ +class BetaManagedAgentsSessionThreadStats +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val activeSeconds: JsonField, + private val durationSeconds: JsonField, + private val startupSeconds: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("active_seconds") + @ExcludeMissing + activeSeconds: JsonField = JsonMissing.of(), + @JsonProperty("duration_seconds") + @ExcludeMissing + durationSeconds: JsonField = JsonMissing.of(), + @JsonProperty("startup_seconds") + @ExcludeMissing + startupSeconds: JsonField = JsonMissing.of(), + ) : this(activeSeconds, durationSeconds, startupSeconds, mutableMapOf()) + + /** + * Cumulative time in seconds the thread spent actively running. Excludes idle time. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun activeSeconds(): Optional = activeSeconds.getOptional("active_seconds") + + /** + * Elapsed time since thread creation in seconds. For archived threads, frozen at the final + * update. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun durationSeconds(): Optional = durationSeconds.getOptional("duration_seconds") + + /** + * Time in seconds for the thread to begin running. Zero for child threads, which start + * immediately. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun startupSeconds(): Optional = startupSeconds.getOptional("startup_seconds") + + /** + * Returns the raw JSON value of [activeSeconds]. + * + * Unlike [activeSeconds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("active_seconds") + @ExcludeMissing + fun _activeSeconds(): JsonField = activeSeconds + + /** + * Returns the raw JSON value of [durationSeconds]. + * + * Unlike [durationSeconds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("duration_seconds") + @ExcludeMissing + fun _durationSeconds(): JsonField = durationSeconds + + /** + * Returns the raw JSON value of [startupSeconds]. + * + * Unlike [startupSeconds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("startup_seconds") + @ExcludeMissing + fun _startupSeconds(): JsonField = startupSeconds + + @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 + * [BetaManagedAgentsSessionThreadStats]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSessionThreadStats]. */ + class Builder internal constructor() { + + private var activeSeconds: JsonField = JsonMissing.of() + private var durationSeconds: JsonField = JsonMissing.of() + private var startupSeconds: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsSessionThreadStats: BetaManagedAgentsSessionThreadStats + ) = apply { + activeSeconds = betaManagedAgentsSessionThreadStats.activeSeconds + durationSeconds = betaManagedAgentsSessionThreadStats.durationSeconds + startupSeconds = betaManagedAgentsSessionThreadStats.startupSeconds + additionalProperties = + betaManagedAgentsSessionThreadStats.additionalProperties.toMutableMap() + } + + /** Cumulative time in seconds the thread spent actively running. Excludes idle time. */ + fun activeSeconds(activeSeconds: Double) = activeSeconds(JsonField.of(activeSeconds)) + + /** + * Sets [Builder.activeSeconds] to an arbitrary JSON value. + * + * You should usually call [Builder.activeSeconds] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun activeSeconds(activeSeconds: JsonField) = apply { + this.activeSeconds = activeSeconds + } + + /** + * Elapsed time since thread creation in seconds. For archived threads, frozen at the final + * update. + */ + fun durationSeconds(durationSeconds: Double) = + durationSeconds(JsonField.of(durationSeconds)) + + /** + * Sets [Builder.durationSeconds] to an arbitrary JSON value. + * + * You should usually call [Builder.durationSeconds] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun durationSeconds(durationSeconds: JsonField) = apply { + this.durationSeconds = durationSeconds + } + + /** + * Time in seconds for the thread to begin running. Zero for child threads, which start + * immediately. + */ + fun startupSeconds(startupSeconds: Double) = startupSeconds(JsonField.of(startupSeconds)) + + /** + * Sets [Builder.startupSeconds] to an arbitrary JSON value. + * + * You should usually call [Builder.startupSeconds] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun startupSeconds(startupSeconds: JsonField) = apply { + this.startupSeconds = startupSeconds + } + + 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 [BetaManagedAgentsSessionThreadStats]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BetaManagedAgentsSessionThreadStats = + BetaManagedAgentsSessionThreadStats( + activeSeconds, + durationSeconds, + startupSeconds, + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSessionThreadStats = apply { + if (validated) { + return@apply + } + + activeSeconds() + durationSeconds() + startupSeconds() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (activeSeconds.asKnown().isPresent) 1 else 0) + + (if (durationSeconds.asKnown().isPresent) 1 else 0) + + (if (startupSeconds.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaManagedAgentsSessionThreadStats && + activeSeconds == other.activeSeconds && + durationSeconds == other.durationSeconds && + startupSeconds == other.startupSeconds && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(activeSeconds, durationSeconds, startupSeconds, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSessionThreadStats{activeSeconds=$activeSeconds, durationSeconds=$durationSeconds, startupSeconds=$startupSeconds, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadStatus.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadStatus.kt new file mode 100644 index 000000000..0eb250da6 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadStatus.kt @@ -0,0 +1,161 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.Enum +import com.anthropic.core.JsonField +import com.anthropic.errors.AnthropicInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator + +/** SessionThreadStatus enum */ +class BetaManagedAgentsSessionThreadStatus +@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 RUNNING = of("running") + + @JvmField val IDLE = of("idle") + + @JvmField val RESCHEDULING = of("rescheduling") + + @JvmField val TERMINATED = of("terminated") + + @JvmStatic fun of(value: String) = BetaManagedAgentsSessionThreadStatus(JsonField.of(value)) + } + + /** An enum containing [BetaManagedAgentsSessionThreadStatus]'s known values. */ + enum class Known { + RUNNING, + IDLE, + RESCHEDULING, + TERMINATED, + } + + /** + * An enum containing [BetaManagedAgentsSessionThreadStatus]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [BetaManagedAgentsSessionThreadStatus] 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 { + RUNNING, + IDLE, + RESCHEDULING, + TERMINATED, + /** + * An enum member indicating that [BetaManagedAgentsSessionThreadStatus] 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) { + RUNNING -> Value.RUNNING + IDLE -> Value.IDLE + RESCHEDULING -> Value.RESCHEDULING + TERMINATED -> Value.TERMINATED + 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 AnthropicInvalidDataException if this class instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + RUNNING -> Known.RUNNING + IDLE -> Known.IDLE + RESCHEDULING -> Known.RESCHEDULING + TERMINATED -> Known.TERMINATED + else -> + throw AnthropicInvalidDataException( + "Unknown BetaManagedAgentsSessionThreadStatus: $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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { AnthropicInvalidDataException("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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSessionThreadStatus = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsSessionThreadStatus && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadUsage.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadUsage.kt new file mode 100644 index 000000000..5e597830d --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadUsage.kt @@ -0,0 +1,314 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.models.beta.sessions.BetaManagedAgentsCacheCreationUsage +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 + +/** Cumulative token usage for a session thread across all turns. */ +class BetaManagedAgentsSessionThreadUsage +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val cacheCreation: JsonField, + private val cacheReadInputTokens: JsonField, + private val inputTokens: JsonField, + private val outputTokens: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("cache_creation") + @ExcludeMissing + cacheCreation: JsonField = JsonMissing.of(), + @JsonProperty("cache_read_input_tokens") + @ExcludeMissing + cacheReadInputTokens: JsonField = JsonMissing.of(), + @JsonProperty("input_tokens") + @ExcludeMissing + inputTokens: JsonField = JsonMissing.of(), + @JsonProperty("output_tokens") + @ExcludeMissing + outputTokens: JsonField = JsonMissing.of(), + ) : this(cacheCreation, cacheReadInputTokens, inputTokens, outputTokens, mutableMapOf()) + + /** + * Prompt-cache creation token usage broken down by cache lifetime. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun cacheCreation(): Optional = + cacheCreation.getOptional("cache_creation") + + /** + * Total tokens read from prompt cache. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun cacheReadInputTokens(): Optional = + cacheReadInputTokens.getOptional("cache_read_input_tokens") + + /** + * Total input tokens consumed across all turns. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputTokens(): Optional = inputTokens.getOptional("input_tokens") + + /** + * Total output tokens generated across all turns. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun outputTokens(): Optional = outputTokens.getOptional("output_tokens") + + /** + * Returns the raw JSON value of [cacheCreation]. + * + * Unlike [cacheCreation], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cache_creation") + @ExcludeMissing + fun _cacheCreation(): JsonField = cacheCreation + + /** + * Returns the raw JSON value of [cacheReadInputTokens]. + * + * Unlike [cacheReadInputTokens], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("cache_read_input_tokens") + @ExcludeMissing + fun _cacheReadInputTokens(): JsonField = cacheReadInputTokens + + /** + * Returns the raw JSON value of [inputTokens]. + * + * Unlike [inputTokens], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_tokens") @ExcludeMissing fun _inputTokens(): JsonField = inputTokens + + /** + * Returns the raw JSON value of [outputTokens]. + * + * Unlike [outputTokens], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("output_tokens") + @ExcludeMissing + fun _outputTokens(): JsonField = outputTokens + + @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 + * [BetaManagedAgentsSessionThreadUsage]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsSessionThreadUsage]. */ + class Builder internal constructor() { + + private var cacheCreation: JsonField = JsonMissing.of() + private var cacheReadInputTokens: JsonField = JsonMissing.of() + private var inputTokens: JsonField = JsonMissing.of() + private var outputTokens: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsSessionThreadUsage: BetaManagedAgentsSessionThreadUsage + ) = apply { + cacheCreation = betaManagedAgentsSessionThreadUsage.cacheCreation + cacheReadInputTokens = betaManagedAgentsSessionThreadUsage.cacheReadInputTokens + inputTokens = betaManagedAgentsSessionThreadUsage.inputTokens + outputTokens = betaManagedAgentsSessionThreadUsage.outputTokens + additionalProperties = + betaManagedAgentsSessionThreadUsage.additionalProperties.toMutableMap() + } + + /** Prompt-cache creation token usage broken down by cache lifetime. */ + fun cacheCreation(cacheCreation: BetaManagedAgentsCacheCreationUsage) = + cacheCreation(JsonField.of(cacheCreation)) + + /** + * Sets [Builder.cacheCreation] to an arbitrary JSON value. + * + * You should usually call [Builder.cacheCreation] with a well-typed + * [BetaManagedAgentsCacheCreationUsage] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun cacheCreation(cacheCreation: JsonField) = apply { + this.cacheCreation = cacheCreation + } + + /** Total tokens read from prompt cache. */ + fun cacheReadInputTokens(cacheReadInputTokens: Int) = + cacheReadInputTokens(JsonField.of(cacheReadInputTokens)) + + /** + * Sets [Builder.cacheReadInputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.cacheReadInputTokens] with a well-typed [Int] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun cacheReadInputTokens(cacheReadInputTokens: JsonField) = apply { + this.cacheReadInputTokens = cacheReadInputTokens + } + + /** Total input tokens consumed across all turns. */ + fun inputTokens(inputTokens: Int) = inputTokens(JsonField.of(inputTokens)) + + /** + * Sets [Builder.inputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.inputTokens] with a well-typed [Int] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun inputTokens(inputTokens: JsonField) = apply { this.inputTokens = inputTokens } + + /** Total output tokens generated across all turns. */ + fun outputTokens(outputTokens: Int) = outputTokens(JsonField.of(outputTokens)) + + /** + * Sets [Builder.outputTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.outputTokens] with a well-typed [Int] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun outputTokens(outputTokens: JsonField) = apply { this.outputTokens = outputTokens } + + 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 [BetaManagedAgentsSessionThreadUsage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BetaManagedAgentsSessionThreadUsage = + BetaManagedAgentsSessionThreadUsage( + cacheCreation, + cacheReadInputTokens, + inputTokens, + outputTokens, + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsSessionThreadUsage = apply { + if (validated) { + return@apply + } + + cacheCreation().ifPresent { it.validate() } + cacheReadInputTokens() + inputTokens() + outputTokens() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (cacheCreation.asKnown().getOrNull()?.validity() ?: 0) + + (if (cacheReadInputTokens.asKnown().isPresent) 1 else 0) + + (if (inputTokens.asKnown().isPresent) 1 else 0) + + (if (outputTokens.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaManagedAgentsSessionThreadUsage && + cacheCreation == other.cacheCreation && + cacheReadInputTokens == other.cacheReadInputTokens && + inputTokens == other.inputTokens && + outputTokens == other.outputTokens && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + cacheCreation, + cacheReadInputTokens, + inputTokens, + outputTokens, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsSessionThreadUsage{cacheCreation=$cacheCreation, cacheReadInputTokens=$cacheReadInputTokens, inputTokens=$inputTokens, outputTokens=$outputTokens, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsStreamSessionThreadEvents.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsStreamSessionThreadEvents.kt new file mode 100644 index 000000000..a4c3d93f0 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsStreamSessionThreadEvents.kt @@ -0,0 +1,1973 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer +import com.anthropic.core.JsonValue +import com.anthropic.core.getOrThrow +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentCustomToolUseEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentMcpToolResultEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentMcpToolUseEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentMessageEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentThinkingEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentThreadContextCompactedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentThreadMessageReceivedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentThreadMessageSentEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentToolResultEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentToolUseEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionDeletedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionErrorEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionStatusIdleEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionStatusRescheduledEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionStatusRunningEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionStatusTerminatedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadCreatedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadStatusIdleEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadStatusRescheduledEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadStatusRunningEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadStatusTerminatedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanModelRequestEndEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanModelRequestStartEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanOutcomeEvaluationEndEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanOutcomeEvaluationStartEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserCustomToolResultEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserDefineOutcomeEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserInterruptEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserMessageEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserToolConfirmationEvent +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.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Server-sent event in a single thread's stream. */ +@JsonDeserialize(using = BetaManagedAgentsStreamSessionThreadEvents.Deserializer::class) +@JsonSerialize(using = BetaManagedAgentsStreamSessionThreadEvents.Serializer::class) +class BetaManagedAgentsStreamSessionThreadEvents +private constructor( + private val userMessage: BetaManagedAgentsUserMessageEvent? = null, + private val userInterrupt: BetaManagedAgentsUserInterruptEvent? = null, + private val userToolConfirmation: BetaManagedAgentsUserToolConfirmationEvent? = null, + private val userCustomToolResult: BetaManagedAgentsUserCustomToolResultEvent? = null, + private val agentCustomToolUse: BetaManagedAgentsAgentCustomToolUseEvent? = null, + private val agentMessage: BetaManagedAgentsAgentMessageEvent? = null, + private val agentThinking: BetaManagedAgentsAgentThinkingEvent? = null, + private val agentMcpToolUse: BetaManagedAgentsAgentMcpToolUseEvent? = null, + private val agentMcpToolResult: BetaManagedAgentsAgentMcpToolResultEvent? = null, + private val agentToolUse: BetaManagedAgentsAgentToolUseEvent? = null, + private val agentToolResult: BetaManagedAgentsAgentToolResultEvent? = null, + private val agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent? = + null, + private val agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent? = null, + private val agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent? = + null, + private val sessionError: BetaManagedAgentsSessionErrorEvent? = null, + private val sessionStatusRescheduled: BetaManagedAgentsSessionStatusRescheduledEvent? = null, + private val sessionStatusRunning: BetaManagedAgentsSessionStatusRunningEvent? = null, + private val sessionStatusIdle: BetaManagedAgentsSessionStatusIdleEvent? = null, + private val sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent? = null, + private val sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent? = null, + private val spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent? = + null, + private val spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent? = null, + private val spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent? = null, + private val spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent? = null, + private val spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent? = + null, + private val userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent? = null, + private val sessionDeleted: BetaManagedAgentsSessionDeletedEvent? = null, + private val sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent? = + null, + private val sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent? = null, + private val sessionThreadStatusTerminated: + BetaManagedAgentsSessionThreadStatusTerminatedEvent? = + null, + private val sessionThreadStatusRescheduled: + BetaManagedAgentsSessionThreadStatusRescheduledEvent? = + null, + private val _json: JsonValue? = null, +) { + + /** A user message event in the session conversation. */ + fun userMessage(): Optional = + Optional.ofNullable(userMessage) + + /** An interrupt event that pauses agent execution and returns control to the user. */ + fun userInterrupt(): Optional = + Optional.ofNullable(userInterrupt) + + /** A tool confirmation event that approves or denies a pending tool execution. */ + fun userToolConfirmation(): Optional = + Optional.ofNullable(userToolConfirmation) + + /** Event sent by the client providing the result of a custom tool execution. */ + fun userCustomToolResult(): Optional = + Optional.ofNullable(userCustomToolResult) + + /** + * Event emitted when the agent calls a custom tool. The session goes idle until the client + * sends a `user.custom_tool_result` event with the result. + */ + fun agentCustomToolUse(): Optional = + Optional.ofNullable(agentCustomToolUse) + + /** An agent response event in the session conversation. */ + fun agentMessage(): Optional = + Optional.ofNullable(agentMessage) + + /** + * Indicates the agent is making forward progress via extended thinking. A progress signal, not + * a content carrier. + */ + fun agentThinking(): Optional = + Optional.ofNullable(agentThinking) + + /** Event emitted when the agent invokes a tool provided by an MCP server. */ + fun agentMcpToolUse(): Optional = + Optional.ofNullable(agentMcpToolUse) + + /** Event representing the result of an MCP tool execution. */ + fun agentMcpToolResult(): Optional = + Optional.ofNullable(agentMcpToolResult) + + /** Event emitted when the agent invokes a built-in agent tool. */ + fun agentToolUse(): Optional = + Optional.ofNullable(agentToolUse) + + /** Event representing the result of an agent tool execution. */ + fun agentToolResult(): Optional = + Optional.ofNullable(agentToolResult) + + /** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ + fun agentThreadMessageReceived(): Optional = + Optional.ofNullable(agentThreadMessageReceived) + + /** + * Observability event emitted to the sender's output stream when an agent-to-agent message is + * sent. + */ + fun agentThreadMessageSent(): Optional = + Optional.ofNullable(agentThreadMessageSent) + + /** Indicates that context compaction (summarization) occurred during the session. */ + fun agentThreadContextCompacted(): Optional = + Optional.ofNullable(agentThreadContextCompacted) + + /** An error event indicating a problem occurred during session execution. */ + fun sessionError(): Optional = + Optional.ofNullable(sessionError) + + /** Indicates the session is recovering from an error state and is rescheduled for execution. */ + fun sessionStatusRescheduled(): Optional = + Optional.ofNullable(sessionStatusRescheduled) + + /** Indicates the session is actively running and the agent is working. */ + fun sessionStatusRunning(): Optional = + Optional.ofNullable(sessionStatusRunning) + + /** Indicates the agent has paused and is awaiting user input. */ + fun sessionStatusIdle(): Optional = + Optional.ofNullable(sessionStatusIdle) + + /** Indicates the session has terminated, either due to an error or completion. */ + fun sessionStatusTerminated(): Optional = + Optional.ofNullable(sessionStatusTerminated) + + /** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output + * stream so clients observing the session see child creation. + */ + fun sessionThreadCreated(): Optional = + Optional.ofNullable(sessionThreadCreated) + + /** Emitted when an outcome evaluation cycle begins. */ + fun spanOutcomeEvaluationStart(): Optional = + Optional.ofNullable(spanOutcomeEvaluationStart) + + /** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate token + * usage. A verdict of `needs_revision` means another evaluation cycle follows; `satisfied`, + * `max_iterations_reached`, `failed`, or `interrupted` are terminal — no further evaluation + * cycles follow. + */ + fun spanOutcomeEvaluationEnd(): Optional = + Optional.ofNullable(spanOutcomeEvaluationEnd) + + /** Emitted when a model request is initiated by the agent. */ + fun spanModelRequestStart(): Optional = + Optional.ofNullable(spanModelRequestStart) + + /** Emitted when a model request completes. */ + fun spanModelRequestEnd(): Optional = + Optional.ofNullable(spanModelRequestEnd) + + /** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. Distinguishes + * 'evaluation is actively running' from 'evaluation is stuck' between the corresponding + * `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ + fun spanOutcomeEvaluationOngoing(): + Optional = + Optional.ofNullable(spanOutcomeEvaluationOngoing) + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` that + * subsequent `span.outcome_evaluation_*` events reference. + */ + fun userDefineOutcome(): Optional = + Optional.ofNullable(userDefineOutcome) + + /** + * Emitted when a session has been deleted. Terminates any active event stream — no further + * events will be emitted for this session. + */ + fun sessionDeleted(): Optional = + Optional.ofNullable(sessionDeleted) + + /** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted to + * the primary stream for child threads. + */ + fun sessionThreadStatusRunning(): Optional = + Optional.ofNullable(sessionThreadStatusRunning) + + /** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream and + * cross-posted to the primary stream for child threads. + */ + fun sessionThreadStatusIdle(): Optional = + Optional.ofNullable(sessionThreadStatusIdle) + + /** + * A session thread has terminated and will accept no further input. Emitted on the thread's own + * stream and cross-posted to the primary stream for child threads. + */ + fun sessionThreadStatusTerminated(): + Optional = + Optional.ofNullable(sessionThreadStatusTerminated) + + /** + * A session thread hit a transient error and is retrying automatically. Emitted on the thread's + * own stream and cross-posted to the primary stream for child threads. + */ + fun sessionThreadStatusRescheduled(): + Optional = + Optional.ofNullable(sessionThreadStatusRescheduled) + + fun isUserMessage(): Boolean = userMessage != null + + fun isUserInterrupt(): Boolean = userInterrupt != null + + fun isUserToolConfirmation(): Boolean = userToolConfirmation != null + + fun isUserCustomToolResult(): Boolean = userCustomToolResult != null + + fun isAgentCustomToolUse(): Boolean = agentCustomToolUse != null + + fun isAgentMessage(): Boolean = agentMessage != null + + fun isAgentThinking(): Boolean = agentThinking != null + + fun isAgentMcpToolUse(): Boolean = agentMcpToolUse != null + + fun isAgentMcpToolResult(): Boolean = agentMcpToolResult != null + + fun isAgentToolUse(): Boolean = agentToolUse != null + + fun isAgentToolResult(): Boolean = agentToolResult != null + + fun isAgentThreadMessageReceived(): Boolean = agentThreadMessageReceived != null + + fun isAgentThreadMessageSent(): Boolean = agentThreadMessageSent != null + + fun isAgentThreadContextCompacted(): Boolean = agentThreadContextCompacted != null + + fun isSessionError(): Boolean = sessionError != null + + fun isSessionStatusRescheduled(): Boolean = sessionStatusRescheduled != null + + fun isSessionStatusRunning(): Boolean = sessionStatusRunning != null + + fun isSessionStatusIdle(): Boolean = sessionStatusIdle != null + + fun isSessionStatusTerminated(): Boolean = sessionStatusTerminated != null + + fun isSessionThreadCreated(): Boolean = sessionThreadCreated != null + + fun isSpanOutcomeEvaluationStart(): Boolean = spanOutcomeEvaluationStart != null + + fun isSpanOutcomeEvaluationEnd(): Boolean = spanOutcomeEvaluationEnd != null + + fun isSpanModelRequestStart(): Boolean = spanModelRequestStart != null + + fun isSpanModelRequestEnd(): Boolean = spanModelRequestEnd != null + + fun isSpanOutcomeEvaluationOngoing(): Boolean = spanOutcomeEvaluationOngoing != null + + fun isUserDefineOutcome(): Boolean = userDefineOutcome != null + + fun isSessionDeleted(): Boolean = sessionDeleted != null + + fun isSessionThreadStatusRunning(): Boolean = sessionThreadStatusRunning != null + + fun isSessionThreadStatusIdle(): Boolean = sessionThreadStatusIdle != null + + fun isSessionThreadStatusTerminated(): Boolean = sessionThreadStatusTerminated != null + + fun isSessionThreadStatusRescheduled(): Boolean = sessionThreadStatusRescheduled != null + + /** A user message event in the session conversation. */ + fun asUserMessage(): BetaManagedAgentsUserMessageEvent = userMessage.getOrThrow("userMessage") + + /** An interrupt event that pauses agent execution and returns control to the user. */ + fun asUserInterrupt(): BetaManagedAgentsUserInterruptEvent = + userInterrupt.getOrThrow("userInterrupt") + + /** A tool confirmation event that approves or denies a pending tool execution. */ + fun asUserToolConfirmation(): BetaManagedAgentsUserToolConfirmationEvent = + userToolConfirmation.getOrThrow("userToolConfirmation") + + /** Event sent by the client providing the result of a custom tool execution. */ + fun asUserCustomToolResult(): BetaManagedAgentsUserCustomToolResultEvent = + userCustomToolResult.getOrThrow("userCustomToolResult") + + /** + * Event emitted when the agent calls a custom tool. The session goes idle until the client + * sends a `user.custom_tool_result` event with the result. + */ + fun asAgentCustomToolUse(): BetaManagedAgentsAgentCustomToolUseEvent = + agentCustomToolUse.getOrThrow("agentCustomToolUse") + + /** An agent response event in the session conversation. */ + fun asAgentMessage(): BetaManagedAgentsAgentMessageEvent = + agentMessage.getOrThrow("agentMessage") + + /** + * Indicates the agent is making forward progress via extended thinking. A progress signal, not + * a content carrier. + */ + fun asAgentThinking(): BetaManagedAgentsAgentThinkingEvent = + agentThinking.getOrThrow("agentThinking") + + /** Event emitted when the agent invokes a tool provided by an MCP server. */ + fun asAgentMcpToolUse(): BetaManagedAgentsAgentMcpToolUseEvent = + agentMcpToolUse.getOrThrow("agentMcpToolUse") + + /** Event representing the result of an MCP tool execution. */ + fun asAgentMcpToolResult(): BetaManagedAgentsAgentMcpToolResultEvent = + agentMcpToolResult.getOrThrow("agentMcpToolResult") + + /** Event emitted when the agent invokes a built-in agent tool. */ + fun asAgentToolUse(): BetaManagedAgentsAgentToolUseEvent = + agentToolUse.getOrThrow("agentToolUse") + + /** Event representing the result of an agent tool execution. */ + fun asAgentToolResult(): BetaManagedAgentsAgentToolResultEvent = + agentToolResult.getOrThrow("agentToolResult") + + /** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ + fun asAgentThreadMessageReceived(): BetaManagedAgentsAgentThreadMessageReceivedEvent = + agentThreadMessageReceived.getOrThrow("agentThreadMessageReceived") + + /** + * Observability event emitted to the sender's output stream when an agent-to-agent message is + * sent. + */ + fun asAgentThreadMessageSent(): BetaManagedAgentsAgentThreadMessageSentEvent = + agentThreadMessageSent.getOrThrow("agentThreadMessageSent") + + /** Indicates that context compaction (summarization) occurred during the session. */ + fun asAgentThreadContextCompacted(): BetaManagedAgentsAgentThreadContextCompactedEvent = + agentThreadContextCompacted.getOrThrow("agentThreadContextCompacted") + + /** An error event indicating a problem occurred during session execution. */ + fun asSessionError(): BetaManagedAgentsSessionErrorEvent = + sessionError.getOrThrow("sessionError") + + /** Indicates the session is recovering from an error state and is rescheduled for execution. */ + fun asSessionStatusRescheduled(): BetaManagedAgentsSessionStatusRescheduledEvent = + sessionStatusRescheduled.getOrThrow("sessionStatusRescheduled") + + /** Indicates the session is actively running and the agent is working. */ + fun asSessionStatusRunning(): BetaManagedAgentsSessionStatusRunningEvent = + sessionStatusRunning.getOrThrow("sessionStatusRunning") + + /** Indicates the agent has paused and is awaiting user input. */ + fun asSessionStatusIdle(): BetaManagedAgentsSessionStatusIdleEvent = + sessionStatusIdle.getOrThrow("sessionStatusIdle") + + /** Indicates the session has terminated, either due to an error or completion. */ + fun asSessionStatusTerminated(): BetaManagedAgentsSessionStatusTerminatedEvent = + sessionStatusTerminated.getOrThrow("sessionStatusTerminated") + + /** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output + * stream so clients observing the session see child creation. + */ + fun asSessionThreadCreated(): BetaManagedAgentsSessionThreadCreatedEvent = + sessionThreadCreated.getOrThrow("sessionThreadCreated") + + /** Emitted when an outcome evaluation cycle begins. */ + fun asSpanOutcomeEvaluationStart(): BetaManagedAgentsSpanOutcomeEvaluationStartEvent = + spanOutcomeEvaluationStart.getOrThrow("spanOutcomeEvaluationStart") + + /** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate token + * usage. A verdict of `needs_revision` means another evaluation cycle follows; `satisfied`, + * `max_iterations_reached`, `failed`, or `interrupted` are terminal — no further evaluation + * cycles follow. + */ + fun asSpanOutcomeEvaluationEnd(): BetaManagedAgentsSpanOutcomeEvaluationEndEvent = + spanOutcomeEvaluationEnd.getOrThrow("spanOutcomeEvaluationEnd") + + /** Emitted when a model request is initiated by the agent. */ + fun asSpanModelRequestStart(): BetaManagedAgentsSpanModelRequestStartEvent = + spanModelRequestStart.getOrThrow("spanModelRequestStart") + + /** Emitted when a model request completes. */ + fun asSpanModelRequestEnd(): BetaManagedAgentsSpanModelRequestEndEvent = + spanModelRequestEnd.getOrThrow("spanModelRequestEnd") + + /** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. Distinguishes + * 'evaluation is actively running' from 'evaluation is stuck' between the corresponding + * `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ + fun asSpanOutcomeEvaluationOngoing(): BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent = + spanOutcomeEvaluationOngoing.getOrThrow("spanOutcomeEvaluationOngoing") + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` that + * subsequent `span.outcome_evaluation_*` events reference. + */ + fun asUserDefineOutcome(): BetaManagedAgentsUserDefineOutcomeEvent = + userDefineOutcome.getOrThrow("userDefineOutcome") + + /** + * Emitted when a session has been deleted. Terminates any active event stream — no further + * events will be emitted for this session. + */ + fun asSessionDeleted(): BetaManagedAgentsSessionDeletedEvent = + sessionDeleted.getOrThrow("sessionDeleted") + + /** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted to + * the primary stream for child threads. + */ + fun asSessionThreadStatusRunning(): BetaManagedAgentsSessionThreadStatusRunningEvent = + sessionThreadStatusRunning.getOrThrow("sessionThreadStatusRunning") + + /** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream and + * cross-posted to the primary stream for child threads. + */ + fun asSessionThreadStatusIdle(): BetaManagedAgentsSessionThreadStatusIdleEvent = + sessionThreadStatusIdle.getOrThrow("sessionThreadStatusIdle") + + /** + * A session thread has terminated and will accept no further input. Emitted on the thread's own + * stream and cross-posted to the primary stream for child threads. + */ + fun asSessionThreadStatusTerminated(): BetaManagedAgentsSessionThreadStatusTerminatedEvent = + sessionThreadStatusTerminated.getOrThrow("sessionThreadStatusTerminated") + + /** + * A session thread hit a transient error and is retrying automatically. Emitted on the thread's + * own stream and cross-posted to the primary stream for child threads. + */ + fun asSessionThreadStatusRescheduled(): BetaManagedAgentsSessionThreadStatusRescheduledEvent = + sessionThreadStatusRescheduled.getOrThrow("sessionThreadStatusRescheduled") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, unless + * [visitor] overrides [Visitor.unknown]. To handle variants not known to this version of the + * SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.anthropic.core.JsonValue; + * import java.util.Optional; + * + * Optional result = betaManagedAgentsStreamSessionThreadEvents.accept(new BetaManagedAgentsStreamSessionThreadEvents.Visitor>() { + * @Override + * public Optional visitUserMessage(BetaManagedAgentsUserMessageEvent userMessage) { + * return Optional.of(userMessage.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws AnthropicInvalidDataException if [Visitor.unknown] is not overridden in [visitor] and + * the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + userMessage != null -> visitor.visitUserMessage(userMessage) + userInterrupt != null -> visitor.visitUserInterrupt(userInterrupt) + userToolConfirmation != null -> visitor.visitUserToolConfirmation(userToolConfirmation) + userCustomToolResult != null -> visitor.visitUserCustomToolResult(userCustomToolResult) + agentCustomToolUse != null -> visitor.visitAgentCustomToolUse(agentCustomToolUse) + agentMessage != null -> visitor.visitAgentMessage(agentMessage) + agentThinking != null -> visitor.visitAgentThinking(agentThinking) + agentMcpToolUse != null -> visitor.visitAgentMcpToolUse(agentMcpToolUse) + agentMcpToolResult != null -> visitor.visitAgentMcpToolResult(agentMcpToolResult) + agentToolUse != null -> visitor.visitAgentToolUse(agentToolUse) + agentToolResult != null -> visitor.visitAgentToolResult(agentToolResult) + agentThreadMessageReceived != null -> + visitor.visitAgentThreadMessageReceived(agentThreadMessageReceived) + agentThreadMessageSent != null -> + visitor.visitAgentThreadMessageSent(agentThreadMessageSent) + agentThreadContextCompacted != null -> + visitor.visitAgentThreadContextCompacted(agentThreadContextCompacted) + sessionError != null -> visitor.visitSessionError(sessionError) + sessionStatusRescheduled != null -> + visitor.visitSessionStatusRescheduled(sessionStatusRescheduled) + sessionStatusRunning != null -> visitor.visitSessionStatusRunning(sessionStatusRunning) + sessionStatusIdle != null -> visitor.visitSessionStatusIdle(sessionStatusIdle) + sessionStatusTerminated != null -> + visitor.visitSessionStatusTerminated(sessionStatusTerminated) + sessionThreadCreated != null -> visitor.visitSessionThreadCreated(sessionThreadCreated) + spanOutcomeEvaluationStart != null -> + visitor.visitSpanOutcomeEvaluationStart(spanOutcomeEvaluationStart) + spanOutcomeEvaluationEnd != null -> + visitor.visitSpanOutcomeEvaluationEnd(spanOutcomeEvaluationEnd) + spanModelRequestStart != null -> + visitor.visitSpanModelRequestStart(spanModelRequestStart) + spanModelRequestEnd != null -> visitor.visitSpanModelRequestEnd(spanModelRequestEnd) + spanOutcomeEvaluationOngoing != null -> + visitor.visitSpanOutcomeEvaluationOngoing(spanOutcomeEvaluationOngoing) + userDefineOutcome != null -> visitor.visitUserDefineOutcome(userDefineOutcome) + sessionDeleted != null -> visitor.visitSessionDeleted(sessionDeleted) + sessionThreadStatusRunning != null -> + visitor.visitSessionThreadStatusRunning(sessionThreadStatusRunning) + sessionThreadStatusIdle != null -> + visitor.visitSessionThreadStatusIdle(sessionThreadStatusIdle) + sessionThreadStatusTerminated != null -> + visitor.visitSessionThreadStatusTerminated(sessionThreadStatusTerminated) + sessionThreadStatusRescheduled != null -> + visitor.visitSessionThreadStatusRescheduled(sessionThreadStatusRescheduled) + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsStreamSessionThreadEvents = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitUserMessage(userMessage: BetaManagedAgentsUserMessageEvent) { + userMessage.validate() + } + + override fun visitUserInterrupt( + userInterrupt: BetaManagedAgentsUserInterruptEvent + ) { + userInterrupt.validate() + } + + override fun visitUserToolConfirmation( + userToolConfirmation: BetaManagedAgentsUserToolConfirmationEvent + ) { + userToolConfirmation.validate() + } + + override fun visitUserCustomToolResult( + userCustomToolResult: BetaManagedAgentsUserCustomToolResultEvent + ) { + userCustomToolResult.validate() + } + + override fun visitAgentCustomToolUse( + agentCustomToolUse: BetaManagedAgentsAgentCustomToolUseEvent + ) { + agentCustomToolUse.validate() + } + + override fun visitAgentMessage(agentMessage: BetaManagedAgentsAgentMessageEvent) { + agentMessage.validate() + } + + override fun visitAgentThinking( + agentThinking: BetaManagedAgentsAgentThinkingEvent + ) { + agentThinking.validate() + } + + override fun visitAgentMcpToolUse( + agentMcpToolUse: BetaManagedAgentsAgentMcpToolUseEvent + ) { + agentMcpToolUse.validate() + } + + override fun visitAgentMcpToolResult( + agentMcpToolResult: BetaManagedAgentsAgentMcpToolResultEvent + ) { + agentMcpToolResult.validate() + } + + override fun visitAgentToolUse(agentToolUse: BetaManagedAgentsAgentToolUseEvent) { + agentToolUse.validate() + } + + override fun visitAgentToolResult( + agentToolResult: BetaManagedAgentsAgentToolResultEvent + ) { + agentToolResult.validate() + } + + override fun visitAgentThreadMessageReceived( + agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent + ) { + agentThreadMessageReceived.validate() + } + + override fun visitAgentThreadMessageSent( + agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent + ) { + agentThreadMessageSent.validate() + } + + override fun visitAgentThreadContextCompacted( + agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent + ) { + agentThreadContextCompacted.validate() + } + + override fun visitSessionError(sessionError: BetaManagedAgentsSessionErrorEvent) { + sessionError.validate() + } + + override fun visitSessionStatusRescheduled( + sessionStatusRescheduled: BetaManagedAgentsSessionStatusRescheduledEvent + ) { + sessionStatusRescheduled.validate() + } + + override fun visitSessionStatusRunning( + sessionStatusRunning: BetaManagedAgentsSessionStatusRunningEvent + ) { + sessionStatusRunning.validate() + } + + override fun visitSessionStatusIdle( + sessionStatusIdle: BetaManagedAgentsSessionStatusIdleEvent + ) { + sessionStatusIdle.validate() + } + + override fun visitSessionStatusTerminated( + sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent + ) { + sessionStatusTerminated.validate() + } + + override fun visitSessionThreadCreated( + sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent + ) { + sessionThreadCreated.validate() + } + + override fun visitSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ) { + spanOutcomeEvaluationStart.validate() + } + + override fun visitSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ) { + spanOutcomeEvaluationEnd.validate() + } + + override fun visitSpanModelRequestStart( + spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent + ) { + spanModelRequestStart.validate() + } + + override fun visitSpanModelRequestEnd( + spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent + ) { + spanModelRequestEnd.validate() + } + + override fun visitSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ) { + spanOutcomeEvaluationOngoing.validate() + } + + override fun visitUserDefineOutcome( + userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent + ) { + userDefineOutcome.validate() + } + + override fun visitSessionDeleted( + sessionDeleted: BetaManagedAgentsSessionDeletedEvent + ) { + sessionDeleted.validate() + } + + override fun visitSessionThreadStatusRunning( + sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent + ) { + sessionThreadStatusRunning.validate() + } + + override fun visitSessionThreadStatusIdle( + sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent + ) { + sessionThreadStatusIdle.validate() + } + + override fun visitSessionThreadStatusTerminated( + sessionThreadStatusTerminated: + BetaManagedAgentsSessionThreadStatusTerminatedEvent + ) { + sessionThreadStatusTerminated.validate() + } + + override fun visitSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled: + BetaManagedAgentsSessionThreadStatusRescheduledEvent + ) { + sessionThreadStatusRescheduled.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 visitUserMessage(userMessage: BetaManagedAgentsUserMessageEvent) = + userMessage.validity() + + override fun visitUserInterrupt( + userInterrupt: BetaManagedAgentsUserInterruptEvent + ) = userInterrupt.validity() + + override fun visitUserToolConfirmation( + userToolConfirmation: BetaManagedAgentsUserToolConfirmationEvent + ) = userToolConfirmation.validity() + + override fun visitUserCustomToolResult( + userCustomToolResult: BetaManagedAgentsUserCustomToolResultEvent + ) = userCustomToolResult.validity() + + override fun visitAgentCustomToolUse( + agentCustomToolUse: BetaManagedAgentsAgentCustomToolUseEvent + ) = agentCustomToolUse.validity() + + override fun visitAgentMessage(agentMessage: BetaManagedAgentsAgentMessageEvent) = + agentMessage.validity() + + override fun visitAgentThinking( + agentThinking: BetaManagedAgentsAgentThinkingEvent + ) = agentThinking.validity() + + override fun visitAgentMcpToolUse( + agentMcpToolUse: BetaManagedAgentsAgentMcpToolUseEvent + ) = agentMcpToolUse.validity() + + override fun visitAgentMcpToolResult( + agentMcpToolResult: BetaManagedAgentsAgentMcpToolResultEvent + ) = agentMcpToolResult.validity() + + override fun visitAgentToolUse(agentToolUse: BetaManagedAgentsAgentToolUseEvent) = + agentToolUse.validity() + + override fun visitAgentToolResult( + agentToolResult: BetaManagedAgentsAgentToolResultEvent + ) = agentToolResult.validity() + + override fun visitAgentThreadMessageReceived( + agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent + ) = agentThreadMessageReceived.validity() + + override fun visitAgentThreadMessageSent( + agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent + ) = agentThreadMessageSent.validity() + + override fun visitAgentThreadContextCompacted( + agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent + ) = agentThreadContextCompacted.validity() + + override fun visitSessionError(sessionError: BetaManagedAgentsSessionErrorEvent) = + sessionError.validity() + + override fun visitSessionStatusRescheduled( + sessionStatusRescheduled: BetaManagedAgentsSessionStatusRescheduledEvent + ) = sessionStatusRescheduled.validity() + + override fun visitSessionStatusRunning( + sessionStatusRunning: BetaManagedAgentsSessionStatusRunningEvent + ) = sessionStatusRunning.validity() + + override fun visitSessionStatusIdle( + sessionStatusIdle: BetaManagedAgentsSessionStatusIdleEvent + ) = sessionStatusIdle.validity() + + override fun visitSessionStatusTerminated( + sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent + ) = sessionStatusTerminated.validity() + + override fun visitSessionThreadCreated( + sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent + ) = sessionThreadCreated.validity() + + override fun visitSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ) = spanOutcomeEvaluationStart.validity() + + override fun visitSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ) = spanOutcomeEvaluationEnd.validity() + + override fun visitSpanModelRequestStart( + spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent + ) = spanModelRequestStart.validity() + + override fun visitSpanModelRequestEnd( + spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent + ) = spanModelRequestEnd.validity() + + override fun visitSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ) = spanOutcomeEvaluationOngoing.validity() + + override fun visitUserDefineOutcome( + userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent + ) = userDefineOutcome.validity() + + override fun visitSessionDeleted( + sessionDeleted: BetaManagedAgentsSessionDeletedEvent + ) = sessionDeleted.validity() + + override fun visitSessionThreadStatusRunning( + sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent + ) = sessionThreadStatusRunning.validity() + + override fun visitSessionThreadStatusIdle( + sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent + ) = sessionThreadStatusIdle.validity() + + override fun visitSessionThreadStatusTerminated( + sessionThreadStatusTerminated: + BetaManagedAgentsSessionThreadStatusTerminatedEvent + ) = sessionThreadStatusTerminated.validity() + + override fun visitSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled: + BetaManagedAgentsSessionThreadStatusRescheduledEvent + ) = sessionThreadStatusRescheduled.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaManagedAgentsStreamSessionThreadEvents && + userMessage == other.userMessage && + userInterrupt == other.userInterrupt && + userToolConfirmation == other.userToolConfirmation && + userCustomToolResult == other.userCustomToolResult && + agentCustomToolUse == other.agentCustomToolUse && + agentMessage == other.agentMessage && + agentThinking == other.agentThinking && + agentMcpToolUse == other.agentMcpToolUse && + agentMcpToolResult == other.agentMcpToolResult && + agentToolUse == other.agentToolUse && + agentToolResult == other.agentToolResult && + agentThreadMessageReceived == other.agentThreadMessageReceived && + agentThreadMessageSent == other.agentThreadMessageSent && + agentThreadContextCompacted == other.agentThreadContextCompacted && + sessionError == other.sessionError && + sessionStatusRescheduled == other.sessionStatusRescheduled && + sessionStatusRunning == other.sessionStatusRunning && + sessionStatusIdle == other.sessionStatusIdle && + sessionStatusTerminated == other.sessionStatusTerminated && + sessionThreadCreated == other.sessionThreadCreated && + spanOutcomeEvaluationStart == other.spanOutcomeEvaluationStart && + spanOutcomeEvaluationEnd == other.spanOutcomeEvaluationEnd && + spanModelRequestStart == other.spanModelRequestStart && + spanModelRequestEnd == other.spanModelRequestEnd && + spanOutcomeEvaluationOngoing == other.spanOutcomeEvaluationOngoing && + userDefineOutcome == other.userDefineOutcome && + sessionDeleted == other.sessionDeleted && + sessionThreadStatusRunning == other.sessionThreadStatusRunning && + sessionThreadStatusIdle == other.sessionThreadStatusIdle && + sessionThreadStatusTerminated == other.sessionThreadStatusTerminated && + sessionThreadStatusRescheduled == other.sessionThreadStatusRescheduled + } + + override fun hashCode(): Int = + Objects.hash( + userMessage, + userInterrupt, + userToolConfirmation, + userCustomToolResult, + agentCustomToolUse, + agentMessage, + agentThinking, + agentMcpToolUse, + agentMcpToolResult, + agentToolUse, + agentToolResult, + agentThreadMessageReceived, + agentThreadMessageSent, + agentThreadContextCompacted, + sessionError, + sessionStatusRescheduled, + sessionStatusRunning, + sessionStatusIdle, + sessionStatusTerminated, + sessionThreadCreated, + spanOutcomeEvaluationStart, + spanOutcomeEvaluationEnd, + spanModelRequestStart, + spanModelRequestEnd, + spanOutcomeEvaluationOngoing, + userDefineOutcome, + sessionDeleted, + sessionThreadStatusRunning, + sessionThreadStatusIdle, + sessionThreadStatusTerminated, + sessionThreadStatusRescheduled, + ) + + override fun toString(): String = + when { + userMessage != null -> + "BetaManagedAgentsStreamSessionThreadEvents{userMessage=$userMessage}" + userInterrupt != null -> + "BetaManagedAgentsStreamSessionThreadEvents{userInterrupt=$userInterrupt}" + userToolConfirmation != null -> + "BetaManagedAgentsStreamSessionThreadEvents{userToolConfirmation=$userToolConfirmation}" + userCustomToolResult != null -> + "BetaManagedAgentsStreamSessionThreadEvents{userCustomToolResult=$userCustomToolResult}" + agentCustomToolUse != null -> + "BetaManagedAgentsStreamSessionThreadEvents{agentCustomToolUse=$agentCustomToolUse}" + agentMessage != null -> + "BetaManagedAgentsStreamSessionThreadEvents{agentMessage=$agentMessage}" + agentThinking != null -> + "BetaManagedAgentsStreamSessionThreadEvents{agentThinking=$agentThinking}" + agentMcpToolUse != null -> + "BetaManagedAgentsStreamSessionThreadEvents{agentMcpToolUse=$agentMcpToolUse}" + agentMcpToolResult != null -> + "BetaManagedAgentsStreamSessionThreadEvents{agentMcpToolResult=$agentMcpToolResult}" + agentToolUse != null -> + "BetaManagedAgentsStreamSessionThreadEvents{agentToolUse=$agentToolUse}" + agentToolResult != null -> + "BetaManagedAgentsStreamSessionThreadEvents{agentToolResult=$agentToolResult}" + agentThreadMessageReceived != null -> + "BetaManagedAgentsStreamSessionThreadEvents{agentThreadMessageReceived=$agentThreadMessageReceived}" + agentThreadMessageSent != null -> + "BetaManagedAgentsStreamSessionThreadEvents{agentThreadMessageSent=$agentThreadMessageSent}" + agentThreadContextCompacted != null -> + "BetaManagedAgentsStreamSessionThreadEvents{agentThreadContextCompacted=$agentThreadContextCompacted}" + sessionError != null -> + "BetaManagedAgentsStreamSessionThreadEvents{sessionError=$sessionError}" + sessionStatusRescheduled != null -> + "BetaManagedAgentsStreamSessionThreadEvents{sessionStatusRescheduled=$sessionStatusRescheduled}" + sessionStatusRunning != null -> + "BetaManagedAgentsStreamSessionThreadEvents{sessionStatusRunning=$sessionStatusRunning}" + sessionStatusIdle != null -> + "BetaManagedAgentsStreamSessionThreadEvents{sessionStatusIdle=$sessionStatusIdle}" + sessionStatusTerminated != null -> + "BetaManagedAgentsStreamSessionThreadEvents{sessionStatusTerminated=$sessionStatusTerminated}" + sessionThreadCreated != null -> + "BetaManagedAgentsStreamSessionThreadEvents{sessionThreadCreated=$sessionThreadCreated}" + spanOutcomeEvaluationStart != null -> + "BetaManagedAgentsStreamSessionThreadEvents{spanOutcomeEvaluationStart=$spanOutcomeEvaluationStart}" + spanOutcomeEvaluationEnd != null -> + "BetaManagedAgentsStreamSessionThreadEvents{spanOutcomeEvaluationEnd=$spanOutcomeEvaluationEnd}" + spanModelRequestStart != null -> + "BetaManagedAgentsStreamSessionThreadEvents{spanModelRequestStart=$spanModelRequestStart}" + spanModelRequestEnd != null -> + "BetaManagedAgentsStreamSessionThreadEvents{spanModelRequestEnd=$spanModelRequestEnd}" + spanOutcomeEvaluationOngoing != null -> + "BetaManagedAgentsStreamSessionThreadEvents{spanOutcomeEvaluationOngoing=$spanOutcomeEvaluationOngoing}" + userDefineOutcome != null -> + "BetaManagedAgentsStreamSessionThreadEvents{userDefineOutcome=$userDefineOutcome}" + sessionDeleted != null -> + "BetaManagedAgentsStreamSessionThreadEvents{sessionDeleted=$sessionDeleted}" + sessionThreadStatusRunning != null -> + "BetaManagedAgentsStreamSessionThreadEvents{sessionThreadStatusRunning=$sessionThreadStatusRunning}" + sessionThreadStatusIdle != null -> + "BetaManagedAgentsStreamSessionThreadEvents{sessionThreadStatusIdle=$sessionThreadStatusIdle}" + sessionThreadStatusTerminated != null -> + "BetaManagedAgentsStreamSessionThreadEvents{sessionThreadStatusTerminated=$sessionThreadStatusTerminated}" + sessionThreadStatusRescheduled != null -> + "BetaManagedAgentsStreamSessionThreadEvents{sessionThreadStatusRescheduled=$sessionThreadStatusRescheduled}" + _json != null -> "BetaManagedAgentsStreamSessionThreadEvents{_unknown=$_json}" + else -> + throw IllegalStateException("Invalid BetaManagedAgentsStreamSessionThreadEvents") + } + + companion object { + + /** A user message event in the session conversation. */ + @JvmStatic + fun ofUserMessage(userMessage: BetaManagedAgentsUserMessageEvent) = + BetaManagedAgentsStreamSessionThreadEvents(userMessage = userMessage) + + /** An interrupt event that pauses agent execution and returns control to the user. */ + @JvmStatic + fun ofUserInterrupt(userInterrupt: BetaManagedAgentsUserInterruptEvent) = + BetaManagedAgentsStreamSessionThreadEvents(userInterrupt = userInterrupt) + + /** A tool confirmation event that approves or denies a pending tool execution. */ + @JvmStatic + fun ofUserToolConfirmation( + userToolConfirmation: BetaManagedAgentsUserToolConfirmationEvent + ) = BetaManagedAgentsStreamSessionThreadEvents(userToolConfirmation = userToolConfirmation) + + /** Event sent by the client providing the result of a custom tool execution. */ + @JvmStatic + fun ofUserCustomToolResult( + userCustomToolResult: BetaManagedAgentsUserCustomToolResultEvent + ) = BetaManagedAgentsStreamSessionThreadEvents(userCustomToolResult = userCustomToolResult) + + /** + * Event emitted when the agent calls a custom tool. The session goes idle until the client + * sends a `user.custom_tool_result` event with the result. + */ + @JvmStatic + fun ofAgentCustomToolUse(agentCustomToolUse: BetaManagedAgentsAgentCustomToolUseEvent) = + BetaManagedAgentsStreamSessionThreadEvents(agentCustomToolUse = agentCustomToolUse) + + /** An agent response event in the session conversation. */ + @JvmStatic + fun ofAgentMessage(agentMessage: BetaManagedAgentsAgentMessageEvent) = + BetaManagedAgentsStreamSessionThreadEvents(agentMessage = agentMessage) + + /** + * Indicates the agent is making forward progress via extended thinking. A progress signal, + * not a content carrier. + */ + @JvmStatic + fun ofAgentThinking(agentThinking: BetaManagedAgentsAgentThinkingEvent) = + BetaManagedAgentsStreamSessionThreadEvents(agentThinking = agentThinking) + + /** Event emitted when the agent invokes a tool provided by an MCP server. */ + @JvmStatic + fun ofAgentMcpToolUse(agentMcpToolUse: BetaManagedAgentsAgentMcpToolUseEvent) = + BetaManagedAgentsStreamSessionThreadEvents(agentMcpToolUse = agentMcpToolUse) + + /** Event representing the result of an MCP tool execution. */ + @JvmStatic + fun ofAgentMcpToolResult(agentMcpToolResult: BetaManagedAgentsAgentMcpToolResultEvent) = + BetaManagedAgentsStreamSessionThreadEvents(agentMcpToolResult = agentMcpToolResult) + + /** Event emitted when the agent invokes a built-in agent tool. */ + @JvmStatic + fun ofAgentToolUse(agentToolUse: BetaManagedAgentsAgentToolUseEvent) = + BetaManagedAgentsStreamSessionThreadEvents(agentToolUse = agentToolUse) + + /** Event representing the result of an agent tool execution. */ + @JvmStatic + fun ofAgentToolResult(agentToolResult: BetaManagedAgentsAgentToolResultEvent) = + BetaManagedAgentsStreamSessionThreadEvents(agentToolResult = agentToolResult) + + /** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ + @JvmStatic + fun ofAgentThreadMessageReceived( + agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + agentThreadMessageReceived = agentThreadMessageReceived + ) + + /** + * Observability event emitted to the sender's output stream when an agent-to-agent message + * is sent. + */ + @JvmStatic + fun ofAgentThreadMessageSent( + agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + agentThreadMessageSent = agentThreadMessageSent + ) + + /** Indicates that context compaction (summarization) occurred during the session. */ + @JvmStatic + fun ofAgentThreadContextCompacted( + agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + agentThreadContextCompacted = agentThreadContextCompacted + ) + + /** An error event indicating a problem occurred during session execution. */ + @JvmStatic + fun ofSessionError(sessionError: BetaManagedAgentsSessionErrorEvent) = + BetaManagedAgentsStreamSessionThreadEvents(sessionError = sessionError) + + /** + * Indicates the session is recovering from an error state and is rescheduled for execution. + */ + @JvmStatic + fun ofSessionStatusRescheduled( + sessionStatusRescheduled: BetaManagedAgentsSessionStatusRescheduledEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + sessionStatusRescheduled = sessionStatusRescheduled + ) + + /** Indicates the session is actively running and the agent is working. */ + @JvmStatic + fun ofSessionStatusRunning( + sessionStatusRunning: BetaManagedAgentsSessionStatusRunningEvent + ) = BetaManagedAgentsStreamSessionThreadEvents(sessionStatusRunning = sessionStatusRunning) + + /** Indicates the agent has paused and is awaiting user input. */ + @JvmStatic + fun ofSessionStatusIdle(sessionStatusIdle: BetaManagedAgentsSessionStatusIdleEvent) = + BetaManagedAgentsStreamSessionThreadEvents(sessionStatusIdle = sessionStatusIdle) + + /** Indicates the session has terminated, either due to an error or completion. */ + @JvmStatic + fun ofSessionStatusTerminated( + sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + sessionStatusTerminated = sessionStatusTerminated + ) + + /** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output + * stream so clients observing the session see child creation. + */ + @JvmStatic + fun ofSessionThreadCreated( + sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent + ) = BetaManagedAgentsStreamSessionThreadEvents(sessionThreadCreated = sessionThreadCreated) + + /** Emitted when an outcome evaluation cycle begins. */ + @JvmStatic + fun ofSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + spanOutcomeEvaluationStart = spanOutcomeEvaluationStart + ) + + /** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate + * token usage. A verdict of `needs_revision` means another evaluation cycle follows; + * `satisfied`, `max_iterations_reached`, `failed`, or `interrupted` are terminal — no + * further evaluation cycles follow. + */ + @JvmStatic + fun ofSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + spanOutcomeEvaluationEnd = spanOutcomeEvaluationEnd + ) + + /** Emitted when a model request is initiated by the agent. */ + @JvmStatic + fun ofSpanModelRequestStart( + spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + spanModelRequestStart = spanModelRequestStart + ) + + /** Emitted when a model request completes. */ + @JvmStatic + fun ofSpanModelRequestEnd(spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent) = + BetaManagedAgentsStreamSessionThreadEvents(spanModelRequestEnd = spanModelRequestEnd) + + /** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. + * Distinguishes 'evaluation is actively running' from 'evaluation is stuck' between the + * corresponding `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ + @JvmStatic + fun ofSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + spanOutcomeEvaluationOngoing = spanOutcomeEvaluationOngoing + ) + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` + * that subsequent `span.outcome_evaluation_*` events reference. + */ + @JvmStatic + fun ofUserDefineOutcome(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent) = + BetaManagedAgentsStreamSessionThreadEvents(userDefineOutcome = userDefineOutcome) + + /** + * Emitted when a session has been deleted. Terminates any active event stream — no further + * events will be emitted for this session. + */ + @JvmStatic + fun ofSessionDeleted(sessionDeleted: BetaManagedAgentsSessionDeletedEvent) = + BetaManagedAgentsStreamSessionThreadEvents(sessionDeleted = sessionDeleted) + + /** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted + * to the primary stream for child threads. + */ + @JvmStatic + fun ofSessionThreadStatusRunning( + sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + sessionThreadStatusRunning = sessionThreadStatusRunning + ) + + /** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream + * and cross-posted to the primary stream for child threads. + */ + @JvmStatic + fun ofSessionThreadStatusIdle( + sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + sessionThreadStatusIdle = sessionThreadStatusIdle + ) + + /** + * A session thread has terminated and will accept no further input. Emitted on the thread's + * own stream and cross-posted to the primary stream for child threads. + */ + @JvmStatic + fun ofSessionThreadStatusTerminated( + sessionThreadStatusTerminated: BetaManagedAgentsSessionThreadStatusTerminatedEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + sessionThreadStatusTerminated = sessionThreadStatusTerminated + ) + + /** + * A session thread hit a transient error and is retrying automatically. Emitted on the + * thread's own stream and cross-posted to the primary stream for child threads. + */ + @JvmStatic + fun ofSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled: BetaManagedAgentsSessionThreadStatusRescheduledEvent + ) = + BetaManagedAgentsStreamSessionThreadEvents( + sessionThreadStatusRescheduled = sessionThreadStatusRescheduled + ) + } + + /** + * An interface that defines how to map each variant of + * [BetaManagedAgentsStreamSessionThreadEvents] to a value of type [T]. + */ + interface Visitor { + + /** A user message event in the session conversation. */ + fun visitUserMessage(userMessage: BetaManagedAgentsUserMessageEvent): T + + /** An interrupt event that pauses agent execution and returns control to the user. */ + fun visitUserInterrupt(userInterrupt: BetaManagedAgentsUserInterruptEvent): T + + /** A tool confirmation event that approves or denies a pending tool execution. */ + fun visitUserToolConfirmation( + userToolConfirmation: BetaManagedAgentsUserToolConfirmationEvent + ): T + + /** Event sent by the client providing the result of a custom tool execution. */ + fun visitUserCustomToolResult( + userCustomToolResult: BetaManagedAgentsUserCustomToolResultEvent + ): T + + /** + * Event emitted when the agent calls a custom tool. The session goes idle until the client + * sends a `user.custom_tool_result` event with the result. + */ + fun visitAgentCustomToolUse(agentCustomToolUse: BetaManagedAgentsAgentCustomToolUseEvent): T + + /** An agent response event in the session conversation. */ + fun visitAgentMessage(agentMessage: BetaManagedAgentsAgentMessageEvent): T + + /** + * Indicates the agent is making forward progress via extended thinking. A progress signal, + * not a content carrier. + */ + fun visitAgentThinking(agentThinking: BetaManagedAgentsAgentThinkingEvent): T + + /** Event emitted when the agent invokes a tool provided by an MCP server. */ + fun visitAgentMcpToolUse(agentMcpToolUse: BetaManagedAgentsAgentMcpToolUseEvent): T + + /** Event representing the result of an MCP tool execution. */ + fun visitAgentMcpToolResult(agentMcpToolResult: BetaManagedAgentsAgentMcpToolResultEvent): T + + /** Event emitted when the agent invokes a built-in agent tool. */ + fun visitAgentToolUse(agentToolUse: BetaManagedAgentsAgentToolUseEvent): T + + /** Event representing the result of an agent tool execution. */ + fun visitAgentToolResult(agentToolResult: BetaManagedAgentsAgentToolResultEvent): T + + /** + * Delivery event written to the target thread's input stream when an agent-to-agent message + * arrives. + */ + fun visitAgentThreadMessageReceived( + agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent + ): T + + /** + * Observability event emitted to the sender's output stream when an agent-to-agent message + * is sent. + */ + fun visitAgentThreadMessageSent( + agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent + ): T + + /** Indicates that context compaction (summarization) occurred during the session. */ + fun visitAgentThreadContextCompacted( + agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent + ): T + + /** An error event indicating a problem occurred during session execution. */ + fun visitSessionError(sessionError: BetaManagedAgentsSessionErrorEvent): T + + /** + * Indicates the session is recovering from an error state and is rescheduled for execution. + */ + fun visitSessionStatusRescheduled( + sessionStatusRescheduled: BetaManagedAgentsSessionStatusRescheduledEvent + ): T + + /** Indicates the session is actively running and the agent is working. */ + fun visitSessionStatusRunning( + sessionStatusRunning: BetaManagedAgentsSessionStatusRunningEvent + ): T + + /** Indicates the agent has paused and is awaiting user input. */ + fun visitSessionStatusIdle(sessionStatusIdle: BetaManagedAgentsSessionStatusIdleEvent): T + + /** Indicates the session has terminated, either due to an error or completion. */ + fun visitSessionStatusTerminated( + sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent + ): T + + /** + * Emitted when a subagent is spawned as a new thread. Written to the parent thread's output + * stream so clients observing the session see child creation. + */ + fun visitSessionThreadCreated( + sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent + ): T + + /** Emitted when an outcome evaluation cycle begins. */ + fun visitSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent + ): T + + /** + * Emitted when an outcome evaluation cycle completes. Carries the verdict and aggregate + * token usage. A verdict of `needs_revision` means another evaluation cycle follows; + * `satisfied`, `max_iterations_reached`, `failed`, or `interrupted` are terminal — no + * further evaluation cycles follow. + */ + fun visitSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent + ): T + + /** Emitted when a model request is initiated by the agent. */ + fun visitSpanModelRequestStart( + spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent + ): T + + /** Emitted when a model request completes. */ + fun visitSpanModelRequestEnd( + spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent + ): T + + /** + * Periodic heartbeat emitted while an outcome evaluation cycle is in progress. + * Distinguishes 'evaluation is actively running' from 'evaluation is stuck' between the + * corresponding `span.outcome_evaluation_start` and `span.outcome_evaluation_end` events. + */ + fun visitSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ): T + + /** + * Echo of a `user.define_outcome` input event. Carries the server-generated `outcome_id` + * that subsequent `span.outcome_evaluation_*` events reference. + */ + fun visitUserDefineOutcome(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent): T + + /** + * Emitted when a session has been deleted. Terminates any active event stream — no further + * events will be emitted for this session. + */ + fun visitSessionDeleted(sessionDeleted: BetaManagedAgentsSessionDeletedEvent): T + + /** + * A session thread has begun executing. Emitted on the thread's own stream and cross-posted + * to the primary stream for child threads. + */ + fun visitSessionThreadStatusRunning( + sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent + ): T + + /** + * A session thread has yielded and is awaiting input. Emitted on the thread's own stream + * and cross-posted to the primary stream for child threads. + */ + fun visitSessionThreadStatusIdle( + sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent + ): T + + /** + * A session thread has terminated and will accept no further input. Emitted on the thread's + * own stream and cross-posted to the primary stream for child threads. + */ + fun visitSessionThreadStatusTerminated( + sessionThreadStatusTerminated: BetaManagedAgentsSessionThreadStatusTerminatedEvent + ): T + + /** + * A session thread hit a transient error and is retrying automatically. Emitted on the + * thread's own stream and cross-posted to the primary stream for child threads. + */ + fun visitSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled: BetaManagedAgentsSessionThreadStatusRescheduledEvent + ): T + + /** + * Maps an unknown variant of [BetaManagedAgentsStreamSessionThreadEvents] to a value of + * type [T]. + * + * An instance of [BetaManagedAgentsStreamSessionThreadEvents] 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 AnthropicInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw AnthropicInvalidDataException( + "Unknown BetaManagedAgentsStreamSessionThreadEvents: $json" + ) + } + } + + internal class Deserializer : + BaseDeserializer( + BetaManagedAgentsStreamSessionThreadEvents::class + ) { + + override fun ObjectCodec.deserialize( + node: JsonNode + ): BetaManagedAgentsStreamSessionThreadEvents { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "user.message" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + userMessage = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "user.interrupt" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + userInterrupt = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "user.tool_confirmation" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + userToolConfirmation = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "user.custom_tool_result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + userCustomToolResult = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "agent.custom_tool_use" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + agentCustomToolUse = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "agent.message" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + agentMessage = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "agent.thinking" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + agentThinking = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "agent.mcp_tool_use" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + agentMcpToolUse = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "agent.mcp_tool_result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + agentMcpToolResult = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "agent.tool_use" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + agentToolUse = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "agent.tool_result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + agentToolResult = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "agent.thread_message_received" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + agentThreadMessageReceived = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "agent.thread_message_sent" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + agentThreadMessageSent = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "agent.thread_context_compacted" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + agentThreadContextCompacted = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "session.error" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + sessionError = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "session.status_rescheduled" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + sessionStatusRescheduled = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "session.status_running" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + sessionStatusRunning = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "session.status_idle" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + sessionStatusIdle = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "session.status_terminated" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + sessionStatusTerminated = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "session.thread_created" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + sessionThreadCreated = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "span.outcome_evaluation_start" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + spanOutcomeEvaluationStart = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "span.outcome_evaluation_end" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + spanOutcomeEvaluationEnd = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "span.model_request_start" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + spanModelRequestStart = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "span.model_request_end" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + spanModelRequestEnd = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "span.outcome_evaluation_ongoing" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + spanOutcomeEvaluationOngoing = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "user.define_outcome" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + userDefineOutcome = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "session.deleted" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + sessionDeleted = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "session.thread_status_running" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + sessionThreadStatusRunning = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "session.thread_status_idle" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + sessionThreadStatusIdle = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "session.thread_status_terminated" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + sessionThreadStatusTerminated = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + "session.thread_status_rescheduled" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaManagedAgentsStreamSessionThreadEvents( + sessionThreadStatusRescheduled = it, + _json = json, + ) + } ?: BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + } + + return BetaManagedAgentsStreamSessionThreadEvents(_json = json) + } + } + + internal class Serializer : + BaseSerializer( + BetaManagedAgentsStreamSessionThreadEvents::class + ) { + + override fun serialize( + value: BetaManagedAgentsStreamSessionThreadEvents, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.userMessage != null -> generator.writeObject(value.userMessage) + value.userInterrupt != null -> generator.writeObject(value.userInterrupt) + value.userToolConfirmation != null -> + generator.writeObject(value.userToolConfirmation) + value.userCustomToolResult != null -> + generator.writeObject(value.userCustomToolResult) + value.agentCustomToolUse != null -> generator.writeObject(value.agentCustomToolUse) + value.agentMessage != null -> generator.writeObject(value.agentMessage) + value.agentThinking != null -> generator.writeObject(value.agentThinking) + value.agentMcpToolUse != null -> generator.writeObject(value.agentMcpToolUse) + value.agentMcpToolResult != null -> generator.writeObject(value.agentMcpToolResult) + value.agentToolUse != null -> generator.writeObject(value.agentToolUse) + value.agentToolResult != null -> generator.writeObject(value.agentToolResult) + value.agentThreadMessageReceived != null -> + generator.writeObject(value.agentThreadMessageReceived) + value.agentThreadMessageSent != null -> + generator.writeObject(value.agentThreadMessageSent) + value.agentThreadContextCompacted != null -> + generator.writeObject(value.agentThreadContextCompacted) + value.sessionError != null -> generator.writeObject(value.sessionError) + value.sessionStatusRescheduled != null -> + generator.writeObject(value.sessionStatusRescheduled) + value.sessionStatusRunning != null -> + generator.writeObject(value.sessionStatusRunning) + value.sessionStatusIdle != null -> generator.writeObject(value.sessionStatusIdle) + value.sessionStatusTerminated != null -> + generator.writeObject(value.sessionStatusTerminated) + value.sessionThreadCreated != null -> + generator.writeObject(value.sessionThreadCreated) + value.spanOutcomeEvaluationStart != null -> + generator.writeObject(value.spanOutcomeEvaluationStart) + value.spanOutcomeEvaluationEnd != null -> + generator.writeObject(value.spanOutcomeEvaluationEnd) + value.spanModelRequestStart != null -> + generator.writeObject(value.spanModelRequestStart) + value.spanModelRequestEnd != null -> + generator.writeObject(value.spanModelRequestEnd) + value.spanOutcomeEvaluationOngoing != null -> + generator.writeObject(value.spanOutcomeEvaluationOngoing) + value.userDefineOutcome != null -> generator.writeObject(value.userDefineOutcome) + value.sessionDeleted != null -> generator.writeObject(value.sessionDeleted) + value.sessionThreadStatusRunning != null -> + generator.writeObject(value.sessionThreadStatusRunning) + value.sessionThreadStatusIdle != null -> + generator.writeObject(value.sessionThreadStatusIdle) + value.sessionThreadStatusTerminated != null -> + generator.writeObject(value.sessionThreadStatusTerminated) + value.sessionThreadStatusRescheduled != null -> + generator.writeObject(value.sessionThreadStatusRescheduled) + value._json != null -> generator.writeObject(value._json) + else -> + throw IllegalStateException( + "Invalid BetaManagedAgentsStreamSessionThreadEvents" + ) + } + } + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadArchiveParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadArchiveParams.kt new file mode 100644 index 000000000..fd11d65fb --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadArchiveParams.kt @@ -0,0 +1,298 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.JsonValue +import com.anthropic.core.Params +import com.anthropic.core.checkRequired +import com.anthropic.core.http.Headers +import com.anthropic.core.http.QueryParams +import com.anthropic.core.toImmutable +import com.anthropic.models.beta.AnthropicBeta +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Archive Session Thread */ +class ThreadArchiveParams +private constructor( + private val sessionId: String, + private val threadId: String?, + private val betas: List?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun sessionId(): String = sessionId + + fun threadId(): Optional = Optional.ofNullable(threadId) + + /** Optional header to specify the beta version(s) you want to use. */ + fun betas(): Optional> = Optional.ofNullable(betas) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ThreadArchiveParams]. + * + * The following fields are required: + * ```java + * .sessionId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadArchiveParams]. */ + class Builder internal constructor() { + + private var sessionId: String? = null + private var threadId: String? = null + private var betas: MutableList? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadArchiveParams: ThreadArchiveParams) = apply { + sessionId = threadArchiveParams.sessionId + threadId = threadArchiveParams.threadId + betas = threadArchiveParams.betas?.toMutableList() + additionalHeaders = threadArchiveParams.additionalHeaders.toBuilder() + additionalQueryParams = threadArchiveParams.additionalQueryParams.toBuilder() + additionalBodyProperties = threadArchiveParams.additionalBodyProperties.toMutableMap() + } + + fun sessionId(sessionId: String) = apply { this.sessionId = sessionId } + + fun threadId(threadId: String?) = apply { this.threadId = threadId } + + /** Alias for calling [Builder.threadId] with `threadId.orElse(null)`. */ + fun threadId(threadId: Optional) = threadId(threadId.getOrNull()) + + /** Optional header to specify the beta version(s) you want to use. */ + fun betas(betas: List?) = apply { this.betas = betas?.toMutableList() } + + /** Alias for calling [Builder.betas] with `betas.orElse(null)`. */ + fun betas(betas: Optional>) = betas(betas.getOrNull()) + + /** + * Adds a single [AnthropicBeta] to [betas]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addBeta(beta: AnthropicBeta) = apply { + betas = (betas ?: mutableListOf()).apply { add(beta) } + } + + /** + * Sets [addBeta] to an arbitrary [String]. + * + * You should usually call [addBeta] with a well-typed [AnthropicBeta] constant instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun addBeta(value: String) = addBeta(AnthropicBeta.of(value)) + + 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 [ThreadArchiveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sessionId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ThreadArchiveParams = + ThreadArchiveParams( + checkRequired("sessionId", sessionId), + threadId, + betas?.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sessionId + 1 -> threadId ?: "" + else -> "" + } + + override fun _headers(): Headers = + Headers.builder() + .apply { + betas?.forEach { put("anthropic-beta", it.toString()) } + putAll(additionalHeaders) + } + .build() + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ThreadArchiveParams && + sessionId == other.sessionId && + threadId == other.threadId && + betas == other.betas && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + sessionId, + threadId, + betas, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "ThreadArchiveParams{sessionId=$sessionId, threadId=$threadId, betas=$betas, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPage.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPage.kt new file mode 100644 index 000000000..268b1b6d9 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPage.kt @@ -0,0 +1,132 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.AutoPager +import com.anthropic.core.Page +import com.anthropic.core.checkRequired +import com.anthropic.services.blocking.beta.sessions.ThreadService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see ThreadService.list */ +class ThreadListPage +private constructor( + private val service: ThreadService, + private val params: ThreadListParams, + private val response: ThreadListPageResponse, +) : Page { + + /** + * Delegates to [ThreadListPageResponse], but gracefully handles missing data. + * + * @see ThreadListPageResponse.data + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [ThreadListPageResponse], but gracefully handles missing data. + * + * @see ThreadListPageResponse.nextPage + */ + fun nextPageRaw(): Optional = response._nextPage().getOptional("next_page") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageRaw().isPresent + + fun nextPageParams(): ThreadListParams { + val nextCursor = + nextPageRaw().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().page(nextCursor).build() + } + + override fun nextPage(): ThreadListPage = service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): ThreadListParams = params + + /** The response that this page was parsed from. */ + fun response(): ThreadListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ThreadListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadListPage]. */ + class Builder internal constructor() { + + private var service: ThreadService? = null + private var params: ThreadListParams? = null + private var response: ThreadListPageResponse? = null + + @JvmSynthetic + internal fun from(threadListPage: ThreadListPage) = apply { + service = threadListPage.service + params = threadListPage.params + response = threadListPage.response + } + + fun service(service: ThreadService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ThreadListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ThreadListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ThreadListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ThreadListPage = + ThreadListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ThreadListPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = "ThreadListPage{service=$service, params=$params, response=$response}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPageAsync.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPageAsync.kt new file mode 100644 index 000000000..828235fbd --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPageAsync.kt @@ -0,0 +1,147 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.AutoPagerAsync +import com.anthropic.core.PageAsync +import com.anthropic.core.checkRequired +import com.anthropic.services.async.beta.sessions.ThreadServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see ThreadServiceAsync.list */ +class ThreadListPageAsync +private constructor( + private val service: ThreadServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: ThreadListParams, + private val response: ThreadListPageResponse, +) : PageAsync { + + /** + * Delegates to [ThreadListPageResponse], but gracefully handles missing data. + * + * @see ThreadListPageResponse.data + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [ThreadListPageResponse], but gracefully handles missing data. + * + * @see ThreadListPageResponse.nextPage + */ + fun nextPageRaw(): Optional = response._nextPage().getOptional("next_page") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageRaw().isPresent + + fun nextPageParams(): ThreadListParams { + val nextCursor = + nextPageRaw().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().page(nextCursor).build() + } + + override fun nextPage(): CompletableFuture = service.list(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) + + /** The parameters that were used to request this page. */ + fun params(): ThreadListParams = params + + /** The response that this page was parsed from. */ + fun response(): ThreadListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ThreadListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadListPageAsync]. */ + class Builder internal constructor() { + + private var service: ThreadServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: ThreadListParams? = null + private var response: ThreadListPageResponse? = null + + @JvmSynthetic + internal fun from(threadListPageAsync: ThreadListPageAsync) = apply { + service = threadListPageAsync.service + streamHandlerExecutor = threadListPageAsync.streamHandlerExecutor + params = threadListPageAsync.params + response = threadListPageAsync.response + } + + fun service(service: ThreadServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: ThreadListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ThreadListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ThreadListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ThreadListPageAsync = + ThreadListPageAsync( + checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ThreadListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) + + override fun toString() = + "ThreadListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPageResponse.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPageResponse.kt new file mode 100644 index 000000000..54d1b8ca9 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPageResponse.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkKnown +import com.anthropic.core.toImmutable +import com.anthropic.errors.AnthropicInvalidDataException +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 threads within a `session`. */ +class ThreadListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField>, + private val nextPage: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("next_page") @ExcludeMissing nextPage: JsonField = JsonMissing.of(), + ) : this(data, nextPage, mutableMapOf()) + + /** + * Threads in the session, primary first then children in spawn order. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun data(): Optional> = data.getOptional("data") + + /** + * Opaque cursor for the next page. Null when no more results. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextPage(): Optional = nextPage.getOptional("next_page") + + /** + * 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 [nextPage]. + * + * Unlike [nextPage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_page") @ExcludeMissing fun _nextPage(): JsonField = nextPage + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [ThreadListPageResponse]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var nextPage: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadListPageResponse: ThreadListPageResponse) = apply { + data = threadListPageResponse.data.map { it.toMutableList() } + nextPage = threadListPageResponse.nextPage + additionalProperties = threadListPageResponse.additionalProperties.toMutableMap() + } + + /** Threads in the session, primary first then children in spawn order. */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [BetaManagedAgentsSessionThread] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: BetaManagedAgentsSessionThread) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** Opaque cursor for the next page. Null when no more results. */ + fun nextPage(nextPage: String?) = nextPage(JsonField.ofNullable(nextPage)) + + /** Alias for calling [Builder.nextPage] with `nextPage.orElse(null)`. */ + fun nextPage(nextPage: Optional) = nextPage(nextPage.getOrNull()) + + /** + * Sets [Builder.nextPage] to an arbitrary JSON value. + * + * You should usually call [Builder.nextPage] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun nextPage(nextPage: JsonField) = apply { this.nextPage = nextPage } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ThreadListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ThreadListPageResponse = + ThreadListPageResponse( + (data ?: JsonMissing.of()).map { it.toImmutable() }, + nextPage, + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): ThreadListPageResponse = apply { + if (validated) { + return@apply + } + + data().ifPresent { it.forEach { it.validate() } } + nextPage() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (nextPage.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ThreadListPageResponse && + data == other.data && + nextPage == other.nextPage && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(data, nextPage, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadListPageResponse{data=$data, nextPage=$nextPage, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListParams.kt new file mode 100644 index 000000000..dee9eed57 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListParams.kt @@ -0,0 +1,276 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.Params +import com.anthropic.core.http.Headers +import com.anthropic.core.http.QueryParams +import com.anthropic.core.toImmutable +import com.anthropic.models.beta.AnthropicBeta +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** List Session Threads */ +class ThreadListParams +private constructor( + private val sessionId: String?, + private val limit: Int?, + private val page: String?, + private val betas: List?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sessionId(): Optional = Optional.ofNullable(sessionId) + + /** Maximum results per page. Defaults to 1000. */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** Opaque pagination cursor from a previous response's next_page. Forward-only. */ + fun page(): Optional = Optional.ofNullable(page) + + /** Optional header to specify the beta version(s) you want to use. */ + fun betas(): Optional> = Optional.ofNullable(betas) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): ThreadListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ThreadListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadListParams]. */ + class Builder internal constructor() { + + private var sessionId: String? = null + private var limit: Int? = null + private var page: String? = null + private var betas: MutableList? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(threadListParams: ThreadListParams) = apply { + sessionId = threadListParams.sessionId + limit = threadListParams.limit + page = threadListParams.page + betas = threadListParams.betas?.toMutableList() + additionalHeaders = threadListParams.additionalHeaders.toBuilder() + additionalQueryParams = threadListParams.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()) + + /** Maximum results per page. Defaults to 1000. */ + fun limit(limit: Int?) = apply { this.limit = limit } + + /** + * Alias for [Builder.limit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun limit(limit: Int) = limit(limit as Int?) + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + /** Opaque pagination cursor from a previous response's next_page. Forward-only. */ + fun page(page: String?) = apply { this.page = page } + + /** Alias for calling [Builder.page] with `page.orElse(null)`. */ + fun page(page: Optional) = page(page.getOrNull()) + + /** Optional header to specify the beta version(s) you want to use. */ + fun betas(betas: List?) = apply { this.betas = betas?.toMutableList() } + + /** Alias for calling [Builder.betas] with `betas.orElse(null)`. */ + fun betas(betas: Optional>) = betas(betas.getOrNull()) + + /** + * Adds a single [AnthropicBeta] to [betas]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addBeta(beta: AnthropicBeta) = apply { + betas = (betas ?: mutableListOf()).apply { add(beta) } + } + + /** + * Sets [addBeta] to an arbitrary [String]. + * + * You should usually call [addBeta] with a well-typed [AnthropicBeta] constant instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun addBeta(value: String) = addBeta(AnthropicBeta.of(value)) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [ThreadListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ThreadListParams = + ThreadListParams( + sessionId, + limit, + page, + betas?.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sessionId ?: "" + else -> "" + } + + override fun _headers(): Headers = + Headers.builder() + .apply { + betas?.forEach { put("anthropic-beta", it.toString()) } + putAll(additionalHeaders) + } + .build() + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + limit?.let { put("limit", it.toString()) } + page?.let { put("page", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ThreadListParams && + sessionId == other.sessionId && + limit == other.limit && + page == other.page && + betas == other.betas && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(sessionId, limit, page, betas, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ThreadListParams{sessionId=$sessionId, limit=$limit, page=$page, betas=$betas, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadRetrieveParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadRetrieveParams.kt new file mode 100644 index 000000000..1d05bdba7 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/ThreadRetrieveParams.kt @@ -0,0 +1,257 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.Params +import com.anthropic.core.checkRequired +import com.anthropic.core.http.Headers +import com.anthropic.core.http.QueryParams +import com.anthropic.core.toImmutable +import com.anthropic.models.beta.AnthropicBeta +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Get Session Thread */ +class ThreadRetrieveParams +private constructor( + private val sessionId: String, + private val threadId: String?, + private val betas: List?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sessionId(): String = sessionId + + fun threadId(): Optional = Optional.ofNullable(threadId) + + /** Optional header to specify the beta version(s) you want to use. */ + fun betas(): Optional> = Optional.ofNullable(betas) + + /** 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 [ThreadRetrieveParams]. + * + * The following fields are required: + * ```java + * .sessionId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ThreadRetrieveParams]. */ + class Builder internal constructor() { + + private var sessionId: String? = null + private var threadId: String? = null + private var betas: MutableList? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(threadRetrieveParams: ThreadRetrieveParams) = apply { + sessionId = threadRetrieveParams.sessionId + threadId = threadRetrieveParams.threadId + betas = threadRetrieveParams.betas?.toMutableList() + additionalHeaders = threadRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = threadRetrieveParams.additionalQueryParams.toBuilder() + } + + fun sessionId(sessionId: String) = apply { this.sessionId = sessionId } + + fun threadId(threadId: String?) = apply { this.threadId = threadId } + + /** Alias for calling [Builder.threadId] with `threadId.orElse(null)`. */ + fun threadId(threadId: Optional) = threadId(threadId.getOrNull()) + + /** Optional header to specify the beta version(s) you want to use. */ + fun betas(betas: List?) = apply { this.betas = betas?.toMutableList() } + + /** Alias for calling [Builder.betas] with `betas.orElse(null)`. */ + fun betas(betas: Optional>) = betas(betas.getOrNull()) + + /** + * Adds a single [AnthropicBeta] to [betas]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addBeta(beta: AnthropicBeta) = apply { + betas = (betas ?: mutableListOf()).apply { add(beta) } + } + + /** + * Sets [addBeta] to an arbitrary [String]. + * + * You should usually call [addBeta] with a well-typed [AnthropicBeta] constant instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun addBeta(value: String) = addBeta(AnthropicBeta.of(value)) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [ThreadRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sessionId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ThreadRetrieveParams = + ThreadRetrieveParams( + checkRequired("sessionId", sessionId), + threadId, + betas?.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sessionId + 1 -> threadId ?: "" + else -> "" + } + + override fun _headers(): Headers = + Headers.builder() + .apply { + betas?.forEach { put("anthropic-beta", it.toString()) } + putAll(additionalHeaders) + } + .build() + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ThreadRetrieveParams && + sessionId == other.sessionId && + threadId == other.threadId && + betas == other.betas && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(sessionId, threadId, betas, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ThreadRetrieveParams{sessionId=$sessionId, threadId=$threadId, betas=$betas, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPage.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPage.kt new file mode 100644 index 000000000..136c90f8e --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPage.kt @@ -0,0 +1,133 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads.events + +import com.anthropic.core.AutoPager +import com.anthropic.core.Page +import com.anthropic.core.checkRequired +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionEvent +import com.anthropic.services.blocking.beta.sessions.threads.EventService +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** @see EventService.list */ +class EventListPage +private constructor( + private val service: EventService, + private val params: EventListParams, + private val response: EventListPageResponse, +) : Page { + + /** + * Delegates to [EventListPageResponse], but gracefully handles missing data. + * + * @see EventListPageResponse.data + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [EventListPageResponse], but gracefully handles missing data. + * + * @see EventListPageResponse.nextPage + */ + fun nextPageRaw(): Optional = response._nextPage().getOptional("next_page") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageRaw().isPresent + + fun nextPageParams(): EventListParams { + val nextCursor = + nextPageRaw().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().page(nextCursor).build() + } + + override fun nextPage(): EventListPage = service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) + + /** The parameters that were used to request this page. */ + fun params(): EventListParams = params + + /** The response that this page was parsed from. */ + fun response(): EventListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EventListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EventListPage]. */ + class Builder internal constructor() { + + private var service: EventService? = null + private var params: EventListParams? = null + private var response: EventListPageResponse? = null + + @JvmSynthetic + internal fun from(eventListPage: EventListPage) = apply { + service = eventListPage.service + params = eventListPage.params + response = eventListPage.response + } + + fun service(service: EventService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: EventListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: EventListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [EventListPage]. + * + * 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(): EventListPage = + EventListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventListPage && + service == other.service && + params == other.params && + response == other.response + } + + override fun hashCode(): Int = Objects.hash(service, params, response) + + override fun toString() = "EventListPage{service=$service, params=$params, response=$response}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPageAsync.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPageAsync.kt new file mode 100644 index 000000000..e3ba357f9 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPageAsync.kt @@ -0,0 +1,148 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads.events + +import com.anthropic.core.AutoPagerAsync +import com.anthropic.core.PageAsync +import com.anthropic.core.checkRequired +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionEvent +import com.anthropic.services.async.beta.sessions.threads.EventServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import kotlin.jvm.optionals.getOrNull + +/** @see EventServiceAsync.list */ +class EventListPageAsync +private constructor( + private val service: EventServiceAsync, + private val streamHandlerExecutor: Executor, + private val params: EventListParams, + private val response: EventListPageResponse, +) : PageAsync { + + /** + * Delegates to [EventListPageResponse], but gracefully handles missing data. + * + * @see EventListPageResponse.data + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [EventListPageResponse], but gracefully handles missing data. + * + * @see EventListPageResponse.nextPage + */ + fun nextPageRaw(): Optional = response._nextPage().getOptional("next_page") + + override fun items(): List = data() + + override fun hasNextPage(): Boolean = items().isNotEmpty() && nextPageRaw().isPresent + + fun nextPageParams(): EventListParams { + val nextCursor = + nextPageRaw().getOrNull() + ?: throw IllegalStateException("Cannot construct next page params") + return params.toBuilder().page(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(): EventListParams = params + + /** The response that this page was parsed from. */ + fun response(): EventListPageResponse = response + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EventListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .streamHandlerExecutor() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EventListPageAsync]. */ + class Builder internal constructor() { + + private var service: EventServiceAsync? = null + private var streamHandlerExecutor: Executor? = null + private var params: EventListParams? = null + private var response: EventListPageResponse? = null + + @JvmSynthetic + internal fun from(eventListPageAsync: EventListPageAsync) = apply { + service = eventListPageAsync.service + streamHandlerExecutor = eventListPageAsync.streamHandlerExecutor + params = eventListPageAsync.params + response = eventListPageAsync.response + } + + fun service(service: EventServiceAsync) = apply { this.service = service } + + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + + /** The parameters that were used to request this page. */ + fun params(params: EventListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: EventListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [EventListPageAsync]. + * + * 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(): EventListPageAsync = + EventListPageAsync( + 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 EventListPageAsync && + 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() = + "EventListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPageResponse.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPageResponse.kt new file mode 100644 index 000000000..5825f5acb --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPageResponse.kt @@ -0,0 +1,539 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads.events + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkKnown +import com.anthropic.core.toImmutable +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentCustomToolUseEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentMcpToolResultEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentMcpToolUseEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentMessageEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentThinkingEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentThreadContextCompactedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentThreadMessageReceivedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentThreadMessageSentEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentToolResultEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentToolUseEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionDeletedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionErrorEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionStatusIdleEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionStatusRescheduledEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionStatusRunningEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionStatusTerminatedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadCreatedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadStatusIdleEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadStatusRescheduledEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadStatusRunningEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadStatusTerminatedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanModelRequestEndEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanModelRequestStartEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanOutcomeEvaluationEndEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanOutcomeEvaluationStartEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserCustomToolResultEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserDefineOutcomeEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserInterruptEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserMessageEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserToolConfirmationEvent +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 events for a single thread within a `session`. */ +class EventListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField>, + private val nextPage: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("next_page") @ExcludeMissing nextPage: JsonField = JsonMissing.of(), + ) : this(data, nextPage, mutableMapOf()) + + /** + * Events for the thread, ordered by `created_at`. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun data(): Optional> = data.getOptional("data") + + /** + * Opaque cursor for the next page. Null when no more results. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextPage(): Optional = nextPage.getOptional("next_page") + + /** + * 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 [nextPage]. + * + * Unlike [nextPage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_page") @ExcludeMissing fun _nextPage(): JsonField = nextPage + + @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 [EventListPageResponse]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EventListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var nextPage: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(eventListPageResponse: EventListPageResponse) = apply { + data = eventListPageResponse.data.map { it.toMutableList() } + nextPage = eventListPageResponse.nextPage + additionalProperties = eventListPageResponse.additionalProperties.toMutableMap() + } + + /** Events for the thread, ordered by `created_at`. */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [BetaManagedAgentsSessionEvent] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: BetaManagedAgentsSessionEvent) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofUserMessage(userMessage)`. + */ + fun addData(userMessage: BetaManagedAgentsUserMessageEvent) = + addData(BetaManagedAgentsSessionEvent.ofUserMessage(userMessage)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofUserInterrupt(userInterrupt)`. + */ + fun addData(userInterrupt: BetaManagedAgentsUserInterruptEvent) = + addData(BetaManagedAgentsSessionEvent.ofUserInterrupt(userInterrupt)) + + /** + * Alias for calling [addData] with the following: + * ```java + * BetaManagedAgentsUserInterruptEvent.builder() + * .type(BetaManagedAgentsUserInterruptEvent.Type.USER_INTERRUPT) + * .id(id) + * .build() + * ``` + */ + fun addUserInterruptData(id: String) = + addData( + BetaManagedAgentsUserInterruptEvent.builder() + .type(BetaManagedAgentsUserInterruptEvent.Type.USER_INTERRUPT) + .id(id) + .build() + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofUserToolConfirmation(userToolConfirmation)`. + */ + fun addData(userToolConfirmation: BetaManagedAgentsUserToolConfirmationEvent) = + addData(BetaManagedAgentsSessionEvent.ofUserToolConfirmation(userToolConfirmation)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofUserCustomToolResult(userCustomToolResult)`. + */ + fun addData(userCustomToolResult: BetaManagedAgentsUserCustomToolResultEvent) = + addData(BetaManagedAgentsSessionEvent.ofUserCustomToolResult(userCustomToolResult)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofAgentCustomToolUse(agentCustomToolUse)`. + */ + fun addData(agentCustomToolUse: BetaManagedAgentsAgentCustomToolUseEvent) = + addData(BetaManagedAgentsSessionEvent.ofAgentCustomToolUse(agentCustomToolUse)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofAgentMessage(agentMessage)`. + */ + fun addData(agentMessage: BetaManagedAgentsAgentMessageEvent) = + addData(BetaManagedAgentsSessionEvent.ofAgentMessage(agentMessage)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofAgentThinking(agentThinking)`. + */ + fun addData(agentThinking: BetaManagedAgentsAgentThinkingEvent) = + addData(BetaManagedAgentsSessionEvent.ofAgentThinking(agentThinking)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofAgentMcpToolUse(agentMcpToolUse)`. + */ + fun addData(agentMcpToolUse: BetaManagedAgentsAgentMcpToolUseEvent) = + addData(BetaManagedAgentsSessionEvent.ofAgentMcpToolUse(agentMcpToolUse)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofAgentMcpToolResult(agentMcpToolResult)`. + */ + fun addData(agentMcpToolResult: BetaManagedAgentsAgentMcpToolResultEvent) = + addData(BetaManagedAgentsSessionEvent.ofAgentMcpToolResult(agentMcpToolResult)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofAgentToolUse(agentToolUse)`. + */ + fun addData(agentToolUse: BetaManagedAgentsAgentToolUseEvent) = + addData(BetaManagedAgentsSessionEvent.ofAgentToolUse(agentToolUse)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofAgentToolResult(agentToolResult)`. + */ + fun addData(agentToolResult: BetaManagedAgentsAgentToolResultEvent) = + addData(BetaManagedAgentsSessionEvent.ofAgentToolResult(agentToolResult)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofAgentThreadMessageReceived(agentThreadMessageReceived)`. + */ + fun addData(agentThreadMessageReceived: BetaManagedAgentsAgentThreadMessageReceivedEvent) = + addData( + BetaManagedAgentsSessionEvent.ofAgentThreadMessageReceived( + agentThreadMessageReceived + ) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofAgentThreadMessageSent(agentThreadMessageSent)`. + */ + fun addData(agentThreadMessageSent: BetaManagedAgentsAgentThreadMessageSentEvent) = + addData(BetaManagedAgentsSessionEvent.ofAgentThreadMessageSent(agentThreadMessageSent)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofAgentThreadContextCompacted(agentThreadContextCompacted)`. + */ + fun addData( + agentThreadContextCompacted: BetaManagedAgentsAgentThreadContextCompactedEvent + ) = + addData( + BetaManagedAgentsSessionEvent.ofAgentThreadContextCompacted( + agentThreadContextCompacted + ) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionError(sessionError)`. + */ + fun addData(sessionError: BetaManagedAgentsSessionErrorEvent) = + addData(BetaManagedAgentsSessionEvent.ofSessionError(sessionError)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionStatusRescheduled(sessionStatusRescheduled)`. + */ + fun addData(sessionStatusRescheduled: BetaManagedAgentsSessionStatusRescheduledEvent) = + addData( + BetaManagedAgentsSessionEvent.ofSessionStatusRescheduled(sessionStatusRescheduled) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionStatusRunning(sessionStatusRunning)`. + */ + fun addData(sessionStatusRunning: BetaManagedAgentsSessionStatusRunningEvent) = + addData(BetaManagedAgentsSessionEvent.ofSessionStatusRunning(sessionStatusRunning)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionStatusIdle(sessionStatusIdle)`. + */ + fun addData(sessionStatusIdle: BetaManagedAgentsSessionStatusIdleEvent) = + addData(BetaManagedAgentsSessionEvent.ofSessionStatusIdle(sessionStatusIdle)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionStatusTerminated(sessionStatusTerminated)`. + */ + fun addData(sessionStatusTerminated: BetaManagedAgentsSessionStatusTerminatedEvent) = + addData( + BetaManagedAgentsSessionEvent.ofSessionStatusTerminated(sessionStatusTerminated) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionThreadCreated(sessionThreadCreated)`. + */ + fun addData(sessionThreadCreated: BetaManagedAgentsSessionThreadCreatedEvent) = + addData(BetaManagedAgentsSessionEvent.ofSessionThreadCreated(sessionThreadCreated)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationStart(spanOutcomeEvaluationStart)`. + */ + fun addData(spanOutcomeEvaluationStart: BetaManagedAgentsSpanOutcomeEvaluationStartEvent) = + addData( + BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart + ) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationEnd(spanOutcomeEvaluationEnd)`. + */ + fun addData(spanOutcomeEvaluationEnd: BetaManagedAgentsSpanOutcomeEvaluationEndEvent) = + addData( + BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationEnd(spanOutcomeEvaluationEnd) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSpanModelRequestStart(spanModelRequestStart)`. + */ + fun addData(spanModelRequestStart: BetaManagedAgentsSpanModelRequestStartEvent) = + addData(BetaManagedAgentsSessionEvent.ofSpanModelRequestStart(spanModelRequestStart)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSpanModelRequestEnd(spanModelRequestEnd)`. + */ + fun addData(spanModelRequestEnd: BetaManagedAgentsSpanModelRequestEndEvent) = + addData(BetaManagedAgentsSessionEvent.ofSpanModelRequestEnd(spanModelRequestEnd)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationOngoing(spanOutcomeEvaluationOngoing)`. + */ + fun addData( + spanOutcomeEvaluationOngoing: BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent + ) = + addData( + BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing + ) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofUserDefineOutcome(userDefineOutcome)`. + */ + fun addData(userDefineOutcome: BetaManagedAgentsUserDefineOutcomeEvent) = + addData(BetaManagedAgentsSessionEvent.ofUserDefineOutcome(userDefineOutcome)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionDeleted(sessionDeleted)`. + */ + fun addData(sessionDeleted: BetaManagedAgentsSessionDeletedEvent) = + addData(BetaManagedAgentsSessionEvent.ofSessionDeleted(sessionDeleted)) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionThreadStatusRunning(sessionThreadStatusRunning)`. + */ + fun addData(sessionThreadStatusRunning: BetaManagedAgentsSessionThreadStatusRunningEvent) = + addData( + BetaManagedAgentsSessionEvent.ofSessionThreadStatusRunning( + sessionThreadStatusRunning + ) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionThreadStatusIdle(sessionThreadStatusIdle)`. + */ + fun addData(sessionThreadStatusIdle: BetaManagedAgentsSessionThreadStatusIdleEvent) = + addData( + BetaManagedAgentsSessionEvent.ofSessionThreadStatusIdle(sessionThreadStatusIdle) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionThreadStatusTerminated(sessionThreadStatusTerminated)`. + */ + fun addData( + sessionThreadStatusTerminated: BetaManagedAgentsSessionThreadStatusTerminatedEvent + ) = + addData( + BetaManagedAgentsSessionEvent.ofSessionThreadStatusTerminated( + sessionThreadStatusTerminated + ) + ) + + /** + * Alias for calling [addData] with + * `BetaManagedAgentsSessionEvent.ofSessionThreadStatusRescheduled(sessionThreadStatusRescheduled)`. + */ + fun addData( + sessionThreadStatusRescheduled: BetaManagedAgentsSessionThreadStatusRescheduledEvent + ) = + addData( + BetaManagedAgentsSessionEvent.ofSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled + ) + ) + + /** Opaque cursor for the next page. Null when no more results. */ + fun nextPage(nextPage: String?) = nextPage(JsonField.ofNullable(nextPage)) + + /** Alias for calling [Builder.nextPage] with `nextPage.orElse(null)`. */ + fun nextPage(nextPage: Optional) = nextPage(nextPage.getOrNull()) + + /** + * Sets [Builder.nextPage] to an arbitrary JSON value. + * + * You should usually call [Builder.nextPage] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun nextPage(nextPage: JsonField) = apply { this.nextPage = nextPage } + + 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 [EventListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): EventListPageResponse = + EventListPageResponse( + (data ?: JsonMissing.of()).map { it.toImmutable() }, + nextPage, + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): EventListPageResponse = apply { + if (validated) { + return@apply + } + + data().ifPresent { it.forEach { it.validate() } } + nextPage() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (nextPage.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventListPageResponse && + data == other.data && + nextPage == other.nextPage && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(data, nextPage, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventListPageResponse{data=$data, nextPage=$nextPage, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListParams.kt new file mode 100644 index 000000000..0740257e1 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListParams.kt @@ -0,0 +1,307 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads.events + +import com.anthropic.core.Params +import com.anthropic.core.checkRequired +import com.anthropic.core.http.Headers +import com.anthropic.core.http.QueryParams +import com.anthropic.core.toImmutable +import com.anthropic.models.beta.AnthropicBeta +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** List Session Thread Events */ +class EventListParams +private constructor( + private val sessionId: String, + private val threadId: String?, + private val limit: Int?, + private val page: String?, + private val betas: List?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sessionId(): String = sessionId + + fun threadId(): Optional = Optional.ofNullable(threadId) + + /** Query parameter for limit */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** Query parameter for page */ + fun page(): Optional = Optional.ofNullable(page) + + /** Optional header to specify the beta version(s) you want to use. */ + fun betas(): Optional> = Optional.ofNullable(betas) + + /** 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 [EventListParams]. + * + * The following fields are required: + * ```java + * .sessionId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EventListParams]. */ + class Builder internal constructor() { + + private var sessionId: String? = null + private var threadId: String? = null + private var limit: Int? = null + private var page: String? = null + private var betas: MutableList? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(eventListParams: EventListParams) = apply { + sessionId = eventListParams.sessionId + threadId = eventListParams.threadId + limit = eventListParams.limit + page = eventListParams.page + betas = eventListParams.betas?.toMutableList() + additionalHeaders = eventListParams.additionalHeaders.toBuilder() + additionalQueryParams = eventListParams.additionalQueryParams.toBuilder() + } + + fun sessionId(sessionId: String) = apply { this.sessionId = sessionId } + + fun threadId(threadId: String?) = apply { this.threadId = threadId } + + /** Alias for calling [Builder.threadId] with `threadId.orElse(null)`. */ + fun threadId(threadId: Optional) = threadId(threadId.getOrNull()) + + /** Query parameter for limit */ + fun limit(limit: Int?) = apply { this.limit = limit } + + /** + * Alias for [Builder.limit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun limit(limit: Int) = limit(limit as Int?) + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + /** Query parameter for page */ + fun page(page: String?) = apply { this.page = page } + + /** Alias for calling [Builder.page] with `page.orElse(null)`. */ + fun page(page: Optional) = page(page.getOrNull()) + + /** Optional header to specify the beta version(s) you want to use. */ + fun betas(betas: List?) = apply { this.betas = betas?.toMutableList() } + + /** Alias for calling [Builder.betas] with `betas.orElse(null)`. */ + fun betas(betas: Optional>) = betas(betas.getOrNull()) + + /** + * Adds a single [AnthropicBeta] to [betas]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addBeta(beta: AnthropicBeta) = apply { + betas = (betas ?: mutableListOf()).apply { add(beta) } + } + + /** + * Sets [addBeta] to an arbitrary [String]. + * + * You should usually call [addBeta] with a well-typed [AnthropicBeta] constant instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun addBeta(value: String) = addBeta(AnthropicBeta.of(value)) + + 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 [EventListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sessionId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventListParams = + EventListParams( + checkRequired("sessionId", sessionId), + threadId, + limit, + page, + betas?.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sessionId + 1 -> threadId ?: "" + else -> "" + } + + override fun _headers(): Headers = + Headers.builder() + .apply { + betas?.forEach { put("anthropic-beta", it.toString()) } + putAll(additionalHeaders) + } + .build() + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + limit?.let { put("limit", it.toString()) } + page?.let { put("page", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventListParams && + sessionId == other.sessionId && + threadId == other.threadId && + limit == other.limit && + page == other.page && + betas == other.betas && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + sessionId, + threadId, + limit, + page, + betas, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "EventListParams{sessionId=$sessionId, threadId=$threadId, limit=$limit, page=$page, betas=$betas, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventStreamParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventStreamParams.kt new file mode 100644 index 000000000..f02f8bf65 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/sessions/threads/events/EventStreamParams.kt @@ -0,0 +1,257 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads.events + +import com.anthropic.core.Params +import com.anthropic.core.checkRequired +import com.anthropic.core.http.Headers +import com.anthropic.core.http.QueryParams +import com.anthropic.core.toImmutable +import com.anthropic.models.beta.AnthropicBeta +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Stream Session Thread Events */ +class EventStreamParams +private constructor( + private val sessionId: String, + private val threadId: String?, + private val betas: List?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun sessionId(): String = sessionId + + fun threadId(): Optional = Optional.ofNullable(threadId) + + /** Optional header to specify the beta version(s) you want to use. */ + fun betas(): Optional> = Optional.ofNullable(betas) + + /** 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 [EventStreamParams]. + * + * The following fields are required: + * ```java + * .sessionId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EventStreamParams]. */ + class Builder internal constructor() { + + private var sessionId: String? = null + private var threadId: String? = null + private var betas: MutableList? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(eventStreamParams: EventStreamParams) = apply { + sessionId = eventStreamParams.sessionId + threadId = eventStreamParams.threadId + betas = eventStreamParams.betas?.toMutableList() + additionalHeaders = eventStreamParams.additionalHeaders.toBuilder() + additionalQueryParams = eventStreamParams.additionalQueryParams.toBuilder() + } + + fun sessionId(sessionId: String) = apply { this.sessionId = sessionId } + + fun threadId(threadId: String?) = apply { this.threadId = threadId } + + /** Alias for calling [Builder.threadId] with `threadId.orElse(null)`. */ + fun threadId(threadId: Optional) = threadId(threadId.getOrNull()) + + /** Optional header to specify the beta version(s) you want to use. */ + fun betas(betas: List?) = apply { this.betas = betas?.toMutableList() } + + /** Alias for calling [Builder.betas] with `betas.orElse(null)`. */ + fun betas(betas: Optional>) = betas(betas.getOrNull()) + + /** + * Adds a single [AnthropicBeta] to [betas]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addBeta(beta: AnthropicBeta) = apply { + betas = (betas ?: mutableListOf()).apply { add(beta) } + } + + /** + * Sets [addBeta] to an arbitrary [String]. + * + * You should usually call [addBeta] with a well-typed [AnthropicBeta] constant instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun addBeta(value: String) = addBeta(AnthropicBeta.of(value)) + + 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 [EventStreamParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sessionId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventStreamParams = + EventStreamParams( + checkRequired("sessionId", sessionId), + threadId, + betas?.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> sessionId + 1 -> threadId ?: "" + else -> "" + } + + override fun _headers(): Headers = + Headers.builder() + .apply { + betas?.forEach { put("anthropic-beta", it.toString()) } + putAll(additionalHeaders) + } + .build() + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventStreamParams && + sessionId == other.sessionId && + threadId == other.threadId && + betas == other.betas && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(sessionId, threadId, betas, additionalHeaders, additionalQueryParams) + + override fun toString() = + "EventStreamParams{sessionId=$sessionId, threadId=$threadId, betas=$betas, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/userprofiles/BetaUserProfile.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/userprofiles/BetaUserProfile.kt index 0a23c9360..c145ebde6 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/userprofiles/BetaUserProfile.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/userprofiles/BetaUserProfile.kt @@ -26,10 +26,12 @@ private constructor( private val id: JsonField, private val createdAt: JsonField, private val metadata: JsonField, + private val relationship: JsonField, private val trustGrants: JsonField, private val type: JsonField, private val updatedAt: JsonField, private val externalId: JsonField, + private val name: JsonField, private val additionalProperties: MutableMap, ) { @@ -40,6 +42,9 @@ private constructor( @ExcludeMissing createdAt: JsonField = JsonMissing.of(), @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("relationship") + @ExcludeMissing + relationship: JsonField = JsonMissing.of(), @JsonProperty("trust_grants") @ExcludeMissing trustGrants: JsonField = JsonMissing.of(), @@ -50,7 +55,19 @@ private constructor( @JsonProperty("external_id") @ExcludeMissing externalId: JsonField = JsonMissing.of(), - ) : this(id, createdAt, metadata, trustGrants, type, updatedAt, externalId, mutableMapOf()) + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this( + id, + createdAt, + metadata, + relationship, + trustGrants, + type, + updatedAt, + externalId, + name, + mutableMapOf(), + ) /** * Unique identifier for this user profile, prefixed `uprof_`. @@ -76,6 +93,16 @@ private constructor( */ fun metadata(): Metadata = metadata.getRequired("metadata") + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform resells + * Claude access to. `internal`: the platform's own usage. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun relationship(): Relationship = relationship.getRequired("relationship") + /** * Trust grants for this profile, keyed by grant name. Key omitted when no grant is active or in * flight. @@ -109,6 +136,15 @@ private constructor( */ fun externalId(): Optional = externalId.getOptional("external_id") + /** + * Display name of the entity this profile represents. For `resold` this is the resold-to + * company's name. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + /** * Returns the raw JSON value of [id]. * @@ -132,6 +168,15 @@ private constructor( */ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + /** + * Returns the raw JSON value of [relationship]. + * + * Unlike [relationship], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("relationship") + @ExcludeMissing + fun _relationship(): JsonField = relationship + /** * Returns the raw JSON value of [trustGrants]. * @@ -164,6 +209,13 @@ private constructor( */ @JsonProperty("external_id") @ExcludeMissing fun _externalId(): JsonField = externalId + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -186,6 +238,7 @@ private constructor( * .id() * .createdAt() * .metadata() + * .relationship() * .trustGrants() * .type() * .updatedAt() @@ -200,10 +253,12 @@ private constructor( private var id: JsonField? = null private var createdAt: JsonField? = null private var metadata: JsonField? = null + private var relationship: JsonField? = null private var trustGrants: JsonField? = null private var type: JsonField? = null private var updatedAt: JsonField? = null private var externalId: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -211,10 +266,12 @@ private constructor( id = betaUserProfile.id createdAt = betaUserProfile.createdAt metadata = betaUserProfile.metadata + relationship = betaUserProfile.relationship trustGrants = betaUserProfile.trustGrants type = betaUserProfile.type updatedAt = betaUserProfile.updatedAt externalId = betaUserProfile.externalId + name = betaUserProfile.name additionalProperties = betaUserProfile.additionalProperties.toMutableMap() } @@ -256,6 +313,24 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform + * resells Claude access to. `internal`: the platform's own usage. + */ + fun relationship(relationship: Relationship) = relationship(JsonField.of(relationship)) + + /** + * Sets [Builder.relationship] to an arbitrary JSON value. + * + * You should usually call [Builder.relationship] with a well-typed [Relationship] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun relationship(relationship: JsonField) = apply { + this.relationship = relationship + } + /** * Trust grants for this profile, keyed by grant name. Key omitted when no grant is active * or in flight. @@ -311,6 +386,23 @@ private constructor( */ fun externalId(externalId: JsonField) = apply { this.externalId = externalId } + /** + * Display name of the entity this profile represents. For `resold` this is the resold-to + * company's name. + */ + 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 } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -340,6 +432,7 @@ private constructor( * .id() * .createdAt() * .metadata() + * .relationship() * .trustGrants() * .type() * .updatedAt() @@ -352,10 +445,12 @@ private constructor( checkRequired("id", id), checkRequired("createdAt", createdAt), checkRequired("metadata", metadata), + checkRequired("relationship", relationship), checkRequired("trustGrants", trustGrants), checkRequired("type", type), checkRequired("updatedAt", updatedAt), externalId, + name, additionalProperties.toMutableMap(), ) } @@ -378,10 +473,12 @@ private constructor( id() createdAt() metadata().validate() + relationship().validate() trustGrants().validate() type().validate() updatedAt() externalId() + name() validated = true } @@ -403,10 +500,12 @@ private constructor( (if (id.asKnown().isPresent) 1 else 0) + (if (createdAt.asKnown().isPresent) 1 else 0) + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (relationship.asKnown().getOrNull()?.validity() ?: 0) + (trustGrants.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + (if (updatedAt.asKnown().isPresent) 1 else 0) + - (if (externalId.asKnown().isPresent) 1 else 0) + (if (externalId.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) /** * Arbitrary key-value metadata. Maximum 16 pairs, keys up to 64 chars, values up to 512 chars. @@ -519,6 +618,156 @@ private constructor( override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform resells + * Claude access to. `internal`: the platform's own usage. + */ + class Relationship @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 EXTERNAL = of("external") + + @JvmField val RESOLD = of("resold") + + @JvmField val INTERNAL = of("internal") + + @JvmStatic fun of(value: String) = Relationship(JsonField.of(value)) + } + + /** An enum containing [Relationship]'s known values. */ + enum class Known { + EXTERNAL, + RESOLD, + INTERNAL, + } + + /** + * An enum containing [Relationship]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Relationship] 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 { + EXTERNAL, + RESOLD, + INTERNAL, + /** + * An enum member indicating that [Relationship] 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) { + EXTERNAL -> Value.EXTERNAL + RESOLD -> Value.RESOLD + INTERNAL -> Value.INTERNAL + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + EXTERNAL -> Known.EXTERNAL + RESOLD -> Known.RESOLD + INTERNAL -> Known.INTERNAL + else -> throw AnthropicInvalidDataException("Unknown Relationship: $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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Relationship = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 Relationship && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + /** * Trust grants for this profile, keyed by grant name. Key omitted when no grant is active or in * flight. @@ -771,10 +1020,12 @@ private constructor( id == other.id && createdAt == other.createdAt && metadata == other.metadata && + relationship == other.relationship && trustGrants == other.trustGrants && type == other.type && updatedAt == other.updatedAt && externalId == other.externalId && + name == other.name && additionalProperties == other.additionalProperties } @@ -783,10 +1034,12 @@ private constructor( id, createdAt, metadata, + relationship, trustGrants, type, updatedAt, externalId, + name, additionalProperties, ) } @@ -794,5 +1047,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "BetaUserProfile{id=$id, createdAt=$createdAt, metadata=$metadata, trustGrants=$trustGrants, type=$type, updatedAt=$updatedAt, externalId=$externalId, additionalProperties=$additionalProperties}" + "BetaUserProfile{id=$id, createdAt=$createdAt, metadata=$metadata, relationship=$relationship, trustGrants=$trustGrants, type=$type, updatedAt=$updatedAt, externalId=$externalId, name=$name, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/userprofiles/UserProfileCreateParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/userprofiles/UserProfileCreateParams.kt index 11f1eeff5..0982fa7b6 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/userprofiles/UserProfileCreateParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/userprofiles/UserProfileCreateParams.kt @@ -2,6 +2,7 @@ package com.anthropic.models.beta.userprofiles +import com.anthropic.core.Enum import com.anthropic.core.ExcludeMissing import com.anthropic.core.JsonField import com.anthropic.core.JsonMissing @@ -50,6 +51,25 @@ private constructor( */ fun metadata(): Optional = body.metadata() + /** + * Display name of the entity this profile represents. Required when relationship is `resold` + * (the resold-to company's name); optional otherwise. Maximum 255 characters. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = body.name() + + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform resells + * Claude access to. `internal`: the platform's own usage. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun relationship(): Optional = body.relationship() + /** * Returns the raw JSON value of [externalId]. * @@ -64,6 +84,20 @@ private constructor( */ fun _metadata(): JsonField = body._metadata() + /** + * 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 [relationship]. + * + * Unlike [relationship], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _relationship(): JsonField = body._relationship() + fun _additionalBodyProperties(): Map = body._additionalProperties() /** Additional headers to send with the request. */ @@ -129,6 +163,8 @@ private constructor( * Otherwise, it's more convenient to use the top-level setters instead: * - [externalId] * - [metadata] + * - [name] + * - [relationship] */ fun body(body: Body) = apply { this.body = body.toBuilder() } @@ -162,6 +198,41 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + /** + * Display name of the entity this profile represents. Required when relationship is + * `resold` (the resold-to company's name); optional otherwise. Maximum 255 characters. + */ + 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) } + + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform + * resells Claude access to. `internal`: the platform's own usage. + */ + fun relationship(relationship: Relationship) = apply { body.relationship(relationship) } + + /** + * Sets [Builder.relationship] to an arbitrary JSON value. + * + * You should usually call [Builder.relationship] with a well-typed [Relationship] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun relationship(relationship: JsonField) = apply { + body.relationship(relationship) + } + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { body.additionalProperties(additionalBodyProperties) } @@ -310,6 +381,8 @@ private constructor( private constructor( private val externalId: JsonField, private val metadata: JsonField, + private val name: JsonField, + private val relationship: JsonField, private val additionalProperties: MutableMap, ) { @@ -321,7 +394,11 @@ private constructor( @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), - ) : this(externalId, metadata, mutableMapOf()) + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("relationship") + @ExcludeMissing + relationship: JsonField = JsonMissing.of(), + ) : this(externalId, metadata, name, relationship, mutableMapOf()) /** * Platform's own identifier for this user. Not enforced unique. Maximum 255 characters. @@ -340,6 +417,25 @@ private constructor( */ fun metadata(): Optional = metadata.getOptional("metadata") + /** + * Display name of the entity this profile represents. Required when relationship is + * `resold` (the resold-to company's name); optional otherwise. Maximum 255 characters. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform + * resells Claude access to. `internal`: the platform's own usage. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun relationship(): Optional = relationship.getOptional("relationship") + /** * Returns the raw JSON value of [externalId]. * @@ -356,6 +452,23 @@ private constructor( */ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + /** + * 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 [relationship]. + * + * Unlike [relationship], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("relationship") + @ExcludeMissing + fun _relationship(): JsonField = relationship + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -379,12 +492,16 @@ private constructor( private var externalId: JsonField = JsonMissing.of() private var metadata: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var relationship: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(body: Body) = apply { externalId = body.externalId metadata = body.metadata + name = body.name + relationship = body.relationship additionalProperties = body.additionalProperties.toMutableMap() } @@ -421,6 +538,42 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + /** + * Display name of the entity this profile represents. Required when relationship is + * `resold` (the resold-to company's name); optional otherwise. Maximum 255 characters. + */ + 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 } + + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform + * resells Claude access to. `internal`: the platform's own usage. + */ + fun relationship(relationship: Relationship) = relationship(JsonField.of(relationship)) + + /** + * Sets [Builder.relationship] to an arbitrary JSON value. + * + * You should usually call [Builder.relationship] with a well-typed [Relationship] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun relationship(relationship: JsonField) = apply { + this.relationship = relationship + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -445,7 +598,8 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Body = Body(externalId, metadata, additionalProperties.toMutableMap()) + fun build(): Body = + Body(externalId, metadata, name, relationship, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -466,6 +620,8 @@ private constructor( externalId() metadata().ifPresent { it.validate() } + name() + relationship().ifPresent { it.validate() } validated = true } @@ -486,7 +642,9 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (externalId.asKnown().isPresent) 1 else 0) + - (metadata.asKnown().getOrNull()?.validity() ?: 0) + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (relationship.asKnown().getOrNull()?.validity() ?: 0) override fun equals(other: Any?): Boolean { if (this === other) { @@ -496,17 +654,19 @@ private constructor( return other is Body && externalId == other.externalId && metadata == other.metadata && + name == other.name && + relationship == other.relationship && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(externalId, metadata, additionalProperties) + Objects.hash(externalId, metadata, name, relationship, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "Body{externalId=$externalId, metadata=$metadata, additionalProperties=$additionalProperties}" + "Body{externalId=$externalId, metadata=$metadata, name=$name, relationship=$relationship, additionalProperties=$additionalProperties}" } /** @@ -621,6 +781,156 @@ private constructor( override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform resells + * Claude access to. `internal`: the platform's own usage. + */ + class Relationship @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 EXTERNAL = of("external") + + @JvmField val RESOLD = of("resold") + + @JvmField val INTERNAL = of("internal") + + @JvmStatic fun of(value: String) = Relationship(JsonField.of(value)) + } + + /** An enum containing [Relationship]'s known values. */ + enum class Known { + EXTERNAL, + RESOLD, + INTERNAL, + } + + /** + * An enum containing [Relationship]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Relationship] 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 { + EXTERNAL, + RESOLD, + INTERNAL, + /** + * An enum member indicating that [Relationship] 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) { + EXTERNAL -> Value.EXTERNAL + RESOLD -> Value.RESOLD + INTERNAL -> Value.INTERNAL + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + EXTERNAL -> Known.EXTERNAL + RESOLD -> Known.RESOLD + INTERNAL -> Known.INTERNAL + else -> throw AnthropicInvalidDataException("Unknown Relationship: $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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Relationship = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 Relationship && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/userprofiles/UserProfileUpdateParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/userprofiles/UserProfileUpdateParams.kt index ceeddde67..399815408 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/userprofiles/UserProfileUpdateParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/userprofiles/UserProfileUpdateParams.kt @@ -2,6 +2,7 @@ package com.anthropic.models.beta.userprofiles +import com.anthropic.core.Enum import com.anthropic.core.ExcludeMissing import com.anthropic.core.JsonField import com.anthropic.core.JsonMissing @@ -54,6 +55,24 @@ private constructor( */ fun metadata(): Optional = body.metadata() + /** + * If present, replaces the stored name. Omit to leave unchanged. Maximum 255 characters. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = body.name() + + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform resells + * Claude access to. `internal`: the platform's own usage. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun relationship(): Optional = body.relationship() + /** * Returns the raw JSON value of [externalId]. * @@ -68,6 +87,20 @@ private constructor( */ fun _metadata(): JsonField = body._metadata() + /** + * 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 [relationship]. + * + * Unlike [relationship], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _relationship(): JsonField = body._relationship() + fun _additionalBodyProperties(): Map = body._additionalProperties() /** Additional headers to send with the request. */ @@ -141,6 +174,8 @@ private constructor( * Otherwise, it's more convenient to use the top-level setters instead: * - [externalId] * - [metadata] + * - [name] + * - [relationship] */ fun body(body: Body) = apply { this.body = body.toBuilder() } @@ -179,6 +214,44 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + /** + * If present, replaces the stored name. Omit to leave unchanged. Maximum 255 characters. + */ + 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) } + + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform + * resells Claude access to. `internal`: the platform's own usage. + */ + fun relationship(relationship: Relationship?) = apply { body.relationship(relationship) } + + /** Alias for calling [Builder.relationship] with `relationship.orElse(null)`. */ + fun relationship(relationship: Optional) = + relationship(relationship.getOrNull()) + + /** + * Sets [Builder.relationship] to an arbitrary JSON value. + * + * You should usually call [Builder.relationship] with a well-typed [Relationship] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun relationship(relationship: JsonField) = apply { + body.relationship(relationship) + } + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { body.additionalProperties(additionalBodyProperties) } @@ -334,6 +407,8 @@ private constructor( private constructor( private val externalId: JsonField, private val metadata: JsonField, + private val name: JsonField, + private val relationship: JsonField, private val additionalProperties: MutableMap, ) { @@ -345,7 +420,11 @@ private constructor( @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), - ) : this(externalId, metadata, mutableMapOf()) + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("relationship") + @ExcludeMissing + relationship: JsonField = JsonMissing.of(), + ) : this(externalId, metadata, name, relationship, mutableMapOf()) /** * If present, replaces the stored external_id. Omit to leave unchanged. Maximum 255 @@ -367,6 +446,24 @@ private constructor( */ fun metadata(): Optional = metadata.getOptional("metadata") + /** + * If present, replaces the stored name. Omit to leave unchanged. Maximum 255 characters. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform + * resells Claude access to. `internal`: the platform's own usage. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun relationship(): Optional = relationship.getOptional("relationship") + /** * Returns the raw JSON value of [externalId]. * @@ -383,6 +480,23 @@ private constructor( */ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + /** + * 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 [relationship]. + * + * Unlike [relationship], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("relationship") + @ExcludeMissing + fun _relationship(): JsonField = relationship + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -406,12 +520,16 @@ private constructor( private var externalId: JsonField = JsonMissing.of() private var metadata: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var relationship: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(body: Body) = apply { externalId = body.externalId metadata = body.metadata + name = body.name + relationship = body.relationship additionalProperties = body.additionalProperties.toMutableMap() } @@ -450,6 +568,47 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + /** + * If present, replaces the stored name. Omit to leave unchanged. Maximum 255 + * characters. + */ + 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 } + + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform + * resells Claude access to. `internal`: the platform's own usage. + */ + fun relationship(relationship: Relationship?) = + relationship(JsonField.ofNullable(relationship)) + + /** Alias for calling [Builder.relationship] with `relationship.orElse(null)`. */ + fun relationship(relationship: Optional) = + relationship(relationship.getOrNull()) + + /** + * Sets [Builder.relationship] to an arbitrary JSON value. + * + * You should usually call [Builder.relationship] with a well-typed [Relationship] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun relationship(relationship: JsonField) = apply { + this.relationship = relationship + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -474,7 +633,8 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Body = Body(externalId, metadata, additionalProperties.toMutableMap()) + fun build(): Body = + Body(externalId, metadata, name, relationship, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -495,6 +655,8 @@ private constructor( externalId() metadata().ifPresent { it.validate() } + name() + relationship().ifPresent { it.validate() } validated = true } @@ -515,7 +677,9 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (externalId.asKnown().isPresent) 1 else 0) + - (metadata.asKnown().getOrNull()?.validity() ?: 0) + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (relationship.asKnown().getOrNull()?.validity() ?: 0) override fun equals(other: Any?): Boolean { if (this === other) { @@ -525,17 +689,19 @@ private constructor( return other is Body && externalId == other.externalId && metadata == other.metadata && + name == other.name && + relationship == other.relationship && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(externalId, metadata, additionalProperties) + Objects.hash(externalId, metadata, name, relationship, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "Body{externalId=$externalId, metadata=$metadata, additionalProperties=$additionalProperties}" + "Body{externalId=$externalId, metadata=$metadata, name=$name, relationship=$relationship, additionalProperties=$additionalProperties}" } /** @@ -651,6 +817,156 @@ private constructor( override fun toString() = "Metadata{additionalProperties=$additionalProperties}" } + /** + * How the entity behind a user profile relates to the platform that owns the API key. + * `external`: an individual end-user of the platform. `resold`: a company the platform resells + * Claude access to. `internal`: the platform's own usage. + */ + class Relationship @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 EXTERNAL = of("external") + + @JvmField val RESOLD = of("resold") + + @JvmField val INTERNAL = of("internal") + + @JvmStatic fun of(value: String) = Relationship(JsonField.of(value)) + } + + /** An enum containing [Relationship]'s known values. */ + enum class Known { + EXTERNAL, + RESOLD, + INTERNAL, + } + + /** + * An enum containing [Relationship]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Relationship] 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 { + EXTERNAL, + RESOLD, + INTERNAL, + /** + * An enum member indicating that [Relationship] 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) { + EXTERNAL -> Value.EXTERNAL + RESOLD -> Value.RESOLD + INTERNAL -> Value.INTERNAL + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + EXTERNAL -> Known.EXTERNAL + RESOLD -> Known.RESOLD + INTERNAL -> Known.INTERNAL + else -> throw AnthropicInvalidDataException("Unknown Relationship: $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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Relationship = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 Relationship && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsCredentialValidation.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsCredentialValidation.kt new file mode 100644 index 000000000..f2b70d257 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsCredentialValidation.kt @@ -0,0 +1,646 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.vaults.credentials + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +/** Result of live-probing a credential against its configured MCP server. */ +class BetaManagedAgentsCredentialValidation +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val credentialId: JsonField, + private val hasRefreshToken: JsonField, + private val mcpProbe: JsonField, + private val refresh: JsonField, + private val status: JsonField, + private val type: JsonField, + private val validatedAt: JsonField, + private val vaultId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("credential_id") + @ExcludeMissing + credentialId: JsonField = JsonMissing.of(), + @JsonProperty("has_refresh_token") + @ExcludeMissing + hasRefreshToken: JsonField = JsonMissing.of(), + @JsonProperty("mcp_probe") + @ExcludeMissing + mcpProbe: JsonField = JsonMissing.of(), + @JsonProperty("refresh") + @ExcludeMissing + refresh: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + status: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("validated_at") + @ExcludeMissing + validatedAt: JsonField = JsonMissing.of(), + @JsonProperty("vault_id") @ExcludeMissing vaultId: JsonField = JsonMissing.of(), + ) : this( + credentialId, + hasRefreshToken, + mcpProbe, + refresh, + status, + type, + validatedAt, + vaultId, + mutableMapOf(), + ) + + /** + * Unique identifier of the credential that was validated. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun credentialId(): String = credentialId.getRequired("credential_id") + + /** + * Whether the credential has a refresh token configured. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun hasRefreshToken(): Boolean = hasRefreshToken.getRequired("has_refresh_token") + + /** + * The failing step of an MCP validation probe. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun mcpProbe(): Optional = mcpProbe.getOptional("mcp_probe") + + /** + * Outcome of a refresh-token exchange attempted during credential validation. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun refresh(): Optional = refresh.getOptional("refresh") + + /** + * Overall verdict of a credential validation probe. + * + * @throws AnthropicInvalidDataException if 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(): BetaManagedAgentsCredentialValidationStatus = status.getRequired("status") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * A timestamp in RFC 3339 format + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun validatedAt(): OffsetDateTime = validatedAt.getRequired("validated_at") + + /** + * Identifier of the vault containing the credential. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun vaultId(): String = vaultId.getRequired("vault_id") + + /** + * Returns the raw JSON value of [credentialId]. + * + * Unlike [credentialId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("credential_id") + @ExcludeMissing + fun _credentialId(): JsonField = credentialId + + /** + * Returns the raw JSON value of [hasRefreshToken]. + * + * Unlike [hasRefreshToken], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_refresh_token") + @ExcludeMissing + fun _hasRefreshToken(): JsonField = hasRefreshToken + + /** + * Returns the raw JSON value of [mcpProbe]. + * + * Unlike [mcpProbe], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("mcp_probe") + @ExcludeMissing + fun _mcpProbe(): JsonField = mcpProbe + + /** + * Returns the raw JSON value of [refresh]. + * + * Unlike [refresh], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("refresh") + @ExcludeMissing + fun _refresh(): JsonField = refresh + + /** + * 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 [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [validatedAt]. + * + * Unlike [validatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("validated_at") + @ExcludeMissing + fun _validatedAt(): JsonField = validatedAt + + /** + * Returns the raw JSON value of [vaultId]. + * + * Unlike [vaultId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("vault_id") @ExcludeMissing fun _vaultId(): JsonField = vaultId + + @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 + * [BetaManagedAgentsCredentialValidation]. + * + * The following fields are required: + * ```java + * .credentialId() + * .hasRefreshToken() + * .mcpProbe() + * .refresh() + * .status() + * .type() + * .validatedAt() + * .vaultId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsCredentialValidation]. */ + class Builder internal constructor() { + + private var credentialId: JsonField? = null + private var hasRefreshToken: JsonField? = null + private var mcpProbe: JsonField? = null + private var refresh: JsonField? = null + private var status: JsonField? = null + private var type: JsonField? = null + private var validatedAt: JsonField? = null + private var vaultId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsCredentialValidation: BetaManagedAgentsCredentialValidation + ) = apply { + credentialId = betaManagedAgentsCredentialValidation.credentialId + hasRefreshToken = betaManagedAgentsCredentialValidation.hasRefreshToken + mcpProbe = betaManagedAgentsCredentialValidation.mcpProbe + refresh = betaManagedAgentsCredentialValidation.refresh + status = betaManagedAgentsCredentialValidation.status + type = betaManagedAgentsCredentialValidation.type + validatedAt = betaManagedAgentsCredentialValidation.validatedAt + vaultId = betaManagedAgentsCredentialValidation.vaultId + additionalProperties = + betaManagedAgentsCredentialValidation.additionalProperties.toMutableMap() + } + + /** Unique identifier of the credential that was validated. */ + fun credentialId(credentialId: String) = credentialId(JsonField.of(credentialId)) + + /** + * Sets [Builder.credentialId] to an arbitrary JSON value. + * + * You should usually call [Builder.credentialId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun credentialId(credentialId: JsonField) = apply { + this.credentialId = credentialId + } + + /** Whether the credential has a refresh token configured. */ + fun hasRefreshToken(hasRefreshToken: Boolean) = + hasRefreshToken(JsonField.of(hasRefreshToken)) + + /** + * Sets [Builder.hasRefreshToken] to an arbitrary JSON value. + * + * You should usually call [Builder.hasRefreshToken] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun hasRefreshToken(hasRefreshToken: JsonField) = apply { + this.hasRefreshToken = hasRefreshToken + } + + /** The failing step of an MCP validation probe. */ + fun mcpProbe(mcpProbe: BetaManagedAgentsMcpProbe?) = + mcpProbe(JsonField.ofNullable(mcpProbe)) + + /** Alias for calling [Builder.mcpProbe] with `mcpProbe.orElse(null)`. */ + fun mcpProbe(mcpProbe: Optional) = mcpProbe(mcpProbe.getOrNull()) + + /** + * Sets [Builder.mcpProbe] to an arbitrary JSON value. + * + * You should usually call [Builder.mcpProbe] with a well-typed [BetaManagedAgentsMcpProbe] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun mcpProbe(mcpProbe: JsonField) = apply { + this.mcpProbe = mcpProbe + } + + /** Outcome of a refresh-token exchange attempted during credential validation. */ + fun refresh(refresh: BetaManagedAgentsRefreshObject?) = + refresh(JsonField.ofNullable(refresh)) + + /** Alias for calling [Builder.refresh] with `refresh.orElse(null)`. */ + fun refresh(refresh: Optional) = + refresh(refresh.getOrNull()) + + /** + * Sets [Builder.refresh] to an arbitrary JSON value. + * + * You should usually call [Builder.refresh] with a well-typed + * [BetaManagedAgentsRefreshObject] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun refresh(refresh: JsonField) = apply { + this.refresh = refresh + } + + /** Overall verdict of a credential validation probe. */ + fun status(status: BetaManagedAgentsCredentialValidationStatus) = + status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed + * [BetaManagedAgentsCredentialValidationStatus] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { + this.status = status + } + + fun 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 } + + /** A timestamp in RFC 3339 format */ + fun validatedAt(validatedAt: OffsetDateTime) = validatedAt(JsonField.of(validatedAt)) + + /** + * Sets [Builder.validatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.validatedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun validatedAt(validatedAt: JsonField) = apply { + this.validatedAt = validatedAt + } + + /** Identifier of the vault containing the credential. */ + fun vaultId(vaultId: String) = vaultId(JsonField.of(vaultId)) + + /** + * Sets [Builder.vaultId] to an arbitrary JSON value. + * + * You should usually call [Builder.vaultId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun vaultId(vaultId: JsonField) = apply { this.vaultId = vaultId } + + 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 [BetaManagedAgentsCredentialValidation]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .credentialId() + * .hasRefreshToken() + * .mcpProbe() + * .refresh() + * .status() + * .type() + * .validatedAt() + * .vaultId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsCredentialValidation = + BetaManagedAgentsCredentialValidation( + checkRequired("credentialId", credentialId), + checkRequired("hasRefreshToken", hasRefreshToken), + checkRequired("mcpProbe", mcpProbe), + checkRequired("refresh", refresh), + checkRequired("status", status), + checkRequired("type", type), + checkRequired("validatedAt", validatedAt), + checkRequired("vaultId", vaultId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsCredentialValidation = apply { + if (validated) { + return@apply + } + + credentialId() + hasRefreshToken() + mcpProbe().ifPresent { it.validate() } + refresh().ifPresent { it.validate() } + status().validate() + type().validate() + validatedAt() + vaultId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (credentialId.asKnown().isPresent) 1 else 0) + + (if (hasRefreshToken.asKnown().isPresent) 1 else 0) + + (mcpProbe.asKnown().getOrNull()?.validity() ?: 0) + + (refresh.asKnown().getOrNull()?.validity() ?: 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (validatedAt.asKnown().isPresent) 1 else 0) + + (if (vaultId.asKnown().isPresent) 1 else 0) + + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val VAULT_CREDENTIAL_VALIDATION = of("vault_credential_validation") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + VAULT_CREDENTIAL_VALIDATION + } + + /** + * 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 { + VAULT_CREDENTIAL_VALIDATION, + /** 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) { + VAULT_CREDENTIAL_VALIDATION -> Value.VAULT_CREDENTIAL_VALIDATION + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + VAULT_CREDENTIAL_VALIDATION -> Known.VAULT_CREDENTIAL_VALIDATION + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsCredentialValidation && + credentialId == other.credentialId && + hasRefreshToken == other.hasRefreshToken && + mcpProbe == other.mcpProbe && + refresh == other.refresh && + status == other.status && + type == other.type && + validatedAt == other.validatedAt && + vaultId == other.vaultId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + credentialId, + hasRefreshToken, + mcpProbe, + refresh, + status, + type, + validatedAt, + vaultId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsCredentialValidation{credentialId=$credentialId, hasRefreshToken=$hasRefreshToken, mcpProbe=$mcpProbe, refresh=$refresh, status=$status, type=$type, validatedAt=$validatedAt, vaultId=$vaultId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsCredentialValidationStatus.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsCredentialValidationStatus.kt new file mode 100644 index 000000000..eddb9d4ef --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsCredentialValidationStatus.kt @@ -0,0 +1,156 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.vaults.credentials + +import com.anthropic.core.Enum +import com.anthropic.core.JsonField +import com.anthropic.errors.AnthropicInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator + +/** Overall verdict of a credential validation probe. */ +class BetaManagedAgentsCredentialValidationStatus +@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 VALID = of("valid") + + @JvmField val INVALID = of("invalid") + + @JvmField val UNKNOWN = of("unknown") + + @JvmStatic + fun of(value: String) = BetaManagedAgentsCredentialValidationStatus(JsonField.of(value)) + } + + /** An enum containing [BetaManagedAgentsCredentialValidationStatus]'s known values. */ + enum class Known { + VALID, + INVALID, + UNKNOWN, + } + + /** + * An enum containing [BetaManagedAgentsCredentialValidationStatus]'s known values, as well as + * an [_UNKNOWN] member. + * + * An instance of [BetaManagedAgentsCredentialValidationStatus] 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 { + VALID, + INVALID, + UNKNOWN, + /** + * An enum member indicating that [BetaManagedAgentsCredentialValidationStatus] 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) { + VALID -> Value.VALID + INVALID -> Value.INVALID + UNKNOWN -> Value.UNKNOWN + 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 AnthropicInvalidDataException if this class instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + VALID -> Known.VALID + INVALID -> Known.INVALID + UNKNOWN -> Known.UNKNOWN + else -> + throw AnthropicInvalidDataException( + "Unknown BetaManagedAgentsCredentialValidationStatus: $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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { AnthropicInvalidDataException("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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsCredentialValidationStatus = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsCredentialValidationStatus && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsMcpProbe.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsMcpProbe.kt new file mode 100644 index 000000000..bb2a03f0f --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsMcpProbe.kt @@ -0,0 +1,235 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.vaults.credentials + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +/** The failing step of an MCP validation probe. */ +class BetaManagedAgentsMcpProbe +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val httpResponse: JsonField, + private val method: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("http_response") + @ExcludeMissing + httpResponse: JsonField = JsonMissing.of(), + @JsonProperty("method") @ExcludeMissing method: JsonField = JsonMissing.of(), + ) : this(httpResponse, method, mutableMapOf()) + + /** + * An HTTP response captured during a credential validation probe. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun httpResponse(): Optional = + httpResponse.getOptional("http_response") + + /** + * The MCP method that failed (for example `initialize` or `tools/list`). + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun method(): String = method.getRequired("method") + + /** + * Returns the raw JSON value of [httpResponse]. + * + * Unlike [httpResponse], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("http_response") + @ExcludeMissing + fun _httpResponse(): JsonField = httpResponse + + /** + * Returns the raw JSON value of [method]. + * + * Unlike [method], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("method") @ExcludeMissing fun _method(): JsonField = method + + @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 [BetaManagedAgentsMcpProbe]. + * + * The following fields are required: + * ```java + * .httpResponse() + * .method() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsMcpProbe]. */ + class Builder internal constructor() { + + private var httpResponse: JsonField? = null + private var method: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaManagedAgentsMcpProbe: BetaManagedAgentsMcpProbe) = apply { + httpResponse = betaManagedAgentsMcpProbe.httpResponse + method = betaManagedAgentsMcpProbe.method + additionalProperties = betaManagedAgentsMcpProbe.additionalProperties.toMutableMap() + } + + /** An HTTP response captured during a credential validation probe. */ + fun httpResponse(httpResponse: BetaManagedAgentsRefreshHttpResponse?) = + httpResponse(JsonField.ofNullable(httpResponse)) + + /** Alias for calling [Builder.httpResponse] with `httpResponse.orElse(null)`. */ + fun httpResponse(httpResponse: Optional) = + httpResponse(httpResponse.getOrNull()) + + /** + * Sets [Builder.httpResponse] to an arbitrary JSON value. + * + * You should usually call [Builder.httpResponse] with a well-typed + * [BetaManagedAgentsRefreshHttpResponse] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun httpResponse(httpResponse: JsonField) = apply { + this.httpResponse = httpResponse + } + + /** The MCP method that failed (for example `initialize` or `tools/list`). */ + fun method(method: String) = method(JsonField.of(method)) + + /** + * Sets [Builder.method] to an arbitrary JSON value. + * + * You should usually call [Builder.method] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun method(method: JsonField) = apply { this.method = method } + + 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 [BetaManagedAgentsMcpProbe]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .httpResponse() + * .method() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsMcpProbe = + BetaManagedAgentsMcpProbe( + checkRequired("httpResponse", httpResponse), + checkRequired("method", method), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsMcpProbe = apply { + if (validated) { + return@apply + } + + httpResponse().ifPresent { it.validate() } + method() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (httpResponse.asKnown().getOrNull()?.validity() ?: 0) + + (if (method.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaManagedAgentsMcpProbe && + httpResponse == other.httpResponse && + method == other.method && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(httpResponse, method, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsMcpProbe{httpResponse=$httpResponse, method=$method, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshHttpResponse.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshHttpResponse.kt new file mode 100644 index 000000000..df837c396 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshHttpResponse.kt @@ -0,0 +1,310 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.vaults.credentials + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +/** An HTTP response captured during a credential validation probe. */ +class BetaManagedAgentsRefreshHttpResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val body: JsonField, + private val bodyTruncated: JsonField, + private val contentType: JsonField, + private val statusCode: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("body") @ExcludeMissing body: JsonField = JsonMissing.of(), + @JsonProperty("body_truncated") + @ExcludeMissing + bodyTruncated: JsonField = JsonMissing.of(), + @JsonProperty("content_type") + @ExcludeMissing + contentType: JsonField = JsonMissing.of(), + @JsonProperty("status_code") @ExcludeMissing statusCode: JsonField = JsonMissing.of(), + ) : this(body, bodyTruncated, contentType, statusCode, mutableMapOf()) + + /** + * Response body. May be truncated and has sensitive values scrubbed. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun body(): String = body.getRequired("body") + + /** + * Whether `body` was truncated. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun bodyTruncated(): Boolean = bodyTruncated.getRequired("body_truncated") + + /** + * Value of the `Content-Type` response header. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun contentType(): String = contentType.getRequired("content_type") + + /** + * HTTP status code. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun statusCode(): Int = statusCode.getRequired("status_code") + + /** + * Returns the raw JSON value of [body]. + * + * Unlike [body], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("body") @ExcludeMissing fun _body(): JsonField = body + + /** + * Returns the raw JSON value of [bodyTruncated]. + * + * Unlike [bodyTruncated], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("body_truncated") + @ExcludeMissing + fun _bodyTruncated(): JsonField = bodyTruncated + + /** + * Returns the raw JSON value of [contentType]. + * + * Unlike [contentType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content_type") + @ExcludeMissing + fun _contentType(): JsonField = contentType + + /** + * Returns the raw JSON value of [statusCode]. + * + * Unlike [statusCode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status_code") @ExcludeMissing fun _statusCode(): JsonField = statusCode + + @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 + * [BetaManagedAgentsRefreshHttpResponse]. + * + * The following fields are required: + * ```java + * .body() + * .bodyTruncated() + * .contentType() + * .statusCode() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsRefreshHttpResponse]. */ + class Builder internal constructor() { + + private var body: JsonField? = null + private var bodyTruncated: JsonField? = null + private var contentType: JsonField? = null + private var statusCode: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaManagedAgentsRefreshHttpResponse: BetaManagedAgentsRefreshHttpResponse + ) = apply { + body = betaManagedAgentsRefreshHttpResponse.body + bodyTruncated = betaManagedAgentsRefreshHttpResponse.bodyTruncated + contentType = betaManagedAgentsRefreshHttpResponse.contentType + statusCode = betaManagedAgentsRefreshHttpResponse.statusCode + additionalProperties = + betaManagedAgentsRefreshHttpResponse.additionalProperties.toMutableMap() + } + + /** Response body. May be truncated and has sensitive values scrubbed. */ + fun body(body: String) = body(JsonField.of(body)) + + /** + * Sets [Builder.body] to an arbitrary JSON value. + * + * You should usually call [Builder.body] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun body(body: JsonField) = apply { this.body = body } + + /** Whether `body` was truncated. */ + fun bodyTruncated(bodyTruncated: Boolean) = bodyTruncated(JsonField.of(bodyTruncated)) + + /** + * Sets [Builder.bodyTruncated] to an arbitrary JSON value. + * + * You should usually call [Builder.bodyTruncated] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun bodyTruncated(bodyTruncated: JsonField) = apply { + this.bodyTruncated = bodyTruncated + } + + /** Value of the `Content-Type` response header. */ + fun contentType(contentType: String) = contentType(JsonField.of(contentType)) + + /** + * Sets [Builder.contentType] to an arbitrary JSON value. + * + * You should usually call [Builder.contentType] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun contentType(contentType: JsonField) = apply { this.contentType = contentType } + + /** HTTP status code. */ + fun statusCode(statusCode: Int) = statusCode(JsonField.of(statusCode)) + + /** + * Sets [Builder.statusCode] to an arbitrary JSON value. + * + * You should usually call [Builder.statusCode] with a well-typed [Int] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun statusCode(statusCode: JsonField) = apply { this.statusCode = statusCode } + + 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 [BetaManagedAgentsRefreshHttpResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .body() + * .bodyTruncated() + * .contentType() + * .statusCode() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsRefreshHttpResponse = + BetaManagedAgentsRefreshHttpResponse( + checkRequired("body", body), + checkRequired("bodyTruncated", bodyTruncated), + checkRequired("contentType", contentType), + checkRequired("statusCode", statusCode), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsRefreshHttpResponse = apply { + if (validated) { + return@apply + } + + body() + bodyTruncated() + contentType() + statusCode() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (body.asKnown().isPresent) 1 else 0) + + (if (bodyTruncated.asKnown().isPresent) 1 else 0) + + (if (contentType.asKnown().isPresent) 1 else 0) + + (if (statusCode.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaManagedAgentsRefreshHttpResponse && + body == other.body && + bodyTruncated == other.bodyTruncated && + contentType == other.contentType && + statusCode == other.statusCode && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(body, bodyTruncated, contentType, statusCode, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsRefreshHttpResponse{body=$body, bodyTruncated=$bodyTruncated, contentType=$contentType, statusCode=$statusCode, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshObject.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshObject.kt new file mode 100644 index 000000000..e6a9c38ec --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshObject.kt @@ -0,0 +1,387 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.vaults.credentials + +import com.anthropic.core.Enum +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +/** Outcome of a refresh-token exchange attempted during credential validation. */ +class BetaManagedAgentsRefreshObject +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val httpResponse: JsonField, + private val status: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("http_response") + @ExcludeMissing + httpResponse: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + ) : this(httpResponse, status, mutableMapOf()) + + /** + * An HTTP response captured during a credential validation probe. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun httpResponse(): Optional = + httpResponse.getOptional("http_response") + + /** + * Outcome of a refresh-token exchange attempted during credential validation. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun status(): Status = status.getRequired("status") + + /** + * Returns the raw JSON value of [httpResponse]. + * + * Unlike [httpResponse], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("http_response") + @ExcludeMissing + fun _httpResponse(): JsonField = httpResponse + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BetaManagedAgentsRefreshObject]. + * + * The following fields are required: + * ```java + * .httpResponse() + * .status() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaManagedAgentsRefreshObject]. */ + class Builder internal constructor() { + + private var httpResponse: JsonField? = null + private var status: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaManagedAgentsRefreshObject: BetaManagedAgentsRefreshObject) = apply { + httpResponse = betaManagedAgentsRefreshObject.httpResponse + status = betaManagedAgentsRefreshObject.status + additionalProperties = + betaManagedAgentsRefreshObject.additionalProperties.toMutableMap() + } + + /** An HTTP response captured during a credential validation probe. */ + fun httpResponse(httpResponse: BetaManagedAgentsRefreshHttpResponse?) = + httpResponse(JsonField.ofNullable(httpResponse)) + + /** Alias for calling [Builder.httpResponse] with `httpResponse.orElse(null)`. */ + fun httpResponse(httpResponse: Optional) = + httpResponse(httpResponse.getOrNull()) + + /** + * Sets [Builder.httpResponse] to an arbitrary JSON value. + * + * You should usually call [Builder.httpResponse] with a well-typed + * [BetaManagedAgentsRefreshHttpResponse] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun httpResponse(httpResponse: JsonField) = apply { + this.httpResponse = httpResponse + } + + /** Outcome of a refresh-token exchange attempted during credential validation. */ + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaManagedAgentsRefreshObject]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .httpResponse() + * .status() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaManagedAgentsRefreshObject = + BetaManagedAgentsRefreshObject( + checkRequired("httpResponse", httpResponse), + checkRequired("status", status), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaManagedAgentsRefreshObject = apply { + if (validated) { + return@apply + } + + httpResponse().ifPresent { it.validate() } + status().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (httpResponse.asKnown().getOrNull()?.validity() ?: 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + /** Outcome of a refresh-token exchange attempted during credential validation. */ + 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 SUCCEEDED = of("succeeded") + + @JvmField val FAILED = of("failed") + + @JvmField val CONNECT_ERROR = of("connect_error") + + @JvmField val NO_REFRESH_TOKEN = of("no_refresh_token") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + SUCCEEDED, + FAILED, + CONNECT_ERROR, + NO_REFRESH_TOKEN, + } + + /** + * 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 { + SUCCEEDED, + FAILED, + CONNECT_ERROR, + NO_REFRESH_TOKEN, + /** 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) { + SUCCEEDED -> Value.SUCCEEDED + FAILED -> Value.FAILED + CONNECT_ERROR -> Value.CONNECT_ERROR + NO_REFRESH_TOKEN -> Value.NO_REFRESH_TOKEN + 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 AnthropicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + SUCCEEDED -> Known.SUCCEEDED + FAILED -> Known.FAILED + CONNECT_ERROR -> Known.CONNECT_ERROR + NO_REFRESH_TOKEN -> Known.NO_REFRESH_TOKEN + else -> throw AnthropicInvalidDataException("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 AnthropicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AnthropicInvalidDataException("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 AnthropicInvalidDataException 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: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 BetaManagedAgentsRefreshObject && + httpResponse == other.httpResponse && + status == other.status && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(httpResponse, status, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaManagedAgentsRefreshObject{httpResponse=$httpResponse, status=$status, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/CredentialMcpOAuthValidateParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/CredentialMcpOAuthValidateParams.kt new file mode 100644 index 000000000..87179858e --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/vaults/credentials/CredentialMcpOAuthValidateParams.kt @@ -0,0 +1,302 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.vaults.credentials + +import com.anthropic.core.JsonValue +import com.anthropic.core.Params +import com.anthropic.core.checkRequired +import com.anthropic.core.http.Headers +import com.anthropic.core.http.QueryParams +import com.anthropic.core.toImmutable +import com.anthropic.models.beta.AnthropicBeta +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Validate Credential */ +class CredentialMcpOAuthValidateParams +private constructor( + private val vaultId: String, + private val credentialId: String?, + private val betas: List?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun vaultId(): String = vaultId + + fun credentialId(): Optional = Optional.ofNullable(credentialId) + + /** Optional header to specify the beta version(s) you want to use. */ + fun betas(): Optional> = Optional.ofNullable(betas) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CredentialMcpOAuthValidateParams]. + * + * The following fields are required: + * ```java + * .vaultId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CredentialMcpOAuthValidateParams]. */ + class Builder internal constructor() { + + private var vaultId: String? = null + private var credentialId: String? = null + private var betas: MutableList? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(credentialMcpOAuthValidateParams: CredentialMcpOAuthValidateParams) = + apply { + vaultId = credentialMcpOAuthValidateParams.vaultId + credentialId = credentialMcpOAuthValidateParams.credentialId + betas = credentialMcpOAuthValidateParams.betas?.toMutableList() + additionalHeaders = credentialMcpOAuthValidateParams.additionalHeaders.toBuilder() + additionalQueryParams = + credentialMcpOAuthValidateParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + credentialMcpOAuthValidateParams.additionalBodyProperties.toMutableMap() + } + + fun vaultId(vaultId: String) = apply { this.vaultId = vaultId } + + fun credentialId(credentialId: String?) = apply { this.credentialId = credentialId } + + /** Alias for calling [Builder.credentialId] with `credentialId.orElse(null)`. */ + fun credentialId(credentialId: Optional) = credentialId(credentialId.getOrNull()) + + /** Optional header to specify the beta version(s) you want to use. */ + fun betas(betas: List?) = apply { this.betas = betas?.toMutableList() } + + /** Alias for calling [Builder.betas] with `betas.orElse(null)`. */ + fun betas(betas: Optional>) = betas(betas.getOrNull()) + + /** + * Adds a single [AnthropicBeta] to [betas]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addBeta(beta: AnthropicBeta) = apply { + betas = (betas ?: mutableListOf()).apply { add(beta) } + } + + /** + * Sets [addBeta] to an arbitrary [String]. + * + * You should usually call [addBeta] with a well-typed [AnthropicBeta] constant instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun addBeta(value: String) = addBeta(AnthropicBeta.of(value)) + + 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 [CredentialMcpOAuthValidateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .vaultId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CredentialMcpOAuthValidateParams = + CredentialMcpOAuthValidateParams( + checkRequired("vaultId", vaultId), + credentialId, + betas?.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> vaultId + 1 -> credentialId ?: "" + else -> "" + } + + override fun _headers(): Headers = + Headers.builder() + .apply { + betas?.forEach { put("anthropic-beta", it.toString()) } + putAll(additionalHeaders) + } + .build() + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CredentialMcpOAuthValidateParams && + vaultId == other.vaultId && + credentialId == other.credentialId && + betas == other.betas && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + vaultId, + credentialId, + betas, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "CredentialMcpOAuthValidateParams{vaultId=$vaultId, credentialId=$credentialId, betas=$betas, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEvent.kt new file mode 100644 index 000000000..f571169d7 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEvent.kt @@ -0,0 +1,442 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +class BetaWebhookEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val data: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + data: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(id, createdAt, data, type, mutableMapOf()) + + /** + * Unique event identifier for idempotency. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * RFC 3339 timestamp when the event occurred. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("created_at") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): BetaWebhookEventData = data.getRequired("data") + + /** + * Object type. Always `event` for webhook payloads. + * + * Expected to always return the following: + * ```java + * JsonValue.from("event") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [BetaWebhookEvent]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .data() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var data: JsonField? = null + private var type: JsonValue = JsonValue.from("event") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaWebhookEvent: BetaWebhookEvent) = apply { + id = betaWebhookEvent.id + createdAt = betaWebhookEvent.createdAt + data = betaWebhookEvent.data + type = betaWebhookEvent.type + additionalProperties = betaWebhookEvent.additionalProperties.toMutableMap() + } + + /** Unique event identifier for idempotency. */ + 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 } + + /** RFC 3339 timestamp when the event occurred. */ + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * 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 } + + fun data(data: BetaWebhookEventData) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [BetaWebhookEventData] 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 } + + /** + * Alias for calling [data] with `BetaWebhookEventData.ofSessionCreated(sessionCreated)`. + */ + fun data(sessionCreated: BetaWebhookSessionCreatedEventData) = + data(BetaWebhookEventData.ofSessionCreated(sessionCreated)) + + /** + * Alias for calling [data] with `BetaWebhookEventData.ofSessionPending(sessionPending)`. + */ + fun data(sessionPending: BetaWebhookSessionPendingEventData) = + data(BetaWebhookEventData.ofSessionPending(sessionPending)) + + /** + * Alias for calling [data] with `BetaWebhookEventData.ofSessionRunning(sessionRunning)`. + */ + fun data(sessionRunning: BetaWebhookSessionRunningEventData) = + data(BetaWebhookEventData.ofSessionRunning(sessionRunning)) + + /** Alias for calling [data] with `BetaWebhookEventData.ofSessionIdled(sessionIdled)`. */ + fun data(sessionIdled: BetaWebhookSessionIdledEventData) = + data(BetaWebhookEventData.ofSessionIdled(sessionIdled)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionRequiresAction(sessionRequiresAction)`. + */ + fun data(sessionRequiresAction: BetaWebhookSessionRequiresActionEventData) = + data(BetaWebhookEventData.ofSessionRequiresAction(sessionRequiresAction)) + + /** + * Alias for calling [data] with `BetaWebhookEventData.ofSessionArchived(sessionArchived)`. + */ + fun data(sessionArchived: BetaWebhookSessionArchivedEventData) = + data(BetaWebhookEventData.ofSessionArchived(sessionArchived)) + + /** + * Alias for calling [data] with `BetaWebhookEventData.ofSessionDeleted(sessionDeleted)`. + */ + fun data(sessionDeleted: BetaWebhookSessionDeletedEventData) = + data(BetaWebhookEventData.ofSessionDeleted(sessionDeleted)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionStatusScheduled(sessionStatusScheduled)`. + */ + fun data(sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData) = + data(BetaWebhookEventData.ofSessionStatusScheduled(sessionStatusScheduled)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionStatusRunStarted(sessionStatusRunStarted)`. + */ + fun data(sessionStatusRunStarted: BetaWebhookSessionStatusRunStartedEventData) = + data(BetaWebhookEventData.ofSessionStatusRunStarted(sessionStatusRunStarted)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionStatusIdled(sessionStatusIdled)`. + */ + fun data(sessionStatusIdled: BetaWebhookSessionStatusIdledEventData) = + data(BetaWebhookEventData.ofSessionStatusIdled(sessionStatusIdled)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionStatusTerminated(sessionStatusTerminated)`. + */ + fun data(sessionStatusTerminated: BetaWebhookSessionStatusTerminatedEventData) = + data(BetaWebhookEventData.ofSessionStatusTerminated(sessionStatusTerminated)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionThreadCreated(sessionThreadCreated)`. + */ + fun data(sessionThreadCreated: BetaWebhookSessionThreadCreatedEventData) = + data(BetaWebhookEventData.ofSessionThreadCreated(sessionThreadCreated)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionThreadIdled(sessionThreadIdled)`. + */ + fun data(sessionThreadIdled: BetaWebhookSessionThreadIdledEventData) = + data(BetaWebhookEventData.ofSessionThreadIdled(sessionThreadIdled)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionThreadTerminated(sessionThreadTerminated)`. + */ + fun data(sessionThreadTerminated: BetaWebhookSessionThreadTerminatedEventData) = + data(BetaWebhookEventData.ofSessionThreadTerminated(sessionThreadTerminated)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionOutcomeEvaluationEnded(sessionOutcomeEvaluationEnded)`. + */ + fun data(sessionOutcomeEvaluationEnded: BetaWebhookSessionOutcomeEvaluationEndedEventData) = + data( + BetaWebhookEventData.ofSessionOutcomeEvaluationEnded(sessionOutcomeEvaluationEnded) + ) + + /** Alias for calling [data] with `BetaWebhookEventData.ofVaultCreated(vaultCreated)`. */ + fun data(vaultCreated: BetaWebhookVaultCreatedEventData) = + data(BetaWebhookEventData.ofVaultCreated(vaultCreated)) + + /** Alias for calling [data] with `BetaWebhookEventData.ofVaultArchived(vaultArchived)`. */ + fun data(vaultArchived: BetaWebhookVaultArchivedEventData) = + data(BetaWebhookEventData.ofVaultArchived(vaultArchived)) + + /** Alias for calling [data] with `BetaWebhookEventData.ofVaultDeleted(vaultDeleted)`. */ + fun data(vaultDeleted: BetaWebhookVaultDeletedEventData) = + data(BetaWebhookEventData.ofVaultDeleted(vaultDeleted)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofVaultCredentialCreated(vaultCredentialCreated)`. + */ + fun data(vaultCredentialCreated: BetaWebhookVaultCredentialCreatedEventData) = + data(BetaWebhookEventData.ofVaultCredentialCreated(vaultCredentialCreated)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofVaultCredentialArchived(vaultCredentialArchived)`. + */ + fun data(vaultCredentialArchived: BetaWebhookVaultCredentialArchivedEventData) = + data(BetaWebhookEventData.ofVaultCredentialArchived(vaultCredentialArchived)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofVaultCredentialDeleted(vaultCredentialDeleted)`. + */ + fun data(vaultCredentialDeleted: BetaWebhookVaultCredentialDeletedEventData) = + data(BetaWebhookEventData.ofVaultCredentialDeleted(vaultCredentialDeleted)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofVaultCredentialRefreshFailed(vaultCredentialRefreshFailed)`. + */ + fun data(vaultCredentialRefreshFailed: BetaWebhookVaultCredentialRefreshFailedEventData) = + data(BetaWebhookEventData.ofVaultCredentialRefreshFailed(vaultCredentialRefreshFailed)) + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("event") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaWebhookEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .data() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookEvent = + BetaWebhookEvent( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("data", data), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookEvent = apply { + if (validated) { + return@apply + } + + id() + createdAt() + data().validate() + _type().let { + if (it != JsonValue.from("event")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (data.asKnown().getOrNull()?.validity() ?: 0) + + type.let { if (it == JsonValue.from("event")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookEvent && + id == other.id && + createdAt == other.createdAt && + data == other.data && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, data, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookEvent{id=$id, createdAt=$createdAt, data=$data, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventData.kt new file mode 100644 index 000000000..7afd99f26 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventData.kt @@ -0,0 +1,1055 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer +import com.anthropic.core.JsonValue +import com.anthropic.core.getOrThrow +import com.anthropic.errors.AnthropicInvalidDataException +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.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +@JsonDeserialize(using = BetaWebhookEventData.Deserializer::class) +@JsonSerialize(using = BetaWebhookEventData.Serializer::class) +class BetaWebhookEventData +private constructor( + private val sessionCreated: BetaWebhookSessionCreatedEventData? = null, + private val sessionPending: BetaWebhookSessionPendingEventData? = null, + private val sessionRunning: BetaWebhookSessionRunningEventData? = null, + private val sessionIdled: BetaWebhookSessionIdledEventData? = null, + private val sessionRequiresAction: BetaWebhookSessionRequiresActionEventData? = null, + private val sessionArchived: BetaWebhookSessionArchivedEventData? = null, + private val sessionDeleted: BetaWebhookSessionDeletedEventData? = null, + private val sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData? = null, + private val sessionStatusRunStarted: BetaWebhookSessionStatusRunStartedEventData? = null, + private val sessionStatusIdled: BetaWebhookSessionStatusIdledEventData? = null, + private val sessionStatusTerminated: BetaWebhookSessionStatusTerminatedEventData? = null, + private val sessionThreadCreated: BetaWebhookSessionThreadCreatedEventData? = null, + private val sessionThreadIdled: BetaWebhookSessionThreadIdledEventData? = null, + private val sessionThreadTerminated: BetaWebhookSessionThreadTerminatedEventData? = null, + private val sessionOutcomeEvaluationEnded: BetaWebhookSessionOutcomeEvaluationEndedEventData? = + null, + private val vaultCreated: BetaWebhookVaultCreatedEventData? = null, + private val vaultArchived: BetaWebhookVaultArchivedEventData? = null, + private val vaultDeleted: BetaWebhookVaultDeletedEventData? = null, + private val vaultCredentialCreated: BetaWebhookVaultCredentialCreatedEventData? = null, + private val vaultCredentialArchived: BetaWebhookVaultCredentialArchivedEventData? = null, + private val vaultCredentialDeleted: BetaWebhookVaultCredentialDeletedEventData? = null, + private val vaultCredentialRefreshFailed: BetaWebhookVaultCredentialRefreshFailedEventData? = + null, + private val _json: JsonValue? = null, +) { + + fun sessionCreated(): Optional = + Optional.ofNullable(sessionCreated) + + fun sessionPending(): Optional = + Optional.ofNullable(sessionPending) + + fun sessionRunning(): Optional = + Optional.ofNullable(sessionRunning) + + fun sessionIdled(): Optional = + Optional.ofNullable(sessionIdled) + + fun sessionRequiresAction(): Optional = + Optional.ofNullable(sessionRequiresAction) + + fun sessionArchived(): Optional = + Optional.ofNullable(sessionArchived) + + fun sessionDeleted(): Optional = + Optional.ofNullable(sessionDeleted) + + fun sessionStatusScheduled(): Optional = + Optional.ofNullable(sessionStatusScheduled) + + fun sessionStatusRunStarted(): Optional = + Optional.ofNullable(sessionStatusRunStarted) + + fun sessionStatusIdled(): Optional = + Optional.ofNullable(sessionStatusIdled) + + fun sessionStatusTerminated(): Optional = + Optional.ofNullable(sessionStatusTerminated) + + fun sessionThreadCreated(): Optional = + Optional.ofNullable(sessionThreadCreated) + + fun sessionThreadIdled(): Optional = + Optional.ofNullable(sessionThreadIdled) + + fun sessionThreadTerminated(): Optional = + Optional.ofNullable(sessionThreadTerminated) + + fun sessionOutcomeEvaluationEnded(): + Optional = + Optional.ofNullable(sessionOutcomeEvaluationEnded) + + fun vaultCreated(): Optional = + Optional.ofNullable(vaultCreated) + + fun vaultArchived(): Optional = + Optional.ofNullable(vaultArchived) + + fun vaultDeleted(): Optional = + Optional.ofNullable(vaultDeleted) + + fun vaultCredentialCreated(): Optional = + Optional.ofNullable(vaultCredentialCreated) + + fun vaultCredentialArchived(): Optional = + Optional.ofNullable(vaultCredentialArchived) + + fun vaultCredentialDeleted(): Optional = + Optional.ofNullable(vaultCredentialDeleted) + + fun vaultCredentialRefreshFailed(): Optional = + Optional.ofNullable(vaultCredentialRefreshFailed) + + fun isSessionCreated(): Boolean = sessionCreated != null + + fun isSessionPending(): Boolean = sessionPending != null + + fun isSessionRunning(): Boolean = sessionRunning != null + + fun isSessionIdled(): Boolean = sessionIdled != null + + fun isSessionRequiresAction(): Boolean = sessionRequiresAction != null + + fun isSessionArchived(): Boolean = sessionArchived != null + + fun isSessionDeleted(): Boolean = sessionDeleted != null + + fun isSessionStatusScheduled(): Boolean = sessionStatusScheduled != null + + fun isSessionStatusRunStarted(): Boolean = sessionStatusRunStarted != null + + fun isSessionStatusIdled(): Boolean = sessionStatusIdled != null + + fun isSessionStatusTerminated(): Boolean = sessionStatusTerminated != null + + fun isSessionThreadCreated(): Boolean = sessionThreadCreated != null + + fun isSessionThreadIdled(): Boolean = sessionThreadIdled != null + + fun isSessionThreadTerminated(): Boolean = sessionThreadTerminated != null + + fun isSessionOutcomeEvaluationEnded(): Boolean = sessionOutcomeEvaluationEnded != null + + fun isVaultCreated(): Boolean = vaultCreated != null + + fun isVaultArchived(): Boolean = vaultArchived != null + + fun isVaultDeleted(): Boolean = vaultDeleted != null + + fun isVaultCredentialCreated(): Boolean = vaultCredentialCreated != null + + fun isVaultCredentialArchived(): Boolean = vaultCredentialArchived != null + + fun isVaultCredentialDeleted(): Boolean = vaultCredentialDeleted != null + + fun isVaultCredentialRefreshFailed(): Boolean = vaultCredentialRefreshFailed != null + + fun asSessionCreated(): BetaWebhookSessionCreatedEventData = + sessionCreated.getOrThrow("sessionCreated") + + fun asSessionPending(): BetaWebhookSessionPendingEventData = + sessionPending.getOrThrow("sessionPending") + + fun asSessionRunning(): BetaWebhookSessionRunningEventData = + sessionRunning.getOrThrow("sessionRunning") + + fun asSessionIdled(): BetaWebhookSessionIdledEventData = sessionIdled.getOrThrow("sessionIdled") + + fun asSessionRequiresAction(): BetaWebhookSessionRequiresActionEventData = + sessionRequiresAction.getOrThrow("sessionRequiresAction") + + fun asSessionArchived(): BetaWebhookSessionArchivedEventData = + sessionArchived.getOrThrow("sessionArchived") + + fun asSessionDeleted(): BetaWebhookSessionDeletedEventData = + sessionDeleted.getOrThrow("sessionDeleted") + + fun asSessionStatusScheduled(): BetaWebhookSessionStatusScheduledEventData = + sessionStatusScheduled.getOrThrow("sessionStatusScheduled") + + fun asSessionStatusRunStarted(): BetaWebhookSessionStatusRunStartedEventData = + sessionStatusRunStarted.getOrThrow("sessionStatusRunStarted") + + fun asSessionStatusIdled(): BetaWebhookSessionStatusIdledEventData = + sessionStatusIdled.getOrThrow("sessionStatusIdled") + + fun asSessionStatusTerminated(): BetaWebhookSessionStatusTerminatedEventData = + sessionStatusTerminated.getOrThrow("sessionStatusTerminated") + + fun asSessionThreadCreated(): BetaWebhookSessionThreadCreatedEventData = + sessionThreadCreated.getOrThrow("sessionThreadCreated") + + fun asSessionThreadIdled(): BetaWebhookSessionThreadIdledEventData = + sessionThreadIdled.getOrThrow("sessionThreadIdled") + + fun asSessionThreadTerminated(): BetaWebhookSessionThreadTerminatedEventData = + sessionThreadTerminated.getOrThrow("sessionThreadTerminated") + + fun asSessionOutcomeEvaluationEnded(): BetaWebhookSessionOutcomeEvaluationEndedEventData = + sessionOutcomeEvaluationEnded.getOrThrow("sessionOutcomeEvaluationEnded") + + fun asVaultCreated(): BetaWebhookVaultCreatedEventData = vaultCreated.getOrThrow("vaultCreated") + + fun asVaultArchived(): BetaWebhookVaultArchivedEventData = + vaultArchived.getOrThrow("vaultArchived") + + fun asVaultDeleted(): BetaWebhookVaultDeletedEventData = vaultDeleted.getOrThrow("vaultDeleted") + + fun asVaultCredentialCreated(): BetaWebhookVaultCredentialCreatedEventData = + vaultCredentialCreated.getOrThrow("vaultCredentialCreated") + + fun asVaultCredentialArchived(): BetaWebhookVaultCredentialArchivedEventData = + vaultCredentialArchived.getOrThrow("vaultCredentialArchived") + + fun asVaultCredentialDeleted(): BetaWebhookVaultCredentialDeletedEventData = + vaultCredentialDeleted.getOrThrow("vaultCredentialDeleted") + + fun asVaultCredentialRefreshFailed(): BetaWebhookVaultCredentialRefreshFailedEventData = + vaultCredentialRefreshFailed.getOrThrow("vaultCredentialRefreshFailed") + + fun _json(): Optional = Optional.ofNullable(_json) + + /** + * Maps this instance's current variant to a value of type [T] using the given [visitor]. + * + * Note that this method is _not_ forwards compatible with new variants from the API, unless + * [visitor] overrides [Visitor.unknown]. To handle variants not known to this version of the + * SDK gracefully, consider overriding [Visitor.unknown]: + * ```java + * import com.anthropic.core.JsonValue; + * import java.util.Optional; + * + * Optional result = betaWebhookEventData.accept(new BetaWebhookEventData.Visitor>() { + * @Override + * public Optional visitSessionCreated(BetaWebhookSessionCreatedEventData sessionCreated) { + * return Optional.of(sessionCreated.toString()); + * } + * + * // ... + * + * @Override + * public Optional unknown(JsonValue json) { + * // Or inspect the `json`. + * return Optional.empty(); + * } + * }); + * ``` + * + * @throws AnthropicInvalidDataException if [Visitor.unknown] is not overridden in [visitor] and + * the current variant is unknown. + */ + fun accept(visitor: Visitor): T = + when { + sessionCreated != null -> visitor.visitSessionCreated(sessionCreated) + sessionPending != null -> visitor.visitSessionPending(sessionPending) + sessionRunning != null -> visitor.visitSessionRunning(sessionRunning) + sessionIdled != null -> visitor.visitSessionIdled(sessionIdled) + sessionRequiresAction != null -> + visitor.visitSessionRequiresAction(sessionRequiresAction) + sessionArchived != null -> visitor.visitSessionArchived(sessionArchived) + sessionDeleted != null -> visitor.visitSessionDeleted(sessionDeleted) + sessionStatusScheduled != null -> + visitor.visitSessionStatusScheduled(sessionStatusScheduled) + sessionStatusRunStarted != null -> + visitor.visitSessionStatusRunStarted(sessionStatusRunStarted) + sessionStatusIdled != null -> visitor.visitSessionStatusIdled(sessionStatusIdled) + sessionStatusTerminated != null -> + visitor.visitSessionStatusTerminated(sessionStatusTerminated) + sessionThreadCreated != null -> visitor.visitSessionThreadCreated(sessionThreadCreated) + sessionThreadIdled != null -> visitor.visitSessionThreadIdled(sessionThreadIdled) + sessionThreadTerminated != null -> + visitor.visitSessionThreadTerminated(sessionThreadTerminated) + sessionOutcomeEvaluationEnded != null -> + visitor.visitSessionOutcomeEvaluationEnded(sessionOutcomeEvaluationEnded) + vaultCreated != null -> visitor.visitVaultCreated(vaultCreated) + vaultArchived != null -> visitor.visitVaultArchived(vaultArchived) + vaultDeleted != null -> visitor.visitVaultDeleted(vaultDeleted) + vaultCredentialCreated != null -> + visitor.visitVaultCredentialCreated(vaultCredentialCreated) + vaultCredentialArchived != null -> + visitor.visitVaultCredentialArchived(vaultCredentialArchived) + vaultCredentialDeleted != null -> + visitor.visitVaultCredentialDeleted(vaultCredentialDeleted) + vaultCredentialRefreshFailed != null -> + visitor.visitVaultCredentialRefreshFailed(vaultCredentialRefreshFailed) + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookEventData = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitSessionCreated( + sessionCreated: BetaWebhookSessionCreatedEventData + ) { + sessionCreated.validate() + } + + override fun visitSessionPending( + sessionPending: BetaWebhookSessionPendingEventData + ) { + sessionPending.validate() + } + + override fun visitSessionRunning( + sessionRunning: BetaWebhookSessionRunningEventData + ) { + sessionRunning.validate() + } + + override fun visitSessionIdled(sessionIdled: BetaWebhookSessionIdledEventData) { + sessionIdled.validate() + } + + override fun visitSessionRequiresAction( + sessionRequiresAction: BetaWebhookSessionRequiresActionEventData + ) { + sessionRequiresAction.validate() + } + + override fun visitSessionArchived( + sessionArchived: BetaWebhookSessionArchivedEventData + ) { + sessionArchived.validate() + } + + override fun visitSessionDeleted( + sessionDeleted: BetaWebhookSessionDeletedEventData + ) { + sessionDeleted.validate() + } + + override fun visitSessionStatusScheduled( + sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData + ) { + sessionStatusScheduled.validate() + } + + override fun visitSessionStatusRunStarted( + sessionStatusRunStarted: BetaWebhookSessionStatusRunStartedEventData + ) { + sessionStatusRunStarted.validate() + } + + override fun visitSessionStatusIdled( + sessionStatusIdled: BetaWebhookSessionStatusIdledEventData + ) { + sessionStatusIdled.validate() + } + + override fun visitSessionStatusTerminated( + sessionStatusTerminated: BetaWebhookSessionStatusTerminatedEventData + ) { + sessionStatusTerminated.validate() + } + + override fun visitSessionThreadCreated( + sessionThreadCreated: BetaWebhookSessionThreadCreatedEventData + ) { + sessionThreadCreated.validate() + } + + override fun visitSessionThreadIdled( + sessionThreadIdled: BetaWebhookSessionThreadIdledEventData + ) { + sessionThreadIdled.validate() + } + + override fun visitSessionThreadTerminated( + sessionThreadTerminated: BetaWebhookSessionThreadTerminatedEventData + ) { + sessionThreadTerminated.validate() + } + + override fun visitSessionOutcomeEvaluationEnded( + sessionOutcomeEvaluationEnded: BetaWebhookSessionOutcomeEvaluationEndedEventData + ) { + sessionOutcomeEvaluationEnded.validate() + } + + override fun visitVaultCreated(vaultCreated: BetaWebhookVaultCreatedEventData) { + vaultCreated.validate() + } + + override fun visitVaultArchived(vaultArchived: BetaWebhookVaultArchivedEventData) { + vaultArchived.validate() + } + + override fun visitVaultDeleted(vaultDeleted: BetaWebhookVaultDeletedEventData) { + vaultDeleted.validate() + } + + override fun visitVaultCredentialCreated( + vaultCredentialCreated: BetaWebhookVaultCredentialCreatedEventData + ) { + vaultCredentialCreated.validate() + } + + override fun visitVaultCredentialArchived( + vaultCredentialArchived: BetaWebhookVaultCredentialArchivedEventData + ) { + vaultCredentialArchived.validate() + } + + override fun visitVaultCredentialDeleted( + vaultCredentialDeleted: BetaWebhookVaultCredentialDeletedEventData + ) { + vaultCredentialDeleted.validate() + } + + override fun visitVaultCredentialRefreshFailed( + vaultCredentialRefreshFailed: BetaWebhookVaultCredentialRefreshFailedEventData + ) { + vaultCredentialRefreshFailed.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 visitSessionCreated( + sessionCreated: BetaWebhookSessionCreatedEventData + ) = sessionCreated.validity() + + override fun visitSessionPending( + sessionPending: BetaWebhookSessionPendingEventData + ) = sessionPending.validity() + + override fun visitSessionRunning( + sessionRunning: BetaWebhookSessionRunningEventData + ) = sessionRunning.validity() + + override fun visitSessionIdled(sessionIdled: BetaWebhookSessionIdledEventData) = + sessionIdled.validity() + + override fun visitSessionRequiresAction( + sessionRequiresAction: BetaWebhookSessionRequiresActionEventData + ) = sessionRequiresAction.validity() + + override fun visitSessionArchived( + sessionArchived: BetaWebhookSessionArchivedEventData + ) = sessionArchived.validity() + + override fun visitSessionDeleted( + sessionDeleted: BetaWebhookSessionDeletedEventData + ) = sessionDeleted.validity() + + override fun visitSessionStatusScheduled( + sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData + ) = sessionStatusScheduled.validity() + + override fun visitSessionStatusRunStarted( + sessionStatusRunStarted: BetaWebhookSessionStatusRunStartedEventData + ) = sessionStatusRunStarted.validity() + + override fun visitSessionStatusIdled( + sessionStatusIdled: BetaWebhookSessionStatusIdledEventData + ) = sessionStatusIdled.validity() + + override fun visitSessionStatusTerminated( + sessionStatusTerminated: BetaWebhookSessionStatusTerminatedEventData + ) = sessionStatusTerminated.validity() + + override fun visitSessionThreadCreated( + sessionThreadCreated: BetaWebhookSessionThreadCreatedEventData + ) = sessionThreadCreated.validity() + + override fun visitSessionThreadIdled( + sessionThreadIdled: BetaWebhookSessionThreadIdledEventData + ) = sessionThreadIdled.validity() + + override fun visitSessionThreadTerminated( + sessionThreadTerminated: BetaWebhookSessionThreadTerminatedEventData + ) = sessionThreadTerminated.validity() + + override fun visitSessionOutcomeEvaluationEnded( + sessionOutcomeEvaluationEnded: BetaWebhookSessionOutcomeEvaluationEndedEventData + ) = sessionOutcomeEvaluationEnded.validity() + + override fun visitVaultCreated(vaultCreated: BetaWebhookVaultCreatedEventData) = + vaultCreated.validity() + + override fun visitVaultArchived(vaultArchived: BetaWebhookVaultArchivedEventData) = + vaultArchived.validity() + + override fun visitVaultDeleted(vaultDeleted: BetaWebhookVaultDeletedEventData) = + vaultDeleted.validity() + + override fun visitVaultCredentialCreated( + vaultCredentialCreated: BetaWebhookVaultCredentialCreatedEventData + ) = vaultCredentialCreated.validity() + + override fun visitVaultCredentialArchived( + vaultCredentialArchived: BetaWebhookVaultCredentialArchivedEventData + ) = vaultCredentialArchived.validity() + + override fun visitVaultCredentialDeleted( + vaultCredentialDeleted: BetaWebhookVaultCredentialDeletedEventData + ) = vaultCredentialDeleted.validity() + + override fun visitVaultCredentialRefreshFailed( + vaultCredentialRefreshFailed: BetaWebhookVaultCredentialRefreshFailedEventData + ) = vaultCredentialRefreshFailed.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookEventData && + sessionCreated == other.sessionCreated && + sessionPending == other.sessionPending && + sessionRunning == other.sessionRunning && + sessionIdled == other.sessionIdled && + sessionRequiresAction == other.sessionRequiresAction && + sessionArchived == other.sessionArchived && + sessionDeleted == other.sessionDeleted && + sessionStatusScheduled == other.sessionStatusScheduled && + sessionStatusRunStarted == other.sessionStatusRunStarted && + sessionStatusIdled == other.sessionStatusIdled && + sessionStatusTerminated == other.sessionStatusTerminated && + sessionThreadCreated == other.sessionThreadCreated && + sessionThreadIdled == other.sessionThreadIdled && + sessionThreadTerminated == other.sessionThreadTerminated && + sessionOutcomeEvaluationEnded == other.sessionOutcomeEvaluationEnded && + vaultCreated == other.vaultCreated && + vaultArchived == other.vaultArchived && + vaultDeleted == other.vaultDeleted && + vaultCredentialCreated == other.vaultCredentialCreated && + vaultCredentialArchived == other.vaultCredentialArchived && + vaultCredentialDeleted == other.vaultCredentialDeleted && + vaultCredentialRefreshFailed == other.vaultCredentialRefreshFailed + } + + override fun hashCode(): Int = + Objects.hash( + sessionCreated, + sessionPending, + sessionRunning, + sessionIdled, + sessionRequiresAction, + sessionArchived, + sessionDeleted, + sessionStatusScheduled, + sessionStatusRunStarted, + sessionStatusIdled, + sessionStatusTerminated, + sessionThreadCreated, + sessionThreadIdled, + sessionThreadTerminated, + sessionOutcomeEvaluationEnded, + vaultCreated, + vaultArchived, + vaultDeleted, + vaultCredentialCreated, + vaultCredentialArchived, + vaultCredentialDeleted, + vaultCredentialRefreshFailed, + ) + + override fun toString(): String = + when { + sessionCreated != null -> "BetaWebhookEventData{sessionCreated=$sessionCreated}" + sessionPending != null -> "BetaWebhookEventData{sessionPending=$sessionPending}" + sessionRunning != null -> "BetaWebhookEventData{sessionRunning=$sessionRunning}" + sessionIdled != null -> "BetaWebhookEventData{sessionIdled=$sessionIdled}" + sessionRequiresAction != null -> + "BetaWebhookEventData{sessionRequiresAction=$sessionRequiresAction}" + sessionArchived != null -> "BetaWebhookEventData{sessionArchived=$sessionArchived}" + sessionDeleted != null -> "BetaWebhookEventData{sessionDeleted=$sessionDeleted}" + sessionStatusScheduled != null -> + "BetaWebhookEventData{sessionStatusScheduled=$sessionStatusScheduled}" + sessionStatusRunStarted != null -> + "BetaWebhookEventData{sessionStatusRunStarted=$sessionStatusRunStarted}" + sessionStatusIdled != null -> + "BetaWebhookEventData{sessionStatusIdled=$sessionStatusIdled}" + sessionStatusTerminated != null -> + "BetaWebhookEventData{sessionStatusTerminated=$sessionStatusTerminated}" + sessionThreadCreated != null -> + "BetaWebhookEventData{sessionThreadCreated=$sessionThreadCreated}" + sessionThreadIdled != null -> + "BetaWebhookEventData{sessionThreadIdled=$sessionThreadIdled}" + sessionThreadTerminated != null -> + "BetaWebhookEventData{sessionThreadTerminated=$sessionThreadTerminated}" + sessionOutcomeEvaluationEnded != null -> + "BetaWebhookEventData{sessionOutcomeEvaluationEnded=$sessionOutcomeEvaluationEnded}" + vaultCreated != null -> "BetaWebhookEventData{vaultCreated=$vaultCreated}" + vaultArchived != null -> "BetaWebhookEventData{vaultArchived=$vaultArchived}" + vaultDeleted != null -> "BetaWebhookEventData{vaultDeleted=$vaultDeleted}" + vaultCredentialCreated != null -> + "BetaWebhookEventData{vaultCredentialCreated=$vaultCredentialCreated}" + vaultCredentialArchived != null -> + "BetaWebhookEventData{vaultCredentialArchived=$vaultCredentialArchived}" + vaultCredentialDeleted != null -> + "BetaWebhookEventData{vaultCredentialDeleted=$vaultCredentialDeleted}" + vaultCredentialRefreshFailed != null -> + "BetaWebhookEventData{vaultCredentialRefreshFailed=$vaultCredentialRefreshFailed}" + _json != null -> "BetaWebhookEventData{_unknown=$_json}" + else -> throw IllegalStateException("Invalid BetaWebhookEventData") + } + + companion object { + + @JvmStatic + fun ofSessionCreated(sessionCreated: BetaWebhookSessionCreatedEventData) = + BetaWebhookEventData(sessionCreated = sessionCreated) + + @JvmStatic + fun ofSessionPending(sessionPending: BetaWebhookSessionPendingEventData) = + BetaWebhookEventData(sessionPending = sessionPending) + + @JvmStatic + fun ofSessionRunning(sessionRunning: BetaWebhookSessionRunningEventData) = + BetaWebhookEventData(sessionRunning = sessionRunning) + + @JvmStatic + fun ofSessionIdled(sessionIdled: BetaWebhookSessionIdledEventData) = + BetaWebhookEventData(sessionIdled = sessionIdled) + + @JvmStatic + fun ofSessionRequiresAction( + sessionRequiresAction: BetaWebhookSessionRequiresActionEventData + ) = BetaWebhookEventData(sessionRequiresAction = sessionRequiresAction) + + @JvmStatic + fun ofSessionArchived(sessionArchived: BetaWebhookSessionArchivedEventData) = + BetaWebhookEventData(sessionArchived = sessionArchived) + + @JvmStatic + fun ofSessionDeleted(sessionDeleted: BetaWebhookSessionDeletedEventData) = + BetaWebhookEventData(sessionDeleted = sessionDeleted) + + @JvmStatic + fun ofSessionStatusScheduled( + sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData + ) = BetaWebhookEventData(sessionStatusScheduled = sessionStatusScheduled) + + @JvmStatic + fun ofSessionStatusRunStarted( + sessionStatusRunStarted: BetaWebhookSessionStatusRunStartedEventData + ) = BetaWebhookEventData(sessionStatusRunStarted = sessionStatusRunStarted) + + @JvmStatic + fun ofSessionStatusIdled(sessionStatusIdled: BetaWebhookSessionStatusIdledEventData) = + BetaWebhookEventData(sessionStatusIdled = sessionStatusIdled) + + @JvmStatic + fun ofSessionStatusTerminated( + sessionStatusTerminated: BetaWebhookSessionStatusTerminatedEventData + ) = BetaWebhookEventData(sessionStatusTerminated = sessionStatusTerminated) + + @JvmStatic + fun ofSessionThreadCreated(sessionThreadCreated: BetaWebhookSessionThreadCreatedEventData) = + BetaWebhookEventData(sessionThreadCreated = sessionThreadCreated) + + @JvmStatic + fun ofSessionThreadIdled(sessionThreadIdled: BetaWebhookSessionThreadIdledEventData) = + BetaWebhookEventData(sessionThreadIdled = sessionThreadIdled) + + @JvmStatic + fun ofSessionThreadTerminated( + sessionThreadTerminated: BetaWebhookSessionThreadTerminatedEventData + ) = BetaWebhookEventData(sessionThreadTerminated = sessionThreadTerminated) + + @JvmStatic + fun ofSessionOutcomeEvaluationEnded( + sessionOutcomeEvaluationEnded: BetaWebhookSessionOutcomeEvaluationEndedEventData + ) = BetaWebhookEventData(sessionOutcomeEvaluationEnded = sessionOutcomeEvaluationEnded) + + @JvmStatic + fun ofVaultCreated(vaultCreated: BetaWebhookVaultCreatedEventData) = + BetaWebhookEventData(vaultCreated = vaultCreated) + + @JvmStatic + fun ofVaultArchived(vaultArchived: BetaWebhookVaultArchivedEventData) = + BetaWebhookEventData(vaultArchived = vaultArchived) + + @JvmStatic + fun ofVaultDeleted(vaultDeleted: BetaWebhookVaultDeletedEventData) = + BetaWebhookEventData(vaultDeleted = vaultDeleted) + + @JvmStatic + fun ofVaultCredentialCreated( + vaultCredentialCreated: BetaWebhookVaultCredentialCreatedEventData + ) = BetaWebhookEventData(vaultCredentialCreated = vaultCredentialCreated) + + @JvmStatic + fun ofVaultCredentialArchived( + vaultCredentialArchived: BetaWebhookVaultCredentialArchivedEventData + ) = BetaWebhookEventData(vaultCredentialArchived = vaultCredentialArchived) + + @JvmStatic + fun ofVaultCredentialDeleted( + vaultCredentialDeleted: BetaWebhookVaultCredentialDeletedEventData + ) = BetaWebhookEventData(vaultCredentialDeleted = vaultCredentialDeleted) + + @JvmStatic + fun ofVaultCredentialRefreshFailed( + vaultCredentialRefreshFailed: BetaWebhookVaultCredentialRefreshFailedEventData + ) = BetaWebhookEventData(vaultCredentialRefreshFailed = vaultCredentialRefreshFailed) + } + + /** + * An interface that defines how to map each variant of [BetaWebhookEventData] to a value of + * type [T]. + */ + interface Visitor { + + fun visitSessionCreated(sessionCreated: BetaWebhookSessionCreatedEventData): T + + fun visitSessionPending(sessionPending: BetaWebhookSessionPendingEventData): T + + fun visitSessionRunning(sessionRunning: BetaWebhookSessionRunningEventData): T + + fun visitSessionIdled(sessionIdled: BetaWebhookSessionIdledEventData): T + + fun visitSessionRequiresAction( + sessionRequiresAction: BetaWebhookSessionRequiresActionEventData + ): T + + fun visitSessionArchived(sessionArchived: BetaWebhookSessionArchivedEventData): T + + fun visitSessionDeleted(sessionDeleted: BetaWebhookSessionDeletedEventData): T + + fun visitSessionStatusScheduled( + sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData + ): T + + fun visitSessionStatusRunStarted( + sessionStatusRunStarted: BetaWebhookSessionStatusRunStartedEventData + ): T + + fun visitSessionStatusIdled(sessionStatusIdled: BetaWebhookSessionStatusIdledEventData): T + + fun visitSessionStatusTerminated( + sessionStatusTerminated: BetaWebhookSessionStatusTerminatedEventData + ): T + + fun visitSessionThreadCreated( + sessionThreadCreated: BetaWebhookSessionThreadCreatedEventData + ): T + + fun visitSessionThreadIdled(sessionThreadIdled: BetaWebhookSessionThreadIdledEventData): T + + fun visitSessionThreadTerminated( + sessionThreadTerminated: BetaWebhookSessionThreadTerminatedEventData + ): T + + fun visitSessionOutcomeEvaluationEnded( + sessionOutcomeEvaluationEnded: BetaWebhookSessionOutcomeEvaluationEndedEventData + ): T + + fun visitVaultCreated(vaultCreated: BetaWebhookVaultCreatedEventData): T + + fun visitVaultArchived(vaultArchived: BetaWebhookVaultArchivedEventData): T + + fun visitVaultDeleted(vaultDeleted: BetaWebhookVaultDeletedEventData): T + + fun visitVaultCredentialCreated( + vaultCredentialCreated: BetaWebhookVaultCredentialCreatedEventData + ): T + + fun visitVaultCredentialArchived( + vaultCredentialArchived: BetaWebhookVaultCredentialArchivedEventData + ): T + + fun visitVaultCredentialDeleted( + vaultCredentialDeleted: BetaWebhookVaultCredentialDeletedEventData + ): T + + fun visitVaultCredentialRefreshFailed( + vaultCredentialRefreshFailed: BetaWebhookVaultCredentialRefreshFailedEventData + ): T + + /** + * Maps an unknown variant of [BetaWebhookEventData] to a value of type [T]. + * + * An instance of [BetaWebhookEventData] 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 AnthropicInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw AnthropicInvalidDataException("Unknown BetaWebhookEventData: $json") + } + } + + internal class Deserializer : + BaseDeserializer(BetaWebhookEventData::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): BetaWebhookEventData { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "session.created" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionCreated = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.pending" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionPending = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.running" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionRunning = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.idled" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { BetaWebhookEventData(sessionIdled = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.requires_action" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionRequiresAction = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.archived" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionArchived = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.deleted" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionDeleted = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.status_scheduled" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionStatusScheduled = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.status_run_started" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionStatusRunStarted = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.status_idled" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionStatusIdled = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.status_terminated" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionStatusTerminated = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.thread_created" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionThreadCreated = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.thread_idled" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionThreadIdled = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.thread_terminated" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(sessionThreadTerminated = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "session.outcome_evaluation_ended" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaWebhookEventData(sessionOutcomeEvaluationEnded = it, _json = json) + } ?: BetaWebhookEventData(_json = json) + } + "vault.created" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { BetaWebhookEventData(vaultCreated = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "vault.archived" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { BetaWebhookEventData(vaultArchived = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "vault.deleted" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { BetaWebhookEventData(vaultDeleted = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "vault_credential.created" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(vaultCredentialCreated = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "vault_credential.archived" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(vaultCredentialArchived = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "vault_credential.deleted" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaWebhookEventData(vaultCredentialDeleted = it, _json = json) } + ?: BetaWebhookEventData(_json = json) + } + "vault_credential.refresh_failed" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + BetaWebhookEventData(vaultCredentialRefreshFailed = it, _json = json) + } ?: BetaWebhookEventData(_json = json) + } + } + + return BetaWebhookEventData(_json = json) + } + } + + internal class Serializer : BaseSerializer(BetaWebhookEventData::class) { + + override fun serialize( + value: BetaWebhookEventData, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.sessionCreated != null -> generator.writeObject(value.sessionCreated) + value.sessionPending != null -> generator.writeObject(value.sessionPending) + value.sessionRunning != null -> generator.writeObject(value.sessionRunning) + value.sessionIdled != null -> generator.writeObject(value.sessionIdled) + value.sessionRequiresAction != null -> + generator.writeObject(value.sessionRequiresAction) + value.sessionArchived != null -> generator.writeObject(value.sessionArchived) + value.sessionDeleted != null -> generator.writeObject(value.sessionDeleted) + value.sessionStatusScheduled != null -> + generator.writeObject(value.sessionStatusScheduled) + value.sessionStatusRunStarted != null -> + generator.writeObject(value.sessionStatusRunStarted) + value.sessionStatusIdled != null -> generator.writeObject(value.sessionStatusIdled) + value.sessionStatusTerminated != null -> + generator.writeObject(value.sessionStatusTerminated) + value.sessionThreadCreated != null -> + generator.writeObject(value.sessionThreadCreated) + value.sessionThreadIdled != null -> generator.writeObject(value.sessionThreadIdled) + value.sessionThreadTerminated != null -> + generator.writeObject(value.sessionThreadTerminated) + value.sessionOutcomeEvaluationEnded != null -> + generator.writeObject(value.sessionOutcomeEvaluationEnded) + value.vaultCreated != null -> generator.writeObject(value.vaultCreated) + value.vaultArchived != null -> generator.writeObject(value.vaultArchived) + value.vaultDeleted != null -> generator.writeObject(value.vaultDeleted) + value.vaultCredentialCreated != null -> + generator.writeObject(value.vaultCredentialCreated) + value.vaultCredentialArchived != null -> + generator.writeObject(value.vaultCredentialArchived) + value.vaultCredentialDeleted != null -> + generator.writeObject(value.vaultCredentialDeleted) + value.vaultCredentialRefreshFailed != null -> + generator.writeObject(value.vaultCredentialRefreshFailed) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid BetaWebhookEventData") + } + } + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionArchivedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionArchivedEventData.kt new file mode 100644 index 000000000..141d22069 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionArchivedEventData.kt @@ -0,0 +1,304 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionArchivedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.archived") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionArchivedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionArchivedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.archived") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookSessionArchivedEventData: BetaWebhookSessionArchivedEventData + ) = apply { + id = betaWebhookSessionArchivedEventData.id + organizationId = betaWebhookSessionArchivedEventData.organizationId + type = betaWebhookSessionArchivedEventData.type + workspaceId = betaWebhookSessionArchivedEventData.workspaceId + additionalProperties = + betaWebhookSessionArchivedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.archived") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionArchivedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionArchivedEventData = + BetaWebhookSessionArchivedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionArchivedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.archived")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.archived")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionArchivedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionArchivedEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionCreatedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionCreatedEventData.kt new file mode 100644 index 000000000..e8dc9b536 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionCreatedEventData.kt @@ -0,0 +1,303 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionCreatedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.created") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionCreatedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionCreatedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.created") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaWebhookSessionCreatedEventData: BetaWebhookSessionCreatedEventData) = + apply { + id = betaWebhookSessionCreatedEventData.id + organizationId = betaWebhookSessionCreatedEventData.organizationId + type = betaWebhookSessionCreatedEventData.type + workspaceId = betaWebhookSessionCreatedEventData.workspaceId + additionalProperties = + betaWebhookSessionCreatedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.created") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionCreatedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionCreatedEventData = + BetaWebhookSessionCreatedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionCreatedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.created")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.created")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionCreatedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionCreatedEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionDeletedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionDeletedEventData.kt new file mode 100644 index 000000000..85a008c0e --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionDeletedEventData.kt @@ -0,0 +1,303 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionDeletedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.deleted") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionDeletedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionDeletedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.deleted") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaWebhookSessionDeletedEventData: BetaWebhookSessionDeletedEventData) = + apply { + id = betaWebhookSessionDeletedEventData.id + organizationId = betaWebhookSessionDeletedEventData.organizationId + type = betaWebhookSessionDeletedEventData.type + workspaceId = betaWebhookSessionDeletedEventData.workspaceId + additionalProperties = + betaWebhookSessionDeletedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.deleted") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionDeletedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionDeletedEventData = + BetaWebhookSessionDeletedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionDeletedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.deleted")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.deleted")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionDeletedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionDeletedEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionIdledEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionIdledEventData.kt new file mode 100644 index 000000000..e3e139e11 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionIdledEventData.kt @@ -0,0 +1,303 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionIdledEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.idled") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionIdledEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionIdledEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.idled") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaWebhookSessionIdledEventData: BetaWebhookSessionIdledEventData) = + apply { + id = betaWebhookSessionIdledEventData.id + organizationId = betaWebhookSessionIdledEventData.organizationId + type = betaWebhookSessionIdledEventData.type + workspaceId = betaWebhookSessionIdledEventData.workspaceId + additionalProperties = + betaWebhookSessionIdledEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.idled") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionIdledEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionIdledEventData = + BetaWebhookSessionIdledEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionIdledEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.idled")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.idled")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionIdledEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionIdledEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionOutcomeEvaluationEndedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionOutcomeEvaluationEndedEventData.kt new file mode 100644 index 000000000..6bb83b379 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionOutcomeEvaluationEndedEventData.kt @@ -0,0 +1,306 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionOutcomeEvaluationEndedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.outcome_evaluation_ended") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionOutcomeEvaluationEndedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionOutcomeEvaluationEndedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.outcome_evaluation_ended") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookSessionOutcomeEvaluationEndedEventData: + BetaWebhookSessionOutcomeEvaluationEndedEventData + ) = apply { + id = betaWebhookSessionOutcomeEvaluationEndedEventData.id + organizationId = betaWebhookSessionOutcomeEvaluationEndedEventData.organizationId + type = betaWebhookSessionOutcomeEvaluationEndedEventData.type + workspaceId = betaWebhookSessionOutcomeEvaluationEndedEventData.workspaceId + additionalProperties = + betaWebhookSessionOutcomeEvaluationEndedEventData.additionalProperties + .toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.outcome_evaluation_ended") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionOutcomeEvaluationEndedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionOutcomeEvaluationEndedEventData = + BetaWebhookSessionOutcomeEvaluationEndedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionOutcomeEvaluationEndedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.outcome_evaluation_ended")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.outcome_evaluation_ended")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionOutcomeEvaluationEndedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionOutcomeEvaluationEndedEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionPendingEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionPendingEventData.kt new file mode 100644 index 000000000..cebc7c6d3 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionPendingEventData.kt @@ -0,0 +1,303 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionPendingEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.pending") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionPendingEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionPendingEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.pending") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaWebhookSessionPendingEventData: BetaWebhookSessionPendingEventData) = + apply { + id = betaWebhookSessionPendingEventData.id + organizationId = betaWebhookSessionPendingEventData.organizationId + type = betaWebhookSessionPendingEventData.type + workspaceId = betaWebhookSessionPendingEventData.workspaceId + additionalProperties = + betaWebhookSessionPendingEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.pending") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionPendingEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionPendingEventData = + BetaWebhookSessionPendingEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionPendingEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.pending")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.pending")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionPendingEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionPendingEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRequiresActionEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRequiresActionEventData.kt new file mode 100644 index 000000000..0645edc95 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRequiresActionEventData.kt @@ -0,0 +1,304 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionRequiresActionEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.requires_action") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionRequiresActionEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionRequiresActionEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.requires_action") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookSessionRequiresActionEventData: BetaWebhookSessionRequiresActionEventData + ) = apply { + id = betaWebhookSessionRequiresActionEventData.id + organizationId = betaWebhookSessionRequiresActionEventData.organizationId + type = betaWebhookSessionRequiresActionEventData.type + workspaceId = betaWebhookSessionRequiresActionEventData.workspaceId + additionalProperties = + betaWebhookSessionRequiresActionEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.requires_action") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionRequiresActionEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionRequiresActionEventData = + BetaWebhookSessionRequiresActionEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionRequiresActionEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.requires_action")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.requires_action")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionRequiresActionEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionRequiresActionEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRunningEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRunningEventData.kt new file mode 100644 index 000000000..76a35f6fa --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRunningEventData.kt @@ -0,0 +1,303 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionRunningEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.running") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionRunningEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionRunningEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.running") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaWebhookSessionRunningEventData: BetaWebhookSessionRunningEventData) = + apply { + id = betaWebhookSessionRunningEventData.id + organizationId = betaWebhookSessionRunningEventData.organizationId + type = betaWebhookSessionRunningEventData.type + workspaceId = betaWebhookSessionRunningEventData.workspaceId + additionalProperties = + betaWebhookSessionRunningEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.running") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionRunningEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionRunningEventData = + BetaWebhookSessionRunningEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionRunningEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.running")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.running")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionRunningEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionRunningEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusIdledEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusIdledEventData.kt new file mode 100644 index 000000000..585cb3fd0 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusIdledEventData.kt @@ -0,0 +1,304 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionStatusIdledEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.status_idled") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionStatusIdledEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionStatusIdledEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.status_idled") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookSessionStatusIdledEventData: BetaWebhookSessionStatusIdledEventData + ) = apply { + id = betaWebhookSessionStatusIdledEventData.id + organizationId = betaWebhookSessionStatusIdledEventData.organizationId + type = betaWebhookSessionStatusIdledEventData.type + workspaceId = betaWebhookSessionStatusIdledEventData.workspaceId + additionalProperties = + betaWebhookSessionStatusIdledEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.status_idled") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionStatusIdledEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionStatusIdledEventData = + BetaWebhookSessionStatusIdledEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionStatusIdledEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.status_idled")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.status_idled")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionStatusIdledEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionStatusIdledEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRunStartedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRunStartedEventData.kt new file mode 100644 index 000000000..bcbd51235 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRunStartedEventData.kt @@ -0,0 +1,304 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionStatusRunStartedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.status_run_started") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionStatusRunStartedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionStatusRunStartedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.status_run_started") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookSessionStatusRunStartedEventData: BetaWebhookSessionStatusRunStartedEventData + ) = apply { + id = betaWebhookSessionStatusRunStartedEventData.id + organizationId = betaWebhookSessionStatusRunStartedEventData.organizationId + type = betaWebhookSessionStatusRunStartedEventData.type + workspaceId = betaWebhookSessionStatusRunStartedEventData.workspaceId + additionalProperties = + betaWebhookSessionStatusRunStartedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.status_run_started") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionStatusRunStartedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionStatusRunStartedEventData = + BetaWebhookSessionStatusRunStartedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionStatusRunStartedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.status_run_started")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.status_run_started")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionStatusRunStartedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionStatusRunStartedEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventData.kt new file mode 100644 index 000000000..37e087ed6 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventData.kt @@ -0,0 +1,304 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionStatusScheduledEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.status_scheduled") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionStatusScheduledEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionStatusScheduledEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.status_scheduled") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookSessionStatusScheduledEventData: BetaWebhookSessionStatusScheduledEventData + ) = apply { + id = betaWebhookSessionStatusScheduledEventData.id + organizationId = betaWebhookSessionStatusScheduledEventData.organizationId + type = betaWebhookSessionStatusScheduledEventData.type + workspaceId = betaWebhookSessionStatusScheduledEventData.workspaceId + additionalProperties = + betaWebhookSessionStatusScheduledEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.status_scheduled") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionStatusScheduledEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionStatusScheduledEventData = + BetaWebhookSessionStatusScheduledEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionStatusScheduledEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.status_scheduled")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.status_scheduled")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionStatusScheduledEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionStatusScheduledEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusTerminatedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusTerminatedEventData.kt new file mode 100644 index 000000000..7c6ff399b --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusTerminatedEventData.kt @@ -0,0 +1,304 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionStatusTerminatedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.status_terminated") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionStatusTerminatedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionStatusTerminatedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.status_terminated") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookSessionStatusTerminatedEventData: BetaWebhookSessionStatusTerminatedEventData + ) = apply { + id = betaWebhookSessionStatusTerminatedEventData.id + organizationId = betaWebhookSessionStatusTerminatedEventData.organizationId + type = betaWebhookSessionStatusTerminatedEventData.type + workspaceId = betaWebhookSessionStatusTerminatedEventData.workspaceId + additionalProperties = + betaWebhookSessionStatusTerminatedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.status_terminated") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionStatusTerminatedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionStatusTerminatedEventData = + BetaWebhookSessionStatusTerminatedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionStatusTerminatedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.status_terminated")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.status_terminated")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionStatusTerminatedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionStatusTerminatedEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadCreatedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadCreatedEventData.kt new file mode 100644 index 000000000..7a5af028d --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadCreatedEventData.kt @@ -0,0 +1,304 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionThreadCreatedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.thread_created") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionThreadCreatedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionThreadCreatedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.thread_created") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookSessionThreadCreatedEventData: BetaWebhookSessionThreadCreatedEventData + ) = apply { + id = betaWebhookSessionThreadCreatedEventData.id + organizationId = betaWebhookSessionThreadCreatedEventData.organizationId + type = betaWebhookSessionThreadCreatedEventData.type + workspaceId = betaWebhookSessionThreadCreatedEventData.workspaceId + additionalProperties = + betaWebhookSessionThreadCreatedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.thread_created") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionThreadCreatedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionThreadCreatedEventData = + BetaWebhookSessionThreadCreatedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionThreadCreatedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.thread_created")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.thread_created")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionThreadCreatedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionThreadCreatedEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadIdledEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadIdledEventData.kt new file mode 100644 index 000000000..ea195ef8b --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadIdledEventData.kt @@ -0,0 +1,304 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionThreadIdledEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.thread_idled") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionThreadIdledEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionThreadIdledEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.thread_idled") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookSessionThreadIdledEventData: BetaWebhookSessionThreadIdledEventData + ) = apply { + id = betaWebhookSessionThreadIdledEventData.id + organizationId = betaWebhookSessionThreadIdledEventData.organizationId + type = betaWebhookSessionThreadIdledEventData.type + workspaceId = betaWebhookSessionThreadIdledEventData.workspaceId + additionalProperties = + betaWebhookSessionThreadIdledEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.thread_idled") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionThreadIdledEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionThreadIdledEventData = + BetaWebhookSessionThreadIdledEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionThreadIdledEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.thread_idled")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.thread_idled")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionThreadIdledEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionThreadIdledEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadTerminatedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadTerminatedEventData.kt new file mode 100644 index 000000000..78a7dd982 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadTerminatedEventData.kt @@ -0,0 +1,304 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookSessionThreadTerminatedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("session.thread_terminated") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookSessionThreadTerminatedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookSessionThreadTerminatedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("session.thread_terminated") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookSessionThreadTerminatedEventData: BetaWebhookSessionThreadTerminatedEventData + ) = apply { + id = betaWebhookSessionThreadTerminatedEventData.id + organizationId = betaWebhookSessionThreadTerminatedEventData.organizationId + type = betaWebhookSessionThreadTerminatedEventData.type + workspaceId = betaWebhookSessionThreadTerminatedEventData.workspaceId + additionalProperties = + betaWebhookSessionThreadTerminatedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("session.thread_terminated") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookSessionThreadTerminatedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookSessionThreadTerminatedEventData = + BetaWebhookSessionThreadTerminatedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookSessionThreadTerminatedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("session.thread_terminated")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("session.thread_terminated")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookSessionThreadTerminatedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookSessionThreadTerminatedEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultArchivedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultArchivedEventData.kt new file mode 100644 index 000000000..b8d3579fa --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultArchivedEventData.kt @@ -0,0 +1,303 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookVaultArchivedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("vault.archived") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookVaultArchivedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookVaultArchivedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("vault.archived") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaWebhookVaultArchivedEventData: BetaWebhookVaultArchivedEventData) = + apply { + id = betaWebhookVaultArchivedEventData.id + organizationId = betaWebhookVaultArchivedEventData.organizationId + type = betaWebhookVaultArchivedEventData.type + workspaceId = betaWebhookVaultArchivedEventData.workspaceId + additionalProperties = + betaWebhookVaultArchivedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("vault.archived") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookVaultArchivedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookVaultArchivedEventData = + BetaWebhookVaultArchivedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookVaultArchivedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("vault.archived")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("vault.archived")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookVaultArchivedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookVaultArchivedEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCreatedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCreatedEventData.kt new file mode 100644 index 000000000..e82d5a3b4 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCreatedEventData.kt @@ -0,0 +1,303 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookVaultCreatedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("vault.created") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookVaultCreatedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookVaultCreatedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("vault.created") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaWebhookVaultCreatedEventData: BetaWebhookVaultCreatedEventData) = + apply { + id = betaWebhookVaultCreatedEventData.id + organizationId = betaWebhookVaultCreatedEventData.organizationId + type = betaWebhookVaultCreatedEventData.type + workspaceId = betaWebhookVaultCreatedEventData.workspaceId + additionalProperties = + betaWebhookVaultCreatedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("vault.created") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookVaultCreatedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookVaultCreatedEventData = + BetaWebhookVaultCreatedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookVaultCreatedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("vault.created")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("vault.created")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookVaultCreatedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookVaultCreatedEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialArchivedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialArchivedEventData.kt new file mode 100644 index 000000000..41142198c --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialArchivedEventData.kt @@ -0,0 +1,340 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookVaultCredentialArchivedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val vaultId: JsonField, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("vault_id") @ExcludeMissing vaultId: JsonField = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, vaultId, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("vault_credential.archived") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * ID of the vault that owns this credential. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun vaultId(): String = vaultId.getRequired("vault_id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [vaultId]. + * + * Unlike [vaultId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("vault_id") @ExcludeMissing fun _vaultId(): JsonField = vaultId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookVaultCredentialArchivedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .vaultId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookVaultCredentialArchivedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("vault_credential.archived") + private var vaultId: JsonField? = null + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookVaultCredentialArchivedEventData: BetaWebhookVaultCredentialArchivedEventData + ) = apply { + id = betaWebhookVaultCredentialArchivedEventData.id + organizationId = betaWebhookVaultCredentialArchivedEventData.organizationId + type = betaWebhookVaultCredentialArchivedEventData.type + vaultId = betaWebhookVaultCredentialArchivedEventData.vaultId + workspaceId = betaWebhookVaultCredentialArchivedEventData.workspaceId + additionalProperties = + betaWebhookVaultCredentialArchivedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("vault_credential.archived") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** ID of the vault that owns this credential. */ + fun vaultId(vaultId: String) = vaultId(JsonField.of(vaultId)) + + /** + * Sets [Builder.vaultId] to an arbitrary JSON value. + * + * You should usually call [Builder.vaultId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun vaultId(vaultId: JsonField) = apply { this.vaultId = vaultId } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookVaultCredentialArchivedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .vaultId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookVaultCredentialArchivedEventData = + BetaWebhookVaultCredentialArchivedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("vaultId", vaultId), + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookVaultCredentialArchivedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("vault_credential.archived")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + vaultId() + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("vault_credential.archived")) 1 else 0 } + + (if (vaultId.asKnown().isPresent) 1 else 0) + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookVaultCredentialArchivedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + vaultId == other.vaultId && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, vaultId, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookVaultCredentialArchivedEventData{id=$id, organizationId=$organizationId, type=$type, vaultId=$vaultId, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialCreatedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialCreatedEventData.kt new file mode 100644 index 000000000..9991ca7b5 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialCreatedEventData.kt @@ -0,0 +1,340 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookVaultCredentialCreatedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val vaultId: JsonField, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("vault_id") @ExcludeMissing vaultId: JsonField = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, vaultId, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("vault_credential.created") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * ID of the vault that owns this credential. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun vaultId(): String = vaultId.getRequired("vault_id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [vaultId]. + * + * Unlike [vaultId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("vault_id") @ExcludeMissing fun _vaultId(): JsonField = vaultId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookVaultCredentialCreatedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .vaultId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookVaultCredentialCreatedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("vault_credential.created") + private var vaultId: JsonField? = null + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookVaultCredentialCreatedEventData: BetaWebhookVaultCredentialCreatedEventData + ) = apply { + id = betaWebhookVaultCredentialCreatedEventData.id + organizationId = betaWebhookVaultCredentialCreatedEventData.organizationId + type = betaWebhookVaultCredentialCreatedEventData.type + vaultId = betaWebhookVaultCredentialCreatedEventData.vaultId + workspaceId = betaWebhookVaultCredentialCreatedEventData.workspaceId + additionalProperties = + betaWebhookVaultCredentialCreatedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("vault_credential.created") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** ID of the vault that owns this credential. */ + fun vaultId(vaultId: String) = vaultId(JsonField.of(vaultId)) + + /** + * Sets [Builder.vaultId] to an arbitrary JSON value. + * + * You should usually call [Builder.vaultId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun vaultId(vaultId: JsonField) = apply { this.vaultId = vaultId } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookVaultCredentialCreatedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .vaultId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookVaultCredentialCreatedEventData = + BetaWebhookVaultCredentialCreatedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("vaultId", vaultId), + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookVaultCredentialCreatedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("vault_credential.created")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + vaultId() + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("vault_credential.created")) 1 else 0 } + + (if (vaultId.asKnown().isPresent) 1 else 0) + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookVaultCredentialCreatedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + vaultId == other.vaultId && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, vaultId, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookVaultCredentialCreatedEventData{id=$id, organizationId=$organizationId, type=$type, vaultId=$vaultId, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialDeletedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialDeletedEventData.kt new file mode 100644 index 000000000..4ae862fea --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialDeletedEventData.kt @@ -0,0 +1,340 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookVaultCredentialDeletedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val vaultId: JsonField, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("vault_id") @ExcludeMissing vaultId: JsonField = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, vaultId, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("vault_credential.deleted") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * ID of the vault that owns this credential. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun vaultId(): String = vaultId.getRequired("vault_id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [vaultId]. + * + * Unlike [vaultId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("vault_id") @ExcludeMissing fun _vaultId(): JsonField = vaultId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookVaultCredentialDeletedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .vaultId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookVaultCredentialDeletedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("vault_credential.deleted") + private var vaultId: JsonField? = null + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookVaultCredentialDeletedEventData: BetaWebhookVaultCredentialDeletedEventData + ) = apply { + id = betaWebhookVaultCredentialDeletedEventData.id + organizationId = betaWebhookVaultCredentialDeletedEventData.organizationId + type = betaWebhookVaultCredentialDeletedEventData.type + vaultId = betaWebhookVaultCredentialDeletedEventData.vaultId + workspaceId = betaWebhookVaultCredentialDeletedEventData.workspaceId + additionalProperties = + betaWebhookVaultCredentialDeletedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("vault_credential.deleted") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** ID of the vault that owns this credential. */ + fun vaultId(vaultId: String) = vaultId(JsonField.of(vaultId)) + + /** + * Sets [Builder.vaultId] to an arbitrary JSON value. + * + * You should usually call [Builder.vaultId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun vaultId(vaultId: JsonField) = apply { this.vaultId = vaultId } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookVaultCredentialDeletedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .vaultId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookVaultCredentialDeletedEventData = + BetaWebhookVaultCredentialDeletedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("vaultId", vaultId), + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookVaultCredentialDeletedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("vault_credential.deleted")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + vaultId() + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("vault_credential.deleted")) 1 else 0 } + + (if (vaultId.asKnown().isPresent) 1 else 0) + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookVaultCredentialDeletedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + vaultId == other.vaultId && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, vaultId, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookVaultCredentialDeletedEventData{id=$id, organizationId=$organizationId, type=$type, vaultId=$vaultId, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialRefreshFailedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialRefreshFailedEventData.kt new file mode 100644 index 000000000..afc440e21 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialRefreshFailedEventData.kt @@ -0,0 +1,341 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookVaultCredentialRefreshFailedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val vaultId: JsonField, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("vault_id") @ExcludeMissing vaultId: JsonField = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, vaultId, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("vault_credential.refresh_failed") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * ID of the vault that owns this credential. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun vaultId(): String = vaultId.getRequired("vault_id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [vaultId]. + * + * Unlike [vaultId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("vault_id") @ExcludeMissing fun _vaultId(): JsonField = vaultId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookVaultCredentialRefreshFailedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .vaultId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookVaultCredentialRefreshFailedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("vault_credential.refresh_failed") + private var vaultId: JsonField? = null + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaWebhookVaultCredentialRefreshFailedEventData: + BetaWebhookVaultCredentialRefreshFailedEventData + ) = apply { + id = betaWebhookVaultCredentialRefreshFailedEventData.id + organizationId = betaWebhookVaultCredentialRefreshFailedEventData.organizationId + type = betaWebhookVaultCredentialRefreshFailedEventData.type + vaultId = betaWebhookVaultCredentialRefreshFailedEventData.vaultId + workspaceId = betaWebhookVaultCredentialRefreshFailedEventData.workspaceId + additionalProperties = + betaWebhookVaultCredentialRefreshFailedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("vault_credential.refresh_failed") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** ID of the vault that owns this credential. */ + fun vaultId(vaultId: String) = vaultId(JsonField.of(vaultId)) + + /** + * Sets [Builder.vaultId] to an arbitrary JSON value. + * + * You should usually call [Builder.vaultId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun vaultId(vaultId: JsonField) = apply { this.vaultId = vaultId } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookVaultCredentialRefreshFailedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .vaultId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookVaultCredentialRefreshFailedEventData = + BetaWebhookVaultCredentialRefreshFailedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("vaultId", vaultId), + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookVaultCredentialRefreshFailedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("vault_credential.refresh_failed")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + vaultId() + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("vault_credential.refresh_failed")) 1 else 0 } + + (if (vaultId.asKnown().isPresent) 1 else 0) + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookVaultCredentialRefreshFailedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + vaultId == other.vaultId && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, vaultId, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookVaultCredentialRefreshFailedEventData{id=$id, organizationId=$organizationId, type=$type, vaultId=$vaultId, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultDeletedEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultDeletedEventData.kt new file mode 100644 index 000000000..27c05d09a --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultDeletedEventData.kt @@ -0,0 +1,303 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 + +class BetaWebhookVaultDeletedEventData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val organizationId: JsonField, + private val type: JsonValue, + private val workspaceId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("organization_id") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("workspace_id") + @ExcludeMissing + workspaceId: JsonField = JsonMissing.of(), + ) : this(id, organizationId, type, workspaceId, mutableMapOf()) + + /** + * ID of the resource that triggered the event. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun organizationId(): String = organizationId.getRequired("organization_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("vault.deleted") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun workspaceId(): String = workspaceId.getRequired("workspace_id") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("organization_id") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [workspaceId]. + * + * Unlike [workspaceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("workspace_id") + @ExcludeMissing + fun _workspaceId(): JsonField = workspaceId + + @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 + * [BetaWebhookVaultDeletedEventData]. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaWebhookVaultDeletedEventData]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var organizationId: JsonField? = null + private var type: JsonValue = JsonValue.from("vault.deleted") + private var workspaceId: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaWebhookVaultDeletedEventData: BetaWebhookVaultDeletedEventData) = + apply { + id = betaWebhookVaultDeletedEventData.id + organizationId = betaWebhookVaultDeletedEventData.organizationId + type = betaWebhookVaultDeletedEventData.type + workspaceId = betaWebhookVaultDeletedEventData.workspaceId + additionalProperties = + betaWebhookVaultDeletedEventData.additionalProperties.toMutableMap() + } + + /** ID of the resource that triggered the event. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun organizationId(organizationId: String) = organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("vault.deleted") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun workspaceId(workspaceId: String) = workspaceId(JsonField.of(workspaceId)) + + /** + * Sets [Builder.workspaceId] to an arbitrary JSON value. + * + * You should usually call [Builder.workspaceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun workspaceId(workspaceId: JsonField) = apply { this.workspaceId = workspaceId } + + 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 [BetaWebhookVaultDeletedEventData]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .organizationId() + * .workspaceId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaWebhookVaultDeletedEventData = + BetaWebhookVaultDeletedEventData( + checkRequired("id", id), + checkRequired("organizationId", organizationId), + type, + checkRequired("workspaceId", workspaceId), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): BetaWebhookVaultDeletedEventData = apply { + if (validated) { + return@apply + } + + id() + organizationId() + _type().let { + if (it != JsonValue.from("vault.deleted")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + workspaceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns 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 (organizationId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("vault.deleted")) 1 else 0 } + + (if (workspaceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaWebhookVaultDeletedEventData && + id == other.id && + organizationId == other.organizationId && + type == other.type && + workspaceId == other.workspaceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, organizationId, type, workspaceId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaWebhookVaultDeletedEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/UnwrapWebhookEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/UnwrapWebhookEvent.kt new file mode 100644 index 000000000..41c70dedb --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/UnwrapWebhookEvent.kt @@ -0,0 +1,442 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +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 kotlin.jvm.optionals.getOrNull + +class UnwrapWebhookEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val data: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + data: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(id, createdAt, data, type, mutableMapOf()) + + /** + * Unique event identifier for idempotency. + * + * @throws AnthropicInvalidDataException if 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") + + /** + * RFC 3339 timestamp when the event occurred. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): OffsetDateTime = createdAt.getRequired("created_at") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): BetaWebhookEventData = data.getRequired("data") + + /** + * Object type. Always `event` for webhook payloads. + * + * Expected to always return the following: + * ```java + * JsonValue.from("event") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [UnwrapWebhookEvent]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .data() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UnwrapWebhookEvent]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var data: JsonField? = null + private var type: JsonValue = JsonValue.from("event") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(unwrapWebhookEvent: UnwrapWebhookEvent) = apply { + id = unwrapWebhookEvent.id + createdAt = unwrapWebhookEvent.createdAt + data = unwrapWebhookEvent.data + type = unwrapWebhookEvent.type + additionalProperties = unwrapWebhookEvent.additionalProperties.toMutableMap() + } + + /** Unique event identifier for idempotency. */ + 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 } + + /** RFC 3339 timestamp when the event occurred. */ + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * 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 } + + fun data(data: BetaWebhookEventData) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [BetaWebhookEventData] 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 } + + /** + * Alias for calling [data] with `BetaWebhookEventData.ofSessionCreated(sessionCreated)`. + */ + fun data(sessionCreated: BetaWebhookSessionCreatedEventData) = + data(BetaWebhookEventData.ofSessionCreated(sessionCreated)) + + /** + * Alias for calling [data] with `BetaWebhookEventData.ofSessionPending(sessionPending)`. + */ + fun data(sessionPending: BetaWebhookSessionPendingEventData) = + data(BetaWebhookEventData.ofSessionPending(sessionPending)) + + /** + * Alias for calling [data] with `BetaWebhookEventData.ofSessionRunning(sessionRunning)`. + */ + fun data(sessionRunning: BetaWebhookSessionRunningEventData) = + data(BetaWebhookEventData.ofSessionRunning(sessionRunning)) + + /** Alias for calling [data] with `BetaWebhookEventData.ofSessionIdled(sessionIdled)`. */ + fun data(sessionIdled: BetaWebhookSessionIdledEventData) = + data(BetaWebhookEventData.ofSessionIdled(sessionIdled)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionRequiresAction(sessionRequiresAction)`. + */ + fun data(sessionRequiresAction: BetaWebhookSessionRequiresActionEventData) = + data(BetaWebhookEventData.ofSessionRequiresAction(sessionRequiresAction)) + + /** + * Alias for calling [data] with `BetaWebhookEventData.ofSessionArchived(sessionArchived)`. + */ + fun data(sessionArchived: BetaWebhookSessionArchivedEventData) = + data(BetaWebhookEventData.ofSessionArchived(sessionArchived)) + + /** + * Alias for calling [data] with `BetaWebhookEventData.ofSessionDeleted(sessionDeleted)`. + */ + fun data(sessionDeleted: BetaWebhookSessionDeletedEventData) = + data(BetaWebhookEventData.ofSessionDeleted(sessionDeleted)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionStatusScheduled(sessionStatusScheduled)`. + */ + fun data(sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData) = + data(BetaWebhookEventData.ofSessionStatusScheduled(sessionStatusScheduled)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionStatusRunStarted(sessionStatusRunStarted)`. + */ + fun data(sessionStatusRunStarted: BetaWebhookSessionStatusRunStartedEventData) = + data(BetaWebhookEventData.ofSessionStatusRunStarted(sessionStatusRunStarted)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionStatusIdled(sessionStatusIdled)`. + */ + fun data(sessionStatusIdled: BetaWebhookSessionStatusIdledEventData) = + data(BetaWebhookEventData.ofSessionStatusIdled(sessionStatusIdled)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionStatusTerminated(sessionStatusTerminated)`. + */ + fun data(sessionStatusTerminated: BetaWebhookSessionStatusTerminatedEventData) = + data(BetaWebhookEventData.ofSessionStatusTerminated(sessionStatusTerminated)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionThreadCreated(sessionThreadCreated)`. + */ + fun data(sessionThreadCreated: BetaWebhookSessionThreadCreatedEventData) = + data(BetaWebhookEventData.ofSessionThreadCreated(sessionThreadCreated)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionThreadIdled(sessionThreadIdled)`. + */ + fun data(sessionThreadIdled: BetaWebhookSessionThreadIdledEventData) = + data(BetaWebhookEventData.ofSessionThreadIdled(sessionThreadIdled)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionThreadTerminated(sessionThreadTerminated)`. + */ + fun data(sessionThreadTerminated: BetaWebhookSessionThreadTerminatedEventData) = + data(BetaWebhookEventData.ofSessionThreadTerminated(sessionThreadTerminated)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofSessionOutcomeEvaluationEnded(sessionOutcomeEvaluationEnded)`. + */ + fun data(sessionOutcomeEvaluationEnded: BetaWebhookSessionOutcomeEvaluationEndedEventData) = + data( + BetaWebhookEventData.ofSessionOutcomeEvaluationEnded(sessionOutcomeEvaluationEnded) + ) + + /** Alias for calling [data] with `BetaWebhookEventData.ofVaultCreated(vaultCreated)`. */ + fun data(vaultCreated: BetaWebhookVaultCreatedEventData) = + data(BetaWebhookEventData.ofVaultCreated(vaultCreated)) + + /** Alias for calling [data] with `BetaWebhookEventData.ofVaultArchived(vaultArchived)`. */ + fun data(vaultArchived: BetaWebhookVaultArchivedEventData) = + data(BetaWebhookEventData.ofVaultArchived(vaultArchived)) + + /** Alias for calling [data] with `BetaWebhookEventData.ofVaultDeleted(vaultDeleted)`. */ + fun data(vaultDeleted: BetaWebhookVaultDeletedEventData) = + data(BetaWebhookEventData.ofVaultDeleted(vaultDeleted)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofVaultCredentialCreated(vaultCredentialCreated)`. + */ + fun data(vaultCredentialCreated: BetaWebhookVaultCredentialCreatedEventData) = + data(BetaWebhookEventData.ofVaultCredentialCreated(vaultCredentialCreated)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofVaultCredentialArchived(vaultCredentialArchived)`. + */ + fun data(vaultCredentialArchived: BetaWebhookVaultCredentialArchivedEventData) = + data(BetaWebhookEventData.ofVaultCredentialArchived(vaultCredentialArchived)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofVaultCredentialDeleted(vaultCredentialDeleted)`. + */ + fun data(vaultCredentialDeleted: BetaWebhookVaultCredentialDeletedEventData) = + data(BetaWebhookEventData.ofVaultCredentialDeleted(vaultCredentialDeleted)) + + /** + * Alias for calling [data] with + * `BetaWebhookEventData.ofVaultCredentialRefreshFailed(vaultCredentialRefreshFailed)`. + */ + fun data(vaultCredentialRefreshFailed: BetaWebhookVaultCredentialRefreshFailedEventData) = + data(BetaWebhookEventData.ofVaultCredentialRefreshFailed(vaultCredentialRefreshFailed)) + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("event") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [UnwrapWebhookEvent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .data() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UnwrapWebhookEvent = + UnwrapWebhookEvent( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("data", data), + 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 AnthropicInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): UnwrapWebhookEvent = apply { + if (validated) { + return@apply + } + + id() + createdAt() + data().validate() + _type().let { + if (it != JsonValue.from("event")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AnthropicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (data.asKnown().getOrNull()?.validity() ?: 0) + + type.let { if (it == JsonValue.from("event")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UnwrapWebhookEvent && + id == other.id && + createdAt == other.createdAt && + data == other.data && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, data, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UnwrapWebhookEvent{id=$id, createdAt=$createdAt, data=$data, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationContentBlockLocation.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationContentBlockLocation.kt index f19693f4f..855947d1a 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationContentBlockLocation.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationContentBlockLocation.kt @@ -68,6 +68,13 @@ private constructor( .build() /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined together. + * The text block is the minimal citable unit; this field is never a substring of a single + * block. Not counted toward output tokens, and not counted toward input tokens when sent back + * in subsequent turns. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -86,6 +93,11 @@ private constructor( fun documentTitle(): Optional = documentTitle.getOptional("document_title") /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -98,6 +110,8 @@ private constructor( fun fileId(): Optional = fileId.getOptional("file_id") /** + * 0-based index of the first cited block in the source's `content` array. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -218,6 +232,14 @@ private constructor( additionalProperties = citationContentBlockLocation.additionalProperties.toMutableMap() } + /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined + * together. The text block is the minimal citable unit; this field is never a substring of + * a single block. Not counted toward output tokens, and not counted toward input tokens + * when sent back in subsequent turns. + */ fun citedText(citedText: String) = citedText(JsonField.of(citedText)) /** @@ -260,6 +282,12 @@ private constructor( this.documentTitle = documentTitle } + /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + */ fun endBlockIndex(endBlockIndex: Long) = endBlockIndex(JsonField.of(endBlockIndex)) /** @@ -286,6 +314,7 @@ private constructor( */ fun fileId(fileId: JsonField) = apply { this.fileId = fileId } + /** 0-based index of the first cited block in the source's `content` array. */ fun startBlockIndex(startBlockIndex: Long) = startBlockIndex(JsonField.of(startBlockIndex)) /** diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationContentBlockLocationParam.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationContentBlockLocationParam.kt index cd614ad84..02cea5ebf 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationContentBlockLocationParam.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationContentBlockLocationParam.kt @@ -56,6 +56,13 @@ private constructor( ) /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined together. + * The text block is the minimal citable unit; this field is never a substring of a single + * block. Not counted toward output tokens, and not counted toward input tokens when sent back + * in subsequent turns. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -74,12 +81,19 @@ private constructor( fun documentTitle(): Optional = documentTitle.getOptional("document_title") /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun endBlockIndex(): Long = endBlockIndex.getRequired("end_block_index") /** + * 0-based index of the first cited block in the source's `content` array. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -193,6 +207,14 @@ private constructor( citationContentBlockLocationParam.additionalProperties.toMutableMap() } + /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined + * together. The text block is the minimal citable unit; this field is never a substring of + * a single block. Not counted toward output tokens, and not counted toward input tokens + * when sent back in subsequent turns. + */ fun citedText(citedText: String) = citedText(JsonField.of(citedText)) /** @@ -235,6 +257,12 @@ private constructor( this.documentTitle = documentTitle } + /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + */ fun endBlockIndex(endBlockIndex: Long) = endBlockIndex(JsonField.of(endBlockIndex)) /** @@ -248,6 +276,7 @@ private constructor( this.endBlockIndex = endBlockIndex } + /** 0-based index of the first cited block in the source's `content` array. */ fun startBlockIndex(startBlockIndex: Long) = startBlockIndex(JsonField.of(startBlockIndex)) /** diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationSearchResultLocationParam.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationSearchResultLocationParam.kt index 81de6b7d9..2529ba577 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationSearchResultLocationParam.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationSearchResultLocationParam.kt @@ -57,18 +57,36 @@ private constructor( ) /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined together. + * The text block is the minimal citable unit; this field is never a substring of a single + * block. Not counted toward output tokens, and not counted toward input tokens when sent back + * in subsequent turns. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun citedText(): String = citedText.getRequired("cited_text") /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun endBlockIndex(): Long = endBlockIndex.getRequired("end_block_index") /** + * 0-based index of the cited search result among all `search_result` content blocks in the + * request, in the order they appear across messages and tool results. + * + * Counted separately from `document_index`; server-side web search results are not included in + * this count. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -81,6 +99,8 @@ private constructor( fun source(): String = source.getRequired("source") /** + * 0-based index of the first cited block in the source's `content` array. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -209,6 +229,14 @@ private constructor( citationSearchResultLocationParam.additionalProperties.toMutableMap() } + /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined + * together. The text block is the minimal citable unit; this field is never a substring of + * a single block. Not counted toward output tokens, and not counted toward input tokens + * when sent back in subsequent turns. + */ fun citedText(citedText: String) = citedText(JsonField.of(citedText)) /** @@ -220,6 +248,12 @@ private constructor( */ fun citedText(citedText: JsonField) = apply { this.citedText = citedText } + /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + */ fun endBlockIndex(endBlockIndex: Long) = endBlockIndex(JsonField.of(endBlockIndex)) /** @@ -233,6 +267,13 @@ private constructor( this.endBlockIndex = endBlockIndex } + /** + * 0-based index of the cited search result among all `search_result` content blocks in the + * request, in the order they appear across messages and tool results. + * + * Counted separately from `document_index`; server-side web search results are not included + * in this count. + */ fun searchResultIndex(searchResultIndex: Long) = searchResultIndex(JsonField.of(searchResultIndex)) @@ -257,6 +298,7 @@ private constructor( */ fun source(source: JsonField) = apply { this.source = source } + /** 0-based index of the first cited block in the source's `content` array. */ fun startBlockIndex(startBlockIndex: Long) = startBlockIndex(JsonField.of(startBlockIndex)) /** diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationsSearchResultLocation.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationsSearchResultLocation.kt index b72773bd4..d36d1cf7e 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationsSearchResultLocation.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/CitationsSearchResultLocation.kt @@ -67,18 +67,36 @@ private constructor( .build() /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined together. + * The text block is the minimal citable unit; this field is never a substring of a single + * block. Not counted toward output tokens, and not counted toward input tokens when sent back + * in subsequent turns. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun citedText(): String = citedText.getRequired("cited_text") /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ fun endBlockIndex(): Long = endBlockIndex.getRequired("end_block_index") /** + * 0-based index of the cited search result among all `search_result` content blocks in the + * request, in the order they appear across messages and tool results. + * + * Counted separately from `document_index`; server-side web search results are not included in + * this count. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -91,6 +109,8 @@ private constructor( fun source(): String = source.getRequired("source") /** + * 0-based index of the first cited block in the source's `content` array. + * * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ @@ -217,6 +237,14 @@ private constructor( additionalProperties = citationsSearchResultLocation.additionalProperties.toMutableMap() } + /** + * The full text of the cited block range, concatenated. + * + * Always equals the contents of `content[start_block_index:end_block_index]` joined + * together. The text block is the minimal citable unit; this field is never a substring of + * a single block. Not counted toward output tokens, and not counted toward input tokens + * when sent back in subsequent turns. + */ fun citedText(citedText: String) = citedText(JsonField.of(citedText)) /** @@ -228,6 +256,12 @@ private constructor( */ fun citedText(citedText: JsonField) = apply { this.citedText = citedText } + /** + * Exclusive 0-based end index of the cited block range in the source's `content` array. + * + * Always greater than `start_block_index`; a single-block citation has `end_block_index = + * start_block_index + 1`. + */ fun endBlockIndex(endBlockIndex: Long) = endBlockIndex(JsonField.of(endBlockIndex)) /** @@ -241,6 +275,13 @@ private constructor( this.endBlockIndex = endBlockIndex } + /** + * 0-based index of the cited search result among all `search_result` content blocks in the + * request, in the order they appear across messages and tool results. + * + * Counted separately from `document_index`; server-side web search results are not included + * in this count. + */ fun searchResultIndex(searchResultIndex: Long) = searchResultIndex(JsonField.of(searchResultIndex)) @@ -265,6 +306,7 @@ private constructor( */ fun source(source: JsonField) = apply { this.source = source } + /** 0-based index of the first cited block in the source's `content` array. */ fun startBlockIndex(startBlockIndex: Long) = startBlockIndex(JsonField.of(startBlockIndex)) /** diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/BetaServiceAsync.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/BetaServiceAsync.kt index fa5adcfe7..eedf78031 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/BetaServiceAsync.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/BetaServiceAsync.kt @@ -13,6 +13,7 @@ import com.anthropic.services.async.beta.SessionServiceAsync import com.anthropic.services.async.beta.SkillServiceAsync import com.anthropic.services.async.beta.UserProfileServiceAsync import com.anthropic.services.async.beta.VaultServiceAsync +import com.anthropic.services.async.beta.WebhookServiceAsync import java.util.function.Consumer interface BetaServiceAsync { @@ -47,6 +48,8 @@ interface BetaServiceAsync { fun skills(): SkillServiceAsync + fun webhooks(): WebhookServiceAsync + fun userProfiles(): UserProfileServiceAsync /** A view of [BetaServiceAsync] that provides access to raw HTTP responses for each method. */ @@ -77,6 +80,8 @@ interface BetaServiceAsync { fun skills(): SkillServiceAsync.WithRawResponse + fun webhooks(): WebhookServiceAsync.WithRawResponse + fun userProfiles(): UserProfileServiceAsync.WithRawResponse } } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/BetaServiceAsyncImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/BetaServiceAsyncImpl.kt index dd8ec1fce..077107560 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/BetaServiceAsyncImpl.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/BetaServiceAsyncImpl.kt @@ -23,6 +23,8 @@ import com.anthropic.services.async.beta.UserProfileServiceAsync import com.anthropic.services.async.beta.UserProfileServiceAsyncImpl import com.anthropic.services.async.beta.VaultServiceAsync import com.anthropic.services.async.beta.VaultServiceAsyncImpl +import com.anthropic.services.async.beta.WebhookServiceAsync +import com.anthropic.services.async.beta.WebhookServiceAsyncImpl import java.util.function.Consumer class BetaServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : @@ -54,6 +56,8 @@ class BetaServiceAsyncImpl internal constructor(private val clientOptions: Clien private val skills: SkillServiceAsync by lazy { SkillServiceAsyncImpl(clientOptions) } + private val webhooks: WebhookServiceAsync by lazy { WebhookServiceAsyncImpl(clientOptions) } + private val userProfiles: UserProfileServiceAsync by lazy { UserProfileServiceAsyncImpl(clientOptions) } @@ -81,6 +85,8 @@ class BetaServiceAsyncImpl internal constructor(private val clientOptions: Clien override fun skills(): SkillServiceAsync = skills + override fun webhooks(): WebhookServiceAsync = webhooks + override fun userProfiles(): UserProfileServiceAsync = userProfiles class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : @@ -122,6 +128,10 @@ class BetaServiceAsyncImpl internal constructor(private val clientOptions: Clien SkillServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val webhooks: WebhookServiceAsync.WithRawResponse by lazy { + WebhookServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + private val userProfiles: UserProfileServiceAsync.WithRawResponse by lazy { UserProfileServiceAsyncImpl.WithRawResponseImpl(clientOptions) } @@ -151,6 +161,8 @@ class BetaServiceAsyncImpl internal constructor(private val clientOptions: Clien override fun skills(): SkillServiceAsync.WithRawResponse = skills + override fun webhooks(): WebhookServiceAsync.WithRawResponse = webhooks + override fun userProfiles(): UserProfileServiceAsync.WithRawResponse = userProfiles } } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/SessionServiceAsync.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/SessionServiceAsync.kt index 91df13679..98c2775cd 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/SessionServiceAsync.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/SessionServiceAsync.kt @@ -16,6 +16,7 @@ import com.anthropic.models.beta.sessions.SessionRetrieveParams import com.anthropic.models.beta.sessions.SessionUpdateParams import com.anthropic.services.async.beta.sessions.EventServiceAsync import com.anthropic.services.async.beta.sessions.ResourceServiceAsync +import com.anthropic.services.async.beta.sessions.ThreadServiceAsync import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -37,6 +38,8 @@ interface SessionServiceAsync { fun resources(): ResourceServiceAsync + fun threads(): ThreadServiceAsync + /** Create Session */ fun create(params: SessionCreateParams): CompletableFuture = create(params, RequestOptions.none()) @@ -227,6 +230,8 @@ interface SessionServiceAsync { fun resources(): ResourceServiceAsync.WithRawResponse + fun threads(): ThreadServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/sessions?beta=true`, but is otherwise the same * as [SessionServiceAsync.create]. diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/SessionServiceAsyncImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/SessionServiceAsyncImpl.kt index 5e61a6d68..703e5210f 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/SessionServiceAsyncImpl.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/SessionServiceAsyncImpl.kt @@ -31,6 +31,8 @@ import com.anthropic.services.async.beta.sessions.EventServiceAsync import com.anthropic.services.async.beta.sessions.EventServiceAsyncImpl import com.anthropic.services.async.beta.sessions.ResourceServiceAsync import com.anthropic.services.async.beta.sessions.ResourceServiceAsyncImpl +import com.anthropic.services.async.beta.sessions.ThreadServiceAsync +import com.anthropic.services.async.beta.sessions.ThreadServiceAsyncImpl import java.util.concurrent.CompletableFuture import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -52,6 +54,8 @@ class SessionServiceAsyncImpl internal constructor(private val clientOptions: Cl private val resources: ResourceServiceAsync by lazy { ResourceServiceAsyncImpl(clientOptions) } + private val threads: ThreadServiceAsync by lazy { ThreadServiceAsyncImpl(clientOptions) } + override fun withRawResponse(): SessionServiceAsync.WithRawResponse = withRawResponse override fun withOptions(modifier: Consumer): SessionServiceAsync = @@ -61,6 +65,8 @@ class SessionServiceAsyncImpl internal constructor(private val clientOptions: Cl override fun resources(): ResourceServiceAsync = resources + override fun threads(): ThreadServiceAsync = threads + override fun create( params: SessionCreateParams, requestOptions: RequestOptions, @@ -117,6 +123,10 @@ class SessionServiceAsyncImpl internal constructor(private val clientOptions: Cl ResourceServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val threads: ThreadServiceAsync.WithRawResponse by lazy { + ThreadServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): SessionServiceAsync.WithRawResponse = @@ -128,6 +138,8 @@ class SessionServiceAsyncImpl internal constructor(private val clientOptions: Cl override fun resources(): ResourceServiceAsync.WithRawResponse = resources + override fun threads(): ThreadServiceAsync.WithRawResponse = threads + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/WebhookServiceAsync.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/WebhookServiceAsync.kt new file mode 100644 index 000000000..dff37c452 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/WebhookServiceAsync.kt @@ -0,0 +1,55 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.async.beta + +import com.anthropic.core.ClientOptions +import com.anthropic.core.UnwrapWebhookParams +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.errors.AnthropicWebhookException +import com.anthropic.models.beta.webhooks.UnwrapWebhookEvent +import java.util.function.Consumer + +interface WebhookServiceAsync { + + /** + * 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): WebhookServiceAsync + + /** + * Unwraps a webhook event from its JSON representation. + * + * @throws AnthropicInvalidDataException if the body could not be parsed. + */ + fun unwrap(body: String): UnwrapWebhookEvent + + /** + * Unwraps a webhook event from its JSON representation. + * + * @throws AnthropicInvalidDataException if the body could not be parsed. + * @throws AnthropicWebhookException if the webhook signature could not be verified + */ + fun unwrap(unwrapParams: UnwrapWebhookParams): UnwrapWebhookEvent + + /** + * A view of [WebhookServiceAsync] 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 + ): WebhookServiceAsync.WithRawResponse + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/WebhookServiceAsyncImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/WebhookServiceAsyncImpl.kt new file mode 100644 index 000000000..6e2fdf14a --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/WebhookServiceAsyncImpl.kt @@ -0,0 +1,39 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.async.beta + +import com.anthropic.core.ClientOptions +import com.anthropic.core.UnwrapWebhookParams +import com.anthropic.models.beta.webhooks.UnwrapWebhookEvent +import com.anthropic.services.blocking.beta.WebhookServiceImpl +import java.util.function.Consumer + +class WebhookServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + WebhookServiceAsync { + + private val withRawResponse: WebhookServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): WebhookServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): WebhookServiceAsync = + WebhookServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun unwrap(body: String): UnwrapWebhookEvent = + WebhookServiceImpl(clientOptions).unwrap(body) + + override fun unwrap(unwrapParams: UnwrapWebhookParams): UnwrapWebhookEvent = + WebhookServiceImpl(clientOptions).unwrap(unwrapParams) + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + WebhookServiceAsync.WithRawResponse { + + override fun withOptions( + modifier: Consumer + ): WebhookServiceAsync.WithRawResponse = + WebhookServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/ThreadServiceAsync.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/ThreadServiceAsync.kt new file mode 100644 index 000000000..5b60c5597 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/ThreadServiceAsync.kt @@ -0,0 +1,237 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.async.beta.sessions + +import com.anthropic.core.ClientOptions +import com.anthropic.core.RequestOptions +import com.anthropic.core.http.HttpResponseFor +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsSessionThread +import com.anthropic.models.beta.sessions.threads.ThreadArchiveParams +import com.anthropic.models.beta.sessions.threads.ThreadListPageAsync +import com.anthropic.models.beta.sessions.threads.ThreadListParams +import com.anthropic.models.beta.sessions.threads.ThreadRetrieveParams +import com.anthropic.services.async.beta.sessions.threads.EventServiceAsync +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface ThreadServiceAsync { + + /** + * 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): ThreadServiceAsync + + fun events(): EventServiceAsync + + /** Get Session Thread */ + fun retrieve( + threadId: String, + params: ThreadRetrieveParams, + ): CompletableFuture = + retrieve(threadId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + threadId: String, + params: ThreadRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: ThreadRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ThreadRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** List Session Threads */ + fun list(sessionId: String): CompletableFuture = + list(sessionId, ThreadListParams.none()) + + /** @see list */ + fun list( + sessionId: String, + params: ThreadListParams = ThreadListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + list(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see list */ + fun list( + sessionId: String, + params: ThreadListParams = ThreadListParams.none(), + ): CompletableFuture = list(sessionId, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: ThreadListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list(params: ThreadListParams): CompletableFuture = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + sessionId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + list(sessionId, ThreadListParams.none(), requestOptions) + + /** Archive Session Thread */ + fun archive( + threadId: String, + params: ThreadArchiveParams, + ): CompletableFuture = + archive(threadId, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + threadId: String, + params: ThreadArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + archive(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see archive */ + fun archive(params: ThreadArchiveParams): CompletableFuture = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: ThreadArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * A view of [ThreadServiceAsync] 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 + ): ThreadServiceAsync.WithRawResponse + + fun events(): EventServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `get + * /v1/sessions/{session_id}/threads/{thread_id}?beta=true`, but is otherwise the same as + * [ThreadServiceAsync.retrieve]. + */ + fun retrieve( + threadId: String, + params: ThreadRetrieveParams, + ): CompletableFuture> = + retrieve(threadId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + threadId: String, + params: ThreadRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + params: ThreadRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ThreadRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /v1/sessions/{session_id}/threads?beta=true`, but is + * otherwise the same as [ThreadServiceAsync.list]. + */ + fun list(sessionId: String): CompletableFuture> = + list(sessionId, ThreadListParams.none()) + + /** @see list */ + fun list( + sessionId: String, + params: ThreadListParams = ThreadListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + list(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see list */ + fun list( + sessionId: String, + params: ThreadListParams = ThreadListParams.none(), + ): CompletableFuture> = + list(sessionId, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: ThreadListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: ThreadListParams + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + sessionId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + list(sessionId, ThreadListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post + * /v1/sessions/{session_id}/threads/{thread_id}/archive?beta=true`, but is otherwise the + * same as [ThreadServiceAsync.archive]. + */ + fun archive( + threadId: String, + params: ThreadArchiveParams, + ): CompletableFuture> = + archive(threadId, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + threadId: String, + params: ThreadArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + archive(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see archive */ + fun archive( + params: ThreadArchiveParams + ): CompletableFuture> = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: ThreadArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/ThreadServiceAsyncImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/ThreadServiceAsyncImpl.kt new file mode 100644 index 000000000..422085552 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/ThreadServiceAsyncImpl.kt @@ -0,0 +1,221 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.async.beta.sessions + +import com.anthropic.core.ClientOptions +import com.anthropic.core.RequestOptions +import com.anthropic.core.checkRequired +import com.anthropic.core.handlers.errorBodyHandler +import com.anthropic.core.handlers.errorHandler +import com.anthropic.core.handlers.jsonHandler +import com.anthropic.core.http.Headers +import com.anthropic.core.http.HttpMethod +import com.anthropic.core.http.HttpRequest +import com.anthropic.core.http.HttpResponse +import com.anthropic.core.http.HttpResponse.Handler +import com.anthropic.core.http.HttpResponseFor +import com.anthropic.core.http.json +import com.anthropic.core.http.parseable +import com.anthropic.core.prepareAsync +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsSessionThread +import com.anthropic.models.beta.sessions.threads.ThreadArchiveParams +import com.anthropic.models.beta.sessions.threads.ThreadListPageAsync +import com.anthropic.models.beta.sessions.threads.ThreadListPageResponse +import com.anthropic.models.beta.sessions.threads.ThreadListParams +import com.anthropic.models.beta.sessions.threads.ThreadRetrieveParams +import com.anthropic.services.async.beta.sessions.threads.EventServiceAsync +import com.anthropic.services.async.beta.sessions.threads.EventServiceAsyncImpl +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class ThreadServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + ThreadServiceAsync { + + companion object { + + private val DEFAULT_HEADERS = + Headers.builder().put("anthropic-beta", "managed-agents-2026-04-01").build() + } + + private val withRawResponse: ThreadServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val events: EventServiceAsync by lazy { EventServiceAsyncImpl(clientOptions) } + + override fun withRawResponse(): ThreadServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): ThreadServiceAsync = + ThreadServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun events(): EventServiceAsync = events + + override fun retrieve( + params: ThreadRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /v1/sessions/{session_id}/threads/{thread_id}?beta=true + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: ThreadListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /v1/sessions/{session_id}/threads?beta=true + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun archive( + params: ThreadArchiveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /v1/sessions/{session_id}/threads/{thread_id}/archive?beta=true + withRawResponse().archive(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + ThreadServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + private val events: EventServiceAsync.WithRawResponse by lazy { + EventServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): ThreadServiceAsync.WithRawResponse = + ThreadServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun events(): EventServiceAsync.WithRawResponse = events + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: ThreadRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("threadId", params.threadId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "v1", + "sessions", + params._pathParam(0), + "threads", + params._pathParam(1), + ) + .putQueryParam("beta", "true") + .putAllHeaders(DEFAULT_HEADERS) + .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: ThreadListParams, + 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("v1", "sessions", params._pathParam(0), "threads") + .putQueryParam("beta", "true") + .putAllHeaders(DEFAULT_HEADERS) + .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 { + ThreadListPageAsync.builder() + .service(ThreadServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) + .params(params) + .response(it) + .build() + } + } + } + } + + private val archiveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun archive( + params: ThreadArchiveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("threadId", params.threadId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "v1", + "sessions", + params._pathParam(0), + "threads", + params._pathParam(1), + "archive", + ) + .putQueryParam("beta", "true") + .putAllHeaders(DEFAULT_HEADERS) + .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 { archiveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/threads/EventServiceAsync.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/threads/EventServiceAsync.kt new file mode 100644 index 000000000..dc14ec1d5 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/threads/EventServiceAsync.kt @@ -0,0 +1,162 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.async.beta.sessions.threads + +import com.anthropic.core.ClientOptions +import com.anthropic.core.RequestOptions +import com.anthropic.core.http.AsyncStreamResponse +import com.anthropic.core.http.HttpResponseFor +import com.anthropic.core.http.StreamResponse +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsStreamSessionThreadEvents +import com.anthropic.models.beta.sessions.threads.events.EventListPageAsync +import com.anthropic.models.beta.sessions.threads.events.EventListParams +import com.anthropic.models.beta.sessions.threads.events.EventStreamParams +import com.google.errorprone.annotations.MustBeClosed +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface EventServiceAsync { + + /** + * 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): EventServiceAsync + + /** List Session Thread Events */ + fun list(threadId: String, params: EventListParams): CompletableFuture = + list(threadId, params, RequestOptions.none()) + + /** @see list */ + fun list( + threadId: String, + params: EventListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + list(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see list */ + fun list(params: EventListParams): CompletableFuture = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + params: EventListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** Stream Session Thread Events */ + fun streamStreaming( + threadId: String, + params: EventStreamParams, + ): AsyncStreamResponse = + streamStreaming(threadId, params, RequestOptions.none()) + + /** @see streamStreaming */ + fun streamStreaming( + threadId: String, + params: EventStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): AsyncStreamResponse = + streamStreaming(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see streamStreaming */ + fun streamStreaming( + params: EventStreamParams + ): AsyncStreamResponse = + streamStreaming(params, RequestOptions.none()) + + /** @see streamStreaming */ + fun streamStreaming( + params: EventStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): AsyncStreamResponse + + /** A view of [EventServiceAsync] 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 + ): EventServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `get + * /v1/sessions/{session_id}/threads/{thread_id}/events?beta=true`, but is otherwise the + * same as [EventServiceAsync.list]. + */ + fun list( + threadId: String, + params: EventListParams, + ): CompletableFuture> = + list(threadId, params, RequestOptions.none()) + + /** @see list */ + fun list( + threadId: String, + params: EventListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + list(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see list */ + fun list(params: EventListParams): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + params: EventListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get + * /v1/sessions/{session_id}/threads/{thread_id}/stream?beta=true`, but is otherwise the + * same as [EventServiceAsync.streamStreaming]. + */ + @MustBeClosed + fun streamStreaming( + threadId: String, + params: EventStreamParams, + ): CompletableFuture< + HttpResponseFor> + > = streamStreaming(threadId, params, RequestOptions.none()) + + /** @see streamStreaming */ + @MustBeClosed + fun streamStreaming( + threadId: String, + params: EventStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture< + HttpResponseFor> + > = streamStreaming(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see streamStreaming */ + @MustBeClosed + fun streamStreaming( + params: EventStreamParams + ): CompletableFuture< + HttpResponseFor> + > = streamStreaming(params, RequestOptions.none()) + + /** @see streamStreaming */ + @MustBeClosed + fun streamStreaming( + params: EventStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture< + HttpResponseFor> + > + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/threads/EventServiceAsyncImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/threads/EventServiceAsyncImpl.kt new file mode 100644 index 000000000..c28db7f10 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/sessions/threads/EventServiceAsyncImpl.kt @@ -0,0 +1,181 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.async.beta.sessions.threads + +import com.anthropic.core.ClientOptions +import com.anthropic.core.RequestOptions +import com.anthropic.core.checkRequired +import com.anthropic.core.handlers.errorBodyHandler +import com.anthropic.core.handlers.errorHandler +import com.anthropic.core.handlers.jsonHandler +import com.anthropic.core.handlers.mapJson +import com.anthropic.core.handlers.sseHandler +import com.anthropic.core.http.AsyncStreamResponse +import com.anthropic.core.http.Headers +import com.anthropic.core.http.HttpMethod +import com.anthropic.core.http.HttpRequest +import com.anthropic.core.http.HttpResponse +import com.anthropic.core.http.HttpResponse.Handler +import com.anthropic.core.http.HttpResponseFor +import com.anthropic.core.http.StreamResponse +import com.anthropic.core.http.map +import com.anthropic.core.http.parseable +import com.anthropic.core.http.toAsync +import com.anthropic.core.prepareAsync +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsStreamSessionThreadEvents +import com.anthropic.models.beta.sessions.threads.events.EventListPageAsync +import com.anthropic.models.beta.sessions.threads.events.EventListPageResponse +import com.anthropic.models.beta.sessions.threads.events.EventListParams +import com.anthropic.models.beta.sessions.threads.events.EventStreamParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class EventServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + EventServiceAsync { + + companion object { + + private val DEFAULT_HEADERS = + Headers.builder().put("anthropic-beta", "managed-agents-2026-04-01").build() + } + + private val withRawResponse: EventServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): EventServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): EventServiceAsync = + EventServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun list( + params: EventListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /v1/sessions/{session_id}/threads/{thread_id}/events?beta=true + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun streamStreaming( + params: EventStreamParams, + requestOptions: RequestOptions, + ): AsyncStreamResponse = + // get /v1/sessions/{session_id}/threads/{thread_id}/stream?beta=true + withRawResponse() + .streamStreaming(params, requestOptions) + .thenApply { it.parse() } + .toAsync(clientOptions.streamHandlerExecutor) + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + EventServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): EventServiceAsync.WithRawResponse = + EventServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: EventListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("threadId", params.threadId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "v1", + "sessions", + params._pathParam(0), + "threads", + params._pathParam(1), + "events", + ) + .putQueryParam("beta", "true") + .putAllHeaders(DEFAULT_HEADERS) + .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 { + EventListPageAsync.builder() + .service(EventServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) + .params(params) + .response(it) + .build() + } + } + } + } + + private val streamStreamingHandler: + Handler> = + sseHandler(clientOptions.jsonMapper) + .mapJson() + + override fun streamStreaming( + params: EventStreamParams, + requestOptions: RequestOptions, + ): CompletableFuture< + HttpResponseFor> + > { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("threadId", params.threadId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "v1", + "sessions", + params._pathParam(0), + "threads", + params._pathParam(1), + "stream", + ) + .putQueryParam("beta", "true") + .putAllHeaders(DEFAULT_HEADERS) + .putHeader("Accept", "text/event-stream") + .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 + .let { streamStreamingHandler.handle(it) } + .let { streamResponse -> + if (requestOptions.responseValidation!!) { + streamResponse.map { it.validate() } + } else { + streamResponse + } + } + } + } + } + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/vaults/CredentialServiceAsync.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/vaults/CredentialServiceAsync.kt index 23dc20ba4..816b47633 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/vaults/CredentialServiceAsync.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/vaults/CredentialServiceAsync.kt @@ -6,12 +6,14 @@ import com.anthropic.core.ClientOptions import com.anthropic.core.RequestOptions import com.anthropic.core.http.HttpResponseFor import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsCredential +import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsCredentialValidation import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsDeletedCredential import com.anthropic.models.beta.vaults.credentials.CredentialArchiveParams import com.anthropic.models.beta.vaults.credentials.CredentialCreateParams import com.anthropic.models.beta.vaults.credentials.CredentialDeleteParams import com.anthropic.models.beta.vaults.credentials.CredentialListPageAsync import com.anthropic.models.beta.vaults.credentials.CredentialListParams +import com.anthropic.models.beta.vaults.credentials.CredentialMcpOAuthValidateParams import com.anthropic.models.beta.vaults.credentials.CredentialRetrieveParams import com.anthropic.models.beta.vaults.credentials.CredentialUpdateParams import java.util.concurrent.CompletableFuture @@ -192,6 +194,33 @@ interface CredentialServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** Validate Credential */ + fun mcpOAuthValidate( + credentialId: String, + params: CredentialMcpOAuthValidateParams, + ): CompletableFuture = + mcpOAuthValidate(credentialId, params, RequestOptions.none()) + + /** @see mcpOAuthValidate */ + fun mcpOAuthValidate( + credentialId: String, + params: CredentialMcpOAuthValidateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + mcpOAuthValidate(params.toBuilder().credentialId(credentialId).build(), requestOptions) + + /** @see mcpOAuthValidate */ + fun mcpOAuthValidate( + params: CredentialMcpOAuthValidateParams + ): CompletableFuture = + mcpOAuthValidate(params, RequestOptions.none()) + + /** @see mcpOAuthValidate */ + fun mcpOAuthValidate( + params: CredentialMcpOAuthValidateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + /** * A view of [CredentialServiceAsync] that provides access to raw HTTP responses for each * method. @@ -401,5 +430,36 @@ interface CredentialServiceAsync { params: CredentialArchiveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** + * Returns a raw HTTP response for `post + * /v1/vaults/{vault_id}/credentials/{credential_id}/mcp_oauth_validate?beta=true`, but is + * otherwise the same as [CredentialServiceAsync.mcpOAuthValidate]. + */ + fun mcpOAuthValidate( + credentialId: String, + params: CredentialMcpOAuthValidateParams, + ): CompletableFuture> = + mcpOAuthValidate(credentialId, params, RequestOptions.none()) + + /** @see mcpOAuthValidate */ + fun mcpOAuthValidate( + credentialId: String, + params: CredentialMcpOAuthValidateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + mcpOAuthValidate(params.toBuilder().credentialId(credentialId).build(), requestOptions) + + /** @see mcpOAuthValidate */ + fun mcpOAuthValidate( + params: CredentialMcpOAuthValidateParams + ): CompletableFuture> = + mcpOAuthValidate(params, RequestOptions.none()) + + /** @see mcpOAuthValidate */ + fun mcpOAuthValidate( + params: CredentialMcpOAuthValidateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> } } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/vaults/CredentialServiceAsyncImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/vaults/CredentialServiceAsyncImpl.kt index f305db5ad..17b6b9f43 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/vaults/CredentialServiceAsyncImpl.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/async/beta/vaults/CredentialServiceAsyncImpl.kt @@ -18,6 +18,7 @@ import com.anthropic.core.http.json import com.anthropic.core.http.parseable import com.anthropic.core.prepareAsync import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsCredential +import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsCredentialValidation import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsDeletedCredential import com.anthropic.models.beta.vaults.credentials.CredentialArchiveParams import com.anthropic.models.beta.vaults.credentials.CredentialCreateParams @@ -25,6 +26,7 @@ import com.anthropic.models.beta.vaults.credentials.CredentialDeleteParams import com.anthropic.models.beta.vaults.credentials.CredentialListPageAsync import com.anthropic.models.beta.vaults.credentials.CredentialListPageResponse import com.anthropic.models.beta.vaults.credentials.CredentialListParams +import com.anthropic.models.beta.vaults.credentials.CredentialMcpOAuthValidateParams import com.anthropic.models.beta.vaults.credentials.CredentialRetrieveParams import com.anthropic.models.beta.vaults.credentials.CredentialUpdateParams import java.util.concurrent.CompletableFuture @@ -91,6 +93,13 @@ class CredentialServiceAsyncImpl internal constructor(private val clientOptions: // post /v1/vaults/{vault_id}/credentials/{credential_id}/archive?beta=true withRawResponse().archive(params, requestOptions).thenApply { it.parse() } + override fun mcpOAuthValidate( + params: CredentialMcpOAuthValidateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /v1/vaults/{vault_id}/credentials/{credential_id}/mcp_oauth_validate?beta=true + withRawResponse().mcpOAuthValidate(params, requestOptions).thenApply { it.parse() } + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : CredentialServiceAsync.WithRawResponse { @@ -350,5 +359,48 @@ class CredentialServiceAsyncImpl internal constructor(private val clientOptions: } } } + + private val mcpOAuthValidateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun mcpOAuthValidate( + params: CredentialMcpOAuthValidateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("credentialId", params.credentialId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "v1", + "vaults", + params._pathParam(0), + "credentials", + params._pathParam(1), + "mcp_oauth_validate", + ) + .putQueryParam("beta", "true") + .putAllHeaders(DEFAULT_HEADERS) + .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 { mcpOAuthValidateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } } } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/BetaService.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/BetaService.kt index d696a5bbc..3a24d28f4 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/BetaService.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/BetaService.kt @@ -13,6 +13,7 @@ import com.anthropic.services.blocking.beta.SessionService import com.anthropic.services.blocking.beta.SkillService import com.anthropic.services.blocking.beta.UserProfileService import com.anthropic.services.blocking.beta.VaultService +import com.anthropic.services.blocking.beta.WebhookService import java.util.function.Consumer interface BetaService { @@ -47,6 +48,8 @@ interface BetaService { fun skills(): SkillService + fun webhooks(): WebhookService + fun userProfiles(): UserProfileService /** A view of [BetaService] that provides access to raw HTTP responses for each method. */ @@ -77,6 +80,8 @@ interface BetaService { fun skills(): SkillService.WithRawResponse + fun webhooks(): WebhookService.WithRawResponse + fun userProfiles(): UserProfileService.WithRawResponse } } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/BetaServiceImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/BetaServiceImpl.kt index be39909b4..9e94f7d02 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/BetaServiceImpl.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/BetaServiceImpl.kt @@ -23,6 +23,8 @@ import com.anthropic.services.blocking.beta.UserProfileService import com.anthropic.services.blocking.beta.UserProfileServiceImpl import com.anthropic.services.blocking.beta.VaultService import com.anthropic.services.blocking.beta.VaultServiceImpl +import com.anthropic.services.blocking.beta.WebhookService +import com.anthropic.services.blocking.beta.WebhookServiceImpl import java.util.function.Consumer class BetaServiceImpl internal constructor(private val clientOptions: ClientOptions) : BetaService { @@ -49,6 +51,8 @@ class BetaServiceImpl internal constructor(private val clientOptions: ClientOpti private val skills: SkillService by lazy { SkillServiceImpl(clientOptions) } + private val webhooks: WebhookService by lazy { WebhookServiceImpl(clientOptions) } + private val userProfiles: UserProfileService by lazy { UserProfileServiceImpl(clientOptions) } override fun withRawResponse(): BetaService.WithRawResponse = withRawResponse @@ -74,6 +78,8 @@ class BetaServiceImpl internal constructor(private val clientOptions: ClientOpti override fun skills(): SkillService = skills + override fun webhooks(): WebhookService = webhooks + override fun userProfiles(): UserProfileService = userProfiles class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : @@ -115,6 +121,10 @@ class BetaServiceImpl internal constructor(private val clientOptions: ClientOpti SkillServiceImpl.WithRawResponseImpl(clientOptions) } + private val webhooks: WebhookService.WithRawResponse by lazy { + WebhookServiceImpl.WithRawResponseImpl(clientOptions) + } + private val userProfiles: UserProfileService.WithRawResponse by lazy { UserProfileServiceImpl.WithRawResponseImpl(clientOptions) } @@ -144,6 +154,8 @@ class BetaServiceImpl internal constructor(private val clientOptions: ClientOpti override fun skills(): SkillService.WithRawResponse = skills + override fun webhooks(): WebhookService.WithRawResponse = webhooks + override fun userProfiles(): UserProfileService.WithRawResponse = userProfiles } } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/SessionService.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/SessionService.kt index c6e7f808a..369c3c322 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/SessionService.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/SessionService.kt @@ -16,6 +16,7 @@ import com.anthropic.models.beta.sessions.SessionRetrieveParams import com.anthropic.models.beta.sessions.SessionUpdateParams import com.anthropic.services.blocking.beta.sessions.EventService import com.anthropic.services.blocking.beta.sessions.ResourceService +import com.anthropic.services.blocking.beta.sessions.ThreadService import com.google.errorprone.annotations.MustBeClosed import java.util.function.Consumer @@ -37,6 +38,8 @@ interface SessionService { fun resources(): ResourceService + fun threads(): ThreadService + /** Create Session */ fun create(params: SessionCreateParams): BetaManagedAgentsSession = create(params, RequestOptions.none()) @@ -206,6 +209,8 @@ interface SessionService { fun resources(): ResourceService.WithRawResponse + fun threads(): ThreadService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/sessions?beta=true`, but is otherwise the same * as [SessionService.create]. diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/SessionServiceImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/SessionServiceImpl.kt index 05243a639..d3f0ec83c 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/SessionServiceImpl.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/SessionServiceImpl.kt @@ -31,6 +31,8 @@ import com.anthropic.services.blocking.beta.sessions.EventService import com.anthropic.services.blocking.beta.sessions.EventServiceImpl import com.anthropic.services.blocking.beta.sessions.ResourceService import com.anthropic.services.blocking.beta.sessions.ResourceServiceImpl +import com.anthropic.services.blocking.beta.sessions.ThreadService +import com.anthropic.services.blocking.beta.sessions.ThreadServiceImpl import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -51,6 +53,8 @@ class SessionServiceImpl internal constructor(private val clientOptions: ClientO private val resources: ResourceService by lazy { ResourceServiceImpl(clientOptions) } + private val threads: ThreadService by lazy { ThreadServiceImpl(clientOptions) } + override fun withRawResponse(): SessionService.WithRawResponse = withRawResponse override fun withOptions(modifier: Consumer): SessionService = @@ -60,6 +64,8 @@ class SessionServiceImpl internal constructor(private val clientOptions: ClientO override fun resources(): ResourceService = resources + override fun threads(): ThreadService = threads + override fun create( params: SessionCreateParams, requestOptions: RequestOptions, @@ -113,6 +119,10 @@ class SessionServiceImpl internal constructor(private val clientOptions: ClientO ResourceServiceImpl.WithRawResponseImpl(clientOptions) } + private val threads: ThreadService.WithRawResponse by lazy { + ThreadServiceImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): SessionService.WithRawResponse = @@ -124,6 +134,8 @@ class SessionServiceImpl internal constructor(private val clientOptions: ClientO override fun resources(): ResourceService.WithRawResponse = resources + override fun threads(): ThreadService.WithRawResponse = threads + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/WebhookService.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/WebhookService.kt new file mode 100644 index 000000000..92083cd76 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/WebhookService.kt @@ -0,0 +1,51 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.blocking.beta + +import com.anthropic.core.ClientOptions +import com.anthropic.core.UnwrapWebhookParams +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.errors.AnthropicWebhookException +import com.anthropic.models.beta.webhooks.UnwrapWebhookEvent +import java.util.function.Consumer + +interface WebhookService { + + /** + * 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): WebhookService + + /** + * Unwraps a webhook event from its JSON representation. + * + * @throws AnthropicInvalidDataException if the body could not be parsed. + */ + fun unwrap(body: String): UnwrapWebhookEvent + + /** + * Unwraps a webhook event from its JSON representation. + * + * @throws AnthropicInvalidDataException if the body could not be parsed. + * @throws AnthropicWebhookException if the webhook signature could not be verified + */ + fun unwrap(unwrapParams: UnwrapWebhookParams): UnwrapWebhookEvent + + /** A view of [WebhookService] 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): WebhookService.WithRawResponse + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/WebhookServiceImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/WebhookServiceImpl.kt new file mode 100644 index 000000000..4cabc0bd2 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/WebhookServiceImpl.kt @@ -0,0 +1,68 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.blocking.beta + +import com.anthropic.core.ClientOptions +import com.anthropic.core.UnwrapWebhookParams +import com.anthropic.core.checkRequired +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.errors.AnthropicWebhookException +import com.anthropic.models.beta.webhooks.UnwrapWebhookEvent +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.standardwebhooks.Webhook +import com.standardwebhooks.exceptions.WebhookVerificationException +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class WebhookServiceImpl internal constructor(private val clientOptions: ClientOptions) : + WebhookService { + + private val withRawResponse: WebhookService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): WebhookService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): WebhookService = + WebhookServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun unwrap(body: String): UnwrapWebhookEvent = + try { + clientOptions.jsonMapper.readValue(body, jacksonTypeRef()) + } catch (e: Exception) { + throw AnthropicInvalidDataException("Error parsing body", e) + } + + override fun unwrap(unwrapParams: UnwrapWebhookParams): UnwrapWebhookEvent { + val headers = unwrapParams.headers().getOrNull() + if (headers != null) { + try { + val webhookSecret = + checkRequired( + "webhookKey", + unwrapParams.secret().getOrNull() ?: clientOptions.webhookKey().getOrNull(), + ) + + val headersMap = + headers.names().associateWith { name -> headers.values(name) }.toMap() + + val webhook = Webhook(webhookSecret) + webhook.verify(unwrapParams.body(), headersMap) + } catch (e: WebhookVerificationException) { + throw AnthropicWebhookException("Could not verify webhook event signature", e) + } + } + return unwrap(unwrapParams.body()) + } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + WebhookService.WithRawResponse { + + override fun withOptions( + modifier: Consumer + ): WebhookService.WithRawResponse = + WebhookServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/ThreadService.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/ThreadService.kt new file mode 100644 index 000000000..1d1c8eec1 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/ThreadService.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.blocking.beta.sessions + +import com.anthropic.core.ClientOptions +import com.anthropic.core.RequestOptions +import com.anthropic.core.http.HttpResponseFor +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsSessionThread +import com.anthropic.models.beta.sessions.threads.ThreadArchiveParams +import com.anthropic.models.beta.sessions.threads.ThreadListPage +import com.anthropic.models.beta.sessions.threads.ThreadListParams +import com.anthropic.models.beta.sessions.threads.ThreadRetrieveParams +import com.anthropic.services.blocking.beta.sessions.threads.EventService +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +interface ThreadService { + + /** + * 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): ThreadService + + fun events(): EventService + + /** Get Session Thread */ + fun retrieve(threadId: String, params: ThreadRetrieveParams): BetaManagedAgentsSessionThread = + retrieve(threadId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + threadId: String, + params: ThreadRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): BetaManagedAgentsSessionThread = + retrieve(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: ThreadRetrieveParams): BetaManagedAgentsSessionThread = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: ThreadRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): BetaManagedAgentsSessionThread + + /** List Session Threads */ + fun list(sessionId: String): ThreadListPage = list(sessionId, ThreadListParams.none()) + + /** @see list */ + fun list( + sessionId: String, + params: ThreadListParams = ThreadListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ThreadListPage = list(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see list */ + fun list( + sessionId: String, + params: ThreadListParams = ThreadListParams.none(), + ): ThreadListPage = list(sessionId, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: ThreadListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ThreadListPage + + /** @see list */ + fun list(params: ThreadListParams): ThreadListPage = list(params, RequestOptions.none()) + + /** @see list */ + fun list(sessionId: String, requestOptions: RequestOptions): ThreadListPage = + list(sessionId, ThreadListParams.none(), requestOptions) + + /** Archive Session Thread */ + fun archive(threadId: String, params: ThreadArchiveParams): BetaManagedAgentsSessionThread = + archive(threadId, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + threadId: String, + params: ThreadArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): BetaManagedAgentsSessionThread = + archive(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see archive */ + fun archive(params: ThreadArchiveParams): BetaManagedAgentsSessionThread = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: ThreadArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): BetaManagedAgentsSessionThread + + /** A view of [ThreadService] 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): ThreadService.WithRawResponse + + fun events(): EventService.WithRawResponse + + /** + * Returns a raw HTTP response for `get + * /v1/sessions/{session_id}/threads/{thread_id}?beta=true`, but is otherwise the same as + * [ThreadService.retrieve]. + */ + @MustBeClosed + fun retrieve( + threadId: String, + params: ThreadRetrieveParams, + ): HttpResponseFor = + retrieve(threadId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + threadId: String, + params: ThreadRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: ThreadRetrieveParams + ): HttpResponseFor = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: ThreadRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /v1/sessions/{session_id}/threads?beta=true`, but is + * otherwise the same as [ThreadService.list]. + */ + @MustBeClosed + fun list(sessionId: String): HttpResponseFor = + list(sessionId, ThreadListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + sessionId: String, + params: ThreadListParams = ThreadListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + list(params.toBuilder().sessionId(sessionId).build(), requestOptions) + + /** @see list */ + @MustBeClosed + fun list( + sessionId: String, + params: ThreadListParams = ThreadListParams.none(), + ): HttpResponseFor = list(sessionId, params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: ThreadListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list(params: ThreadListParams): HttpResponseFor = + list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list( + sessionId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + list(sessionId, ThreadListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post + * /v1/sessions/{session_id}/threads/{thread_id}/archive?beta=true`, but is otherwise the + * same as [ThreadService.archive]. + */ + @MustBeClosed + fun archive( + threadId: String, + params: ThreadArchiveParams, + ): HttpResponseFor = + archive(threadId, params, RequestOptions.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + threadId: String, + params: ThreadArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + archive(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see archive */ + @MustBeClosed + fun archive(params: ThreadArchiveParams): HttpResponseFor = + archive(params, RequestOptions.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + params: ThreadArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/ThreadServiceImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/ThreadServiceImpl.kt new file mode 100644 index 000000000..e89184ea9 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/ThreadServiceImpl.kt @@ -0,0 +1,207 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.blocking.beta.sessions + +import com.anthropic.core.ClientOptions +import com.anthropic.core.RequestOptions +import com.anthropic.core.checkRequired +import com.anthropic.core.handlers.errorBodyHandler +import com.anthropic.core.handlers.errorHandler +import com.anthropic.core.handlers.jsonHandler +import com.anthropic.core.http.Headers +import com.anthropic.core.http.HttpMethod +import com.anthropic.core.http.HttpRequest +import com.anthropic.core.http.HttpResponse +import com.anthropic.core.http.HttpResponse.Handler +import com.anthropic.core.http.HttpResponseFor +import com.anthropic.core.http.json +import com.anthropic.core.http.parseable +import com.anthropic.core.prepare +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsSessionThread +import com.anthropic.models.beta.sessions.threads.ThreadArchiveParams +import com.anthropic.models.beta.sessions.threads.ThreadListPage +import com.anthropic.models.beta.sessions.threads.ThreadListPageResponse +import com.anthropic.models.beta.sessions.threads.ThreadListParams +import com.anthropic.models.beta.sessions.threads.ThreadRetrieveParams +import com.anthropic.services.blocking.beta.sessions.threads.EventService +import com.anthropic.services.blocking.beta.sessions.threads.EventServiceImpl +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class ThreadServiceImpl internal constructor(private val clientOptions: ClientOptions) : + ThreadService { + + companion object { + + private val DEFAULT_HEADERS = + Headers.builder().put("anthropic-beta", "managed-agents-2026-04-01").build() + } + + private val withRawResponse: ThreadService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val events: EventService by lazy { EventServiceImpl(clientOptions) } + + override fun withRawResponse(): ThreadService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): ThreadService = + ThreadServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun events(): EventService = events + + override fun retrieve( + params: ThreadRetrieveParams, + requestOptions: RequestOptions, + ): BetaManagedAgentsSessionThread = + // get /v1/sessions/{session_id}/threads/{thread_id}?beta=true + withRawResponse().retrieve(params, requestOptions).parse() + + override fun list(params: ThreadListParams, requestOptions: RequestOptions): ThreadListPage = + // get /v1/sessions/{session_id}/threads?beta=true + withRawResponse().list(params, requestOptions).parse() + + override fun archive( + params: ThreadArchiveParams, + requestOptions: RequestOptions, + ): BetaManagedAgentsSessionThread = + // post /v1/sessions/{session_id}/threads/{thread_id}/archive?beta=true + withRawResponse().archive(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + ThreadService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + private val events: EventService.WithRawResponse by lazy { + EventServiceImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): ThreadService.WithRawResponse = + ThreadServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun events(): EventService.WithRawResponse = events + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: ThreadRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("threadId", params.threadId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "v1", + "sessions", + params._pathParam(0), + "threads", + params._pathParam(1), + ) + .putQueryParam("beta", "true") + .putAllHeaders(DEFAULT_HEADERS) + .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: ThreadListParams, + 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("v1", "sessions", params._pathParam(0), "threads") + .putQueryParam("beta", "true") + .putAllHeaders(DEFAULT_HEADERS) + .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 { + ThreadListPage.builder() + .service(ThreadServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } + } + } + + private val archiveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun archive( + params: ThreadArchiveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("threadId", params.threadId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "v1", + "sessions", + params._pathParam(0), + "threads", + params._pathParam(1), + "archive", + ) + .putQueryParam("beta", "true") + .putAllHeaders(DEFAULT_HEADERS) + .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 { archiveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/threads/EventService.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/threads/EventService.kt new file mode 100644 index 000000000..09165169c --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/threads/EventService.kt @@ -0,0 +1,156 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.blocking.beta.sessions.threads + +import com.anthropic.core.ClientOptions +import com.anthropic.core.RequestOptions +import com.anthropic.core.http.HttpResponseFor +import com.anthropic.core.http.StreamResponse +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsStreamSessionThreadEvents +import com.anthropic.models.beta.sessions.threads.events.EventListPage +import com.anthropic.models.beta.sessions.threads.events.EventListParams +import com.anthropic.models.beta.sessions.threads.events.EventStreamParams +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +interface EventService { + + /** + * 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): EventService + + /** List Session Thread Events */ + fun list(threadId: String, params: EventListParams): EventListPage = + list(threadId, params, RequestOptions.none()) + + /** @see list */ + fun list( + threadId: String, + params: EventListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): EventListPage = list(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see list */ + fun list(params: EventListParams): EventListPage = list(params, RequestOptions.none()) + + /** @see list */ + fun list( + params: EventListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): EventListPage + + /** Stream Session Thread Events */ + @MustBeClosed + fun streamStreaming( + threadId: String, + params: EventStreamParams, + ): StreamResponse = + streamStreaming(threadId, params, RequestOptions.none()) + + /** @see streamStreaming */ + @MustBeClosed + fun streamStreaming( + threadId: String, + params: EventStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): StreamResponse = + streamStreaming(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see streamStreaming */ + @MustBeClosed + fun streamStreaming( + params: EventStreamParams + ): StreamResponse = + streamStreaming(params, RequestOptions.none()) + + /** @see streamStreaming */ + @MustBeClosed + fun streamStreaming( + params: EventStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): StreamResponse + + /** A view of [EventService] 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): EventService.WithRawResponse + + /** + * Returns a raw HTTP response for `get + * /v1/sessions/{session_id}/threads/{thread_id}/events?beta=true`, but is otherwise the + * same as [EventService.list]. + */ + @MustBeClosed + fun list(threadId: String, params: EventListParams): HttpResponseFor = + list(threadId, params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list( + threadId: String, + params: EventListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + list(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see list */ + @MustBeClosed + fun list(params: EventListParams): HttpResponseFor = + list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: EventListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get + * /v1/sessions/{session_id}/threads/{thread_id}/stream?beta=true`, but is otherwise the + * same as [EventService.streamStreaming]. + */ + @MustBeClosed + fun streamStreaming( + threadId: String, + params: EventStreamParams, + ): HttpResponseFor> = + streamStreaming(threadId, params, RequestOptions.none()) + + /** @see streamStreaming */ + @MustBeClosed + fun streamStreaming( + threadId: String, + params: EventStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor> = + streamStreaming(params.toBuilder().threadId(threadId).build(), requestOptions) + + /** @see streamStreaming */ + @MustBeClosed + fun streamStreaming( + params: EventStreamParams + ): HttpResponseFor> = + streamStreaming(params, RequestOptions.none()) + + /** @see streamStreaming */ + @MustBeClosed + fun streamStreaming( + params: EventStreamParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor> + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/threads/EventServiceImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/threads/EventServiceImpl.kt new file mode 100644 index 000000000..d5000f9d8 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/sessions/threads/EventServiceImpl.kt @@ -0,0 +1,163 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.blocking.beta.sessions.threads + +import com.anthropic.core.ClientOptions +import com.anthropic.core.RequestOptions +import com.anthropic.core.checkRequired +import com.anthropic.core.handlers.errorBodyHandler +import com.anthropic.core.handlers.errorHandler +import com.anthropic.core.handlers.jsonHandler +import com.anthropic.core.handlers.mapJson +import com.anthropic.core.handlers.sseHandler +import com.anthropic.core.http.Headers +import com.anthropic.core.http.HttpMethod +import com.anthropic.core.http.HttpRequest +import com.anthropic.core.http.HttpResponse +import com.anthropic.core.http.HttpResponse.Handler +import com.anthropic.core.http.HttpResponseFor +import com.anthropic.core.http.StreamResponse +import com.anthropic.core.http.map +import com.anthropic.core.http.parseable +import com.anthropic.core.prepare +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsStreamSessionThreadEvents +import com.anthropic.models.beta.sessions.threads.events.EventListPage +import com.anthropic.models.beta.sessions.threads.events.EventListPageResponse +import com.anthropic.models.beta.sessions.threads.events.EventListParams +import com.anthropic.models.beta.sessions.threads.events.EventStreamParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class EventServiceImpl internal constructor(private val clientOptions: ClientOptions) : + EventService { + + companion object { + + private val DEFAULT_HEADERS = + Headers.builder().put("anthropic-beta", "managed-agents-2026-04-01").build() + } + + private val withRawResponse: EventService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): EventService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): EventService = + EventServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun list(params: EventListParams, requestOptions: RequestOptions): EventListPage = + // get /v1/sessions/{session_id}/threads/{thread_id}/events?beta=true + withRawResponse().list(params, requestOptions).parse() + + override fun streamStreaming( + params: EventStreamParams, + requestOptions: RequestOptions, + ): StreamResponse = + // get /v1/sessions/{session_id}/threads/{thread_id}/stream?beta=true + withRawResponse().streamStreaming(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + EventService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): EventService.WithRawResponse = + EventServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: EventListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("threadId", params.threadId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "v1", + "sessions", + params._pathParam(0), + "threads", + params._pathParam(1), + "events", + ) + .putQueryParam("beta", "true") + .putAllHeaders(DEFAULT_HEADERS) + .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 { + EventListPage.builder() + .service(EventServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } + } + } + + private val streamStreamingHandler: + Handler> = + sseHandler(clientOptions.jsonMapper) + .mapJson() + + override fun streamStreaming( + params: EventStreamParams, + requestOptions: RequestOptions, + ): HttpResponseFor> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("threadId", params.threadId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "v1", + "sessions", + params._pathParam(0), + "threads", + params._pathParam(1), + "stream", + ) + .putQueryParam("beta", "true") + .putAllHeaders(DEFAULT_HEADERS) + .putHeader("Accept", "text/event-stream") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .let { streamStreamingHandler.handle(it) } + .let { streamResponse -> + if (requestOptions.responseValidation!!) { + streamResponse.map { it.validate() } + } else { + streamResponse + } + } + } + } + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/vaults/CredentialService.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/vaults/CredentialService.kt index 2e5bf8090..a782005a0 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/vaults/CredentialService.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/vaults/CredentialService.kt @@ -6,12 +6,14 @@ import com.anthropic.core.ClientOptions import com.anthropic.core.RequestOptions import com.anthropic.core.http.HttpResponseFor import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsCredential +import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsCredentialValidation import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsDeletedCredential import com.anthropic.models.beta.vaults.credentials.CredentialArchiveParams import com.anthropic.models.beta.vaults.credentials.CredentialCreateParams import com.anthropic.models.beta.vaults.credentials.CredentialDeleteParams import com.anthropic.models.beta.vaults.credentials.CredentialListPage import com.anthropic.models.beta.vaults.credentials.CredentialListParams +import com.anthropic.models.beta.vaults.credentials.CredentialMcpOAuthValidateParams import com.anthropic.models.beta.vaults.credentials.CredentialRetrieveParams import com.anthropic.models.beta.vaults.credentials.CredentialUpdateParams import com.google.errorprone.annotations.MustBeClosed @@ -176,6 +178,32 @@ interface CredentialService { requestOptions: RequestOptions = RequestOptions.none(), ): BetaManagedAgentsCredential + /** Validate Credential */ + fun mcpOAuthValidate( + credentialId: String, + params: CredentialMcpOAuthValidateParams, + ): BetaManagedAgentsCredentialValidation = + mcpOAuthValidate(credentialId, params, RequestOptions.none()) + + /** @see mcpOAuthValidate */ + fun mcpOAuthValidate( + credentialId: String, + params: CredentialMcpOAuthValidateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): BetaManagedAgentsCredentialValidation = + mcpOAuthValidate(params.toBuilder().credentialId(credentialId).build(), requestOptions) + + /** @see mcpOAuthValidate */ + fun mcpOAuthValidate( + params: CredentialMcpOAuthValidateParams + ): BetaManagedAgentsCredentialValidation = mcpOAuthValidate(params, RequestOptions.none()) + + /** @see mcpOAuthValidate */ + fun mcpOAuthValidate( + params: CredentialMcpOAuthValidateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): BetaManagedAgentsCredentialValidation + /** A view of [CredentialService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -398,5 +426,40 @@ interface CredentialService { params: CredentialArchiveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** + * Returns a raw HTTP response for `post + * /v1/vaults/{vault_id}/credentials/{credential_id}/mcp_oauth_validate?beta=true`, but is + * otherwise the same as [CredentialService.mcpOAuthValidate]. + */ + @MustBeClosed + fun mcpOAuthValidate( + credentialId: String, + params: CredentialMcpOAuthValidateParams, + ): HttpResponseFor = + mcpOAuthValidate(credentialId, params, RequestOptions.none()) + + /** @see mcpOAuthValidate */ + @MustBeClosed + fun mcpOAuthValidate( + credentialId: String, + params: CredentialMcpOAuthValidateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + mcpOAuthValidate(params.toBuilder().credentialId(credentialId).build(), requestOptions) + + /** @see mcpOAuthValidate */ + @MustBeClosed + fun mcpOAuthValidate( + params: CredentialMcpOAuthValidateParams + ): HttpResponseFor = + mcpOAuthValidate(params, RequestOptions.none()) + + /** @see mcpOAuthValidate */ + @MustBeClosed + fun mcpOAuthValidate( + params: CredentialMcpOAuthValidateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor } } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/vaults/CredentialServiceImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/vaults/CredentialServiceImpl.kt index e984bfdb5..fece810af 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/vaults/CredentialServiceImpl.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/services/blocking/beta/vaults/CredentialServiceImpl.kt @@ -18,6 +18,7 @@ import com.anthropic.core.http.json import com.anthropic.core.http.parseable import com.anthropic.core.prepare import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsCredential +import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsCredentialValidation import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsDeletedCredential import com.anthropic.models.beta.vaults.credentials.CredentialArchiveParams import com.anthropic.models.beta.vaults.credentials.CredentialCreateParams @@ -25,6 +26,7 @@ import com.anthropic.models.beta.vaults.credentials.CredentialDeleteParams import com.anthropic.models.beta.vaults.credentials.CredentialListPage import com.anthropic.models.beta.vaults.credentials.CredentialListPageResponse import com.anthropic.models.beta.vaults.credentials.CredentialListParams +import com.anthropic.models.beta.vaults.credentials.CredentialMcpOAuthValidateParams import com.anthropic.models.beta.vaults.credentials.CredentialRetrieveParams import com.anthropic.models.beta.vaults.credentials.CredentialUpdateParams import java.util.function.Consumer @@ -90,6 +92,13 @@ class CredentialServiceImpl internal constructor(private val clientOptions: Clie // post /v1/vaults/{vault_id}/credentials/{credential_id}/archive?beta=true withRawResponse().archive(params, requestOptions).parse() + override fun mcpOAuthValidate( + params: CredentialMcpOAuthValidateParams, + requestOptions: RequestOptions, + ): BetaManagedAgentsCredentialValidation = + // post /v1/vaults/{vault_id}/credentials/{credential_id}/mcp_oauth_validate?beta=true + withRawResponse().mcpOAuthValidate(params, requestOptions).parse() + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : CredentialService.WithRawResponse { @@ -330,5 +339,45 @@ class CredentialServiceImpl internal constructor(private val clientOptions: Clie } } } + + private val mcpOAuthValidateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun mcpOAuthValidate( + params: CredentialMcpOAuthValidateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("credentialId", params.credentialId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "v1", + "vaults", + params._pathParam(0), + "credentials", + params._pathParam(1), + "mcp_oauth_validate", + ) + .putQueryParam("beta", "true") + .putAllHeaders(DEFAULT_HEADERS) + .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 { mcpOAuthValidateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } } } diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/AgentCreateParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/AgentCreateParamsTest.kt index 2bc707db2..bbf9f3db8 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/AgentCreateParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/AgentCreateParamsTest.kt @@ -5,6 +5,7 @@ package com.anthropic.models.beta.agents import com.anthropic.core.JsonValue import com.anthropic.core.http.Headers import com.anthropic.models.beta.AnthropicBeta +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagentParams import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -30,6 +31,17 @@ internal class AgentCreateParamsTest { .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) + .multiagent( + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + ) .addSkill( BetaManagedAgentsAnthropicSkillParams.builder() .skillId("xlsx") @@ -89,6 +101,17 @@ internal class AgentCreateParamsTest { .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) + .multiagent( + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + ) .addSkill( BetaManagedAgentsAnthropicSkillParams.builder() .skillId("xlsx") @@ -170,6 +193,17 @@ internal class AgentCreateParamsTest { .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) + .multiagent( + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + ) .addSkill( BetaManagedAgentsAnthropicSkillParams.builder() .skillId("xlsx") @@ -234,6 +268,18 @@ internal class AgentCreateParamsTest { .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) + assertThat(body.multiagent()) + .contains( + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + ) assertThat(body.skills().getOrNull()) .containsExactly( BetaManagedAgentsSkillParams.ofAnthropic( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/AgentListPageResponseTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/AgentListPageResponseTest.kt index a81f7e65f..8ab1b7e0e 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/AgentListPageResponseTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/AgentListPageResponseTest.kt @@ -4,6 +4,7 @@ package com.anthropic.models.beta.agents import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagent import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull @@ -40,6 +41,18 @@ internal class AgentListPageResponseTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagent.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() @@ -125,6 +138,18 @@ internal class AgentListPageResponseTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagent.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() @@ -208,6 +233,18 @@ internal class AgentListPageResponseTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagent.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/AgentUpdateParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/AgentUpdateParamsTest.kt index 83f27b79f..f2138b700 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/AgentUpdateParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/AgentUpdateParamsTest.kt @@ -5,6 +5,7 @@ package com.anthropic.models.beta.agents import com.anthropic.core.JsonValue import com.anthropic.core.http.Headers import com.anthropic.models.beta.AnthropicBeta +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagentParams import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -36,6 +37,17 @@ internal class AgentUpdateParamsTest { .speed(BetaManagedAgentsModelConfigParams.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + ) .name("name") .addSkill( BetaManagedAgentsAnthropicSkillParams.builder() @@ -112,6 +124,17 @@ internal class AgentUpdateParamsTest { .speed(BetaManagedAgentsModelConfigParams.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + ) .name("name") .addSkill( BetaManagedAgentsAnthropicSkillParams.builder() @@ -197,6 +220,17 @@ internal class AgentUpdateParamsTest { .speed(BetaManagedAgentsModelConfigParams.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + ) .name("name") .addSkill( BetaManagedAgentsAnthropicSkillParams.builder() @@ -265,6 +299,18 @@ internal class AgentUpdateParamsTest { .build() ) ) + assertThat(body.multiagent()) + .contains( + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + ) assertThat(body.name()).contains("name") assertThat(body.skills().getOrNull()) .containsExactly( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgentReferenceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgentReferenceTest.kt new file mode 100644 index 000000000..feac93c3d --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgentReferenceTest.kt @@ -0,0 +1,46 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.agents + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsAgentReferenceTest { + + @Test + fun create() { + val betaManagedAgentsAgentReference = + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + + assertThat(betaManagedAgentsAgentReference.id()).isEqualTo("agent_011CZkYqphY8vELVzwCUpqiQ") + assertThat(betaManagedAgentsAgentReference.type()) + .isEqualTo(BetaManagedAgentsAgentReference.Type.AGENT) + assertThat(betaManagedAgentsAgentReference.version()).isEqualTo(1) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsAgentReference = + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + + val roundtrippedBetaManagedAgentsAgentReference = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsAgentReference), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsAgentReference) + .isEqualTo(betaManagedAgentsAgentReference) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgentTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgentTest.kt index 48b0a09a1..77097e59b 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgentTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsAgentTest.kt @@ -4,6 +4,7 @@ package com.anthropic.models.beta.agents import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagent import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat @@ -37,6 +38,18 @@ internal class BetaManagedAgentsAgentTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagent.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() @@ -113,6 +126,19 @@ internal class BetaManagedAgentsAgentTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + assertThat(betaManagedAgentsAgent.multiagent()) + .contains( + BetaManagedAgentsMultiagent.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + .build() + ) assertThat(betaManagedAgentsAgent.name()).isEqualTo("My First Agent") assertThat(betaManagedAgentsAgent.skills()) .containsExactly( @@ -197,6 +223,18 @@ internal class BetaManagedAgentsAgentTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagent.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinatorParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinatorParamsTest.kt new file mode 100644 index 000000000..d5003c6b4 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinatorParamsTest.kt @@ -0,0 +1,64 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.agents + +import com.anthropic.core.jsonMapper +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagentRosterEntryParams +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsMultiagentCoordinatorParamsTest { + + @Test + fun create() { + val betaManagedAgentsMultiagentCoordinatorParams = + BetaManagedAgentsMultiagentCoordinatorParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentCoordinatorParams.Type.COORDINATOR) + .build() + + assertThat(betaManagedAgentsMultiagentCoordinatorParams.agents()) + .containsExactly( + BetaManagedAgentsMultiagentRosterEntryParams.ofString( + "agent_011CZkYqphY8vELVzwCUpqiQ" + ), + BetaManagedAgentsMultiagentRosterEntryParams.ofSelf( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ), + ) + assertThat(betaManagedAgentsMultiagentCoordinatorParams.type()) + .isEqualTo(BetaManagedAgentsMultiagentCoordinatorParams.Type.COORDINATOR) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsMultiagentCoordinatorParams = + BetaManagedAgentsMultiagentCoordinatorParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentCoordinatorParams.Type.COORDINATOR) + .build() + + val roundtrippedBetaManagedAgentsMultiagentCoordinatorParams = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsMultiagentCoordinatorParams), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsMultiagentCoordinatorParams) + .isEqualTo(betaManagedAgentsMultiagentCoordinatorParams) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinatorTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinatorTest.kt new file mode 100644 index 000000000..21a97d7d5 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentCoordinatorTest.kt @@ -0,0 +1,62 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.agents + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsMultiagentCoordinatorTest { + + @Test + fun create() { + val betaManagedAgentsMultiagentCoordinator = + BetaManagedAgentsMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagentCoordinator.Type.COORDINATOR) + .build() + + assertThat(betaManagedAgentsMultiagentCoordinator.agents()) + .containsExactly( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + assertThat(betaManagedAgentsMultiagentCoordinator.type()) + .isEqualTo(BetaManagedAgentsMultiagentCoordinator.Type.COORDINATOR) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsMultiagentCoordinator = + BetaManagedAgentsMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagentCoordinator.Type.COORDINATOR) + .build() + + val roundtrippedBetaManagedAgentsMultiagentCoordinator = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsMultiagentCoordinator), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsMultiagentCoordinator) + .isEqualTo(betaManagedAgentsMultiagentCoordinator) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentSelfParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentSelfParamsTest.kt new file mode 100644 index 000000000..515608434 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/BetaManagedAgentsMultiagentSelfParamsTest.kt @@ -0,0 +1,40 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.agents + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsMultiagentSelfParamsTest { + + @Test + fun create() { + val betaManagedAgentsMultiagentSelfParams = + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + + assertThat(betaManagedAgentsMultiagentSelfParams.type()) + .isEqualTo(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsMultiagentSelfParams = + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + + val roundtrippedBetaManagedAgentsMultiagentSelfParams = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsMultiagentSelfParams), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsMultiagentSelfParams) + .isEqualTo(betaManagedAgentsMultiagentSelfParams) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/versions/VersionListPageResponseTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/versions/VersionListPageResponseTest.kt index 6412f7332..d2590c621 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/versions/VersionListPageResponseTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/agents/versions/VersionListPageResponseTest.kt @@ -5,6 +5,7 @@ package com.anthropic.models.beta.agents.versions import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper import com.anthropic.models.beta.agents.BetaManagedAgentsAgent +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentReference import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolConfig import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolset20260401 import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolsetDefaultConfig @@ -15,6 +16,7 @@ import com.anthropic.models.beta.agents.BetaManagedAgentsCustomSkill import com.anthropic.models.beta.agents.BetaManagedAgentsMcpServerUrlDefinition import com.anthropic.models.beta.agents.BetaManagedAgentsModel import com.anthropic.models.beta.agents.BetaManagedAgentsModelConfig +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagent import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull @@ -51,6 +53,18 @@ internal class VersionListPageResponseTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagent.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() @@ -136,6 +150,18 @@ internal class VersionListPageResponseTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagent.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() @@ -219,6 +245,18 @@ internal class VersionListPageResponseTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagent.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentParamsTest.kt new file mode 100644 index 000000000..913e78a02 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentParamsTest.kt @@ -0,0 +1,64 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions + +import com.anthropic.core.jsonMapper +import com.anthropic.models.beta.agents.BetaManagedAgentsMultiagentSelfParams +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsMultiagentParamsTest { + + @Test + fun create() { + val betaManagedAgentsMultiagentParams = + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + + assertThat(betaManagedAgentsMultiagentParams.agents()) + .containsExactly( + BetaManagedAgentsMultiagentRosterEntryParams.ofString( + "agent_011CZkYqphY8vELVzwCUpqiQ" + ), + BetaManagedAgentsMultiagentRosterEntryParams.ofSelf( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ), + ) + assertThat(betaManagedAgentsMultiagentParams.type()) + .isEqualTo(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsMultiagentParams = + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + + val roundtrippedBetaManagedAgentsMultiagentParams = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsMultiagentParams), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsMultiagentParams) + .isEqualTo(betaManagedAgentsMultiagentParams) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentRosterEntryParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentRosterEntryParamsTest.kt new file mode 100644 index 000000000..b221a947f --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentRosterEntryParamsTest.kt @@ -0,0 +1,143 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions + +import com.anthropic.core.JsonValue +import com.anthropic.core.jsonMapper +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.models.beta.agents.BetaManagedAgentsMultiagentSelfParams +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +internal class BetaManagedAgentsMultiagentRosterEntryParamsTest { + + @Test + fun ofString() { + val string = "string" + + val betaManagedAgentsMultiagentRosterEntryParams = + BetaManagedAgentsMultiagentRosterEntryParams.ofString(string) + + assertThat(betaManagedAgentsMultiagentRosterEntryParams.string()).contains(string) + assertThat(betaManagedAgentsMultiagentRosterEntryParams.agent()).isEmpty + assertThat(betaManagedAgentsMultiagentRosterEntryParams.self()).isEmpty + } + + @Test + fun ofStringRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsMultiagentRosterEntryParams = + BetaManagedAgentsMultiagentRosterEntryParams.ofString("string") + + val roundtrippedBetaManagedAgentsMultiagentRosterEntryParams = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsMultiagentRosterEntryParams), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsMultiagentRosterEntryParams) + .isEqualTo(betaManagedAgentsMultiagentRosterEntryParams) + } + + @Test + fun ofAgent() { + val agent = + BetaManagedAgentsAgentParams.builder() + .id("x") + .type(BetaManagedAgentsAgentParams.Type.AGENT) + .version(0) + .build() + + val betaManagedAgentsMultiagentRosterEntryParams = + BetaManagedAgentsMultiagentRosterEntryParams.ofAgent(agent) + + assertThat(betaManagedAgentsMultiagentRosterEntryParams.string()).isEmpty + assertThat(betaManagedAgentsMultiagentRosterEntryParams.agent()).contains(agent) + assertThat(betaManagedAgentsMultiagentRosterEntryParams.self()).isEmpty + } + + @Test + fun ofAgentRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsMultiagentRosterEntryParams = + BetaManagedAgentsMultiagentRosterEntryParams.ofAgent( + BetaManagedAgentsAgentParams.builder() + .id("x") + .type(BetaManagedAgentsAgentParams.Type.AGENT) + .version(0) + .build() + ) + + val roundtrippedBetaManagedAgentsMultiagentRosterEntryParams = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsMultiagentRosterEntryParams), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsMultiagentRosterEntryParams) + .isEqualTo(betaManagedAgentsMultiagentRosterEntryParams) + } + + @Test + fun ofSelf() { + val self = + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + + val betaManagedAgentsMultiagentRosterEntryParams = + BetaManagedAgentsMultiagentRosterEntryParams.ofSelf(self) + + assertThat(betaManagedAgentsMultiagentRosterEntryParams.string()).isEmpty + assertThat(betaManagedAgentsMultiagentRosterEntryParams.agent()).isEmpty + assertThat(betaManagedAgentsMultiagentRosterEntryParams.self()).contains(self) + } + + @Test + fun ofSelfRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsMultiagentRosterEntryParams = + BetaManagedAgentsMultiagentRosterEntryParams.ofSelf( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + + val roundtrippedBetaManagedAgentsMultiagentRosterEntryParams = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsMultiagentRosterEntryParams), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsMultiagentRosterEntryParams) + .isEqualTo(betaManagedAgentsMultiagentRosterEntryParams) + } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val betaManagedAgentsMultiagentRosterEntryParams = + jsonMapper() + .convertValue( + testCase.value, + jacksonTypeRef(), + ) + + val e = + assertThrows { + betaManagedAgentsMultiagentRosterEntryParams.validate() + } + assertThat(e).hasMessageStartingWith("Unknown ") + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentTest.kt new file mode 100644 index 000000000..c80981aab --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsMultiagentTest.kt @@ -0,0 +1,62 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions + +import com.anthropic.core.jsonMapper +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentReference +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsMultiagentTest { + + @Test + fun create() { + val betaManagedAgentsMultiagent = + BetaManagedAgentsMultiagent.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + .build() + + assertThat(betaManagedAgentsMultiagent.agents()) + .containsExactly( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + assertThat(betaManagedAgentsMultiagent.type()) + .isEqualTo(BetaManagedAgentsMultiagent.Type.COORDINATOR) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsMultiagent = + BetaManagedAgentsMultiagent.builder() + .addAgent( + BetaManagedAgentsAgentReference.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .type(BetaManagedAgentsAgentReference.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsMultiagent.Type.COORDINATOR) + .build() + + val roundtrippedBetaManagedAgentsMultiagent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsMultiagent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsMultiagent).isEqualTo(betaManagedAgentsMultiagent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsOutcomeEvaluationResourceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsOutcomeEvaluationResourceTest.kt new file mode 100644 index 000000000..08aab9ed9 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsOutcomeEvaluationResourceTest.kt @@ -0,0 +1,63 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions + +import com.anthropic.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 BetaManagedAgentsOutcomeEvaluationResourceTest { + + @Test + fun create() { + val betaManagedAgentsOutcomeEvaluationResource = + BetaManagedAgentsOutcomeEvaluationResource.builder() + .completedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .description("Produce a 2-page summary as summary.md") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .result("satisfied") + .type(BetaManagedAgentsOutcomeEvaluationResource.Type.OUTCOME_EVALUATION) + .build() + + assertThat(betaManagedAgentsOutcomeEvaluationResource.completedAt()) + .contains(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + assertThat(betaManagedAgentsOutcomeEvaluationResource.description()) + .isEqualTo("Produce a 2-page summary as summary.md") + assertThat(betaManagedAgentsOutcomeEvaluationResource.explanation()) + .contains("All five sections present with inline citations.") + assertThat(betaManagedAgentsOutcomeEvaluationResource.iteration()).isEqualTo(0) + assertThat(betaManagedAgentsOutcomeEvaluationResource.outcomeId()) + .isEqualTo("outc_011CZkZRSw2kEfs6ncTVljxP") + assertThat(betaManagedAgentsOutcomeEvaluationResource.result()).isEqualTo("satisfied") + assertThat(betaManagedAgentsOutcomeEvaluationResource.type()) + .isEqualTo(BetaManagedAgentsOutcomeEvaluationResource.Type.OUTCOME_EVALUATION) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsOutcomeEvaluationResource = + BetaManagedAgentsOutcomeEvaluationResource.builder() + .completedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .description("Produce a 2-page summary as summary.md") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .result("satisfied") + .type(BetaManagedAgentsOutcomeEvaluationResource.Type.OUTCOME_EVALUATION) + .build() + + val roundtrippedBetaManagedAgentsOutcomeEvaluationResource = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsOutcomeEvaluationResource), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsOutcomeEvaluationResource) + .isEqualTo(betaManagedAgentsOutcomeEvaluationResource) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionAgentTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionAgentTest.kt index 6adae146b..292ee9bba 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionAgentTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionAgentTest.kt @@ -13,6 +13,7 @@ import com.anthropic.models.beta.agents.BetaManagedAgentsCustomSkill import com.anthropic.models.beta.agents.BetaManagedAgentsMcpServerUrlDefinition import com.anthropic.models.beta.agents.BetaManagedAgentsModel import com.anthropic.models.beta.agents.BetaManagedAgentsModelConfig +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsSessionThreadAgent import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -38,6 +39,78 @@ internal class BetaManagedAgentsSessionAgentTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsSessionMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy.Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type( + BetaManagedAgentsAlwaysAskPolicy.Type + .ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsSessionMultiagentCoordinator.Type.COORDINATOR) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() @@ -104,6 +177,79 @@ internal class BetaManagedAgentsSessionAgentTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + assertThat(betaManagedAgentsSessionAgent.multiagent()) + .contains( + BetaManagedAgentsSessionMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy.Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type( + BetaManagedAgentsAlwaysAskPolicy.Type + .ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsSessionMultiagentCoordinator.Type.COORDINATOR) + .build() + ) assertThat(betaManagedAgentsSessionAgent.name()).isEqualTo("My First Agent") assertThat(betaManagedAgentsSessionAgent.skills()) .containsExactly( @@ -180,6 +326,78 @@ internal class BetaManagedAgentsSessionAgentTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsSessionMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy.Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type( + BetaManagedAgentsAlwaysAskPolicy.Type + .ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsSessionMultiagentCoordinator.Type.COORDINATOR) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionMultiagentCoordinatorTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionMultiagentCoordinatorTest.kt new file mode 100644 index 000000000..6eadfe574 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionMultiagentCoordinatorTest.kt @@ -0,0 +1,243 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions + +import com.anthropic.core.jsonMapper +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolConfig +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolset20260401 +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolsetDefaultConfig +import com.anthropic.models.beta.agents.BetaManagedAgentsAlwaysAllowPolicy +import com.anthropic.models.beta.agents.BetaManagedAgentsAlwaysAskPolicy +import com.anthropic.models.beta.agents.BetaManagedAgentsAnthropicSkill +import com.anthropic.models.beta.agents.BetaManagedAgentsMcpServerUrlDefinition +import com.anthropic.models.beta.agents.BetaManagedAgentsModel +import com.anthropic.models.beta.agents.BetaManagedAgentsModelConfig +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsSessionThreadAgent +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsSessionMultiagentCoordinatorTest { + + @Test + fun create() { + val betaManagedAgentsSessionMultiagentCoordinator = + BetaManagedAgentsSessionMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy.Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type( + BetaManagedAgentsAlwaysAskPolicy.Type.ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsSessionMultiagentCoordinator.Type.COORDINATOR) + .build() + + assertThat(betaManagedAgentsSessionMultiagentCoordinator.agents()) + .containsExactly( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy.Type.ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type(BetaManagedAgentsAlwaysAskPolicy.Type.ALWAYS_ASK) + .build() + ) + .build() + ) + .type(BetaManagedAgentsAgentToolset20260401.Type.AGENT_TOOLSET_20260401) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + assertThat(betaManagedAgentsSessionMultiagentCoordinator.type()) + .isEqualTo(BetaManagedAgentsSessionMultiagentCoordinator.Type.COORDINATOR) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionMultiagentCoordinator = + BetaManagedAgentsSessionMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy.Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type( + BetaManagedAgentsAlwaysAskPolicy.Type.ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsSessionMultiagentCoordinator.Type.COORDINATOR) + .build() + + val roundtrippedBetaManagedAgentsSessionMultiagentCoordinator = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionMultiagentCoordinator), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionMultiagentCoordinator) + .isEqualTo(betaManagedAgentsSessionMultiagentCoordinator) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionTest.kt index 518ab97d1..be5aa54d9 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/BetaManagedAgentsSessionTest.kt @@ -16,6 +16,7 @@ import com.anthropic.models.beta.agents.BetaManagedAgentsModelConfig import com.anthropic.models.beta.sessions.resources.BetaManagedAgentsFileResource import com.anthropic.models.beta.sessions.resources.BetaManagedAgentsGitHubRepositoryResource import com.anthropic.models.beta.sessions.resources.BetaManagedAgentsSessionResource +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsSessionThreadAgent import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat @@ -45,6 +46,94 @@ internal class BetaManagedAgentsSessionTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsSessionMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type( + BetaManagedAgentsMcpServerUrlDefinition.Type.URL + ) + .url( + "https://example-server.modelcontextprotocol.io/sse" + ) + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type( + BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC + ) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name( + BetaManagedAgentsAgentToolConfig.Name + .BASH + ) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy + .builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy + .Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig + .builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy + .builder() + .type( + BetaManagedAgentsAlwaysAskPolicy + .Type + .ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .type( + BetaManagedAgentsSessionMultiagentCoordinator.Type.COORDINATOR + ) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() @@ -105,6 +194,17 @@ internal class BetaManagedAgentsSessionTest { .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .environmentId("env_011CZkZ9X2dpNyB7HsEFoRfW") .metadata(BetaManagedAgentsSession.Metadata.builder().build()) + .addOutcomeEvaluation( + BetaManagedAgentsOutcomeEvaluationResource.builder() + .completedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .description("Produce a 2-page summary as summary.md") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .result("satisfied") + .type(BetaManagedAgentsOutcomeEvaluationResource.Type.OUTCOME_EVALUATION) + .build() + ) .addResource( BetaManagedAgentsFileResource.builder() .id("sesrsc_011CZkZBJq5dWxk9fVLNcPht") @@ -171,6 +271,84 @@ internal class BetaManagedAgentsSessionTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsSessionMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url( + "https://example-server.modelcontextprotocol.io/sse" + ) + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name( + BetaManagedAgentsAgentToolConfig.Name.BASH + ) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy + .Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type( + BetaManagedAgentsAlwaysAskPolicy + .Type + .ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .type(BetaManagedAgentsSessionMultiagentCoordinator.Type.COORDINATOR) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() @@ -228,6 +406,18 @@ internal class BetaManagedAgentsSessionTest { .isEqualTo("env_011CZkZ9X2dpNyB7HsEFoRfW") assertThat(betaManagedAgentsSession.metadata()) .isEqualTo(BetaManagedAgentsSession.Metadata.builder().build()) + assertThat(betaManagedAgentsSession.outcomeEvaluations()) + .containsExactly( + BetaManagedAgentsOutcomeEvaluationResource.builder() + .completedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .description("Produce a 2-page summary as summary.md") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .result("satisfied") + .type(BetaManagedAgentsOutcomeEvaluationResource.Type.OUTCOME_EVALUATION) + .build() + ) assertThat(betaManagedAgentsSession.resources()) .containsExactly( BetaManagedAgentsSessionResource.ofFile( @@ -306,6 +496,94 @@ internal class BetaManagedAgentsSessionTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsSessionMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type( + BetaManagedAgentsMcpServerUrlDefinition.Type.URL + ) + .url( + "https://example-server.modelcontextprotocol.io/sse" + ) + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type( + BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC + ) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name( + BetaManagedAgentsAgentToolConfig.Name + .BASH + ) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy + .builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy + .Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig + .builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy + .builder() + .type( + BetaManagedAgentsAlwaysAskPolicy + .Type + .ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .type( + BetaManagedAgentsSessionMultiagentCoordinator.Type.COORDINATOR + ) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() @@ -366,6 +644,17 @@ internal class BetaManagedAgentsSessionTest { .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .environmentId("env_011CZkZ9X2dpNyB7HsEFoRfW") .metadata(BetaManagedAgentsSession.Metadata.builder().build()) + .addOutcomeEvaluation( + BetaManagedAgentsOutcomeEvaluationResource.builder() + .completedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .description("Produce a 2-page summary as summary.md") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .result("satisfied") + .type(BetaManagedAgentsOutcomeEvaluationResource.Type.OUTCOME_EVALUATION) + .build() + ) .addResource( BetaManagedAgentsFileResource.builder() .id("sesrsc_011CZkZBJq5dWxk9fVLNcPht") diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/SessionListPageResponseTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/SessionListPageResponseTest.kt index 15400f66f..5bca13560 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/SessionListPageResponseTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/SessionListPageResponseTest.kt @@ -15,6 +15,7 @@ import com.anthropic.models.beta.agents.BetaManagedAgentsModel import com.anthropic.models.beta.agents.BetaManagedAgentsModelConfig import com.anthropic.models.beta.sessions.resources.BetaManagedAgentsFileResource import com.anthropic.models.beta.sessions.resources.BetaManagedAgentsGitHubRepositoryResource +import com.anthropic.models.beta.sessions.threads.BetaManagedAgentsSessionThreadAgent import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime import kotlin.jvm.optionals.getOrNull @@ -47,6 +48,109 @@ internal class SessionListPageResponseTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsSessionMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition + .builder() + .name("example-mcp") + .type( + BetaManagedAgentsMcpServerUrlDefinition + .Type + .URL + ) + .url( + "https://example-server.modelcontextprotocol.io/sse" + ) + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id( + BetaManagedAgentsModel.CLAUDE_SONNET_4_6 + ) + .speed( + BetaManagedAgentsModelConfig.Speed + .STANDARD + ) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type( + BetaManagedAgentsAnthropicSkill.Type + .ANTHROPIC + ) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig + .builder() + .enabled(true) + .name( + BetaManagedAgentsAgentToolConfig + .Name + .BASH + ) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy + .builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy + .Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig + .builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy + .builder() + .type( + BetaManagedAgentsAlwaysAskPolicy + .Type + .ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401 + .Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type( + BetaManagedAgentsSessionThreadAgent.Type.AGENT + ) + .version(1) + .build() + ) + .type( + BetaManagedAgentsSessionMultiagentCoordinator.Type + .COORDINATOR + ) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() @@ -108,6 +212,20 @@ internal class SessionListPageResponseTest { .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .environmentId("env_011CZkZ9X2dpNyB7HsEFoRfW") .metadata(BetaManagedAgentsSession.Metadata.builder().build()) + .addOutcomeEvaluation( + BetaManagedAgentsOutcomeEvaluationResource.builder() + .completedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .description("Produce a 2-page summary as summary.md") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .result("satisfied") + .type( + BetaManagedAgentsOutcomeEvaluationResource.Type + .OUTCOME_EVALUATION + ) + .build() + ) .addResource( BetaManagedAgentsFileResource.builder() .id("sesrsc_011CZkZBJq5dWxk9fVLNcPht") @@ -181,6 +299,100 @@ internal class SessionListPageResponseTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsSessionMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type( + BetaManagedAgentsMcpServerUrlDefinition.Type + .URL + ) + .url( + "https://example-server.modelcontextprotocol.io/sse" + ) + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed( + BetaManagedAgentsModelConfig.Speed.STANDARD + ) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type( + BetaManagedAgentsAnthropicSkill.Type + .ANTHROPIC + ) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name( + BetaManagedAgentsAgentToolConfig + .Name + .BASH + ) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy + .builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy + .Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig + .builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy + .builder() + .type( + BetaManagedAgentsAlwaysAskPolicy + .Type + .ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .type( + BetaManagedAgentsSessionMultiagentCoordinator.Type + .COORDINATOR + ) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() @@ -242,6 +454,19 @@ internal class SessionListPageResponseTest { .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .environmentId("env_011CZkZ9X2dpNyB7HsEFoRfW") .metadata(BetaManagedAgentsSession.Metadata.builder().build()) + .addOutcomeEvaluation( + BetaManagedAgentsOutcomeEvaluationResource.builder() + .completedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .description("Produce a 2-page summary as summary.md") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .result("satisfied") + .type( + BetaManagedAgentsOutcomeEvaluationResource.Type.OUTCOME_EVALUATION + ) + .build() + ) .addResource( BetaManagedAgentsFileResource.builder() .id("sesrsc_011CZkZBJq5dWxk9fVLNcPht") @@ -317,6 +542,109 @@ internal class SessionListPageResponseTest { .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsSessionMultiagentCoordinator.builder() + .addAgent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition + .builder() + .name("example-mcp") + .type( + BetaManagedAgentsMcpServerUrlDefinition + .Type + .URL + ) + .url( + "https://example-server.modelcontextprotocol.io/sse" + ) + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id( + BetaManagedAgentsModel.CLAUDE_SONNET_4_6 + ) + .speed( + BetaManagedAgentsModelConfig.Speed + .STANDARD + ) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type( + BetaManagedAgentsAnthropicSkill.Type + .ANTHROPIC + ) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig + .builder() + .enabled(true) + .name( + BetaManagedAgentsAgentToolConfig + .Name + .BASH + ) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy + .builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy + .Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig + .builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy + .builder() + .type( + BetaManagedAgentsAlwaysAskPolicy + .Type + .ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401 + .Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type( + BetaManagedAgentsSessionThreadAgent.Type.AGENT + ) + .version(1) + .build() + ) + .type( + BetaManagedAgentsSessionMultiagentCoordinator.Type + .COORDINATOR + ) + .build() + ) .name("My First Agent") .addSkill( BetaManagedAgentsAnthropicSkill.builder() @@ -378,6 +706,20 @@ internal class SessionListPageResponseTest { .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .environmentId("env_011CZkZ9X2dpNyB7HsEFoRfW") .metadata(BetaManagedAgentsSession.Metadata.builder().build()) + .addOutcomeEvaluation( + BetaManagedAgentsOutcomeEvaluationResource.builder() + .completedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .description("Produce a 2-page summary as summary.md") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .result("satisfied") + .type( + BetaManagedAgentsOutcomeEvaluationResource.Type + .OUTCOME_EVALUATION + ) + .build() + ) .addResource( BetaManagedAgentsFileResource.builder() .id("sesrsc_011CZkZBJq5dWxk9fVLNcPht") diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/SessionListParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/SessionListParamsTest.kt index 30de3f0e5..798c178b8 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/SessionListParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/SessionListParamsTest.kt @@ -25,6 +25,7 @@ internal class SessionListParamsTest { .memoryStoreId("memory_store_id") .order(SessionListParams.Order.ASC) .page("page") + .addStatus(SessionListParams.Status.RESCHEDULING) .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) .build() } @@ -44,6 +45,7 @@ internal class SessionListParamsTest { .memoryStoreId("memory_store_id") .order(SessionListParams.Order.ASC) .page("page") + .addStatus(SessionListParams.Status.RESCHEDULING) .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) .build() @@ -79,6 +81,7 @@ internal class SessionListParamsTest { .memoryStoreId("memory_store_id") .order(SessionListParams.Order.ASC) .page("page") + .addStatus(SessionListParams.Status.RESCHEDULING) .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) .build() @@ -98,6 +101,7 @@ internal class SessionListParamsTest { .put("memory_store_id", "memory_store_id") .put("order", "asc") .put("page", "page") + .put("statuses[]", "rescheduling") .build() ) } diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentCustomToolUseEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentCustomToolUseEventTest.kt index ba4f87075..16e85dd5e 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentCustomToolUseEventTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentCustomToolUseEventTest.kt @@ -24,6 +24,7 @@ internal class BetaManagedAgentsAgentCustomToolUseEventTest { .name("name") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .type(BetaManagedAgentsAgentCustomToolUseEvent.Type.AGENT_CUSTOM_TOOL_USE) + .sessionThreadId("session_thread_id") .build() assertThat(betaManagedAgentsAgentCustomToolUseEvent.id()).isEqualTo("id") @@ -38,6 +39,8 @@ internal class BetaManagedAgentsAgentCustomToolUseEventTest { .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) assertThat(betaManagedAgentsAgentCustomToolUseEvent.type()) .isEqualTo(BetaManagedAgentsAgentCustomToolUseEvent.Type.AGENT_CUSTOM_TOOL_USE) + assertThat(betaManagedAgentsAgentCustomToolUseEvent.sessionThreadId()) + .contains("session_thread_id") } @Test @@ -54,6 +57,7 @@ internal class BetaManagedAgentsAgentCustomToolUseEventTest { .name("name") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .type(BetaManagedAgentsAgentCustomToolUseEvent.Type.AGENT_CUSTOM_TOOL_USE) + .sessionThreadId("session_thread_id") .build() val roundtrippedBetaManagedAgentsAgentCustomToolUseEvent = diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentMcpToolUseEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentMcpToolUseEventTest.kt index e019bd859..aebf4cd6e 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentMcpToolUseEventTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentMcpToolUseEventTest.kt @@ -28,6 +28,7 @@ internal class BetaManagedAgentsAgentMcpToolUseEventTest { .evaluatedPermission( BetaManagedAgentsAgentMcpToolUseEvent.EvaluatedPermission.ALLOW ) + .sessionThreadId("session_thread_id") .build() assertThat(betaManagedAgentsAgentMcpToolUseEvent.id()).isEqualTo("id") @@ -46,6 +47,8 @@ internal class BetaManagedAgentsAgentMcpToolUseEventTest { .isEqualTo(BetaManagedAgentsAgentMcpToolUseEvent.Type.AGENT_MCP_TOOL_USE) assertThat(betaManagedAgentsAgentMcpToolUseEvent.evaluatedPermission()) .contains(BetaManagedAgentsAgentMcpToolUseEvent.EvaluatedPermission.ALLOW) + assertThat(betaManagedAgentsAgentMcpToolUseEvent.sessionThreadId()) + .contains("session_thread_id") } @Test @@ -66,6 +69,7 @@ internal class BetaManagedAgentsAgentMcpToolUseEventTest { .evaluatedPermission( BetaManagedAgentsAgentMcpToolUseEvent.EvaluatedPermission.ALLOW ) + .sessionThreadId("session_thread_id") .build() val roundtrippedBetaManagedAgentsAgentMcpToolUseEvent = diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageReceivedEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageReceivedEventTest.kt new file mode 100644 index 000000000..be4bd67bc --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageReceivedEventTest.kt @@ -0,0 +1,75 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.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 BetaManagedAgentsAgentThreadMessageReceivedEventTest { + + @Test + fun create() { + val betaManagedAgentsAgentThreadMessageReceivedEvent = + BetaManagedAgentsAgentThreadMessageReceivedEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .fromSessionThreadId("from_session_thread_id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsAgentThreadMessageReceivedEvent.Type + .AGENT_THREAD_MESSAGE_RECEIVED + ) + .fromAgentName("from_agent_name") + .build() + + assertThat(betaManagedAgentsAgentThreadMessageReceivedEvent.id()).isEqualTo("id") + assertThat(betaManagedAgentsAgentThreadMessageReceivedEvent.content()) + .containsExactly( + BetaManagedAgentsAgentThreadMessageReceivedEvent.Content.ofText( + BetaManagedAgentsTextBlock.builder() + .text("Where is my order #1234?") + .type(BetaManagedAgentsTextBlock.Type.TEXT) + .build() + ) + ) + assertThat(betaManagedAgentsAgentThreadMessageReceivedEvent.fromSessionThreadId()) + .isEqualTo("from_session_thread_id") + assertThat(betaManagedAgentsAgentThreadMessageReceivedEvent.processedAt()) + .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(betaManagedAgentsAgentThreadMessageReceivedEvent.type()) + .isEqualTo( + BetaManagedAgentsAgentThreadMessageReceivedEvent.Type.AGENT_THREAD_MESSAGE_RECEIVED + ) + assertThat(betaManagedAgentsAgentThreadMessageReceivedEvent.fromAgentName()) + .contains("from_agent_name") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsAgentThreadMessageReceivedEvent = + BetaManagedAgentsAgentThreadMessageReceivedEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .fromSessionThreadId("from_session_thread_id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsAgentThreadMessageReceivedEvent.Type + .AGENT_THREAD_MESSAGE_RECEIVED + ) + .fromAgentName("from_agent_name") + .build() + + val roundtrippedBetaManagedAgentsAgentThreadMessageReceivedEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsAgentThreadMessageReceivedEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsAgentThreadMessageReceivedEvent) + .isEqualTo(betaManagedAgentsAgentThreadMessageReceivedEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageSentEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageSentEventTest.kt new file mode 100644 index 000000000..f92fecf6b --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentThreadMessageSentEventTest.kt @@ -0,0 +1,67 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.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 BetaManagedAgentsAgentThreadMessageSentEventTest { + + @Test + fun create() { + val betaManagedAgentsAgentThreadMessageSentEvent = + BetaManagedAgentsAgentThreadMessageSentEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .toSessionThreadId("to_session_thread_id") + .type(BetaManagedAgentsAgentThreadMessageSentEvent.Type.AGENT_THREAD_MESSAGE_SENT) + .toAgentName("to_agent_name") + .build() + + assertThat(betaManagedAgentsAgentThreadMessageSentEvent.id()).isEqualTo("id") + assertThat(betaManagedAgentsAgentThreadMessageSentEvent.content()) + .containsExactly( + BetaManagedAgentsAgentThreadMessageSentEvent.Content.ofText( + BetaManagedAgentsTextBlock.builder() + .text("Where is my order #1234?") + .type(BetaManagedAgentsTextBlock.Type.TEXT) + .build() + ) + ) + assertThat(betaManagedAgentsAgentThreadMessageSentEvent.processedAt()) + .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(betaManagedAgentsAgentThreadMessageSentEvent.toSessionThreadId()) + .isEqualTo("to_session_thread_id") + assertThat(betaManagedAgentsAgentThreadMessageSentEvent.type()) + .isEqualTo(BetaManagedAgentsAgentThreadMessageSentEvent.Type.AGENT_THREAD_MESSAGE_SENT) + assertThat(betaManagedAgentsAgentThreadMessageSentEvent.toAgentName()) + .contains("to_agent_name") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsAgentThreadMessageSentEvent = + BetaManagedAgentsAgentThreadMessageSentEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .toSessionThreadId("to_session_thread_id") + .type(BetaManagedAgentsAgentThreadMessageSentEvent.Type.AGENT_THREAD_MESSAGE_SENT) + .toAgentName("to_agent_name") + .build() + + val roundtrippedBetaManagedAgentsAgentThreadMessageSentEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsAgentThreadMessageSentEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsAgentThreadMessageSentEvent) + .isEqualTo(betaManagedAgentsAgentThreadMessageSentEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentToolUseEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentToolUseEventTest.kt index 520cc9874..d4535dc3f 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentToolUseEventTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsAgentToolUseEventTest.kt @@ -25,6 +25,7 @@ internal class BetaManagedAgentsAgentToolUseEventTest { .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .type(BetaManagedAgentsAgentToolUseEvent.Type.AGENT_TOOL_USE) .evaluatedPermission(BetaManagedAgentsAgentToolUseEvent.EvaluatedPermission.ALLOW) + .sessionThreadId("session_thread_id") .build() assertThat(betaManagedAgentsAgentToolUseEvent.id()).isEqualTo("id") @@ -41,6 +42,8 @@ internal class BetaManagedAgentsAgentToolUseEventTest { .isEqualTo(BetaManagedAgentsAgentToolUseEvent.Type.AGENT_TOOL_USE) assertThat(betaManagedAgentsAgentToolUseEvent.evaluatedPermission()) .contains(BetaManagedAgentsAgentToolUseEvent.EvaluatedPermission.ALLOW) + assertThat(betaManagedAgentsAgentToolUseEvent.sessionThreadId()) + .contains("session_thread_id") } @Test @@ -58,6 +61,7 @@ internal class BetaManagedAgentsAgentToolUseEventTest { .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .type(BetaManagedAgentsAgentToolUseEvent.Type.AGENT_TOOL_USE) .evaluatedPermission(BetaManagedAgentsAgentToolUseEvent.EvaluatedPermission.ALLOW) + .sessionThreadId("session_thread_id") .build() val roundtrippedBetaManagedAgentsAgentToolUseEvent = diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsEventParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsEventParamsTest.kt index 301463c19..8e0de591d 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsEventParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsEventParamsTest.kt @@ -28,6 +28,7 @@ internal class BetaManagedAgentsEventParamsTest { assertThat(betaManagedAgentsEventParams.userInterrupt()).isEmpty assertThat(betaManagedAgentsEventParams.userToolConfirmation()).isEmpty assertThat(betaManagedAgentsEventParams.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsEventParams.userDefineOutcome()).isEmpty } @Test @@ -55,6 +56,7 @@ internal class BetaManagedAgentsEventParamsTest { val userInterrupt = BetaManagedAgentsUserInterruptEventParams.builder() .type(BetaManagedAgentsUserInterruptEventParams.Type.USER_INTERRUPT) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsEventParams = @@ -64,6 +66,7 @@ internal class BetaManagedAgentsEventParamsTest { assertThat(betaManagedAgentsEventParams.userInterrupt()).contains(userInterrupt) assertThat(betaManagedAgentsEventParams.userToolConfirmation()).isEmpty assertThat(betaManagedAgentsEventParams.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsEventParams.userDefineOutcome()).isEmpty } @Test @@ -73,6 +76,7 @@ internal class BetaManagedAgentsEventParamsTest { BetaManagedAgentsEventParams.ofUserInterrupt( BetaManagedAgentsUserInterruptEventParams.builder() .type(BetaManagedAgentsUserInterruptEventParams.Type.USER_INTERRUPT) + .sessionThreadId("session_thread_id") .build() ) @@ -103,6 +107,7 @@ internal class BetaManagedAgentsEventParamsTest { assertThat(betaManagedAgentsEventParams.userToolConfirmation()) .contains(userToolConfirmation) assertThat(betaManagedAgentsEventParams.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsEventParams.userDefineOutcome()).isEmpty } @Test @@ -147,6 +152,7 @@ internal class BetaManagedAgentsEventParamsTest { assertThat(betaManagedAgentsEventParams.userToolConfirmation()).isEmpty assertThat(betaManagedAgentsEventParams.userCustomToolResult()) .contains(userCustomToolResult) + assertThat(betaManagedAgentsEventParams.userDefineOutcome()).isEmpty } @Test @@ -174,6 +180,48 @@ internal class BetaManagedAgentsEventParamsTest { assertThat(roundtrippedBetaManagedAgentsEventParams).isEqualTo(betaManagedAgentsEventParams) } + @Test + fun ofUserDefineOutcome() { + val userDefineOutcome = + BetaManagedAgentsUserDefineOutcomeEventParams.builder() + .description("Produce a 2-page summary as summary.md") + .textRubric("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsUserDefineOutcomeEventParams.Type.USER_DEFINE_OUTCOME) + .maxIterations(3) + .build() + + val betaManagedAgentsEventParams = + BetaManagedAgentsEventParams.ofUserDefineOutcome(userDefineOutcome) + + assertThat(betaManagedAgentsEventParams.userMessage()).isEmpty + assertThat(betaManagedAgentsEventParams.userInterrupt()).isEmpty + assertThat(betaManagedAgentsEventParams.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsEventParams.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsEventParams.userDefineOutcome()).contains(userDefineOutcome) + } + + @Test + fun ofUserDefineOutcomeRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsEventParams = + BetaManagedAgentsEventParams.ofUserDefineOutcome( + BetaManagedAgentsUserDefineOutcomeEventParams.builder() + .description("Produce a 2-page summary as summary.md") + .textRubric("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsUserDefineOutcomeEventParams.Type.USER_DEFINE_OUTCOME) + .maxIterations(3) + .build() + ) + + val roundtrippedBetaManagedAgentsEventParams = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsEventParams), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsEventParams).isEqualTo(betaManagedAgentsEventParams) + } + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { BOOLEAN(JsonValue.from(false)), STRING(JsonValue.from("invalid")), diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubricParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubricParamsTest.kt new file mode 100644 index 000000000..c119af9d7 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubricParamsTest.kt @@ -0,0 +1,44 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsFileRubricParamsTest { + + @Test + fun create() { + val betaManagedAgentsFileRubricParams = + BetaManagedAgentsFileRubricParams.builder() + .fileId("file_011CNha8iCJcU1wXNR6q4V8w") + .type(BetaManagedAgentsFileRubricParams.Type.FILE) + .build() + + assertThat(betaManagedAgentsFileRubricParams.fileId()) + .isEqualTo("file_011CNha8iCJcU1wXNR6q4V8w") + assertThat(betaManagedAgentsFileRubricParams.type()) + .isEqualTo(BetaManagedAgentsFileRubricParams.Type.FILE) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsFileRubricParams = + BetaManagedAgentsFileRubricParams.builder() + .fileId("file_011CNha8iCJcU1wXNR6q4V8w") + .type(BetaManagedAgentsFileRubricParams.Type.FILE) + .build() + + val roundtrippedBetaManagedAgentsFileRubricParams = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsFileRubricParams), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsFileRubricParams) + .isEqualTo(betaManagedAgentsFileRubricParams) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubricTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubricTest.kt new file mode 100644 index 000000000..716d68c14 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsFileRubricTest.kt @@ -0,0 +1,42 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsFileRubricTest { + + @Test + fun create() { + val betaManagedAgentsFileRubric = + BetaManagedAgentsFileRubric.builder() + .fileId("file_id") + .type(BetaManagedAgentsFileRubric.Type.FILE) + .build() + + assertThat(betaManagedAgentsFileRubric.fileId()).isEqualTo("file_id") + assertThat(betaManagedAgentsFileRubric.type()) + .isEqualTo(BetaManagedAgentsFileRubric.Type.FILE) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsFileRubric = + BetaManagedAgentsFileRubric.builder() + .fileId("file_id") + .type(BetaManagedAgentsFileRubric.Type.FILE) + .build() + + val roundtrippedBetaManagedAgentsFileRubric = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsFileRubric), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsFileRubric).isEqualTo(betaManagedAgentsFileRubric) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionEventTest.kt index 272b481ae..0caba8cb9 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionEventTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionEventTest.kt @@ -38,15 +38,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -79,6 +90,7 @@ internal class BetaManagedAgentsSessionEventTest { .id("id") .type(BetaManagedAgentsUserInterruptEvent.Type.USER_INTERRUPT) .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsSessionEvent = @@ -95,15 +107,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -115,6 +138,7 @@ internal class BetaManagedAgentsSessionEventTest { .id("id") .type(BetaManagedAgentsUserInterruptEvent.Type.USER_INTERRUPT) .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() ) @@ -138,6 +162,7 @@ internal class BetaManagedAgentsSessionEventTest { .type(BetaManagedAgentsUserToolConfirmationEvent.Type.USER_TOOL_CONFIRMATION) .denyMessage("deny_message") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsSessionEvent = @@ -155,15 +180,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -178,6 +214,7 @@ internal class BetaManagedAgentsSessionEventTest { .type(BetaManagedAgentsUserToolConfirmationEvent.Type.USER_TOOL_CONFIRMATION) .denyMessage("deny_message") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() ) @@ -201,6 +238,7 @@ internal class BetaManagedAgentsSessionEventTest { .addTextContent("Where is my order #1234?") .isError(true) .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsSessionEvent = @@ -218,15 +256,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -241,6 +290,7 @@ internal class BetaManagedAgentsSessionEventTest { .addTextContent("Where is my order #1234?") .isError(true) .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() ) @@ -267,6 +317,7 @@ internal class BetaManagedAgentsSessionEventTest { .name("name") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .type(BetaManagedAgentsAgentCustomToolUseEvent.Type.AGENT_CUSTOM_TOOL_USE) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsSessionEvent = @@ -283,15 +334,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -309,6 +371,7 @@ internal class BetaManagedAgentsSessionEventTest { .name("name") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .type(BetaManagedAgentsAgentCustomToolUseEvent.Type.AGENT_CUSTOM_TOOL_USE) + .sessionThreadId("session_thread_id") .build() ) @@ -351,15 +414,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -413,15 +487,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -463,6 +548,7 @@ internal class BetaManagedAgentsSessionEventTest { .evaluatedPermission( BetaManagedAgentsAgentMcpToolUseEvent.EvaluatedPermission.ALLOW ) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsSessionEvent = @@ -479,15 +565,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -509,6 +606,7 @@ internal class BetaManagedAgentsSessionEventTest { .evaluatedPermission( BetaManagedAgentsAgentMcpToolUseEvent.EvaluatedPermission.ALLOW ) + .sessionThreadId("session_thread_id") .build() ) @@ -548,15 +646,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).contains(agentMcpToolResult) assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -598,6 +707,7 @@ internal class BetaManagedAgentsSessionEventTest { .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .type(BetaManagedAgentsAgentToolUseEvent.Type.AGENT_TOOL_USE) .evaluatedPermission(BetaManagedAgentsAgentToolUseEvent.EvaluatedPermission.ALLOW) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsSessionEvent = @@ -614,15 +724,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).contains(agentToolUse) assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -643,6 +764,7 @@ internal class BetaManagedAgentsSessionEventTest { .evaluatedPermission( BetaManagedAgentsAgentToolUseEvent.EvaluatedPermission.ALLOW ) + .sessionThreadId("session_thread_id") .build() ) @@ -682,15 +804,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).contains(agentToolResult) + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -718,6 +851,162 @@ internal class BetaManagedAgentsSessionEventTest { .isEqualTo(betaManagedAgentsSessionEvent) } + @Test + fun ofAgentThreadMessageReceived() { + val agentThreadMessageReceived = + BetaManagedAgentsAgentThreadMessageReceivedEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .fromSessionThreadId("from_session_thread_id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsAgentThreadMessageReceivedEvent.Type + .AGENT_THREAD_MESSAGE_RECEIVED + ) + .fromAgentName("from_agent_name") + .build() + + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofAgentThreadMessageReceived(agentThreadMessageReceived) + + assertThat(betaManagedAgentsSessionEvent.userMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userInterrupt()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThinking()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()) + .contains(agentThreadMessageReceived) + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofAgentThreadMessageReceivedRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofAgentThreadMessageReceived( + BetaManagedAgentsAgentThreadMessageReceivedEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .fromSessionThreadId("from_session_thread_id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsAgentThreadMessageReceivedEvent.Type + .AGENT_THREAD_MESSAGE_RECEIVED + ) + .fromAgentName("from_agent_name") + .build() + ) + + val roundtrippedBetaManagedAgentsSessionEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionEvent) + .isEqualTo(betaManagedAgentsSessionEvent) + } + + @Test + fun ofAgentThreadMessageSent() { + val agentThreadMessageSent = + BetaManagedAgentsAgentThreadMessageSentEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .toSessionThreadId("to_session_thread_id") + .type(BetaManagedAgentsAgentThreadMessageSentEvent.Type.AGENT_THREAD_MESSAGE_SENT) + .toAgentName("to_agent_name") + .build() + + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofAgentThreadMessageSent(agentThreadMessageSent) + + assertThat(betaManagedAgentsSessionEvent.userMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userInterrupt()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThinking()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()) + .contains(agentThreadMessageSent) + assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofAgentThreadMessageSentRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofAgentThreadMessageSent( + BetaManagedAgentsAgentThreadMessageSentEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .toSessionThreadId("to_session_thread_id") + .type( + BetaManagedAgentsAgentThreadMessageSentEvent.Type.AGENT_THREAD_MESSAGE_SENT + ) + .toAgentName("to_agent_name") + .build() + ) + + val roundtrippedBetaManagedAgentsSessionEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionEvent) + .isEqualTo(betaManagedAgentsSessionEvent) + } + @Test fun ofAgentThreadContextCompacted() { val agentThreadContextCompacted = @@ -744,6 +1033,8 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()) .contains(agentThreadContextCompacted) assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty @@ -751,9 +1042,18 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -815,15 +1115,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).contains(sessionError) assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -884,6 +1195,8 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()) @@ -891,9 +1204,18 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -944,6 +1266,8 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty @@ -951,9 +1275,18 @@ internal class BetaManagedAgentsSessionEventTest { .contains(sessionStatusRunning) assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -1006,15 +1339,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).contains(sessionStatusIdle) assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -1067,6 +1411,8 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty @@ -1074,9 +1420,18 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()) .contains(sessionStatusTerminated) + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -1103,6 +1458,257 @@ internal class BetaManagedAgentsSessionEventTest { .isEqualTo(betaManagedAgentsSessionEvent) } + @Test + fun ofSessionThreadCreated() { + val sessionThreadCreated = + BetaManagedAgentsSessionThreadCreatedEvent.builder() + .id("sevt_011CZkZWXb7pJkx1shYaqoCu") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .type(BetaManagedAgentsSessionThreadCreatedEvent.Type.SESSION_THREAD_CREATED) + .build() + + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSessionThreadCreated(sessionThreadCreated) + + assertThat(betaManagedAgentsSessionEvent.userMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userInterrupt()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThinking()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()) + .contains(sessionThreadCreated) + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSessionThreadCreatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSessionThreadCreated( + BetaManagedAgentsSessionThreadCreatedEvent.builder() + .id("sevt_011CZkZWXb7pJkx1shYaqoCu") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .type(BetaManagedAgentsSessionThreadCreatedEvent.Type.SESSION_THREAD_CREATED) + .build() + ) + + val roundtrippedBetaManagedAgentsSessionEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionEvent) + .isEqualTo(betaManagedAgentsSessionEvent) + } + + @Test + fun ofSpanOutcomeEvaluationStart() { + val spanOutcomeEvaluationStart = + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.builder() + .id("sevt_011CZkZTUy4mGhu8peVXnlzr") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.Type + .SPAN_OUTCOME_EVALUATION_START + ) + .build() + + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationStart(spanOutcomeEvaluationStart) + + assertThat(betaManagedAgentsSessionEvent.userMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userInterrupt()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThinking()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()) + .contains(spanOutcomeEvaluationStart) + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSpanOutcomeEvaluationStartRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationStart( + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.builder() + .id("sevt_011CZkZTUy4mGhu8peVXnlzr") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.Type + .SPAN_OUTCOME_EVALUATION_START + ) + .build() + ) + + val roundtrippedBetaManagedAgentsSessionEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionEvent) + .isEqualTo(betaManagedAgentsSessionEvent) + } + + @Test + fun ofSpanOutcomeEvaluationEnd() { + val spanOutcomeEvaluationEnd = + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.builder() + .id("sevt_011CZkZUVz5nHiv9qfWYomas") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeEvaluationStartId("sevt_011CZkZTUy4mGhu8peVXnlzr") + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .result("satisfied") + .type( + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.Type.SPAN_OUTCOME_EVALUATION_END + ) + .usage( + BetaManagedAgentsSpanModelUsage.builder() + .cacheCreationInputTokens(0) + .cacheReadInputTokens(1536) + .inputTokens(1842) + .outputTokens(213) + .speed(BetaManagedAgentsSpanModelUsage.Speed.STANDARD) + .build() + ) + .build() + + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationEnd(spanOutcomeEvaluationEnd) + + assertThat(betaManagedAgentsSessionEvent.userMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userInterrupt()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThinking()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()) + .contains(spanOutcomeEvaluationEnd) + assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSpanOutcomeEvaluationEndRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationEnd( + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.builder() + .id("sevt_011CZkZUVz5nHiv9qfWYomas") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeEvaluationStartId("sevt_011CZkZTUy4mGhu8peVXnlzr") + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .result("satisfied") + .type( + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.Type + .SPAN_OUTCOME_EVALUATION_END + ) + .usage( + BetaManagedAgentsSpanModelUsage.builder() + .cacheCreationInputTokens(0) + .cacheReadInputTokens(1536) + .inputTokens(1842) + .outputTokens(213) + .speed(BetaManagedAgentsSpanModelUsage.Speed.STANDARD) + .build() + ) + .build() + ) + + val roundtrippedBetaManagedAgentsSessionEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionEvent) + .isEqualTo(betaManagedAgentsSessionEvent) + } + @Test fun ofSpanModelRequestStart() { val spanModelRequestStart = @@ -1126,16 +1732,27 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()) .contains(spanModelRequestStart) assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -1194,16 +1811,27 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()) .contains(spanModelRequestEnd) + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -1240,9 +1868,164 @@ internal class BetaManagedAgentsSessionEventTest { } @Test - fun ofSessionDeleted() { - val sessionDeleted = - BetaManagedAgentsSessionDeletedEvent.builder() + fun ofSpanOutcomeEvaluationOngoing() { + val spanOutcomeEvaluationOngoing = + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.builder() + .id("sevt_011CZkZbCG2uOpc6xmDfvTzh") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.Type + .SPAN_OUTCOME_EVALUATION_ONGOING + ) + .build() + + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing + ) + + assertThat(betaManagedAgentsSessionEvent.userMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userInterrupt()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThinking()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()) + .contains(spanOutcomeEvaluationOngoing) + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSpanOutcomeEvaluationOngoingRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSpanOutcomeEvaluationOngoing( + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.builder() + .id("sevt_011CZkZbCG2uOpc6xmDfvTzh") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.Type + .SPAN_OUTCOME_EVALUATION_ONGOING + ) + .build() + ) + + val roundtrippedBetaManagedAgentsSessionEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionEvent) + .isEqualTo(betaManagedAgentsSessionEvent) + } + + @Test + fun ofUserDefineOutcome() { + val userDefineOutcome = + BetaManagedAgentsUserDefineOutcomeEvent.builder() + .id("sevt_011CZkZSTx3lFgt7odUWmkyq") + .description("Produce a 2-page summary as summary.md") + .maxIterations(3) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .textRubric("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsUserDefineOutcomeEvent.Type.USER_DEFINE_OUTCOME) + .build() + + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofUserDefineOutcome(userDefineOutcome) + + assertThat(betaManagedAgentsSessionEvent.userMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userInterrupt()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThinking()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).contains(userDefineOutcome) + assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofUserDefineOutcomeRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofUserDefineOutcome( + BetaManagedAgentsUserDefineOutcomeEvent.builder() + .id("sevt_011CZkZSTx3lFgt7odUWmkyq") + .description("Produce a 2-page summary as summary.md") + .maxIterations(3) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .textRubric("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsUserDefineOutcomeEvent.Type.USER_DEFINE_OUTCOME) + .build() + ) + + val roundtrippedBetaManagedAgentsSessionEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionEvent) + .isEqualTo(betaManagedAgentsSessionEvent) + } + + @Test + fun ofSessionDeleted() { + val sessionDeleted = + BetaManagedAgentsSessionDeletedEvent.builder() .id("id") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .type(BetaManagedAgentsSessionDeletedEvent.Type.SESSION_DELETED) @@ -1262,15 +2045,26 @@ internal class BetaManagedAgentsSessionEventTest { assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).contains(sessionDeleted) + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -1295,6 +2089,329 @@ internal class BetaManagedAgentsSessionEventTest { .isEqualTo(betaManagedAgentsSessionEvent) } + @Test + fun ofSessionThreadStatusRunning() { + val sessionThreadStatusRunning = + BetaManagedAgentsSessionThreadStatusRunningEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRunningEvent.Type + .SESSION_THREAD_STATUS_RUNNING + ) + .build() + + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSessionThreadStatusRunning(sessionThreadStatusRunning) + + assertThat(betaManagedAgentsSessionEvent.userMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userInterrupt()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThinking()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()) + .contains(sessionThreadStatusRunning) + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSessionThreadStatusRunningRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSessionThreadStatusRunning( + BetaManagedAgentsSessionThreadStatusRunningEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRunningEvent.Type + .SESSION_THREAD_STATUS_RUNNING + ) + .build() + ) + + val roundtrippedBetaManagedAgentsSessionEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionEvent) + .isEqualTo(betaManagedAgentsSessionEvent) + } + + @Test + fun ofSessionThreadStatusIdle() { + val sessionThreadStatusIdle = + BetaManagedAgentsSessionThreadStatusIdleEvent.builder() + .id("sevt_011CZkZXYc8qKly2tiZbrpDv") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .stopReason( + BetaManagedAgentsSessionEndTurn.builder() + .type(BetaManagedAgentsSessionEndTurn.Type.END_TURN) + .build() + ) + .type(BetaManagedAgentsSessionThreadStatusIdleEvent.Type.SESSION_THREAD_STATUS_IDLE) + .build() + + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSessionThreadStatusIdle(sessionThreadStatusIdle) + + assertThat(betaManagedAgentsSessionEvent.userMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userInterrupt()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThinking()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()) + .contains(sessionThreadStatusIdle) + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSessionThreadStatusIdleRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSessionThreadStatusIdle( + BetaManagedAgentsSessionThreadStatusIdleEvent.builder() + .id("sevt_011CZkZXYc8qKly2tiZbrpDv") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .stopReason( + BetaManagedAgentsSessionEndTurn.builder() + .type(BetaManagedAgentsSessionEndTurn.Type.END_TURN) + .build() + ) + .type( + BetaManagedAgentsSessionThreadStatusIdleEvent.Type + .SESSION_THREAD_STATUS_IDLE + ) + .build() + ) + + val roundtrippedBetaManagedAgentsSessionEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionEvent) + .isEqualTo(betaManagedAgentsSessionEvent) + } + + @Test + fun ofSessionThreadStatusTerminated() { + val sessionThreadStatusTerminated = + BetaManagedAgentsSessionThreadStatusTerminatedEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusTerminatedEvent.Type + .SESSION_THREAD_STATUS_TERMINATED + ) + .build() + + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSessionThreadStatusTerminated( + sessionThreadStatusTerminated + ) + + assertThat(betaManagedAgentsSessionEvent.userMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userInterrupt()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThinking()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()) + .contains(sessionThreadStatusTerminated) + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSessionThreadStatusTerminatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSessionThreadStatusTerminated( + BetaManagedAgentsSessionThreadStatusTerminatedEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusTerminatedEvent.Type + .SESSION_THREAD_STATUS_TERMINATED + ) + .build() + ) + + val roundtrippedBetaManagedAgentsSessionEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionEvent) + .isEqualTo(betaManagedAgentsSessionEvent) + } + + @Test + fun ofSessionThreadStatusRescheduled() { + val sessionThreadStatusRescheduled = + BetaManagedAgentsSessionThreadStatusRescheduledEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRescheduledEvent.Type + .SESSION_THREAD_STATUS_RESCHEDULED + ) + .build() + + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled + ) + + assertThat(betaManagedAgentsSessionEvent.userMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userInterrupt()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMessage()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThinking()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolUse()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentToolResult()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsSessionEvent.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionError()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsSessionEvent.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsSessionEvent.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsSessionEvent.sessionThreadStatusRescheduled()) + .contains(sessionThreadStatusRescheduled) + } + + @Test + fun ofSessionThreadStatusRescheduledRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionEvent = + BetaManagedAgentsSessionEvent.ofSessionThreadStatusRescheduled( + BetaManagedAgentsSessionThreadStatusRescheduledEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRescheduledEvent.Type + .SESSION_THREAD_STATUS_RESCHEDULED + ) + .build() + ) + + val roundtrippedBetaManagedAgentsSessionEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionEvent) + .isEqualTo(betaManagedAgentsSessionEvent) + } + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { BOOLEAN(JsonValue.from(false)), STRING(JsonValue.from("invalid")), diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadCreatedEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadCreatedEventTest.kt new file mode 100644 index 000000000..11145c368 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadCreatedEventTest.kt @@ -0,0 +1,56 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.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 BetaManagedAgentsSessionThreadCreatedEventTest { + + @Test + fun create() { + val betaManagedAgentsSessionThreadCreatedEvent = + BetaManagedAgentsSessionThreadCreatedEvent.builder() + .id("sevt_011CZkZWXb7pJkx1shYaqoCu") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .type(BetaManagedAgentsSessionThreadCreatedEvent.Type.SESSION_THREAD_CREATED) + .build() + + assertThat(betaManagedAgentsSessionThreadCreatedEvent.id()) + .isEqualTo("sevt_011CZkZWXb7pJkx1shYaqoCu") + assertThat(betaManagedAgentsSessionThreadCreatedEvent.agentName()).isEqualTo("Researcher") + assertThat(betaManagedAgentsSessionThreadCreatedEvent.processedAt()) + .isEqualTo(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + assertThat(betaManagedAgentsSessionThreadCreatedEvent.sessionThreadId()) + .isEqualTo("sthr_011CZkZVWa6oIjw0rgXZpnBt") + assertThat(betaManagedAgentsSessionThreadCreatedEvent.type()) + .isEqualTo(BetaManagedAgentsSessionThreadCreatedEvent.Type.SESSION_THREAD_CREATED) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionThreadCreatedEvent = + BetaManagedAgentsSessionThreadCreatedEvent.builder() + .id("sevt_011CZkZWXb7pJkx1shYaqoCu") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .type(BetaManagedAgentsSessionThreadCreatedEvent.Type.SESSION_THREAD_CREATED) + .build() + + val roundtrippedBetaManagedAgentsSessionThreadCreatedEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionThreadCreatedEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionThreadCreatedEvent) + .isEqualTo(betaManagedAgentsSessionThreadCreatedEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusIdleEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusIdleEventTest.kt new file mode 100644 index 000000000..e5223404c --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusIdleEventTest.kt @@ -0,0 +1,77 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.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 BetaManagedAgentsSessionThreadStatusIdleEventTest { + + @Test + fun create() { + val betaManagedAgentsSessionThreadStatusIdleEvent = + BetaManagedAgentsSessionThreadStatusIdleEvent.builder() + .id("sevt_011CZkZXYc8qKly2tiZbrpDv") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .stopReason( + BetaManagedAgentsSessionEndTurn.builder() + .type(BetaManagedAgentsSessionEndTurn.Type.END_TURN) + .build() + ) + .type(BetaManagedAgentsSessionThreadStatusIdleEvent.Type.SESSION_THREAD_STATUS_IDLE) + .build() + + assertThat(betaManagedAgentsSessionThreadStatusIdleEvent.id()) + .isEqualTo("sevt_011CZkZXYc8qKly2tiZbrpDv") + assertThat(betaManagedAgentsSessionThreadStatusIdleEvent.agentName()) + .isEqualTo("Researcher") + assertThat(betaManagedAgentsSessionThreadStatusIdleEvent.processedAt()) + .isEqualTo(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + assertThat(betaManagedAgentsSessionThreadStatusIdleEvent.sessionThreadId()) + .isEqualTo("sthr_011CZkZVWa6oIjw0rgXZpnBt") + assertThat(betaManagedAgentsSessionThreadStatusIdleEvent.stopReason()) + .isEqualTo( + BetaManagedAgentsSessionThreadStatusIdleEvent.StopReason.ofEndTurn( + BetaManagedAgentsSessionEndTurn.builder() + .type(BetaManagedAgentsSessionEndTurn.Type.END_TURN) + .build() + ) + ) + assertThat(betaManagedAgentsSessionThreadStatusIdleEvent.type()) + .isEqualTo( + BetaManagedAgentsSessionThreadStatusIdleEvent.Type.SESSION_THREAD_STATUS_IDLE + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionThreadStatusIdleEvent = + BetaManagedAgentsSessionThreadStatusIdleEvent.builder() + .id("sevt_011CZkZXYc8qKly2tiZbrpDv") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .stopReason( + BetaManagedAgentsSessionEndTurn.builder() + .type(BetaManagedAgentsSessionEndTurn.Type.END_TURN) + .build() + ) + .type(BetaManagedAgentsSessionThreadStatusIdleEvent.Type.SESSION_THREAD_STATUS_IDLE) + .build() + + val roundtrippedBetaManagedAgentsSessionThreadStatusIdleEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionThreadStatusIdleEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionThreadStatusIdleEvent) + .isEqualTo(betaManagedAgentsSessionThreadStatusIdleEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRescheduledEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRescheduledEventTest.kt new file mode 100644 index 000000000..f433c9507 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRescheduledEventTest.kt @@ -0,0 +1,65 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.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 BetaManagedAgentsSessionThreadStatusRescheduledEventTest { + + @Test + fun create() { + val betaManagedAgentsSessionThreadStatusRescheduledEvent = + BetaManagedAgentsSessionThreadStatusRescheduledEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRescheduledEvent.Type + .SESSION_THREAD_STATUS_RESCHEDULED + ) + .build() + + assertThat(betaManagedAgentsSessionThreadStatusRescheduledEvent.id()).isEqualTo("id") + assertThat(betaManagedAgentsSessionThreadStatusRescheduledEvent.agentName()) + .isEqualTo("agent_name") + assertThat(betaManagedAgentsSessionThreadStatusRescheduledEvent.processedAt()) + .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(betaManagedAgentsSessionThreadStatusRescheduledEvent.sessionThreadId()) + .isEqualTo("session_thread_id") + assertThat(betaManagedAgentsSessionThreadStatusRescheduledEvent.type()) + .isEqualTo( + BetaManagedAgentsSessionThreadStatusRescheduledEvent.Type + .SESSION_THREAD_STATUS_RESCHEDULED + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionThreadStatusRescheduledEvent = + BetaManagedAgentsSessionThreadStatusRescheduledEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRescheduledEvent.Type + .SESSION_THREAD_STATUS_RESCHEDULED + ) + .build() + + val roundtrippedBetaManagedAgentsSessionThreadStatusRescheduledEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionThreadStatusRescheduledEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionThreadStatusRescheduledEvent) + .isEqualTo(betaManagedAgentsSessionThreadStatusRescheduledEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRunningEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRunningEventTest.kt new file mode 100644 index 000000000..087ed543f --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusRunningEventTest.kt @@ -0,0 +1,64 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.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 BetaManagedAgentsSessionThreadStatusRunningEventTest { + + @Test + fun create() { + val betaManagedAgentsSessionThreadStatusRunningEvent = + BetaManagedAgentsSessionThreadStatusRunningEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRunningEvent.Type + .SESSION_THREAD_STATUS_RUNNING + ) + .build() + + assertThat(betaManagedAgentsSessionThreadStatusRunningEvent.id()).isEqualTo("id") + assertThat(betaManagedAgentsSessionThreadStatusRunningEvent.agentName()) + .isEqualTo("agent_name") + assertThat(betaManagedAgentsSessionThreadStatusRunningEvent.processedAt()) + .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(betaManagedAgentsSessionThreadStatusRunningEvent.sessionThreadId()) + .isEqualTo("session_thread_id") + assertThat(betaManagedAgentsSessionThreadStatusRunningEvent.type()) + .isEqualTo( + BetaManagedAgentsSessionThreadStatusRunningEvent.Type.SESSION_THREAD_STATUS_RUNNING + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionThreadStatusRunningEvent = + BetaManagedAgentsSessionThreadStatusRunningEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRunningEvent.Type + .SESSION_THREAD_STATUS_RUNNING + ) + .build() + + val roundtrippedBetaManagedAgentsSessionThreadStatusRunningEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionThreadStatusRunningEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionThreadStatusRunningEvent) + .isEqualTo(betaManagedAgentsSessionThreadStatusRunningEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusTerminatedEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusTerminatedEventTest.kt new file mode 100644 index 000000000..c591535ef --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSessionThreadStatusTerminatedEventTest.kt @@ -0,0 +1,65 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.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 BetaManagedAgentsSessionThreadStatusTerminatedEventTest { + + @Test + fun create() { + val betaManagedAgentsSessionThreadStatusTerminatedEvent = + BetaManagedAgentsSessionThreadStatusTerminatedEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusTerminatedEvent.Type + .SESSION_THREAD_STATUS_TERMINATED + ) + .build() + + assertThat(betaManagedAgentsSessionThreadStatusTerminatedEvent.id()).isEqualTo("id") + assertThat(betaManagedAgentsSessionThreadStatusTerminatedEvent.agentName()) + .isEqualTo("agent_name") + assertThat(betaManagedAgentsSessionThreadStatusTerminatedEvent.processedAt()) + .isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(betaManagedAgentsSessionThreadStatusTerminatedEvent.sessionThreadId()) + .isEqualTo("session_thread_id") + assertThat(betaManagedAgentsSessionThreadStatusTerminatedEvent.type()) + .isEqualTo( + BetaManagedAgentsSessionThreadStatusTerminatedEvent.Type + .SESSION_THREAD_STATUS_TERMINATED + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionThreadStatusTerminatedEvent = + BetaManagedAgentsSessionThreadStatusTerminatedEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusTerminatedEvent.Type + .SESSION_THREAD_STATUS_TERMINATED + ) + .build() + + val roundtrippedBetaManagedAgentsSessionThreadStatusTerminatedEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionThreadStatusTerminatedEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionThreadStatusTerminatedEvent) + .isEqualTo(betaManagedAgentsSessionThreadStatusTerminatedEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationEndEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationEndEventTest.kt new file mode 100644 index 000000000..88b9bf929 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationEndEventTest.kt @@ -0,0 +1,101 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.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 BetaManagedAgentsSpanOutcomeEvaluationEndEventTest { + + @Test + fun create() { + val betaManagedAgentsSpanOutcomeEvaluationEndEvent = + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.builder() + .id("sevt_011CZkZUVz5nHiv9qfWYomas") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeEvaluationStartId("sevt_011CZkZTUy4mGhu8peVXnlzr") + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .result("satisfied") + .type( + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.Type.SPAN_OUTCOME_EVALUATION_END + ) + .usage( + BetaManagedAgentsSpanModelUsage.builder() + .cacheCreationInputTokens(0) + .cacheReadInputTokens(1536) + .inputTokens(1842) + .outputTokens(213) + .speed(BetaManagedAgentsSpanModelUsage.Speed.STANDARD) + .build() + ) + .build() + + assertThat(betaManagedAgentsSpanOutcomeEvaluationEndEvent.id()) + .isEqualTo("sevt_011CZkZUVz5nHiv9qfWYomas") + assertThat(betaManagedAgentsSpanOutcomeEvaluationEndEvent.explanation()) + .isEqualTo("All five sections present with inline citations.") + assertThat(betaManagedAgentsSpanOutcomeEvaluationEndEvent.iteration()).isEqualTo(0) + assertThat(betaManagedAgentsSpanOutcomeEvaluationEndEvent.outcomeEvaluationStartId()) + .isEqualTo("sevt_011CZkZTUy4mGhu8peVXnlzr") + assertThat(betaManagedAgentsSpanOutcomeEvaluationEndEvent.outcomeId()) + .isEqualTo("outc_011CZkZRSw2kEfs6ncTVljxP") + assertThat(betaManagedAgentsSpanOutcomeEvaluationEndEvent.processedAt()) + .isEqualTo(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + assertThat(betaManagedAgentsSpanOutcomeEvaluationEndEvent.result()).isEqualTo("satisfied") + assertThat(betaManagedAgentsSpanOutcomeEvaluationEndEvent.type()) + .isEqualTo( + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.Type.SPAN_OUTCOME_EVALUATION_END + ) + assertThat(betaManagedAgentsSpanOutcomeEvaluationEndEvent.usage()) + .isEqualTo( + BetaManagedAgentsSpanModelUsage.builder() + .cacheCreationInputTokens(0) + .cacheReadInputTokens(1536) + .inputTokens(1842) + .outputTokens(213) + .speed(BetaManagedAgentsSpanModelUsage.Speed.STANDARD) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSpanOutcomeEvaluationEndEvent = + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.builder() + .id("sevt_011CZkZUVz5nHiv9qfWYomas") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeEvaluationStartId("sevt_011CZkZTUy4mGhu8peVXnlzr") + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .result("satisfied") + .type( + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.Type.SPAN_OUTCOME_EVALUATION_END + ) + .usage( + BetaManagedAgentsSpanModelUsage.builder() + .cacheCreationInputTokens(0) + .cacheReadInputTokens(1536) + .inputTokens(1842) + .outputTokens(213) + .speed(BetaManagedAgentsSpanModelUsage.Speed.STANDARD) + .build() + ) + .build() + + val roundtrippedBetaManagedAgentsSpanOutcomeEvaluationEndEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSpanOutcomeEvaluationEndEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSpanOutcomeEvaluationEndEvent) + .isEqualTo(betaManagedAgentsSpanOutcomeEvaluationEndEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationOngoingEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationOngoingEventTest.kt new file mode 100644 index 000000000..53a25080f --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationOngoingEventTest.kt @@ -0,0 +1,65 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.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 BetaManagedAgentsSpanOutcomeEvaluationOngoingEventTest { + + @Test + fun create() { + val betaManagedAgentsSpanOutcomeEvaluationOngoingEvent = + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.builder() + .id("sevt_011CZkZbCG2uOpc6xmDfvTzh") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.Type + .SPAN_OUTCOME_EVALUATION_ONGOING + ) + .build() + + assertThat(betaManagedAgentsSpanOutcomeEvaluationOngoingEvent.id()) + .isEqualTo("sevt_011CZkZbCG2uOpc6xmDfvTzh") + assertThat(betaManagedAgentsSpanOutcomeEvaluationOngoingEvent.iteration()).isEqualTo(0) + assertThat(betaManagedAgentsSpanOutcomeEvaluationOngoingEvent.outcomeId()) + .isEqualTo("outc_011CZkZRSw2kEfs6ncTVljxP") + assertThat(betaManagedAgentsSpanOutcomeEvaluationOngoingEvent.processedAt()) + .isEqualTo(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + assertThat(betaManagedAgentsSpanOutcomeEvaluationOngoingEvent.type()) + .isEqualTo( + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.Type + .SPAN_OUTCOME_EVALUATION_ONGOING + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSpanOutcomeEvaluationOngoingEvent = + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.builder() + .id("sevt_011CZkZbCG2uOpc6xmDfvTzh") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.Type + .SPAN_OUTCOME_EVALUATION_ONGOING + ) + .build() + + val roundtrippedBetaManagedAgentsSpanOutcomeEvaluationOngoingEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSpanOutcomeEvaluationOngoingEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSpanOutcomeEvaluationOngoingEvent) + .isEqualTo(betaManagedAgentsSpanOutcomeEvaluationOngoingEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationStartEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationStartEventTest.kt new file mode 100644 index 000000000..22b835e88 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsSpanOutcomeEvaluationStartEventTest.kt @@ -0,0 +1,64 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.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 BetaManagedAgentsSpanOutcomeEvaluationStartEventTest { + + @Test + fun create() { + val betaManagedAgentsSpanOutcomeEvaluationStartEvent = + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.builder() + .id("sevt_011CZkZTUy4mGhu8peVXnlzr") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.Type + .SPAN_OUTCOME_EVALUATION_START + ) + .build() + + assertThat(betaManagedAgentsSpanOutcomeEvaluationStartEvent.id()) + .isEqualTo("sevt_011CZkZTUy4mGhu8peVXnlzr") + assertThat(betaManagedAgentsSpanOutcomeEvaluationStartEvent.iteration()).isEqualTo(0) + assertThat(betaManagedAgentsSpanOutcomeEvaluationStartEvent.outcomeId()) + .isEqualTo("outc_011CZkZRSw2kEfs6ncTVljxP") + assertThat(betaManagedAgentsSpanOutcomeEvaluationStartEvent.processedAt()) + .isEqualTo(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + assertThat(betaManagedAgentsSpanOutcomeEvaluationStartEvent.type()) + .isEqualTo( + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.Type.SPAN_OUTCOME_EVALUATION_START + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSpanOutcomeEvaluationStartEvent = + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.builder() + .id("sevt_011CZkZTUy4mGhu8peVXnlzr") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.Type + .SPAN_OUTCOME_EVALUATION_START + ) + .build() + + val roundtrippedBetaManagedAgentsSpanOutcomeEvaluationStartEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSpanOutcomeEvaluationStartEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSpanOutcomeEvaluationStartEvent) + .isEqualTo(betaManagedAgentsSpanOutcomeEvaluationStartEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsStreamSessionEventsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsStreamSessionEventsTest.kt index 55b60e307..fd039ad28 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsStreamSessionEventsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsStreamSessionEventsTest.kt @@ -39,15 +39,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -80,6 +91,7 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .id("id") .type(BetaManagedAgentsUserInterruptEvent.Type.USER_INTERRUPT) .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsStreamSessionEvents = @@ -96,15 +108,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -116,6 +139,7 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .id("id") .type(BetaManagedAgentsUserInterruptEvent.Type.USER_INTERRUPT) .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() ) @@ -139,6 +163,7 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .type(BetaManagedAgentsUserToolConfirmationEvent.Type.USER_TOOL_CONFIRMATION) .denyMessage("deny_message") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsStreamSessionEvents = @@ -156,15 +181,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -179,6 +215,7 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .type(BetaManagedAgentsUserToolConfirmationEvent.Type.USER_TOOL_CONFIRMATION) .denyMessage("deny_message") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() ) @@ -202,6 +239,7 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .addTextContent("Where is my order #1234?") .isError(true) .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsStreamSessionEvents = @@ -219,15 +257,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -242,6 +291,7 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .addTextContent("Where is my order #1234?") .isError(true) .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() ) @@ -268,6 +318,7 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .name("name") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .type(BetaManagedAgentsAgentCustomToolUseEvent.Type.AGENT_CUSTOM_TOOL_USE) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsStreamSessionEvents = @@ -285,15 +336,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -311,6 +373,7 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .name("name") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .type(BetaManagedAgentsAgentCustomToolUseEvent.Type.AGENT_CUSTOM_TOOL_USE) + .sessionThreadId("session_thread_id") .build() ) @@ -353,15 +416,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -415,15 +489,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -465,6 +550,7 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .evaluatedPermission( BetaManagedAgentsAgentMcpToolUseEvent.EvaluatedPermission.ALLOW ) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsStreamSessionEvents = @@ -481,15 +567,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -511,6 +608,7 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .evaluatedPermission( BetaManagedAgentsAgentMcpToolUseEvent.EvaluatedPermission.ALLOW ) + .sessionThreadId("session_thread_id") .build() ) @@ -551,15 +649,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .contains(agentMcpToolResult) assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -601,6 +710,7 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .type(BetaManagedAgentsAgentToolUseEvent.Type.AGENT_TOOL_USE) .evaluatedPermission(BetaManagedAgentsAgentToolUseEvent.EvaluatedPermission.ALLOW) + .sessionThreadId("session_thread_id") .build() val betaManagedAgentsStreamSessionEvents = @@ -617,15 +727,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).contains(agentToolUse) assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -646,6 +767,7 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .evaluatedPermission( BetaManagedAgentsAgentToolUseEvent.EvaluatedPermission.ALLOW ) + .sessionThreadId("session_thread_id") .build() ) @@ -685,15 +807,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).contains(agentToolResult) + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -721,6 +854,164 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .isEqualTo(betaManagedAgentsStreamSessionEvents) } + @Test + fun ofAgentThreadMessageReceived() { + val agentThreadMessageReceived = + BetaManagedAgentsAgentThreadMessageReceivedEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .fromSessionThreadId("from_session_thread_id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsAgentThreadMessageReceivedEvent.Type + .AGENT_THREAD_MESSAGE_RECEIVED + ) + .fromAgentName("from_agent_name") + .build() + + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofAgentThreadMessageReceived( + agentThreadMessageReceived + ) + + assertThat(betaManagedAgentsStreamSessionEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()) + .contains(agentThreadMessageReceived) + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofAgentThreadMessageReceivedRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofAgentThreadMessageReceived( + BetaManagedAgentsAgentThreadMessageReceivedEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .fromSessionThreadId("from_session_thread_id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsAgentThreadMessageReceivedEvent.Type + .AGENT_THREAD_MESSAGE_RECEIVED + ) + .fromAgentName("from_agent_name") + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionEvents) + .isEqualTo(betaManagedAgentsStreamSessionEvents) + } + + @Test + fun ofAgentThreadMessageSent() { + val agentThreadMessageSent = + BetaManagedAgentsAgentThreadMessageSentEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .toSessionThreadId("to_session_thread_id") + .type(BetaManagedAgentsAgentThreadMessageSentEvent.Type.AGENT_THREAD_MESSAGE_SENT) + .toAgentName("to_agent_name") + .build() + + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofAgentThreadMessageSent(agentThreadMessageSent) + + assertThat(betaManagedAgentsStreamSessionEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()) + .contains(agentThreadMessageSent) + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofAgentThreadMessageSentRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofAgentThreadMessageSent( + BetaManagedAgentsAgentThreadMessageSentEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .toSessionThreadId("to_session_thread_id") + .type( + BetaManagedAgentsAgentThreadMessageSentEvent.Type.AGENT_THREAD_MESSAGE_SENT + ) + .toAgentName("to_agent_name") + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionEvents) + .isEqualTo(betaManagedAgentsStreamSessionEvents) + } + @Test fun ofAgentThreadContextCompacted() { val agentThreadContextCompacted = @@ -749,6 +1040,8 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()) .contains(agentThreadContextCompacted) assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty @@ -756,9 +1049,18 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -820,15 +1122,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).contains(sessionError) assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -891,6 +1204,8 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()) @@ -898,9 +1213,18 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -951,6 +1275,8 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty @@ -958,9 +1284,18 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .contains(sessionStatusRunning) assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -1013,6 +1348,8 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty @@ -1020,9 +1357,18 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()) .contains(sessionStatusIdle) assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -1075,6 +1421,8 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty @@ -1082,9 +1430,18 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()) .contains(sessionStatusTerminated) + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -1111,6 +1468,261 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .isEqualTo(betaManagedAgentsStreamSessionEvents) } + @Test + fun ofSessionThreadCreated() { + val sessionThreadCreated = + BetaManagedAgentsSessionThreadCreatedEvent.builder() + .id("sevt_011CZkZWXb7pJkx1shYaqoCu") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .type(BetaManagedAgentsSessionThreadCreatedEvent.Type.SESSION_THREAD_CREATED) + .build() + + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSessionThreadCreated(sessionThreadCreated) + + assertThat(betaManagedAgentsStreamSessionEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()) + .contains(sessionThreadCreated) + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSessionThreadCreatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSessionThreadCreated( + BetaManagedAgentsSessionThreadCreatedEvent.builder() + .id("sevt_011CZkZWXb7pJkx1shYaqoCu") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .type(BetaManagedAgentsSessionThreadCreatedEvent.Type.SESSION_THREAD_CREATED) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionEvents) + .isEqualTo(betaManagedAgentsStreamSessionEvents) + } + + @Test + fun ofSpanOutcomeEvaluationStart() { + val spanOutcomeEvaluationStart = + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.builder() + .id("sevt_011CZkZTUy4mGhu8peVXnlzr") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.Type + .SPAN_OUTCOME_EVALUATION_START + ) + .build() + + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart + ) + + assertThat(betaManagedAgentsStreamSessionEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()) + .contains(spanOutcomeEvaluationStart) + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSpanOutcomeEvaluationStartRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSpanOutcomeEvaluationStart( + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.builder() + .id("sevt_011CZkZTUy4mGhu8peVXnlzr") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.Type + .SPAN_OUTCOME_EVALUATION_START + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionEvents) + .isEqualTo(betaManagedAgentsStreamSessionEvents) + } + + @Test + fun ofSpanOutcomeEvaluationEnd() { + val spanOutcomeEvaluationEnd = + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.builder() + .id("sevt_011CZkZUVz5nHiv9qfWYomas") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeEvaluationStartId("sevt_011CZkZTUy4mGhu8peVXnlzr") + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .result("satisfied") + .type( + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.Type.SPAN_OUTCOME_EVALUATION_END + ) + .usage( + BetaManagedAgentsSpanModelUsage.builder() + .cacheCreationInputTokens(0) + .cacheReadInputTokens(1536) + .inputTokens(1842) + .outputTokens(213) + .speed(BetaManagedAgentsSpanModelUsage.Speed.STANDARD) + .build() + ) + .build() + + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd + ) + + assertThat(betaManagedAgentsStreamSessionEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()) + .contains(spanOutcomeEvaluationEnd) + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSpanOutcomeEvaluationEndRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSpanOutcomeEvaluationEnd( + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.builder() + .id("sevt_011CZkZUVz5nHiv9qfWYomas") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeEvaluationStartId("sevt_011CZkZTUy4mGhu8peVXnlzr") + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .result("satisfied") + .type( + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.Type + .SPAN_OUTCOME_EVALUATION_END + ) + .usage( + BetaManagedAgentsSpanModelUsage.builder() + .cacheCreationInputTokens(0) + .cacheReadInputTokens(1536) + .inputTokens(1842) + .outputTokens(213) + .speed(BetaManagedAgentsSpanModelUsage.Speed.STANDARD) + .build() + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionEvents) + .isEqualTo(betaManagedAgentsStreamSessionEvents) + } + @Test fun ofSpanModelRequestStart() { val spanModelRequestStart = @@ -1134,16 +1746,27 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()) .contains(spanModelRequestStart) assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -1202,16 +1825,27 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()) .contains(spanModelRequestEnd) + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -1247,6 +1881,162 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .isEqualTo(betaManagedAgentsStreamSessionEvents) } + @Test + fun ofSpanOutcomeEvaluationOngoing() { + val spanOutcomeEvaluationOngoing = + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.builder() + .id("sevt_011CZkZbCG2uOpc6xmDfvTzh") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.Type + .SPAN_OUTCOME_EVALUATION_ONGOING + ) + .build() + + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing + ) + + assertThat(betaManagedAgentsStreamSessionEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()) + .contains(spanOutcomeEvaluationOngoing) + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSpanOutcomeEvaluationOngoingRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSpanOutcomeEvaluationOngoing( + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.builder() + .id("sevt_011CZkZbCG2uOpc6xmDfvTzh") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.Type + .SPAN_OUTCOME_EVALUATION_ONGOING + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionEvents) + .isEqualTo(betaManagedAgentsStreamSessionEvents) + } + + @Test + fun ofUserDefineOutcome() { + val userDefineOutcome = + BetaManagedAgentsUserDefineOutcomeEvent.builder() + .id("sevt_011CZkZSTx3lFgt7odUWmkyq") + .description("Produce a 2-page summary as summary.md") + .maxIterations(3) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .textRubric("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsUserDefineOutcomeEvent.Type.USER_DEFINE_OUTCOME) + .build() + + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofUserDefineOutcome(userDefineOutcome) + + assertThat(betaManagedAgentsStreamSessionEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()) + .contains(userDefineOutcome) + assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofUserDefineOutcomeRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofUserDefineOutcome( + BetaManagedAgentsUserDefineOutcomeEvent.builder() + .id("sevt_011CZkZSTx3lFgt7odUWmkyq") + .description("Produce a 2-page summary as summary.md") + .maxIterations(3) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .textRubric("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsUserDefineOutcomeEvent.Type.USER_DEFINE_OUTCOME) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionEvents) + .isEqualTo(betaManagedAgentsStreamSessionEvents) + } + @Test fun ofSessionDeleted() { val sessionDeleted = @@ -1270,15 +2060,26 @@ internal class BetaManagedAgentsStreamSessionEventsTest { assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).contains(sessionDeleted) + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty } @Test @@ -1303,6 +2104,331 @@ internal class BetaManagedAgentsStreamSessionEventsTest { .isEqualTo(betaManagedAgentsStreamSessionEvents) } + @Test + fun ofSessionThreadStatusRunning() { + val sessionThreadStatusRunning = + BetaManagedAgentsSessionThreadStatusRunningEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRunningEvent.Type + .SESSION_THREAD_STATUS_RUNNING + ) + .build() + + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSessionThreadStatusRunning( + sessionThreadStatusRunning + ) + + assertThat(betaManagedAgentsStreamSessionEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()) + .contains(sessionThreadStatusRunning) + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSessionThreadStatusRunningRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSessionThreadStatusRunning( + BetaManagedAgentsSessionThreadStatusRunningEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRunningEvent.Type + .SESSION_THREAD_STATUS_RUNNING + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionEvents) + .isEqualTo(betaManagedAgentsStreamSessionEvents) + } + + @Test + fun ofSessionThreadStatusIdle() { + val sessionThreadStatusIdle = + BetaManagedAgentsSessionThreadStatusIdleEvent.builder() + .id("sevt_011CZkZXYc8qKly2tiZbrpDv") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .stopReason( + BetaManagedAgentsSessionEndTurn.builder() + .type(BetaManagedAgentsSessionEndTurn.Type.END_TURN) + .build() + ) + .type(BetaManagedAgentsSessionThreadStatusIdleEvent.Type.SESSION_THREAD_STATUS_IDLE) + .build() + + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSessionThreadStatusIdle(sessionThreadStatusIdle) + + assertThat(betaManagedAgentsStreamSessionEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()) + .contains(sessionThreadStatusIdle) + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSessionThreadStatusIdleRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSessionThreadStatusIdle( + BetaManagedAgentsSessionThreadStatusIdleEvent.builder() + .id("sevt_011CZkZXYc8qKly2tiZbrpDv") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .stopReason( + BetaManagedAgentsSessionEndTurn.builder() + .type(BetaManagedAgentsSessionEndTurn.Type.END_TURN) + .build() + ) + .type( + BetaManagedAgentsSessionThreadStatusIdleEvent.Type + .SESSION_THREAD_STATUS_IDLE + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionEvents) + .isEqualTo(betaManagedAgentsStreamSessionEvents) + } + + @Test + fun ofSessionThreadStatusTerminated() { + val sessionThreadStatusTerminated = + BetaManagedAgentsSessionThreadStatusTerminatedEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusTerminatedEvent.Type + .SESSION_THREAD_STATUS_TERMINATED + ) + .build() + + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSessionThreadStatusTerminated( + sessionThreadStatusTerminated + ) + + assertThat(betaManagedAgentsStreamSessionEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()) + .contains(sessionThreadStatusTerminated) + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()).isEmpty + } + + @Test + fun ofSessionThreadStatusTerminatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSessionThreadStatusTerminated( + BetaManagedAgentsSessionThreadStatusTerminatedEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusTerminatedEvent.Type + .SESSION_THREAD_STATUS_TERMINATED + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionEvents) + .isEqualTo(betaManagedAgentsStreamSessionEvents) + } + + @Test + fun ofSessionThreadStatusRescheduled() { + val sessionThreadStatusRescheduled = + BetaManagedAgentsSessionThreadStatusRescheduledEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRescheduledEvent.Type + .SESSION_THREAD_STATUS_RESCHEDULED + ) + .build() + + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled + ) + + assertThat(betaManagedAgentsStreamSessionEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.spanOutcomeEvaluationOngoing()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionEvents.sessionThreadStatusRescheduled()) + .contains(sessionThreadStatusRescheduled) + } + + @Test + fun ofSessionThreadStatusRescheduledRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionEvents = + BetaManagedAgentsStreamSessionEvents.ofSessionThreadStatusRescheduled( + BetaManagedAgentsSessionThreadStatusRescheduledEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRescheduledEvent.Type + .SESSION_THREAD_STATUS_RESCHEDULED + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionEvents) + .isEqualTo(betaManagedAgentsStreamSessionEvents) + } + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { BOOLEAN(JsonValue.from(false)), STRING(JsonValue.from("invalid")), diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubricParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubricParamsTest.kt new file mode 100644 index 000000000..efab41c2d --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubricParamsTest.kt @@ -0,0 +1,44 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsTextRubricParamsTest { + + @Test + fun create() { + val betaManagedAgentsTextRubricParams = + BetaManagedAgentsTextRubricParams.builder() + .content("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsTextRubricParams.Type.TEXT) + .build() + + assertThat(betaManagedAgentsTextRubricParams.content()) + .isEqualTo("Must cover all five sections; cite sources inline.") + assertThat(betaManagedAgentsTextRubricParams.type()) + .isEqualTo(BetaManagedAgentsTextRubricParams.Type.TEXT) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsTextRubricParams = + BetaManagedAgentsTextRubricParams.builder() + .content("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsTextRubricParams.Type.TEXT) + .build() + + val roundtrippedBetaManagedAgentsTextRubricParams = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsTextRubricParams), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsTextRubricParams) + .isEqualTo(betaManagedAgentsTextRubricParams) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubricTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubricTest.kt new file mode 100644 index 000000000..f821c0965 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsTextRubricTest.kt @@ -0,0 +1,42 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsTextRubricTest { + + @Test + fun create() { + val betaManagedAgentsTextRubric = + BetaManagedAgentsTextRubric.builder() + .content("content") + .type(BetaManagedAgentsTextRubric.Type.TEXT) + .build() + + assertThat(betaManagedAgentsTextRubric.content()).isEqualTo("content") + assertThat(betaManagedAgentsTextRubric.type()) + .isEqualTo(BetaManagedAgentsTextRubric.Type.TEXT) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsTextRubric = + BetaManagedAgentsTextRubric.builder() + .content("content") + .type(BetaManagedAgentsTextRubric.Type.TEXT) + .build() + + val roundtrippedBetaManagedAgentsTextRubric = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsTextRubric), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsTextRubric).isEqualTo(betaManagedAgentsTextRubric) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserCustomToolResultEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserCustomToolResultEventTest.kt index 207fd4224..79d7c287d 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserCustomToolResultEventTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserCustomToolResultEventTest.kt @@ -21,6 +21,7 @@ internal class BetaManagedAgentsUserCustomToolResultEventTest { .addTextContent("Where is my order #1234?") .isError(true) .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() assertThat(betaManagedAgentsUserCustomToolResultEvent.id()).isEqualTo("id") @@ -40,6 +41,8 @@ internal class BetaManagedAgentsUserCustomToolResultEventTest { assertThat(betaManagedAgentsUserCustomToolResultEvent.isError()).contains(true) assertThat(betaManagedAgentsUserCustomToolResultEvent.processedAt()) .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(betaManagedAgentsUserCustomToolResultEvent.sessionThreadId()) + .contains("session_thread_id") } @Test @@ -53,6 +56,7 @@ internal class BetaManagedAgentsUserCustomToolResultEventTest { .addTextContent("Where is my order #1234?") .isError(true) .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() val roundtrippedBetaManagedAgentsUserCustomToolResultEvent = diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEventParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEventParamsTest.kt new file mode 100644 index 000000000..b32c96eed --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEventParamsTest.kt @@ -0,0 +1,58 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsUserDefineOutcomeEventParamsTest { + + @Test + fun create() { + val betaManagedAgentsUserDefineOutcomeEventParams = + BetaManagedAgentsUserDefineOutcomeEventParams.builder() + .description("Produce a 2-page summary as summary.md") + .textRubric("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsUserDefineOutcomeEventParams.Type.USER_DEFINE_OUTCOME) + .maxIterations(3) + .build() + + assertThat(betaManagedAgentsUserDefineOutcomeEventParams.description()) + .isEqualTo("Produce a 2-page summary as summary.md") + assertThat(betaManagedAgentsUserDefineOutcomeEventParams.rubric()) + .isEqualTo( + BetaManagedAgentsUserDefineOutcomeEventParams.Rubric.ofText( + BetaManagedAgentsTextRubricParams.builder() + .content("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsTextRubricParams.Type.TEXT) + .build() + ) + ) + assertThat(betaManagedAgentsUserDefineOutcomeEventParams.type()) + .isEqualTo(BetaManagedAgentsUserDefineOutcomeEventParams.Type.USER_DEFINE_OUTCOME) + assertThat(betaManagedAgentsUserDefineOutcomeEventParams.maxIterations()).contains(3) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsUserDefineOutcomeEventParams = + BetaManagedAgentsUserDefineOutcomeEventParams.builder() + .description("Produce a 2-page summary as summary.md") + .textRubric("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsUserDefineOutcomeEventParams.Type.USER_DEFINE_OUTCOME) + .maxIterations(3) + .build() + + val roundtrippedBetaManagedAgentsUserDefineOutcomeEventParams = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsUserDefineOutcomeEventParams), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsUserDefineOutcomeEventParams) + .isEqualTo(betaManagedAgentsUserDefineOutcomeEventParams) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEventTest.kt new file mode 100644 index 000000000..7fed69928 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserDefineOutcomeEventTest.kt @@ -0,0 +1,71 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.events + +import com.anthropic.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 BetaManagedAgentsUserDefineOutcomeEventTest { + + @Test + fun create() { + val betaManagedAgentsUserDefineOutcomeEvent = + BetaManagedAgentsUserDefineOutcomeEvent.builder() + .id("sevt_011CZkZSTx3lFgt7odUWmkyq") + .description("Produce a 2-page summary as summary.md") + .maxIterations(3) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .textRubric("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsUserDefineOutcomeEvent.Type.USER_DEFINE_OUTCOME) + .build() + + assertThat(betaManagedAgentsUserDefineOutcomeEvent.id()) + .isEqualTo("sevt_011CZkZSTx3lFgt7odUWmkyq") + assertThat(betaManagedAgentsUserDefineOutcomeEvent.description()) + .isEqualTo("Produce a 2-page summary as summary.md") + assertThat(betaManagedAgentsUserDefineOutcomeEvent.maxIterations()).contains(3) + assertThat(betaManagedAgentsUserDefineOutcomeEvent.outcomeId()) + .isEqualTo("outc_011CZkZRSw2kEfs6ncTVljxP") + assertThat(betaManagedAgentsUserDefineOutcomeEvent.processedAt()) + .isEqualTo(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + assertThat(betaManagedAgentsUserDefineOutcomeEvent.rubric()) + .isEqualTo( + BetaManagedAgentsUserDefineOutcomeEvent.Rubric.ofText( + BetaManagedAgentsTextRubric.builder() + .content("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsTextRubric.Type.TEXT) + .build() + ) + ) + assertThat(betaManagedAgentsUserDefineOutcomeEvent.type()) + .isEqualTo(BetaManagedAgentsUserDefineOutcomeEvent.Type.USER_DEFINE_OUTCOME) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsUserDefineOutcomeEvent = + BetaManagedAgentsUserDefineOutcomeEvent.builder() + .id("sevt_011CZkZSTx3lFgt7odUWmkyq") + .description("Produce a 2-page summary as summary.md") + .maxIterations(3) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .textRubric("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsUserDefineOutcomeEvent.Type.USER_DEFINE_OUTCOME) + .build() + + val roundtrippedBetaManagedAgentsUserDefineOutcomeEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsUserDefineOutcomeEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsUserDefineOutcomeEvent) + .isEqualTo(betaManagedAgentsUserDefineOutcomeEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEventParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEventParamsTest.kt index c4fe43ab5..93f0f53b1 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEventParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEventParamsTest.kt @@ -14,10 +14,13 @@ internal class BetaManagedAgentsUserInterruptEventParamsTest { val betaManagedAgentsUserInterruptEventParams = BetaManagedAgentsUserInterruptEventParams.builder() .type(BetaManagedAgentsUserInterruptEventParams.Type.USER_INTERRUPT) + .sessionThreadId("session_thread_id") .build() assertThat(betaManagedAgentsUserInterruptEventParams.type()) .isEqualTo(BetaManagedAgentsUserInterruptEventParams.Type.USER_INTERRUPT) + assertThat(betaManagedAgentsUserInterruptEventParams.sessionThreadId()) + .contains("session_thread_id") } @Test @@ -26,6 +29,7 @@ internal class BetaManagedAgentsUserInterruptEventParamsTest { val betaManagedAgentsUserInterruptEventParams = BetaManagedAgentsUserInterruptEventParams.builder() .type(BetaManagedAgentsUserInterruptEventParams.Type.USER_INTERRUPT) + .sessionThreadId("session_thread_id") .build() val roundtrippedBetaManagedAgentsUserInterruptEventParams = diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEventTest.kt index fb1aa8913..8e187db7e 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEventTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserInterruptEventTest.kt @@ -17,6 +17,7 @@ internal class BetaManagedAgentsUserInterruptEventTest { .id("id") .type(BetaManagedAgentsUserInterruptEvent.Type.USER_INTERRUPT) .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() assertThat(betaManagedAgentsUserInterruptEvent.id()).isEqualTo("id") @@ -24,6 +25,8 @@ internal class BetaManagedAgentsUserInterruptEventTest { .isEqualTo(BetaManagedAgentsUserInterruptEvent.Type.USER_INTERRUPT) assertThat(betaManagedAgentsUserInterruptEvent.processedAt()) .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(betaManagedAgentsUserInterruptEvent.sessionThreadId()) + .contains("session_thread_id") } @Test @@ -34,6 +37,7 @@ internal class BetaManagedAgentsUserInterruptEventTest { .id("id") .type(BetaManagedAgentsUserInterruptEvent.Type.USER_INTERRUPT) .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() val roundtrippedBetaManagedAgentsUserInterruptEvent = diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserToolConfirmationEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserToolConfirmationEventTest.kt index 9a5273e44..aaeb56104 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserToolConfirmationEventTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/BetaManagedAgentsUserToolConfirmationEventTest.kt @@ -20,6 +20,7 @@ internal class BetaManagedAgentsUserToolConfirmationEventTest { .type(BetaManagedAgentsUserToolConfirmationEvent.Type.USER_TOOL_CONFIRMATION) .denyMessage("deny_message") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() assertThat(betaManagedAgentsUserToolConfirmationEvent.id()).isEqualTo("id") @@ -32,6 +33,8 @@ internal class BetaManagedAgentsUserToolConfirmationEventTest { .contains("deny_message") assertThat(betaManagedAgentsUserToolConfirmationEvent.processedAt()) .contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(betaManagedAgentsUserToolConfirmationEvent.sessionThreadId()) + .contains("session_thread_id") } @Test @@ -45,6 +48,7 @@ internal class BetaManagedAgentsUserToolConfirmationEventTest { .type(BetaManagedAgentsUserToolConfirmationEvent.Type.USER_TOOL_CONFIRMATION) .denyMessage("deny_message") .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") .build() val roundtrippedBetaManagedAgentsUserToolConfirmationEvent = diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/EventListParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/EventListParamsTest.kt index 1170e4e3e..a62373786 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/EventListParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/events/EventListParamsTest.kt @@ -5,6 +5,7 @@ package com.anthropic.models.beta.sessions.events import com.anthropic.core.http.Headers import com.anthropic.core.http.QueryParams import com.anthropic.models.beta.AnthropicBeta +import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -14,9 +15,14 @@ internal class EventListParamsTest { fun create() { EventListParams.builder() .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .createdAtGt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAtGte(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAtLt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAtLte(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .limit(0) .order(EventListParams.Order.ASC) .page("page") + .addType("string") .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) .build() } @@ -35,9 +41,14 @@ internal class EventListParamsTest { val params = EventListParams.builder() .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .createdAtGt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAtGte(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAtLt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAtLte(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .limit(0) .order(EventListParams.Order.ASC) .page("page") + .addType("string") .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) .build() @@ -63,9 +74,14 @@ internal class EventListParamsTest { val params = EventListParams.builder() .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .createdAtGt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAtGte(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAtLt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAtLte(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .limit(0) .order(EventListParams.Order.ASC) .page("page") + .addType("string") .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) .build() @@ -74,9 +90,14 @@ internal class EventListParamsTest { assertThat(queryParams) .isEqualTo( QueryParams.builder() + .put("created_at[gt]", "2019-12-27T18:11:19.117Z") + .put("created_at[gte]", "2019-12-27T18:11:19.117Z") + .put("created_at[lt]", "2019-12-27T18:11:19.117Z") + .put("created_at[lte]", "2019-12-27T18:11:19.117Z") .put("limit", "0") .put("order", "asc") .put("page", "page") + .put("types[]", "string") .build() ) } diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadAgentTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadAgentTest.kt new file mode 100644 index 000000000..1da3a36cd --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadAgentTest.kt @@ -0,0 +1,219 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.jsonMapper +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolConfig +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolset20260401 +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolsetDefaultConfig +import com.anthropic.models.beta.agents.BetaManagedAgentsAlwaysAllowPolicy +import com.anthropic.models.beta.agents.BetaManagedAgentsAlwaysAskPolicy +import com.anthropic.models.beta.agents.BetaManagedAgentsAnthropicSkill +import com.anthropic.models.beta.agents.BetaManagedAgentsMcpServerUrlDefinition +import com.anthropic.models.beta.agents.BetaManagedAgentsModel +import com.anthropic.models.beta.agents.BetaManagedAgentsModelConfig +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsSessionThreadAgentTest { + + @Test + fun create() { + val betaManagedAgentsSessionThreadAgent = + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type(BetaManagedAgentsAlwaysAllowPolicy.Type.ALWAYS_ALLOW) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type(BetaManagedAgentsAlwaysAskPolicy.Type.ALWAYS_ASK) + .build() + ) + .build() + ) + .type(BetaManagedAgentsAgentToolset20260401.Type.AGENT_TOOLSET_20260401) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + + assertThat(betaManagedAgentsSessionThreadAgent.id()) + .isEqualTo("agent_011CZkYqphY8vELVzwCUpqiQ") + assertThat(betaManagedAgentsSessionThreadAgent.description()) + .contains("A focused research subagent.") + assertThat(betaManagedAgentsSessionThreadAgent.mcpServers()) + .containsExactly( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + assertThat(betaManagedAgentsSessionThreadAgent.model()) + .isEqualTo( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + assertThat(betaManagedAgentsSessionThreadAgent.name()).isEqualTo("Researcher") + assertThat(betaManagedAgentsSessionThreadAgent.skills()) + .containsExactly( + BetaManagedAgentsSessionThreadAgent.Skill.ofAnthropic( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + ) + assertThat(betaManagedAgentsSessionThreadAgent.system()) + .contains( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + assertThat(betaManagedAgentsSessionThreadAgent.tools()) + .containsExactly( + BetaManagedAgentsSessionThreadAgent.Tool.ofAgentToolset20260401( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type(BetaManagedAgentsAlwaysAllowPolicy.Type.ALWAYS_ALLOW) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type(BetaManagedAgentsAlwaysAskPolicy.Type.ALWAYS_ASK) + .build() + ) + .build() + ) + .type(BetaManagedAgentsAgentToolset20260401.Type.AGENT_TOOLSET_20260401) + .build() + ) + ) + assertThat(betaManagedAgentsSessionThreadAgent.type()) + .isEqualTo(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + assertThat(betaManagedAgentsSessionThreadAgent.version()).isEqualTo(1) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionThreadAgent = + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type(BetaManagedAgentsAlwaysAllowPolicy.Type.ALWAYS_ALLOW) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type(BetaManagedAgentsAlwaysAskPolicy.Type.ALWAYS_ASK) + .build() + ) + .build() + ) + .type(BetaManagedAgentsAgentToolset20260401.Type.AGENT_TOOLSET_20260401) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + + val roundtrippedBetaManagedAgentsSessionThreadAgent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionThreadAgent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionThreadAgent) + .isEqualTo(betaManagedAgentsSessionThreadAgent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadStatsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadStatsTest.kt new file mode 100644 index 000000000..2c8695cc7 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadStatsTest.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsSessionThreadStatsTest { + + @Test + fun create() { + val betaManagedAgentsSessionThreadStats = + BetaManagedAgentsSessionThreadStats.builder() + .activeSeconds(0.0) + .durationSeconds(0.0) + .startupSeconds(0.0) + .build() + + assertThat(betaManagedAgentsSessionThreadStats.activeSeconds()).contains(0.0) + assertThat(betaManagedAgentsSessionThreadStats.durationSeconds()).contains(0.0) + assertThat(betaManagedAgentsSessionThreadStats.startupSeconds()).contains(0.0) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionThreadStats = + BetaManagedAgentsSessionThreadStats.builder() + .activeSeconds(0.0) + .durationSeconds(0.0) + .startupSeconds(0.0) + .build() + + val roundtrippedBetaManagedAgentsSessionThreadStats = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionThreadStats), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionThreadStats) + .isEqualTo(betaManagedAgentsSessionThreadStats) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadTest.kt new file mode 100644 index 000000000..9d3b3f090 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadTest.kt @@ -0,0 +1,331 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.jsonMapper +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolConfig +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolset20260401 +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolsetDefaultConfig +import com.anthropic.models.beta.agents.BetaManagedAgentsAlwaysAllowPolicy +import com.anthropic.models.beta.agents.BetaManagedAgentsAlwaysAskPolicy +import com.anthropic.models.beta.agents.BetaManagedAgentsAnthropicSkill +import com.anthropic.models.beta.agents.BetaManagedAgentsMcpServerUrlDefinition +import com.anthropic.models.beta.agents.BetaManagedAgentsModel +import com.anthropic.models.beta.agents.BetaManagedAgentsModelConfig +import com.anthropic.models.beta.sessions.BetaManagedAgentsCacheCreationUsage +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 BetaManagedAgentsSessionThreadTest { + + @Test + fun create() { + val betaManagedAgentsSessionThread = + BetaManagedAgentsSessionThread.builder() + .id("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .agent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy.Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type( + BetaManagedAgentsAlwaysAskPolicy.Type.ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .archivedAt(null) + .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .parentThreadId(null) + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .stats( + BetaManagedAgentsSessionThreadStats.builder() + .activeSeconds(0.0) + .durationSeconds(0.0) + .startupSeconds(0.0) + .build() + ) + .status(BetaManagedAgentsSessionThreadStatus.IDLE) + .type(BetaManagedAgentsSessionThread.Type.SESSION_THREAD) + .updatedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .usage( + BetaManagedAgentsSessionThreadUsage.builder() + .cacheCreation( + BetaManagedAgentsCacheCreationUsage.builder() + .ephemeral1hInputTokens(0) + .ephemeral5mInputTokens(0) + .build() + ) + .cacheReadInputTokens(0) + .inputTokens(0) + .outputTokens(0) + .build() + ) + .build() + + assertThat(betaManagedAgentsSessionThread.id()).isEqualTo("sthr_011CZkZVWa6oIjw0rgXZpnBt") + assertThat(betaManagedAgentsSessionThread.agent()) + .isEqualTo( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy.Type.ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type(BetaManagedAgentsAlwaysAskPolicy.Type.ALWAYS_ASK) + .build() + ) + .build() + ) + .type(BetaManagedAgentsAgentToolset20260401.Type.AGENT_TOOLSET_20260401) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + assertThat(betaManagedAgentsSessionThread.archivedAt()).isEmpty + assertThat(betaManagedAgentsSessionThread.createdAt()) + .isEqualTo(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + assertThat(betaManagedAgentsSessionThread.parentThreadId()).isEmpty + assertThat(betaManagedAgentsSessionThread.sessionId()) + .isEqualTo("sesn_011CZkZAtmR3yMPDzynEDxu7") + assertThat(betaManagedAgentsSessionThread.stats()) + .contains( + BetaManagedAgentsSessionThreadStats.builder() + .activeSeconds(0.0) + .durationSeconds(0.0) + .startupSeconds(0.0) + .build() + ) + assertThat(betaManagedAgentsSessionThread.status()) + .isEqualTo(BetaManagedAgentsSessionThreadStatus.IDLE) + assertThat(betaManagedAgentsSessionThread.type()) + .isEqualTo(BetaManagedAgentsSessionThread.Type.SESSION_THREAD) + assertThat(betaManagedAgentsSessionThread.updatedAt()) + .isEqualTo(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + assertThat(betaManagedAgentsSessionThread.usage()) + .contains( + BetaManagedAgentsSessionThreadUsage.builder() + .cacheCreation( + BetaManagedAgentsCacheCreationUsage.builder() + .ephemeral1hInputTokens(0) + .ephemeral5mInputTokens(0) + .build() + ) + .cacheReadInputTokens(0) + .inputTokens(0) + .outputTokens(0) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionThread = + BetaManagedAgentsSessionThread.builder() + .id("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .agent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy.Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type( + BetaManagedAgentsAlwaysAskPolicy.Type.ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .archivedAt(null) + .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .parentThreadId(null) + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .stats( + BetaManagedAgentsSessionThreadStats.builder() + .activeSeconds(0.0) + .durationSeconds(0.0) + .startupSeconds(0.0) + .build() + ) + .status(BetaManagedAgentsSessionThreadStatus.IDLE) + .type(BetaManagedAgentsSessionThread.Type.SESSION_THREAD) + .updatedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .usage( + BetaManagedAgentsSessionThreadUsage.builder() + .cacheCreation( + BetaManagedAgentsCacheCreationUsage.builder() + .ephemeral1hInputTokens(0) + .ephemeral5mInputTokens(0) + .build() + ) + .cacheReadInputTokens(0) + .inputTokens(0) + .outputTokens(0) + .build() + ) + .build() + + val roundtrippedBetaManagedAgentsSessionThread = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionThread), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionThread) + .isEqualTo(betaManagedAgentsSessionThread) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadUsageTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadUsageTest.kt new file mode 100644 index 000000000..5e2cc2b27 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsSessionThreadUsageTest.kt @@ -0,0 +1,65 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.jsonMapper +import com.anthropic.models.beta.sessions.BetaManagedAgentsCacheCreationUsage +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsSessionThreadUsageTest { + + @Test + fun create() { + val betaManagedAgentsSessionThreadUsage = + BetaManagedAgentsSessionThreadUsage.builder() + .cacheCreation( + BetaManagedAgentsCacheCreationUsage.builder() + .ephemeral1hInputTokens(0) + .ephemeral5mInputTokens(0) + .build() + ) + .cacheReadInputTokens(0) + .inputTokens(0) + .outputTokens(0) + .build() + + assertThat(betaManagedAgentsSessionThreadUsage.cacheCreation()) + .contains( + BetaManagedAgentsCacheCreationUsage.builder() + .ephemeral1hInputTokens(0) + .ephemeral5mInputTokens(0) + .build() + ) + assertThat(betaManagedAgentsSessionThreadUsage.cacheReadInputTokens()).contains(0) + assertThat(betaManagedAgentsSessionThreadUsage.inputTokens()).contains(0) + assertThat(betaManagedAgentsSessionThreadUsage.outputTokens()).contains(0) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsSessionThreadUsage = + BetaManagedAgentsSessionThreadUsage.builder() + .cacheCreation( + BetaManagedAgentsCacheCreationUsage.builder() + .ephemeral1hInputTokens(0) + .ephemeral5mInputTokens(0) + .build() + ) + .cacheReadInputTokens(0) + .inputTokens(0) + .outputTokens(0) + .build() + + val roundtrippedBetaManagedAgentsSessionThreadUsage = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsSessionThreadUsage), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsSessionThreadUsage) + .isEqualTo(betaManagedAgentsSessionThreadUsage) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsStreamSessionThreadEventsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsStreamSessionThreadEventsTest.kt new file mode 100644 index 000000000..ce0b85429 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/BetaManagedAgentsStreamSessionThreadEventsTest.kt @@ -0,0 +1,2595 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.JsonValue +import com.anthropic.core.jsonMapper +import com.anthropic.errors.AnthropicInvalidDataException +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentCustomToolUseEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentMcpToolResultEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentMcpToolUseEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentMessageEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentThinkingEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentThreadContextCompactedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentThreadMessageReceivedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentThreadMessageSentEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentToolResultEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsAgentToolUseEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsRetryStatusRetrying +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionDeletedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionEndTurn +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionErrorEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionStatusIdleEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionStatusRescheduledEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionStatusRunningEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionStatusTerminatedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadCreatedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadStatusIdleEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadStatusRescheduledEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadStatusRunningEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionThreadStatusTerminatedEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanModelRequestEndEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanModelRequestStartEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanModelUsage +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanOutcomeEvaluationEndEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSpanOutcomeEvaluationStartEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsTextBlock +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUnknownError +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserCustomToolResultEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserDefineOutcomeEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserInterruptEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserMessageEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserToolConfirmationEvent +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +internal class BetaManagedAgentsStreamSessionThreadEventsTest { + + @Test + fun ofUserMessage() { + val userMessage = + BetaManagedAgentsUserMessageEvent.builder() + .id("sevt_011CZkZGOp0iBcp4kaQSihUmy") + .addTextContent("Where is my order #1234?") + .type(BetaManagedAgentsUserMessageEvent.Type.USER_MESSAGE) + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofUserMessage(userMessage) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).contains(userMessage) + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofUserMessageRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofUserMessage( + BetaManagedAgentsUserMessageEvent.builder() + .id("sevt_011CZkZGOp0iBcp4kaQSihUmy") + .addTextContent("Where is my order #1234?") + .type(BetaManagedAgentsUserMessageEvent.Type.USER_MESSAGE) + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofUserInterrupt() { + val userInterrupt = + BetaManagedAgentsUserInterruptEvent.builder() + .id("id") + .type(BetaManagedAgentsUserInterruptEvent.Type.USER_INTERRUPT) + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofUserInterrupt(userInterrupt) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()) + .contains(userInterrupt) + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofUserInterruptRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofUserInterrupt( + BetaManagedAgentsUserInterruptEvent.builder() + .id("id") + .type(BetaManagedAgentsUserInterruptEvent.Type.USER_INTERRUPT) + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofUserToolConfirmation() { + val userToolConfirmation = + BetaManagedAgentsUserToolConfirmationEvent.builder() + .id("id") + .result(BetaManagedAgentsUserToolConfirmationEvent.Result.ALLOW) + .toolUseId("tool_use_id") + .type(BetaManagedAgentsUserToolConfirmationEvent.Type.USER_TOOL_CONFIRMATION) + .denyMessage("deny_message") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofUserToolConfirmation(userToolConfirmation) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()) + .contains(userToolConfirmation) + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofUserToolConfirmationRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofUserToolConfirmation( + BetaManagedAgentsUserToolConfirmationEvent.builder() + .id("id") + .result(BetaManagedAgentsUserToolConfirmationEvent.Result.ALLOW) + .toolUseId("tool_use_id") + .type(BetaManagedAgentsUserToolConfirmationEvent.Type.USER_TOOL_CONFIRMATION) + .denyMessage("deny_message") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofUserCustomToolResult() { + val userCustomToolResult = + BetaManagedAgentsUserCustomToolResultEvent.builder() + .id("id") + .customToolUseId("custom_tool_use_id") + .type(BetaManagedAgentsUserCustomToolResultEvent.Type.USER_CUSTOM_TOOL_RESULT) + .addTextContent("Where is my order #1234?") + .isError(true) + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofUserCustomToolResult(userCustomToolResult) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()) + .contains(userCustomToolResult) + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofUserCustomToolResultRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofUserCustomToolResult( + BetaManagedAgentsUserCustomToolResultEvent.builder() + .id("id") + .customToolUseId("custom_tool_use_id") + .type(BetaManagedAgentsUserCustomToolResultEvent.Type.USER_CUSTOM_TOOL_RESULT) + .addTextContent("Where is my order #1234?") + .isError(true) + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofAgentCustomToolUse() { + val agentCustomToolUse = + BetaManagedAgentsAgentCustomToolUseEvent.builder() + .id("id") + .input( + BetaManagedAgentsAgentCustomToolUseEvent.Input.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .name("name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsAgentCustomToolUseEvent.Type.AGENT_CUSTOM_TOOL_USE) + .sessionThreadId("session_thread_id") + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentCustomToolUse(agentCustomToolUse) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()) + .contains(agentCustomToolUse) + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofAgentCustomToolUseRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentCustomToolUse( + BetaManagedAgentsAgentCustomToolUseEvent.builder() + .id("id") + .input( + BetaManagedAgentsAgentCustomToolUseEvent.Input.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .name("name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsAgentCustomToolUseEvent.Type.AGENT_CUSTOM_TOOL_USE) + .sessionThreadId("session_thread_id") + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofAgentMessage() { + val agentMessage = + BetaManagedAgentsAgentMessageEvent.builder() + .id("sevt_011CZkZHPq1jCdq5lbRTjiVnz") + .addContent( + BetaManagedAgentsTextBlock.builder() + .text("Let me look up order #1234 for you.") + .type(BetaManagedAgentsTextBlock.Type.TEXT) + .build() + ) + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .type(BetaManagedAgentsAgentMessageEvent.Type.AGENT_MESSAGE) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentMessage(agentMessage) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).contains(agentMessage) + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofAgentMessageRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentMessage( + BetaManagedAgentsAgentMessageEvent.builder() + .id("sevt_011CZkZHPq1jCdq5lbRTjiVnz") + .addContent( + BetaManagedAgentsTextBlock.builder() + .text("Let me look up order #1234 for you.") + .type(BetaManagedAgentsTextBlock.Type.TEXT) + .build() + ) + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .type(BetaManagedAgentsAgentMessageEvent.Type.AGENT_MESSAGE) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofAgentThinking() { + val agentThinking = + BetaManagedAgentsAgentThinkingEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsAgentThinkingEvent.Type.AGENT_THINKING) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentThinking(agentThinking) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()) + .contains(agentThinking) + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofAgentThinkingRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentThinking( + BetaManagedAgentsAgentThinkingEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsAgentThinkingEvent.Type.AGENT_THINKING) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofAgentMcpToolUse() { + val agentMcpToolUse = + BetaManagedAgentsAgentMcpToolUseEvent.builder() + .id("id") + .input( + BetaManagedAgentsAgentMcpToolUseEvent.Input.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .mcpServerName("mcp_server_name") + .name("name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsAgentMcpToolUseEvent.Type.AGENT_MCP_TOOL_USE) + .evaluatedPermission( + BetaManagedAgentsAgentMcpToolUseEvent.EvaluatedPermission.ALLOW + ) + .sessionThreadId("session_thread_id") + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentMcpToolUse(agentMcpToolUse) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()) + .contains(agentMcpToolUse) + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofAgentMcpToolUseRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentMcpToolUse( + BetaManagedAgentsAgentMcpToolUseEvent.builder() + .id("id") + .input( + BetaManagedAgentsAgentMcpToolUseEvent.Input.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .mcpServerName("mcp_server_name") + .name("name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsAgentMcpToolUseEvent.Type.AGENT_MCP_TOOL_USE) + .evaluatedPermission( + BetaManagedAgentsAgentMcpToolUseEvent.EvaluatedPermission.ALLOW + ) + .sessionThreadId("session_thread_id") + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofAgentMcpToolResult() { + val agentMcpToolResult = + BetaManagedAgentsAgentMcpToolResultEvent.builder() + .id("id") + .mcpToolUseId("mcp_tool_use_id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsAgentMcpToolResultEvent.Type.AGENT_MCP_TOOL_RESULT) + .addTextContent("Where is my order #1234?") + .isError(true) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentMcpToolResult(agentMcpToolResult) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()) + .contains(agentMcpToolResult) + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofAgentMcpToolResultRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentMcpToolResult( + BetaManagedAgentsAgentMcpToolResultEvent.builder() + .id("id") + .mcpToolUseId("mcp_tool_use_id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsAgentMcpToolResultEvent.Type.AGENT_MCP_TOOL_RESULT) + .addTextContent("Where is my order #1234?") + .isError(true) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofAgentToolUse() { + val agentToolUse = + BetaManagedAgentsAgentToolUseEvent.builder() + .id("id") + .input( + BetaManagedAgentsAgentToolUseEvent.Input.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .name("name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsAgentToolUseEvent.Type.AGENT_TOOL_USE) + .evaluatedPermission(BetaManagedAgentsAgentToolUseEvent.EvaluatedPermission.ALLOW) + .sessionThreadId("session_thread_id") + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentToolUse(agentToolUse) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).contains(agentToolUse) + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofAgentToolUseRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentToolUse( + BetaManagedAgentsAgentToolUseEvent.builder() + .id("id") + .input( + BetaManagedAgentsAgentToolUseEvent.Input.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .name("name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsAgentToolUseEvent.Type.AGENT_TOOL_USE) + .evaluatedPermission( + BetaManagedAgentsAgentToolUseEvent.EvaluatedPermission.ALLOW + ) + .sessionThreadId("session_thread_id") + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofAgentToolResult() { + val agentToolResult = + BetaManagedAgentsAgentToolResultEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .toolUseId("tool_use_id") + .type(BetaManagedAgentsAgentToolResultEvent.Type.AGENT_TOOL_RESULT) + .addTextContent("Where is my order #1234?") + .isError(true) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentToolResult(agentToolResult) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()) + .contains(agentToolResult) + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofAgentToolResultRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentToolResult( + BetaManagedAgentsAgentToolResultEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .toolUseId("tool_use_id") + .type(BetaManagedAgentsAgentToolResultEvent.Type.AGENT_TOOL_RESULT) + .addTextContent("Where is my order #1234?") + .isError(true) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofAgentThreadMessageReceived() { + val agentThreadMessageReceived = + BetaManagedAgentsAgentThreadMessageReceivedEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .fromSessionThreadId("from_session_thread_id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsAgentThreadMessageReceivedEvent.Type + .AGENT_THREAD_MESSAGE_RECEIVED + ) + .fromAgentName("from_agent_name") + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentThreadMessageReceived( + agentThreadMessageReceived + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()) + .contains(agentThreadMessageReceived) + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofAgentThreadMessageReceivedRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentThreadMessageReceived( + BetaManagedAgentsAgentThreadMessageReceivedEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .fromSessionThreadId("from_session_thread_id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsAgentThreadMessageReceivedEvent.Type + .AGENT_THREAD_MESSAGE_RECEIVED + ) + .fromAgentName("from_agent_name") + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofAgentThreadMessageSent() { + val agentThreadMessageSent = + BetaManagedAgentsAgentThreadMessageSentEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .toSessionThreadId("to_session_thread_id") + .type(BetaManagedAgentsAgentThreadMessageSentEvent.Type.AGENT_THREAD_MESSAGE_SENT) + .toAgentName("to_agent_name") + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentThreadMessageSent( + agentThreadMessageSent + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()) + .contains(agentThreadMessageSent) + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofAgentThreadMessageSentRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentThreadMessageSent( + BetaManagedAgentsAgentThreadMessageSentEvent.builder() + .id("id") + .addTextContent("Where is my order #1234?") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .toSessionThreadId("to_session_thread_id") + .type( + BetaManagedAgentsAgentThreadMessageSentEvent.Type.AGENT_THREAD_MESSAGE_SENT + ) + .toAgentName("to_agent_name") + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofAgentThreadContextCompacted() { + val agentThreadContextCompacted = + BetaManagedAgentsAgentThreadContextCompactedEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsAgentThreadContextCompactedEvent.Type + .AGENT_THREAD_CONTEXT_COMPACTED + ) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentThreadContextCompacted( + agentThreadContextCompacted + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()) + .contains(agentThreadContextCompacted) + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofAgentThreadContextCompactedRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofAgentThreadContextCompacted( + BetaManagedAgentsAgentThreadContextCompactedEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsAgentThreadContextCompactedEvent.Type + .AGENT_THREAD_CONTEXT_COMPACTED + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSessionError() { + val sessionError = + BetaManagedAgentsSessionErrorEvent.builder() + .id("id") + .error( + BetaManagedAgentsUnknownError.builder() + .message("message") + .retryStatus( + BetaManagedAgentsRetryStatusRetrying.builder() + .type(BetaManagedAgentsRetryStatusRetrying.Type.RETRYING) + .build() + ) + .type(BetaManagedAgentsUnknownError.Type.UNKNOWN_ERROR) + .build() + ) + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsSessionErrorEvent.Type.SESSION_ERROR) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionError(sessionError) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).contains(sessionError) + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSessionErrorRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionError( + BetaManagedAgentsSessionErrorEvent.builder() + .id("id") + .error( + BetaManagedAgentsUnknownError.builder() + .message("message") + .retryStatus( + BetaManagedAgentsRetryStatusRetrying.builder() + .type(BetaManagedAgentsRetryStatusRetrying.Type.RETRYING) + .build() + ) + .type(BetaManagedAgentsUnknownError.Type.UNKNOWN_ERROR) + .build() + ) + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsSessionErrorEvent.Type.SESSION_ERROR) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSessionStatusRescheduled() { + val sessionStatusRescheduled = + BetaManagedAgentsSessionStatusRescheduledEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsSessionStatusRescheduledEvent.Type.SESSION_STATUS_RESCHEDULED + ) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionStatusRescheduled( + sessionStatusRescheduled + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()) + .contains(sessionStatusRescheduled) + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSessionStatusRescheduledRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionStatusRescheduled( + BetaManagedAgentsSessionStatusRescheduledEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsSessionStatusRescheduledEvent.Type + .SESSION_STATUS_RESCHEDULED + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSessionStatusRunning() { + val sessionStatusRunning = + BetaManagedAgentsSessionStatusRunningEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsSessionStatusRunningEvent.Type.SESSION_STATUS_RUNNING) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionStatusRunning(sessionStatusRunning) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()) + .contains(sessionStatusRunning) + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSessionStatusRunningRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionStatusRunning( + BetaManagedAgentsSessionStatusRunningEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsSessionStatusRunningEvent.Type.SESSION_STATUS_RUNNING) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSessionStatusIdle() { + val sessionStatusIdle = + BetaManagedAgentsSessionStatusIdleEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .stopReason( + BetaManagedAgentsSessionEndTurn.builder() + .type(BetaManagedAgentsSessionEndTurn.Type.END_TURN) + .build() + ) + .type(BetaManagedAgentsSessionStatusIdleEvent.Type.SESSION_STATUS_IDLE) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionStatusIdle(sessionStatusIdle) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()) + .contains(sessionStatusIdle) + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSessionStatusIdleRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionStatusIdle( + BetaManagedAgentsSessionStatusIdleEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .stopReason( + BetaManagedAgentsSessionEndTurn.builder() + .type(BetaManagedAgentsSessionEndTurn.Type.END_TURN) + .build() + ) + .type(BetaManagedAgentsSessionStatusIdleEvent.Type.SESSION_STATUS_IDLE) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSessionStatusTerminated() { + val sessionStatusTerminated = + BetaManagedAgentsSessionStatusTerminatedEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsSessionStatusTerminatedEvent.Type.SESSION_STATUS_TERMINATED) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionStatusTerminated( + sessionStatusTerminated + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()) + .contains(sessionStatusTerminated) + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSessionStatusTerminatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionStatusTerminated( + BetaManagedAgentsSessionStatusTerminatedEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type( + BetaManagedAgentsSessionStatusTerminatedEvent.Type.SESSION_STATUS_TERMINATED + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSessionThreadCreated() { + val sessionThreadCreated = + BetaManagedAgentsSessionThreadCreatedEvent.builder() + .id("sevt_011CZkZWXb7pJkx1shYaqoCu") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .type(BetaManagedAgentsSessionThreadCreatedEvent.Type.SESSION_THREAD_CREATED) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionThreadCreated(sessionThreadCreated) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()) + .contains(sessionThreadCreated) + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSessionThreadCreatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionThreadCreated( + BetaManagedAgentsSessionThreadCreatedEvent.builder() + .id("sevt_011CZkZWXb7pJkx1shYaqoCu") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .type(BetaManagedAgentsSessionThreadCreatedEvent.Type.SESSION_THREAD_CREATED) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSpanOutcomeEvaluationStart() { + val spanOutcomeEvaluationStart = + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.builder() + .id("sevt_011CZkZTUy4mGhu8peVXnlzr") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.Type + .SPAN_OUTCOME_EVALUATION_START + ) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSpanOutcomeEvaluationStart( + spanOutcomeEvaluationStart + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()) + .contains(spanOutcomeEvaluationStart) + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSpanOutcomeEvaluationStartRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSpanOutcomeEvaluationStart( + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.builder() + .id("sevt_011CZkZTUy4mGhu8peVXnlzr") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationStartEvent.Type + .SPAN_OUTCOME_EVALUATION_START + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSpanOutcomeEvaluationEnd() { + val spanOutcomeEvaluationEnd = + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.builder() + .id("sevt_011CZkZUVz5nHiv9qfWYomas") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeEvaluationStartId("sevt_011CZkZTUy4mGhu8peVXnlzr") + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .result("satisfied") + .type( + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.Type.SPAN_OUTCOME_EVALUATION_END + ) + .usage( + BetaManagedAgentsSpanModelUsage.builder() + .cacheCreationInputTokens(0) + .cacheReadInputTokens(1536) + .inputTokens(1842) + .outputTokens(213) + .speed(BetaManagedAgentsSpanModelUsage.Speed.STANDARD) + .build() + ) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSpanOutcomeEvaluationEnd( + spanOutcomeEvaluationEnd + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()) + .contains(spanOutcomeEvaluationEnd) + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSpanOutcomeEvaluationEndRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSpanOutcomeEvaluationEnd( + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.builder() + .id("sevt_011CZkZUVz5nHiv9qfWYomas") + .explanation("All five sections present with inline citations.") + .iteration(0) + .outcomeEvaluationStartId("sevt_011CZkZTUy4mGhu8peVXnlzr") + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:31Z")) + .result("satisfied") + .type( + BetaManagedAgentsSpanOutcomeEvaluationEndEvent.Type + .SPAN_OUTCOME_EVALUATION_END + ) + .usage( + BetaManagedAgentsSpanModelUsage.builder() + .cacheCreationInputTokens(0) + .cacheReadInputTokens(1536) + .inputTokens(1842) + .outputTokens(213) + .speed(BetaManagedAgentsSpanModelUsage.Speed.STANDARD) + .build() + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSpanModelRequestStart() { + val spanModelRequestStart = + BetaManagedAgentsSpanModelRequestStartEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsSpanModelRequestStartEvent.Type.SPAN_MODEL_REQUEST_START) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSpanModelRequestStart( + spanModelRequestStart + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()) + .contains(spanModelRequestStart) + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSpanModelRequestStartRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSpanModelRequestStart( + BetaManagedAgentsSpanModelRequestStartEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsSpanModelRequestStartEvent.Type.SPAN_MODEL_REQUEST_START) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSpanModelRequestEnd() { + val spanModelRequestEnd = + BetaManagedAgentsSpanModelRequestEndEvent.builder() + .id("id") + .isError(true) + .modelRequestStartId("model_request_start_id") + .modelUsage( + BetaManagedAgentsSpanModelUsage.builder() + .cacheCreationInputTokens(0) + .cacheReadInputTokens(0) + .inputTokens(0) + .outputTokens(0) + .speed(BetaManagedAgentsSpanModelUsage.Speed.STANDARD) + .build() + ) + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsSpanModelRequestEndEvent.Type.SPAN_MODEL_REQUEST_END) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSpanModelRequestEnd(spanModelRequestEnd) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()) + .contains(spanModelRequestEnd) + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSpanModelRequestEndRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSpanModelRequestEnd( + BetaManagedAgentsSpanModelRequestEndEvent.builder() + .id("id") + .isError(true) + .modelRequestStartId("model_request_start_id") + .modelUsage( + BetaManagedAgentsSpanModelUsage.builder() + .cacheCreationInputTokens(0) + .cacheReadInputTokens(0) + .inputTokens(0) + .outputTokens(0) + .speed(BetaManagedAgentsSpanModelUsage.Speed.STANDARD) + .build() + ) + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsSpanModelRequestEndEvent.Type.SPAN_MODEL_REQUEST_END) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSpanOutcomeEvaluationOngoing() { + val spanOutcomeEvaluationOngoing = + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.builder() + .id("sevt_011CZkZbCG2uOpc6xmDfvTzh") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.Type + .SPAN_OUTCOME_EVALUATION_ONGOING + ) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSpanOutcomeEvaluationOngoing( + spanOutcomeEvaluationOngoing + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .contains(spanOutcomeEvaluationOngoing) + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSpanOutcomeEvaluationOngoingRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSpanOutcomeEvaluationOngoing( + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.builder() + .id("sevt_011CZkZbCG2uOpc6xmDfvTzh") + .iteration(0) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .type( + BetaManagedAgentsSpanOutcomeEvaluationOngoingEvent.Type + .SPAN_OUTCOME_EVALUATION_ONGOING + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofUserDefineOutcome() { + val userDefineOutcome = + BetaManagedAgentsUserDefineOutcomeEvent.builder() + .id("sevt_011CZkZSTx3lFgt7odUWmkyq") + .description("Produce a 2-page summary as summary.md") + .maxIterations(3) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .textRubric("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsUserDefineOutcomeEvent.Type.USER_DEFINE_OUTCOME) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofUserDefineOutcome(userDefineOutcome) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()) + .contains(userDefineOutcome) + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofUserDefineOutcomeRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofUserDefineOutcome( + BetaManagedAgentsUserDefineOutcomeEvent.builder() + .id("sevt_011CZkZSTx3lFgt7odUWmkyq") + .description("Produce a 2-page summary as summary.md") + .maxIterations(3) + .outcomeId("outc_011CZkZRSw2kEfs6ncTVljxP") + .processedAt(OffsetDateTime.parse("2026-03-15T10:02:14Z")) + .textRubric("Must cover all five sections; cite sources inline.") + .type(BetaManagedAgentsUserDefineOutcomeEvent.Type.USER_DEFINE_OUTCOME) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSessionDeleted() { + val sessionDeleted = + BetaManagedAgentsSessionDeletedEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsSessionDeletedEvent.Type.SESSION_DELETED) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionDeleted(sessionDeleted) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()) + .contains(sessionDeleted) + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSessionDeletedRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionDeleted( + BetaManagedAgentsSessionDeletedEvent.builder() + .id("id") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .type(BetaManagedAgentsSessionDeletedEvent.Type.SESSION_DELETED) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSessionThreadStatusRunning() { + val sessionThreadStatusRunning = + BetaManagedAgentsSessionThreadStatusRunningEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRunningEvent.Type + .SESSION_THREAD_STATUS_RUNNING + ) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionThreadStatusRunning( + sessionThreadStatusRunning + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()) + .contains(sessionThreadStatusRunning) + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSessionThreadStatusRunningRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionThreadStatusRunning( + BetaManagedAgentsSessionThreadStatusRunningEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRunningEvent.Type + .SESSION_THREAD_STATUS_RUNNING + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSessionThreadStatusIdle() { + val sessionThreadStatusIdle = + BetaManagedAgentsSessionThreadStatusIdleEvent.builder() + .id("sevt_011CZkZXYc8qKly2tiZbrpDv") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .stopReason( + BetaManagedAgentsSessionEndTurn.builder() + .type(BetaManagedAgentsSessionEndTurn.Type.END_TURN) + .build() + ) + .type(BetaManagedAgentsSessionThreadStatusIdleEvent.Type.SESSION_THREAD_STATUS_IDLE) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionThreadStatusIdle( + sessionThreadStatusIdle + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()) + .contains(sessionThreadStatusIdle) + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSessionThreadStatusIdleRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionThreadStatusIdle( + BetaManagedAgentsSessionThreadStatusIdleEvent.builder() + .id("sevt_011CZkZXYc8qKly2tiZbrpDv") + .agentName("Researcher") + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .sessionThreadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .stopReason( + BetaManagedAgentsSessionEndTurn.builder() + .type(BetaManagedAgentsSessionEndTurn.Type.END_TURN) + .build() + ) + .type( + BetaManagedAgentsSessionThreadStatusIdleEvent.Type + .SESSION_THREAD_STATUS_IDLE + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSessionThreadStatusTerminated() { + val sessionThreadStatusTerminated = + BetaManagedAgentsSessionThreadStatusTerminatedEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusTerminatedEvent.Type + .SESSION_THREAD_STATUS_TERMINATED + ) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionThreadStatusTerminated( + sessionThreadStatusTerminated + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .contains(sessionThreadStatusTerminated) + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .isEmpty + } + + @Test + fun ofSessionThreadStatusTerminatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionThreadStatusTerminated( + BetaManagedAgentsSessionThreadStatusTerminatedEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusTerminatedEvent.Type + .SESSION_THREAD_STATUS_TERMINATED + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + @Test + fun ofSessionThreadStatusRescheduled() { + val sessionThreadStatusRescheduled = + BetaManagedAgentsSessionThreadStatusRescheduledEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRescheduledEvent.Type + .SESSION_THREAD_STATUS_RESCHEDULED + ) + .build() + + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionThreadStatusRescheduled( + sessionThreadStatusRescheduled + ) + + assertThat(betaManagedAgentsStreamSessionThreadEvents.userMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userInterrupt()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userToolConfirmation()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userCustomToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentCustomToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMessage()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThinking()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentMcpToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolUse()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentToolResult()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageReceived()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadMessageSent()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.agentThreadContextCompacted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionError()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRescheduled()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionStatusTerminated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadCreated()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestStart()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanModelRequestEnd()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.spanOutcomeEvaluationOngoing()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.userDefineOutcome()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionDeleted()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRunning()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusIdle()).isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusTerminated()) + .isEmpty + assertThat(betaManagedAgentsStreamSessionThreadEvents.sessionThreadStatusRescheduled()) + .contains(sessionThreadStatusRescheduled) + } + + @Test + fun ofSessionThreadStatusRescheduledRoundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsStreamSessionThreadEvents = + BetaManagedAgentsStreamSessionThreadEvents.ofSessionThreadStatusRescheduled( + BetaManagedAgentsSessionThreadStatusRescheduledEvent.builder() + .id("id") + .agentName("agent_name") + .processedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .sessionThreadId("session_thread_id") + .type( + BetaManagedAgentsSessionThreadStatusRescheduledEvent.Type + .SESSION_THREAD_STATUS_RESCHEDULED + ) + .build() + ) + + val roundtrippedBetaManagedAgentsStreamSessionThreadEvents = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsStreamSessionThreadEvents), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsStreamSessionThreadEvents) + .isEqualTo(betaManagedAgentsStreamSessionThreadEvents) + } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + STRING(JsonValue.from("invalid")), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val betaManagedAgentsStreamSessionThreadEvents = + jsonMapper() + .convertValue( + testCase.value, + jacksonTypeRef(), + ) + + val e = + assertThrows { + betaManagedAgentsStreamSessionThreadEvents.validate() + } + assertThat(e).hasMessageStartingWith("Unknown ") + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadArchiveParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadArchiveParamsTest.kt new file mode 100644 index 000000000..1a1c7a1da --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadArchiveParamsTest.kt @@ -0,0 +1,64 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.http.Headers +import com.anthropic.models.beta.AnthropicBeta +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ThreadArchiveParamsTest { + + @Test + fun create() { + ThreadArchiveParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + } + + @Test + fun pathParams() { + val params = + ThreadArchiveParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .build() + + assertThat(params._pathParam(0)).isEqualTo("sesn_011CZkZAtmR3yMPDzynEDxu7") + assertThat(params._pathParam(1)).isEqualTo("sthr_011CZkZVWa6oIjw0rgXZpnBt") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } + + @Test + fun headers() { + val params = + ThreadArchiveParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + + val headers = params._headers() + + assertThat(headers) + .isEqualTo( + Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() + ) + } + + @Test + fun headersWithoutOptionalFields() { + val params = + ThreadArchiveParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .build() + + val headers = params._headers() + + assertThat(headers).isEqualTo(Headers.builder().build()) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPageResponseTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPageResponseTest.kt new file mode 100644 index 000000000..f00f403ba --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListPageResponseTest.kt @@ -0,0 +1,348 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.jsonMapper +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolConfig +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolset20260401 +import com.anthropic.models.beta.agents.BetaManagedAgentsAgentToolsetDefaultConfig +import com.anthropic.models.beta.agents.BetaManagedAgentsAlwaysAllowPolicy +import com.anthropic.models.beta.agents.BetaManagedAgentsAlwaysAskPolicy +import com.anthropic.models.beta.agents.BetaManagedAgentsAnthropicSkill +import com.anthropic.models.beta.agents.BetaManagedAgentsMcpServerUrlDefinition +import com.anthropic.models.beta.agents.BetaManagedAgentsModel +import com.anthropic.models.beta.agents.BetaManagedAgentsModelConfig +import com.anthropic.models.beta.sessions.BetaManagedAgentsCacheCreationUsage +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 ThreadListPageResponseTest { + + @Test + fun create() { + val threadListPageResponse = + ThreadListPageResponse.builder() + .addData( + BetaManagedAgentsSessionThread.builder() + .id("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .agent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy.Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type( + BetaManagedAgentsAlwaysAskPolicy.Type + .ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .archivedAt(null) + .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .parentThreadId(null) + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .stats( + BetaManagedAgentsSessionThreadStats.builder() + .activeSeconds(0.0) + .durationSeconds(0.0) + .startupSeconds(0.0) + .build() + ) + .status(BetaManagedAgentsSessionThreadStatus.IDLE) + .type(BetaManagedAgentsSessionThread.Type.SESSION_THREAD) + .updatedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .usage( + BetaManagedAgentsSessionThreadUsage.builder() + .cacheCreation( + BetaManagedAgentsCacheCreationUsage.builder() + .ephemeral1hInputTokens(0) + .ephemeral5mInputTokens(0) + .build() + ) + .cacheReadInputTokens(0) + .inputTokens(0) + .outputTokens(0) + .build() + ) + .build() + ) + .nextPage("page_MjAyNS0wNS0xNFQwMDowMDowMFo=") + .build() + + assertThat(threadListPageResponse.data().getOrNull()) + .containsExactly( + BetaManagedAgentsSessionThread.builder() + .id("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .agent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy.Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type( + BetaManagedAgentsAlwaysAskPolicy.Type + .ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .archivedAt(null) + .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .parentThreadId(null) + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .stats( + BetaManagedAgentsSessionThreadStats.builder() + .activeSeconds(0.0) + .durationSeconds(0.0) + .startupSeconds(0.0) + .build() + ) + .status(BetaManagedAgentsSessionThreadStatus.IDLE) + .type(BetaManagedAgentsSessionThread.Type.SESSION_THREAD) + .updatedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .usage( + BetaManagedAgentsSessionThreadUsage.builder() + .cacheCreation( + BetaManagedAgentsCacheCreationUsage.builder() + .ephemeral1hInputTokens(0) + .ephemeral5mInputTokens(0) + .build() + ) + .cacheReadInputTokens(0) + .inputTokens(0) + .outputTokens(0) + .build() + ) + .build() + ) + assertThat(threadListPageResponse.nextPage()).contains("page_MjAyNS0wNS0xNFQwMDowMDowMFo=") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val threadListPageResponse = + ThreadListPageResponse.builder() + .addData( + BetaManagedAgentsSessionThread.builder() + .id("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .agent( + BetaManagedAgentsSessionThreadAgent.builder() + .id("agent_011CZkYqphY8vELVzwCUpqiQ") + .description("A focused research subagent.") + .addMcpServer( + BetaManagedAgentsMcpServerUrlDefinition.builder() + .name("example-mcp") + .type(BetaManagedAgentsMcpServerUrlDefinition.Type.URL) + .url("https://example-server.modelcontextprotocol.io/sse") + .build() + ) + .model( + BetaManagedAgentsModelConfig.builder() + .id(BetaManagedAgentsModel.CLAUDE_SONNET_4_6) + .speed(BetaManagedAgentsModelConfig.Speed.STANDARD) + .build() + ) + .name("Researcher") + .addSkill( + BetaManagedAgentsAnthropicSkill.builder() + .skillId("xlsx") + .type(BetaManagedAgentsAnthropicSkill.Type.ANTHROPIC) + .version("1") + .build() + ) + .system( + "You are a research subagent that gathers and summarises sources for the coordinating agent." + ) + .addTool( + BetaManagedAgentsAgentToolset20260401.builder() + .addConfig( + BetaManagedAgentsAgentToolConfig.builder() + .enabled(true) + .name(BetaManagedAgentsAgentToolConfig.Name.BASH) + .permissionPolicy( + BetaManagedAgentsAlwaysAllowPolicy.builder() + .type( + BetaManagedAgentsAlwaysAllowPolicy.Type + .ALWAYS_ALLOW + ) + .build() + ) + .build() + ) + .defaultConfig( + BetaManagedAgentsAgentToolsetDefaultConfig.builder() + .enabled(true) + .permissionPolicy( + BetaManagedAgentsAlwaysAskPolicy.builder() + .type( + BetaManagedAgentsAlwaysAskPolicy.Type + .ALWAYS_ASK + ) + .build() + ) + .build() + ) + .type( + BetaManagedAgentsAgentToolset20260401.Type + .AGENT_TOOLSET_20260401 + ) + .build() + ) + .type(BetaManagedAgentsSessionThreadAgent.Type.AGENT) + .version(1) + .build() + ) + .archivedAt(null) + .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .parentThreadId(null) + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .stats( + BetaManagedAgentsSessionThreadStats.builder() + .activeSeconds(0.0) + .durationSeconds(0.0) + .startupSeconds(0.0) + .build() + ) + .status(BetaManagedAgentsSessionThreadStatus.IDLE) + .type(BetaManagedAgentsSessionThread.Type.SESSION_THREAD) + .updatedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .usage( + BetaManagedAgentsSessionThreadUsage.builder() + .cacheCreation( + BetaManagedAgentsCacheCreationUsage.builder() + .ephemeral1hInputTokens(0) + .ephemeral5mInputTokens(0) + .build() + ) + .cacheReadInputTokens(0) + .inputTokens(0) + .outputTokens(0) + .build() + ) + .build() + ) + .nextPage("page_MjAyNS0wNS0xNFQwMDowMDowMFo=") + .build() + + val roundtrippedThreadListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(threadListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedThreadListPageResponse).isEqualTo(threadListPageResponse) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListParamsTest.kt new file mode 100644 index 000000000..7e043b012 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadListParamsTest.kt @@ -0,0 +1,83 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.http.Headers +import com.anthropic.core.http.QueryParams +import com.anthropic.models.beta.AnthropicBeta +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ThreadListParamsTest { + + @Test + fun create() { + ThreadListParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .limit(0) + .page("page") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + } + + @Test + fun pathParams() { + val params = ThreadListParams.builder().sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7").build() + + assertThat(params._pathParam(0)).isEqualTo("sesn_011CZkZAtmR3yMPDzynEDxu7") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun headers() { + val params = + ThreadListParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .limit(0) + .page("page") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + + val headers = params._headers() + + assertThat(headers) + .isEqualTo( + Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() + ) + } + + @Test + fun headersWithoutOptionalFields() { + val params = ThreadListParams.builder().sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7").build() + + val headers = params._headers() + + assertThat(headers).isEqualTo(Headers.builder().build()) + } + + @Test + fun queryParams() { + val params = + ThreadListParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .limit(0) + .page("page") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo(QueryParams.builder().put("limit", "0").put("page", "page").build()) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = ThreadListParams.builder().sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadRetrieveParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadRetrieveParamsTest.kt new file mode 100644 index 000000000..56e3ab1bd --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/ThreadRetrieveParamsTest.kt @@ -0,0 +1,64 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads + +import com.anthropic.core.http.Headers +import com.anthropic.models.beta.AnthropicBeta +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ThreadRetrieveParamsTest { + + @Test + fun create() { + ThreadRetrieveParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + } + + @Test + fun pathParams() { + val params = + ThreadRetrieveParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .build() + + assertThat(params._pathParam(0)).isEqualTo("sesn_011CZkZAtmR3yMPDzynEDxu7") + assertThat(params._pathParam(1)).isEqualTo("sthr_011CZkZVWa6oIjw0rgXZpnBt") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } + + @Test + fun headers() { + val params = + ThreadRetrieveParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + + val headers = params._headers() + + assertThat(headers) + .isEqualTo( + Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() + ) + } + + @Test + fun headersWithoutOptionalFields() { + val params = + ThreadRetrieveParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .build() + + val headers = params._headers() + + assertThat(headers).isEqualTo(Headers.builder().build()) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPageResponseTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPageResponseTest.kt new file mode 100644 index 000000000..ec0f65742 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListPageResponseTest.kt @@ -0,0 +1,69 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads.events + +import com.anthropic.core.jsonMapper +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsSessionEvent +import com.anthropic.models.beta.sessions.events.BetaManagedAgentsUserMessageEvent +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 EventListPageResponseTest { + + @Test + fun create() { + val eventListPageResponse = + EventListPageResponse.builder() + .addData( + BetaManagedAgentsUserMessageEvent.builder() + .id("sevt_011CZkZGOp0iBcp4kaQSihUmy") + .addTextContent("Where is my order #1234?") + .type(BetaManagedAgentsUserMessageEvent.Type.USER_MESSAGE) + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .build() + ) + .nextPage("next_page") + .build() + + assertThat(eventListPageResponse.data().getOrNull()) + .containsExactly( + BetaManagedAgentsSessionEvent.ofUserMessage( + BetaManagedAgentsUserMessageEvent.builder() + .id("sevt_011CZkZGOp0iBcp4kaQSihUmy") + .addTextContent("Where is my order #1234?") + .type(BetaManagedAgentsUserMessageEvent.Type.USER_MESSAGE) + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .build() + ) + ) + assertThat(eventListPageResponse.nextPage()).contains("next_page") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val eventListPageResponse = + EventListPageResponse.builder() + .addData( + BetaManagedAgentsUserMessageEvent.builder() + .id("sevt_011CZkZGOp0iBcp4kaQSihUmy") + .addTextContent("Where is my order #1234?") + .type(BetaManagedAgentsUserMessageEvent.Type.USER_MESSAGE) + .processedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .build() + ) + .nextPage("next_page") + .build() + + val roundtrippedEventListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(eventListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedEventListPageResponse).isEqualTo(eventListPageResponse) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListParamsTest.kt new file mode 100644 index 000000000..52dec31b9 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/events/EventListParamsTest.kt @@ -0,0 +1,99 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads.events + +import com.anthropic.core.http.Headers +import com.anthropic.core.http.QueryParams +import com.anthropic.models.beta.AnthropicBeta +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class EventListParamsTest { + + @Test + fun create() { + EventListParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .limit(0) + .page("page") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + } + + @Test + fun pathParams() { + val params = + EventListParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .build() + + assertThat(params._pathParam(0)).isEqualTo("sesn_011CZkZAtmR3yMPDzynEDxu7") + assertThat(params._pathParam(1)).isEqualTo("sthr_011CZkZVWa6oIjw0rgXZpnBt") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } + + @Test + fun headers() { + val params = + EventListParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .limit(0) + .page("page") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + + val headers = params._headers() + + assertThat(headers) + .isEqualTo( + Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() + ) + } + + @Test + fun headersWithoutOptionalFields() { + val params = + EventListParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .build() + + val headers = params._headers() + + assertThat(headers).isEqualTo(Headers.builder().build()) + } + + @Test + fun queryParams() { + val params = + EventListParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .limit(0) + .page("page") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo(QueryParams.builder().put("limit", "0").put("page", "page").build()) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = + EventListParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/events/EventStreamParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/events/EventStreamParamsTest.kt new file mode 100644 index 000000000..e1d77f077 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/sessions/threads/events/EventStreamParamsTest.kt @@ -0,0 +1,64 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.sessions.threads.events + +import com.anthropic.core.http.Headers +import com.anthropic.models.beta.AnthropicBeta +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class EventStreamParamsTest { + + @Test + fun create() { + EventStreamParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + } + + @Test + fun pathParams() { + val params = + EventStreamParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .build() + + assertThat(params._pathParam(0)).isEqualTo("sesn_011CZkZAtmR3yMPDzynEDxu7") + assertThat(params._pathParam(1)).isEqualTo("sthr_011CZkZVWa6oIjw0rgXZpnBt") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } + + @Test + fun headers() { + val params = + EventStreamParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + + val headers = params._headers() + + assertThat(headers) + .isEqualTo( + Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() + ) + } + + @Test + fun headersWithoutOptionalFields() { + val params = + EventStreamParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .build() + + val headers = params._headers() + + assertThat(headers).isEqualTo(Headers.builder().build()) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/BetaUserProfileTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/BetaUserProfileTest.kt index e5d4547ba..8940957de 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/BetaUserProfileTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/BetaUserProfileTest.kt @@ -18,6 +18,7 @@ internal class BetaUserProfileTest { .id("uprof_011CZkZCu8hGbp5mYRQgUmz9") .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .metadata(BetaUserProfile.Metadata.builder().build()) + .relationship(BetaUserProfile.Relationship.EXTERNAL) .trustGrants( BetaUserProfile.TrustGrants.builder() .putAdditionalProperty("cyber", JsonValue.from(mapOf("status" to "active"))) @@ -26,12 +27,14 @@ internal class BetaUserProfileTest { .type(BetaUserProfile.Type.USER_PROFILE) .updatedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .externalId("user_12345") + .name("Example User") .build() assertThat(betaUserProfile.id()).isEqualTo("uprof_011CZkZCu8hGbp5mYRQgUmz9") assertThat(betaUserProfile.createdAt()) .isEqualTo(OffsetDateTime.parse("2026-03-15T10:00:00Z")) assertThat(betaUserProfile.metadata()).isEqualTo(BetaUserProfile.Metadata.builder().build()) + assertThat(betaUserProfile.relationship()).isEqualTo(BetaUserProfile.Relationship.EXTERNAL) assertThat(betaUserProfile.trustGrants()) .isEqualTo( BetaUserProfile.TrustGrants.builder() @@ -42,6 +45,7 @@ internal class BetaUserProfileTest { assertThat(betaUserProfile.updatedAt()) .isEqualTo(OffsetDateTime.parse("2026-03-15T10:00:00Z")) assertThat(betaUserProfile.externalId()).contains("user_12345") + assertThat(betaUserProfile.name()).contains("Example User") } @Test @@ -52,6 +56,7 @@ internal class BetaUserProfileTest { .id("uprof_011CZkZCu8hGbp5mYRQgUmz9") .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .metadata(BetaUserProfile.Metadata.builder().build()) + .relationship(BetaUserProfile.Relationship.EXTERNAL) .trustGrants( BetaUserProfile.TrustGrants.builder() .putAdditionalProperty("cyber", JsonValue.from(mapOf("status" to "active"))) @@ -60,6 +65,7 @@ internal class BetaUserProfileTest { .type(BetaUserProfile.Type.USER_PROFILE) .updatedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .externalId("user_12345") + .name("Example User") .build() val roundtrippedBetaUserProfile = diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/UserProfileCreateParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/UserProfileCreateParamsTest.kt index bc91fba6a..a8dee3c6e 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/UserProfileCreateParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/UserProfileCreateParamsTest.kt @@ -15,6 +15,8 @@ internal class UserProfileCreateParamsTest { .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) .externalId("user_12345") .metadata(UserProfileCreateParams.Metadata.builder().build()) + .name("x") + .relationship(UserProfileCreateParams.Relationship.EXTERNAL) .build() } @@ -25,6 +27,8 @@ internal class UserProfileCreateParamsTest { .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) .externalId("user_12345") .metadata(UserProfileCreateParams.Metadata.builder().build()) + .name("x") + .relationship(UserProfileCreateParams.Relationship.EXTERNAL) .build() val headers = params._headers() @@ -51,12 +55,16 @@ internal class UserProfileCreateParamsTest { .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) .externalId("user_12345") .metadata(UserProfileCreateParams.Metadata.builder().build()) + .name("x") + .relationship(UserProfileCreateParams.Relationship.EXTERNAL) .build() val body = params._body() assertThat(body.externalId()).contains("user_12345") assertThat(body.metadata()).contains(UserProfileCreateParams.Metadata.builder().build()) + assertThat(body.name()).contains("x") + assertThat(body.relationship()).contains(UserProfileCreateParams.Relationship.EXTERNAL) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/UserProfileListPageResponseTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/UserProfileListPageResponseTest.kt index 51c724518..0e1ff85ed 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/UserProfileListPageResponseTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/UserProfileListPageResponseTest.kt @@ -20,6 +20,7 @@ internal class UserProfileListPageResponseTest { .id("uprof_011CZkZCu8hGbp5mYRQgUmz9") .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .metadata(BetaUserProfile.Metadata.builder().build()) + .relationship(BetaUserProfile.Relationship.EXTERNAL) .trustGrants( BetaUserProfile.TrustGrants.builder() .putAdditionalProperty( @@ -31,6 +32,7 @@ internal class UserProfileListPageResponseTest { .type(BetaUserProfile.Type.USER_PROFILE) .updatedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .externalId("user_12345") + .name("Example User") .build() ) .nextPage("page_MjAyNS0wNS0xNFQwMDowMDowMFo=") @@ -42,6 +44,7 @@ internal class UserProfileListPageResponseTest { .id("uprof_011CZkZCu8hGbp5mYRQgUmz9") .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .metadata(BetaUserProfile.Metadata.builder().build()) + .relationship(BetaUserProfile.Relationship.EXTERNAL) .trustGrants( BetaUserProfile.TrustGrants.builder() .putAdditionalProperty( @@ -53,6 +56,7 @@ internal class UserProfileListPageResponseTest { .type(BetaUserProfile.Type.USER_PROFILE) .updatedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .externalId("user_12345") + .name("Example User") .build() ) assertThat(userProfileListPageResponse.nextPage()) @@ -69,6 +73,7 @@ internal class UserProfileListPageResponseTest { .id("uprof_011CZkZCu8hGbp5mYRQgUmz9") .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .metadata(BetaUserProfile.Metadata.builder().build()) + .relationship(BetaUserProfile.Relationship.EXTERNAL) .trustGrants( BetaUserProfile.TrustGrants.builder() .putAdditionalProperty( @@ -80,6 +85,7 @@ internal class UserProfileListPageResponseTest { .type(BetaUserProfile.Type.USER_PROFILE) .updatedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) .externalId("user_12345") + .name("Example User") .build() ) .nextPage("page_MjAyNS0wNS0xNFQwMDowMDowMFo=") diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/UserProfileUpdateParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/UserProfileUpdateParamsTest.kt index 0fed1abd1..47e35d92d 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/UserProfileUpdateParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/userprofiles/UserProfileUpdateParamsTest.kt @@ -21,6 +21,8 @@ internal class UserProfileUpdateParamsTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .name("x") + .relationship(UserProfileUpdateParams.Relationship.EXTERNAL) .build() } @@ -48,6 +50,8 @@ internal class UserProfileUpdateParamsTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .name("x") + .relationship(UserProfileUpdateParams.Relationship.EXTERNAL) .build() val headers = params._headers() @@ -82,6 +86,8 @@ internal class UserProfileUpdateParamsTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .name("x") + .relationship(UserProfileUpdateParams.Relationship.EXTERNAL) .build() val body = params._body() @@ -93,6 +99,8 @@ internal class UserProfileUpdateParamsTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + assertThat(body.name()).contains("x") + assertThat(body.relationship()).contains(UserProfileUpdateParams.Relationship.EXTERNAL) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsCredentialValidationTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsCredentialValidationTest.kt new file mode 100644 index 000000000..c2a41f8e0 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsCredentialValidationTest.kt @@ -0,0 +1,140 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.vaults.credentials + +import com.anthropic.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 BetaManagedAgentsCredentialValidationTest { + + @Test + fun create() { + val betaManagedAgentsCredentialValidation = + BetaManagedAgentsCredentialValidation.builder() + .credentialId("vcrd_011CZkZEMt8gZan2iYOQfSkw") + .hasRefreshToken(true) + .mcpProbe( + BetaManagedAgentsMcpProbe.builder() + .httpResponse( + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + ) + .method("method") + .build() + ) + .refresh( + BetaManagedAgentsRefreshObject.builder() + .httpResponse( + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + ) + .status(BetaManagedAgentsRefreshObject.Status.SUCCEEDED) + .build() + ) + .status(BetaManagedAgentsCredentialValidationStatus.VALID) + .type(BetaManagedAgentsCredentialValidation.Type.VAULT_CREDENTIAL_VALIDATION) + .validatedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .vaultId("vlt_011CZkZDLs7fYzm1hXNPeRjv") + .build() + + assertThat(betaManagedAgentsCredentialValidation.credentialId()) + .isEqualTo("vcrd_011CZkZEMt8gZan2iYOQfSkw") + assertThat(betaManagedAgentsCredentialValidation.hasRefreshToken()).isEqualTo(true) + assertThat(betaManagedAgentsCredentialValidation.mcpProbe()) + .contains( + BetaManagedAgentsMcpProbe.builder() + .httpResponse( + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + ) + .method("method") + .build() + ) + assertThat(betaManagedAgentsCredentialValidation.refresh()) + .contains( + BetaManagedAgentsRefreshObject.builder() + .httpResponse( + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + ) + .status(BetaManagedAgentsRefreshObject.Status.SUCCEEDED) + .build() + ) + assertThat(betaManagedAgentsCredentialValidation.status()) + .isEqualTo(BetaManagedAgentsCredentialValidationStatus.VALID) + assertThat(betaManagedAgentsCredentialValidation.type()) + .isEqualTo(BetaManagedAgentsCredentialValidation.Type.VAULT_CREDENTIAL_VALIDATION) + assertThat(betaManagedAgentsCredentialValidation.validatedAt()) + .isEqualTo(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + assertThat(betaManagedAgentsCredentialValidation.vaultId()) + .isEqualTo("vlt_011CZkZDLs7fYzm1hXNPeRjv") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsCredentialValidation = + BetaManagedAgentsCredentialValidation.builder() + .credentialId("vcrd_011CZkZEMt8gZan2iYOQfSkw") + .hasRefreshToken(true) + .mcpProbe( + BetaManagedAgentsMcpProbe.builder() + .httpResponse( + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + ) + .method("method") + .build() + ) + .refresh( + BetaManagedAgentsRefreshObject.builder() + .httpResponse( + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + ) + .status(BetaManagedAgentsRefreshObject.Status.SUCCEEDED) + .build() + ) + .status(BetaManagedAgentsCredentialValidationStatus.VALID) + .type(BetaManagedAgentsCredentialValidation.Type.VAULT_CREDENTIAL_VALIDATION) + .validatedAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .vaultId("vlt_011CZkZDLs7fYzm1hXNPeRjv") + .build() + + val roundtrippedBetaManagedAgentsCredentialValidation = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsCredentialValidation), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsCredentialValidation) + .isEqualTo(betaManagedAgentsCredentialValidation) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsMcpProbeTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsMcpProbeTest.kt new file mode 100644 index 000000000..34e003c22 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsMcpProbeTest.kt @@ -0,0 +1,63 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.vaults.credentials + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsMcpProbeTest { + + @Test + fun create() { + val betaManagedAgentsMcpProbe = + BetaManagedAgentsMcpProbe.builder() + .httpResponse( + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + ) + .method("method") + .build() + + assertThat(betaManagedAgentsMcpProbe.httpResponse()) + .contains( + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + ) + assertThat(betaManagedAgentsMcpProbe.method()).isEqualTo("method") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsMcpProbe = + BetaManagedAgentsMcpProbe.builder() + .httpResponse( + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + ) + .method("method") + .build() + + val roundtrippedBetaManagedAgentsMcpProbe = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsMcpProbe), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsMcpProbe).isEqualTo(betaManagedAgentsMcpProbe) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshHttpResponseTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshHttpResponseTest.kt new file mode 100644 index 000000000..ec1698377 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshHttpResponseTest.kt @@ -0,0 +1,48 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.vaults.credentials + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsRefreshHttpResponseTest { + + @Test + fun create() { + val betaManagedAgentsRefreshHttpResponse = + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + + assertThat(betaManagedAgentsRefreshHttpResponse.body()).isEqualTo("body") + assertThat(betaManagedAgentsRefreshHttpResponse.bodyTruncated()).isEqualTo(true) + assertThat(betaManagedAgentsRefreshHttpResponse.contentType()).isEqualTo("content_type") + assertThat(betaManagedAgentsRefreshHttpResponse.statusCode()).isEqualTo(0) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsRefreshHttpResponse = + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + + val roundtrippedBetaManagedAgentsRefreshHttpResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsRefreshHttpResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsRefreshHttpResponse) + .isEqualTo(betaManagedAgentsRefreshHttpResponse) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshObjectTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshObjectTest.kt new file mode 100644 index 000000000..3890ee1b0 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/BetaManagedAgentsRefreshObjectTest.kt @@ -0,0 +1,65 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.vaults.credentials + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaManagedAgentsRefreshObjectTest { + + @Test + fun create() { + val betaManagedAgentsRefreshObject = + BetaManagedAgentsRefreshObject.builder() + .httpResponse( + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + ) + .status(BetaManagedAgentsRefreshObject.Status.SUCCEEDED) + .build() + + assertThat(betaManagedAgentsRefreshObject.httpResponse()) + .contains( + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + ) + assertThat(betaManagedAgentsRefreshObject.status()) + .isEqualTo(BetaManagedAgentsRefreshObject.Status.SUCCEEDED) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaManagedAgentsRefreshObject = + BetaManagedAgentsRefreshObject.builder() + .httpResponse( + BetaManagedAgentsRefreshHttpResponse.builder() + .body("body") + .bodyTruncated(true) + .contentType("content_type") + .statusCode(0) + .build() + ) + .status(BetaManagedAgentsRefreshObject.Status.SUCCEEDED) + .build() + + val roundtrippedBetaManagedAgentsRefreshObject = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaManagedAgentsRefreshObject), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaManagedAgentsRefreshObject) + .isEqualTo(betaManagedAgentsRefreshObject) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/CredentialMcpOAuthValidateParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/CredentialMcpOAuthValidateParamsTest.kt new file mode 100644 index 000000000..3a2f43e15 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/vaults/credentials/CredentialMcpOAuthValidateParamsTest.kt @@ -0,0 +1,64 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.vaults.credentials + +import com.anthropic.core.http.Headers +import com.anthropic.models.beta.AnthropicBeta +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CredentialMcpOAuthValidateParamsTest { + + @Test + fun create() { + CredentialMcpOAuthValidateParams.builder() + .vaultId("vlt_011CZkZDLs7fYzm1hXNPeRjv") + .credentialId("vcrd_011CZkZEMt8gZan2iYOQfSkw") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + } + + @Test + fun pathParams() { + val params = + CredentialMcpOAuthValidateParams.builder() + .vaultId("vlt_011CZkZDLs7fYzm1hXNPeRjv") + .credentialId("vcrd_011CZkZEMt8gZan2iYOQfSkw") + .build() + + assertThat(params._pathParam(0)).isEqualTo("vlt_011CZkZDLs7fYzm1hXNPeRjv") + assertThat(params._pathParam(1)).isEqualTo("vcrd_011CZkZEMt8gZan2iYOQfSkw") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } + + @Test + fun headers() { + val params = + CredentialMcpOAuthValidateParams.builder() + .vaultId("vlt_011CZkZDLs7fYzm1hXNPeRjv") + .credentialId("vcrd_011CZkZEMt8gZan2iYOQfSkw") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + + val headers = params._headers() + + assertThat(headers) + .isEqualTo( + Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() + ) + } + + @Test + fun headersWithoutOptionalFields() { + val params = + CredentialMcpOAuthValidateParams.builder() + .vaultId("vlt_011CZkZDLs7fYzm1hXNPeRjv") + .credentialId("vcrd_011CZkZEMt8gZan2iYOQfSkw") + .build() + + val headers = params._headers() + + assertThat(headers).isEqualTo(Headers.builder().build()) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventDataTest.kt new file mode 100644 index 000000000..18747fbad --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventDataTest.kt @@ -0,0 +1,1286 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.JsonValue +import com.anthropic.core.jsonMapper +import com.anthropic.errors.AnthropicInvalidDataException +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +internal class BetaWebhookEventDataTest { + + @Test + fun ofSessionCreated() { + val sessionCreated = + BetaWebhookSessionCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = BetaWebhookEventData.ofSessionCreated(sessionCreated) + + assertThat(betaWebhookEventData.sessionCreated()).contains(sessionCreated) + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionCreatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionCreated( + BetaWebhookSessionCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionPending() { + val sessionPending = + BetaWebhookSessionPendingEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = BetaWebhookEventData.ofSessionPending(sessionPending) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).contains(sessionPending) + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionPendingRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionPending( + BetaWebhookSessionPendingEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionRunning() { + val sessionRunning = + BetaWebhookSessionRunningEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = BetaWebhookEventData.ofSessionRunning(sessionRunning) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).contains(sessionRunning) + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionRunningRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionRunning( + BetaWebhookSessionRunningEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionIdled() { + val sessionIdled = + BetaWebhookSessionIdledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = BetaWebhookEventData.ofSessionIdled(sessionIdled) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).contains(sessionIdled) + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionIdledRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionIdled( + BetaWebhookSessionIdledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionRequiresAction() { + val sessionRequiresAction = + BetaWebhookSessionRequiresActionEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = + BetaWebhookEventData.ofSessionRequiresAction(sessionRequiresAction) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).contains(sessionRequiresAction) + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionRequiresActionRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionRequiresAction( + BetaWebhookSessionRequiresActionEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionArchived() { + val sessionArchived = + BetaWebhookSessionArchivedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = BetaWebhookEventData.ofSessionArchived(sessionArchived) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).contains(sessionArchived) + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionArchivedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionArchived( + BetaWebhookSessionArchivedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionDeleted() { + val sessionDeleted = + BetaWebhookSessionDeletedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = BetaWebhookEventData.ofSessionDeleted(sessionDeleted) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).contains(sessionDeleted) + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionDeletedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionDeleted( + BetaWebhookSessionDeletedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionStatusScheduled() { + val sessionStatusScheduled = + BetaWebhookSessionStatusScheduledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = + BetaWebhookEventData.ofSessionStatusScheduled(sessionStatusScheduled) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).contains(sessionStatusScheduled) + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionStatusScheduledRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionStatusScheduled( + BetaWebhookSessionStatusScheduledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionStatusRunStarted() { + val sessionStatusRunStarted = + BetaWebhookSessionStatusRunStartedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = + BetaWebhookEventData.ofSessionStatusRunStarted(sessionStatusRunStarted) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).contains(sessionStatusRunStarted) + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionStatusRunStartedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionStatusRunStarted( + BetaWebhookSessionStatusRunStartedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionStatusIdled() { + val sessionStatusIdled = + BetaWebhookSessionStatusIdledEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + + val betaWebhookEventData = BetaWebhookEventData.ofSessionStatusIdled(sessionStatusIdled) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).contains(sessionStatusIdled) + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionStatusIdledRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionStatusIdled( + BetaWebhookSessionStatusIdledEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionStatusTerminated() { + val sessionStatusTerminated = + BetaWebhookSessionStatusTerminatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = + BetaWebhookEventData.ofSessionStatusTerminated(sessionStatusTerminated) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).contains(sessionStatusTerminated) + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionStatusTerminatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionStatusTerminated( + BetaWebhookSessionStatusTerminatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionThreadCreated() { + val sessionThreadCreated = + BetaWebhookSessionThreadCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = BetaWebhookEventData.ofSessionThreadCreated(sessionThreadCreated) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).contains(sessionThreadCreated) + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionThreadCreatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionThreadCreated( + BetaWebhookSessionThreadCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionThreadIdled() { + val sessionThreadIdled = + BetaWebhookSessionThreadIdledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = BetaWebhookEventData.ofSessionThreadIdled(sessionThreadIdled) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).contains(sessionThreadIdled) + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionThreadIdledRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionThreadIdled( + BetaWebhookSessionThreadIdledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionThreadTerminated() { + val sessionThreadTerminated = + BetaWebhookSessionThreadTerminatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = + BetaWebhookEventData.ofSessionThreadTerminated(sessionThreadTerminated) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).contains(sessionThreadTerminated) + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionThreadTerminatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionThreadTerminated( + BetaWebhookSessionThreadTerminatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofSessionOutcomeEvaluationEnded() { + val sessionOutcomeEvaluationEnded = + BetaWebhookSessionOutcomeEvaluationEndedEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + + val betaWebhookEventData = + BetaWebhookEventData.ofSessionOutcomeEvaluationEnded(sessionOutcomeEvaluationEnded) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()) + .contains(sessionOutcomeEvaluationEnded) + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofSessionOutcomeEvaluationEndedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofSessionOutcomeEvaluationEnded( + BetaWebhookSessionOutcomeEvaluationEndedEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofVaultCreated() { + val vaultCreated = + BetaWebhookVaultCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = BetaWebhookEventData.ofVaultCreated(vaultCreated) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).contains(vaultCreated) + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofVaultCreatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofVaultCreated( + BetaWebhookVaultCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofVaultArchived() { + val vaultArchived = + BetaWebhookVaultArchivedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = BetaWebhookEventData.ofVaultArchived(vaultArchived) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).contains(vaultArchived) + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofVaultArchivedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofVaultArchived( + BetaWebhookVaultArchivedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofVaultDeleted() { + val vaultDeleted = + BetaWebhookVaultDeletedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = BetaWebhookEventData.ofVaultDeleted(vaultDeleted) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).contains(vaultDeleted) + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofVaultDeletedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofVaultDeleted( + BetaWebhookVaultDeletedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofVaultCredentialCreated() { + val vaultCredentialCreated = + BetaWebhookVaultCredentialCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = + BetaWebhookEventData.ofVaultCredentialCreated(vaultCredentialCreated) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).contains(vaultCredentialCreated) + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofVaultCredentialCreatedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofVaultCredentialCreated( + BetaWebhookVaultCredentialCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofVaultCredentialArchived() { + val vaultCredentialArchived = + BetaWebhookVaultCredentialArchivedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = + BetaWebhookEventData.ofVaultCredentialArchived(vaultCredentialArchived) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).contains(vaultCredentialArchived) + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofVaultCredentialArchivedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofVaultCredentialArchived( + BetaWebhookVaultCredentialArchivedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofVaultCredentialDeleted() { + val vaultCredentialDeleted = + BetaWebhookVaultCredentialDeletedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = + BetaWebhookEventData.ofVaultCredentialDeleted(vaultCredentialDeleted) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).contains(vaultCredentialDeleted) + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()).isEmpty + } + + @Test + fun ofVaultCredentialDeletedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofVaultCredentialDeleted( + BetaWebhookVaultCredentialDeletedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + @Test + fun ofVaultCredentialRefreshFailed() { + val vaultCredentialRefreshFailed = + BetaWebhookVaultCredentialRefreshFailedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + + val betaWebhookEventData = + BetaWebhookEventData.ofVaultCredentialRefreshFailed(vaultCredentialRefreshFailed) + + assertThat(betaWebhookEventData.sessionCreated()).isEmpty + assertThat(betaWebhookEventData.sessionPending()).isEmpty + assertThat(betaWebhookEventData.sessionRunning()).isEmpty + assertThat(betaWebhookEventData.sessionIdled()).isEmpty + assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty + assertThat(betaWebhookEventData.sessionArchived()).isEmpty + assertThat(betaWebhookEventData.sessionDeleted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty + assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadCreated()).isEmpty + assertThat(betaWebhookEventData.sessionThreadIdled()).isEmpty + assertThat(betaWebhookEventData.sessionThreadTerminated()).isEmpty + assertThat(betaWebhookEventData.sessionOutcomeEvaluationEnded()).isEmpty + assertThat(betaWebhookEventData.vaultCreated()).isEmpty + assertThat(betaWebhookEventData.vaultArchived()).isEmpty + assertThat(betaWebhookEventData.vaultDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialCreated()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialArchived()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialDeleted()).isEmpty + assertThat(betaWebhookEventData.vaultCredentialRefreshFailed()) + .contains(vaultCredentialRefreshFailed) + } + + @Test + fun ofVaultCredentialRefreshFailedRoundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEventData = + BetaWebhookEventData.ofVaultCredentialRefreshFailed( + BetaWebhookVaultCredentialRefreshFailedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + ) + + val roundtrippedBetaWebhookEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEventData).isEqualTo(betaWebhookEventData) + } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + STRING(JsonValue.from("invalid")), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val betaWebhookEventData = + jsonMapper().convertValue(testCase.value, jacksonTypeRef()) + + val e = assertThrows { betaWebhookEventData.validate() } + assertThat(e).hasMessageStartingWith("Unknown ") + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventTest.kt new file mode 100644 index 000000000..6f1545e95 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventTest.kt @@ -0,0 +1,67 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.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 BetaWebhookEventTest { + + @Test + fun create() { + val betaWebhookEvent = + BetaWebhookEvent.builder() + .id("wevt_011CZkZYZd9rLmz3ujAcsqEw") + .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .data( + BetaWebhookSessionStatusIdledEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + ) + .build() + + assertThat(betaWebhookEvent.id()).isEqualTo("wevt_011CZkZYZd9rLmz3ujAcsqEw") + assertThat(betaWebhookEvent.createdAt()) + .isEqualTo(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + assertThat(betaWebhookEvent.data()) + .isEqualTo( + BetaWebhookEventData.ofSessionStatusIdled( + BetaWebhookSessionStatusIdledEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + ) + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookEvent = + BetaWebhookEvent.builder() + .id("wevt_011CZkZYZd9rLmz3ujAcsqEw") + .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .data( + BetaWebhookSessionStatusIdledEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + ) + .build() + + val roundtrippedBetaWebhookEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookEvent).isEqualTo(betaWebhookEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionArchivedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionArchivedEventDataTest.kt new file mode 100644 index 000000000..e88b5f603 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionArchivedEventDataTest.kt @@ -0,0 +1,46 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionArchivedEventDataTest { + + @Test + fun create() { + val betaWebhookSessionArchivedEventData = + BetaWebhookSessionArchivedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionArchivedEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionArchivedEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookSessionArchivedEventData.workspaceId()).isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionArchivedEventData = + BetaWebhookSessionArchivedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionArchivedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionArchivedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionArchivedEventData) + .isEqualTo(betaWebhookSessionArchivedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionCreatedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionCreatedEventDataTest.kt new file mode 100644 index 000000000..b501a98fe --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionCreatedEventDataTest.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionCreatedEventDataTest { + + @Test + fun create() { + val betaWebhookSessionCreatedEventData = + BetaWebhookSessionCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionCreatedEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionCreatedEventData.organizationId()).isEqualTo("organization_id") + assertThat(betaWebhookSessionCreatedEventData.workspaceId()).isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionCreatedEventData = + BetaWebhookSessionCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionCreatedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionCreatedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionCreatedEventData) + .isEqualTo(betaWebhookSessionCreatedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionDeletedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionDeletedEventDataTest.kt new file mode 100644 index 000000000..3400aad81 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionDeletedEventDataTest.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionDeletedEventDataTest { + + @Test + fun create() { + val betaWebhookSessionDeletedEventData = + BetaWebhookSessionDeletedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionDeletedEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionDeletedEventData.organizationId()).isEqualTo("organization_id") + assertThat(betaWebhookSessionDeletedEventData.workspaceId()).isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionDeletedEventData = + BetaWebhookSessionDeletedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionDeletedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionDeletedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionDeletedEventData) + .isEqualTo(betaWebhookSessionDeletedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionIdledEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionIdledEventDataTest.kt new file mode 100644 index 000000000..9f9236ef7 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionIdledEventDataTest.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionIdledEventDataTest { + + @Test + fun create() { + val betaWebhookSessionIdledEventData = + BetaWebhookSessionIdledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionIdledEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionIdledEventData.organizationId()).isEqualTo("organization_id") + assertThat(betaWebhookSessionIdledEventData.workspaceId()).isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionIdledEventData = + BetaWebhookSessionIdledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionIdledEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionIdledEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionIdledEventData) + .isEqualTo(betaWebhookSessionIdledEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionOutcomeEvaluationEndedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionOutcomeEvaluationEndedEventDataTest.kt new file mode 100644 index 000000000..1b6e439e4 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionOutcomeEvaluationEndedEventDataTest.kt @@ -0,0 +1,48 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionOutcomeEvaluationEndedEventDataTest { + + @Test + fun create() { + val betaWebhookSessionOutcomeEvaluationEndedEventData = + BetaWebhookSessionOutcomeEvaluationEndedEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + + assertThat(betaWebhookSessionOutcomeEvaluationEndedEventData.id()) + .isEqualTo("sesn_011CZkZAtmR3yMPDzynEDxu7") + assertThat(betaWebhookSessionOutcomeEvaluationEndedEventData.organizationId()) + .isEqualTo("org_011CZkZZAe0sMna4vkBdtrfx") + assertThat(betaWebhookSessionOutcomeEvaluationEndedEventData.workspaceId()) + .isEqualTo("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionOutcomeEvaluationEndedEventData = + BetaWebhookSessionOutcomeEvaluationEndedEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + + val roundtrippedBetaWebhookSessionOutcomeEvaluationEndedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionOutcomeEvaluationEndedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionOutcomeEvaluationEndedEventData) + .isEqualTo(betaWebhookSessionOutcomeEvaluationEndedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionPendingEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionPendingEventDataTest.kt new file mode 100644 index 000000000..f31389ba6 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionPendingEventDataTest.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionPendingEventDataTest { + + @Test + fun create() { + val betaWebhookSessionPendingEventData = + BetaWebhookSessionPendingEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionPendingEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionPendingEventData.organizationId()).isEqualTo("organization_id") + assertThat(betaWebhookSessionPendingEventData.workspaceId()).isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionPendingEventData = + BetaWebhookSessionPendingEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionPendingEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionPendingEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionPendingEventData) + .isEqualTo(betaWebhookSessionPendingEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRequiresActionEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRequiresActionEventDataTest.kt new file mode 100644 index 000000000..7fb001a73 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRequiresActionEventDataTest.kt @@ -0,0 +1,47 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionRequiresActionEventDataTest { + + @Test + fun create() { + val betaWebhookSessionRequiresActionEventData = + BetaWebhookSessionRequiresActionEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionRequiresActionEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionRequiresActionEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookSessionRequiresActionEventData.workspaceId()) + .isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionRequiresActionEventData = + BetaWebhookSessionRequiresActionEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionRequiresActionEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionRequiresActionEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionRequiresActionEventData) + .isEqualTo(betaWebhookSessionRequiresActionEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRunningEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRunningEventDataTest.kt new file mode 100644 index 000000000..ab0e72f33 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionRunningEventDataTest.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionRunningEventDataTest { + + @Test + fun create() { + val betaWebhookSessionRunningEventData = + BetaWebhookSessionRunningEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionRunningEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionRunningEventData.organizationId()).isEqualTo("organization_id") + assertThat(betaWebhookSessionRunningEventData.workspaceId()).isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionRunningEventData = + BetaWebhookSessionRunningEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionRunningEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionRunningEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionRunningEventData) + .isEqualTo(betaWebhookSessionRunningEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusIdledEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusIdledEventDataTest.kt new file mode 100644 index 000000000..a0a514574 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusIdledEventDataTest.kt @@ -0,0 +1,48 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionStatusIdledEventDataTest { + + @Test + fun create() { + val betaWebhookSessionStatusIdledEventData = + BetaWebhookSessionStatusIdledEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + + assertThat(betaWebhookSessionStatusIdledEventData.id()) + .isEqualTo("sesn_011CZkZAtmR3yMPDzynEDxu7") + assertThat(betaWebhookSessionStatusIdledEventData.organizationId()) + .isEqualTo("org_011CZkZZAe0sMna4vkBdtrfx") + assertThat(betaWebhookSessionStatusIdledEventData.workspaceId()) + .isEqualTo("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionStatusIdledEventData = + BetaWebhookSessionStatusIdledEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + + val roundtrippedBetaWebhookSessionStatusIdledEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionStatusIdledEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionStatusIdledEventData) + .isEqualTo(betaWebhookSessionStatusIdledEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRunStartedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRunStartedEventDataTest.kt new file mode 100644 index 000000000..738589f8b --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRunStartedEventDataTest.kt @@ -0,0 +1,47 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionStatusRunStartedEventDataTest { + + @Test + fun create() { + val betaWebhookSessionStatusRunStartedEventData = + BetaWebhookSessionStatusRunStartedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionStatusRunStartedEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionStatusRunStartedEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookSessionStatusRunStartedEventData.workspaceId()) + .isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionStatusRunStartedEventData = + BetaWebhookSessionStatusRunStartedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionStatusRunStartedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionStatusRunStartedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionStatusRunStartedEventData) + .isEqualTo(betaWebhookSessionStatusRunStartedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventDataTest.kt new file mode 100644 index 000000000..ccb353c25 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventDataTest.kt @@ -0,0 +1,47 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionStatusScheduledEventDataTest { + + @Test + fun create() { + val betaWebhookSessionStatusScheduledEventData = + BetaWebhookSessionStatusScheduledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionStatusScheduledEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionStatusScheduledEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookSessionStatusScheduledEventData.workspaceId()) + .isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionStatusScheduledEventData = + BetaWebhookSessionStatusScheduledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionStatusScheduledEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionStatusScheduledEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionStatusScheduledEventData) + .isEqualTo(betaWebhookSessionStatusScheduledEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusTerminatedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusTerminatedEventDataTest.kt new file mode 100644 index 000000000..b2cd74008 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusTerminatedEventDataTest.kt @@ -0,0 +1,47 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionStatusTerminatedEventDataTest { + + @Test + fun create() { + val betaWebhookSessionStatusTerminatedEventData = + BetaWebhookSessionStatusTerminatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionStatusTerminatedEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionStatusTerminatedEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookSessionStatusTerminatedEventData.workspaceId()) + .isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionStatusTerminatedEventData = + BetaWebhookSessionStatusTerminatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionStatusTerminatedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionStatusTerminatedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionStatusTerminatedEventData) + .isEqualTo(betaWebhookSessionStatusTerminatedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadCreatedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadCreatedEventDataTest.kt new file mode 100644 index 000000000..16f3bfb2a --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadCreatedEventDataTest.kt @@ -0,0 +1,46 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionThreadCreatedEventDataTest { + + @Test + fun create() { + val betaWebhookSessionThreadCreatedEventData = + BetaWebhookSessionThreadCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionThreadCreatedEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionThreadCreatedEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookSessionThreadCreatedEventData.workspaceId()).isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionThreadCreatedEventData = + BetaWebhookSessionThreadCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionThreadCreatedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionThreadCreatedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionThreadCreatedEventData) + .isEqualTo(betaWebhookSessionThreadCreatedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadIdledEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadIdledEventDataTest.kt new file mode 100644 index 000000000..8b0932522 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadIdledEventDataTest.kt @@ -0,0 +1,46 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionThreadIdledEventDataTest { + + @Test + fun create() { + val betaWebhookSessionThreadIdledEventData = + BetaWebhookSessionThreadIdledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionThreadIdledEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionThreadIdledEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookSessionThreadIdledEventData.workspaceId()).isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionThreadIdledEventData = + BetaWebhookSessionThreadIdledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionThreadIdledEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionThreadIdledEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionThreadIdledEventData) + .isEqualTo(betaWebhookSessionThreadIdledEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadTerminatedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadTerminatedEventDataTest.kt new file mode 100644 index 000000000..6cb89f2fc --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionThreadTerminatedEventDataTest.kt @@ -0,0 +1,47 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionThreadTerminatedEventDataTest { + + @Test + fun create() { + val betaWebhookSessionThreadTerminatedEventData = + BetaWebhookSessionThreadTerminatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionThreadTerminatedEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionThreadTerminatedEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookSessionThreadTerminatedEventData.workspaceId()) + .isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionThreadTerminatedEventData = + BetaWebhookSessionThreadTerminatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionThreadTerminatedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionThreadTerminatedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionThreadTerminatedEventData) + .isEqualTo(betaWebhookSessionThreadTerminatedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultArchivedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultArchivedEventDataTest.kt new file mode 100644 index 000000000..1007ec9bb --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultArchivedEventDataTest.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookVaultArchivedEventDataTest { + + @Test + fun create() { + val betaWebhookVaultArchivedEventData = + BetaWebhookVaultArchivedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookVaultArchivedEventData.id()).isEqualTo("id") + assertThat(betaWebhookVaultArchivedEventData.organizationId()).isEqualTo("organization_id") + assertThat(betaWebhookVaultArchivedEventData.workspaceId()).isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookVaultArchivedEventData = + BetaWebhookVaultArchivedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookVaultArchivedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookVaultArchivedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookVaultArchivedEventData) + .isEqualTo(betaWebhookVaultArchivedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCreatedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCreatedEventDataTest.kt new file mode 100644 index 000000000..7dd9cb029 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCreatedEventDataTest.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookVaultCreatedEventDataTest { + + @Test + fun create() { + val betaWebhookVaultCreatedEventData = + BetaWebhookVaultCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookVaultCreatedEventData.id()).isEqualTo("id") + assertThat(betaWebhookVaultCreatedEventData.organizationId()).isEqualTo("organization_id") + assertThat(betaWebhookVaultCreatedEventData.workspaceId()).isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookVaultCreatedEventData = + BetaWebhookVaultCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookVaultCreatedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookVaultCreatedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookVaultCreatedEventData) + .isEqualTo(betaWebhookVaultCreatedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialArchivedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialArchivedEventDataTest.kt new file mode 100644 index 000000000..46a853c42 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialArchivedEventDataTest.kt @@ -0,0 +1,50 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookVaultCredentialArchivedEventDataTest { + + @Test + fun create() { + val betaWebhookVaultCredentialArchivedEventData = + BetaWebhookVaultCredentialArchivedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookVaultCredentialArchivedEventData.id()).isEqualTo("id") + assertThat(betaWebhookVaultCredentialArchivedEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookVaultCredentialArchivedEventData.vaultId()).isEqualTo("vault_id") + assertThat(betaWebhookVaultCredentialArchivedEventData.workspaceId()) + .isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookVaultCredentialArchivedEventData = + BetaWebhookVaultCredentialArchivedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookVaultCredentialArchivedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookVaultCredentialArchivedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookVaultCredentialArchivedEventData) + .isEqualTo(betaWebhookVaultCredentialArchivedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialCreatedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialCreatedEventDataTest.kt new file mode 100644 index 000000000..9a614766a --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialCreatedEventDataTest.kt @@ -0,0 +1,50 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookVaultCredentialCreatedEventDataTest { + + @Test + fun create() { + val betaWebhookVaultCredentialCreatedEventData = + BetaWebhookVaultCredentialCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookVaultCredentialCreatedEventData.id()).isEqualTo("id") + assertThat(betaWebhookVaultCredentialCreatedEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookVaultCredentialCreatedEventData.vaultId()).isEqualTo("vault_id") + assertThat(betaWebhookVaultCredentialCreatedEventData.workspaceId()) + .isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookVaultCredentialCreatedEventData = + BetaWebhookVaultCredentialCreatedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookVaultCredentialCreatedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookVaultCredentialCreatedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookVaultCredentialCreatedEventData) + .isEqualTo(betaWebhookVaultCredentialCreatedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialDeletedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialDeletedEventDataTest.kt new file mode 100644 index 000000000..abc60a7b9 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialDeletedEventDataTest.kt @@ -0,0 +1,50 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookVaultCredentialDeletedEventDataTest { + + @Test + fun create() { + val betaWebhookVaultCredentialDeletedEventData = + BetaWebhookVaultCredentialDeletedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookVaultCredentialDeletedEventData.id()).isEqualTo("id") + assertThat(betaWebhookVaultCredentialDeletedEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookVaultCredentialDeletedEventData.vaultId()).isEqualTo("vault_id") + assertThat(betaWebhookVaultCredentialDeletedEventData.workspaceId()) + .isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookVaultCredentialDeletedEventData = + BetaWebhookVaultCredentialDeletedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookVaultCredentialDeletedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookVaultCredentialDeletedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookVaultCredentialDeletedEventData) + .isEqualTo(betaWebhookVaultCredentialDeletedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialRefreshFailedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialRefreshFailedEventDataTest.kt new file mode 100644 index 000000000..88dae8de8 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultCredentialRefreshFailedEventDataTest.kt @@ -0,0 +1,50 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookVaultCredentialRefreshFailedEventDataTest { + + @Test + fun create() { + val betaWebhookVaultCredentialRefreshFailedEventData = + BetaWebhookVaultCredentialRefreshFailedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookVaultCredentialRefreshFailedEventData.id()).isEqualTo("id") + assertThat(betaWebhookVaultCredentialRefreshFailedEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookVaultCredentialRefreshFailedEventData.vaultId()).isEqualTo("vault_id") + assertThat(betaWebhookVaultCredentialRefreshFailedEventData.workspaceId()) + .isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookVaultCredentialRefreshFailedEventData = + BetaWebhookVaultCredentialRefreshFailedEventData.builder() + .id("id") + .organizationId("organization_id") + .vaultId("vault_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookVaultCredentialRefreshFailedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookVaultCredentialRefreshFailedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookVaultCredentialRefreshFailedEventData) + .isEqualTo(betaWebhookVaultCredentialRefreshFailedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultDeletedEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultDeletedEventDataTest.kt new file mode 100644 index 000000000..85bd110dd --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookVaultDeletedEventDataTest.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookVaultDeletedEventDataTest { + + @Test + fun create() { + val betaWebhookVaultDeletedEventData = + BetaWebhookVaultDeletedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookVaultDeletedEventData.id()).isEqualTo("id") + assertThat(betaWebhookVaultDeletedEventData.organizationId()).isEqualTo("organization_id") + assertThat(betaWebhookVaultDeletedEventData.workspaceId()).isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookVaultDeletedEventData = + BetaWebhookVaultDeletedEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookVaultDeletedEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookVaultDeletedEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookVaultDeletedEventData) + .isEqualTo(betaWebhookVaultDeletedEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/UnwrapWebhookEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/UnwrapWebhookEventTest.kt new file mode 100644 index 000000000..aeadce626 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/UnwrapWebhookEventTest.kt @@ -0,0 +1,67 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.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 UnwrapWebhookEventTest { + + @Test + fun create() { + val unwrapWebhookEvent = + UnwrapWebhookEvent.builder() + .id("wevt_011CZkZYZd9rLmz3ujAcsqEw") + .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .data( + BetaWebhookSessionStatusIdledEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + ) + .build() + + assertThat(unwrapWebhookEvent.id()).isEqualTo("wevt_011CZkZYZd9rLmz3ujAcsqEw") + assertThat(unwrapWebhookEvent.createdAt()) + .isEqualTo(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + assertThat(unwrapWebhookEvent.data()) + .isEqualTo( + BetaWebhookEventData.ofSessionStatusIdled( + BetaWebhookSessionStatusIdledEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + ) + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val unwrapWebhookEvent = + UnwrapWebhookEvent.builder() + .id("wevt_011CZkZYZd9rLmz3ujAcsqEw") + .createdAt(OffsetDateTime.parse("2026-03-15T10:00:00Z")) + .data( + BetaWebhookSessionStatusIdledEventData.builder() + .id("sesn_011CZkZAtmR3yMPDzynEDxu7") + .organizationId("org_011CZkZZAe0sMna4vkBdtrfx") + .workspaceId("wrkspc_011CZkZaBF1tNoB5wlCeusgy") + .build() + ) + .build() + + val roundtrippedUnwrapWebhookEvent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(unwrapWebhookEvent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedUnwrapWebhookEvent).isEqualTo(unwrapWebhookEvent) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/AgentServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/AgentServiceAsyncTest.kt index 007ebd1f3..265dd814e 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/AgentServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/AgentServiceAsyncTest.kt @@ -17,7 +17,9 @@ import com.anthropic.models.beta.agents.BetaManagedAgentsAlwaysAllowPolicy import com.anthropic.models.beta.agents.BetaManagedAgentsAnthropicSkillParams import com.anthropic.models.beta.agents.BetaManagedAgentsModel import com.anthropic.models.beta.agents.BetaManagedAgentsModelConfigParams +import com.anthropic.models.beta.agents.BetaManagedAgentsMultiagentSelfParams import com.anthropic.models.beta.agents.BetaManagedAgentsUrlMcpServerParams +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagentParams import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -53,6 +55,17 @@ internal class AgentServiceAsyncTest { .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) + .multiagent( + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + ) .addSkill( BetaManagedAgentsAnthropicSkillParams.builder() .skillId("xlsx") @@ -160,6 +173,17 @@ internal class AgentServiceAsyncTest { .speed(BetaManagedAgentsModelConfigParams.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + ) .name("name") .addSkill( BetaManagedAgentsAnthropicSkillParams.builder() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/UserProfileServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/UserProfileServiceAsyncTest.kt index f29b49c10..d8ac692a6 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/UserProfileServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/UserProfileServiceAsyncTest.kt @@ -31,6 +31,8 @@ internal class UserProfileServiceAsyncTest { .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) .externalId("user_12345") .metadata(UserProfileCreateParams.Metadata.builder().build()) + .name("x") + .relationship(UserProfileCreateParams.Relationship.EXTERNAL) .build() ) @@ -79,6 +81,8 @@ internal class UserProfileServiceAsyncTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .name("x") + .relationship(UserProfileUpdateParams.Relationship.EXTERNAL) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/WebhookServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/WebhookServiceAsyncTest.kt new file mode 100644 index 000000000..0506e5f0a --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/WebhookServiceAsyncTest.kt @@ -0,0 +1,159 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.async.beta + +import com.anthropic.TestServerExtension +import com.anthropic.client.okhttp.AnthropicOkHttpClientAsync +import com.anthropic.core.UnwrapWebhookParams +import com.anthropic.core.http.Headers +import com.anthropic.errors.AnthropicWebhookException +import com.standardwebhooks.Webhook +import java.time.Instant +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class WebhookServiceAsyncTest { + + @Test + fun unwrap() { + val client = AnthropicOkHttpClientAsync.builder().apiKey("my-anthropic-api-key").build() + val webhookServiceAsync = client.beta().webhooks() + + val payload = + "{\"id\":\"wevt_011CZkZYZd9rLmz3ujAcsqEw\",\"created_at\":\"2026-03-15T10:00:00Z\",\"data\":{\"id\":\"sesn_011CZkZAtmR3yMPDzynEDxu7\",\"organization_id\":\"org_011CZkZZAe0sMna4vkBdtrfx\",\"type\":\"session.status_idled\",\"workspace_id\":\"wrkspc_011CZkZaBF1tNoB5wlCeusgy\"},\"type\":\"event\"}" + val webhookSecret = "whsec_c2VjcmV0Cg==" + val messageId = "1" + val timestampSeconds = Instant.now().epochSecond + val webhook = Webhook(webhookSecret) + val signature = webhook.sign(messageId, timestampSeconds, payload) + val headers = + Headers.builder() + .putAll( + mapOf( + "webhook-signature" to listOf(signature), + "webhook-id" to listOf(messageId), + "webhook-timestamp" to listOf(timestampSeconds.toString()), + ) + ) + .build() + + // Correct key should not throw + webhookServiceAsync.unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(headers) + .secret(webhookSecret) + .build() + ) + webhookServiceAsync + .withOptions { it.webhookKey(webhookSecret) } + .unwrap(UnwrapWebhookParams.builder().body(payload).headers(headers).build()) + + // Secret in method takes precedence to secret on client + val wrongKey = "whsec_aaaaaaaaaa" + webhookServiceAsync + .withOptions { it.webhookKey(wrongKey) } + .unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(headers) + .secret(webhookSecret) + .build() + ) + + // Wrong key should throw + assertThrows { + val wrongKey = "whsec_aaaaaaaaaa" + webhookServiceAsync.unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(headers) + .secret(wrongKey) + .build() + ) + } + assertThrows { + val wrongKey = "whsec_aaaaaaaaaa" + webhookServiceAsync + .withOptions { it.webhookKey(wrongKey) } + .unwrap(UnwrapWebhookParams.builder().body(payload).headers(headers).build()) + } + + assertThrows { + val wrongKey = "whsec_aaaaaaaaaa" + webhookServiceAsync.unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(headers) + .secret(wrongKey) + .build() + ) + } + assertThrows { + val wrongKey = "whsec_aaaaaaaaaa" + webhookServiceAsync + .withOptions { it.webhookKey(wrongKey) } + .unwrap(UnwrapWebhookParams.builder().body(payload).headers(headers).build()) + } + + // Bad signature should throw + assertThrows { + val badSig = webhook.sign(messageId, timestampSeconds, "some other payload") + val badHeaders = + headers.toBuilder().replace("webhook-signature", listOf(badSig)).build() + webhookServiceAsync.unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(badHeaders) + .secret(webhookSecret) + .build() + ) + } + assertThrows { + val badSig = webhook.sign(messageId, timestampSeconds, "some other payload") + val badHeaders = + headers.toBuilder().replace("webhook-signature", listOf(badSig)).build() + webhookServiceAsync + .withOptions { it.webhookKey(webhookSecret) } + .unwrap(UnwrapWebhookParams.builder().body(payload).headers(badHeaders).build()) + } + + // Old timestamp should throw + assertThrows { + val oldHeaders = headers.toBuilder().replace("webhook-timestamp", listOf("5")).build() + webhookServiceAsync.unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(oldHeaders) + .secret(webhookSecret) + .build() + ) + } + assertThrows { + val oldHeaders = headers.toBuilder().replace("webhook-timestamp", listOf("5")).build() + webhookServiceAsync + .withOptions { it.webhookKey(webhookSecret) } + .unwrap(UnwrapWebhookParams.builder().body(payload).headers(oldHeaders).build()) + } + + // Wrong message ID should throw + assertThrows { + val wrongIdHeaders = headers.toBuilder().replace("webhook-id", listOf("wrong")).build() + webhookServiceAsync.unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(wrongIdHeaders) + .secret(webhookSecret) + .build() + ) + } + assertThrows { + val wrongIdHeaders = headers.toBuilder().replace("webhook-id", listOf("wrong")).build() + webhookServiceAsync + .withOptions { it.webhookKey(webhookSecret) } + .unwrap(UnwrapWebhookParams.builder().body(payload).headers(wrongIdHeaders).build()) + } + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/sessions/ThreadServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/sessions/ThreadServiceAsyncTest.kt new file mode 100644 index 000000000..305f41e8b --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/sessions/ThreadServiceAsyncTest.kt @@ -0,0 +1,76 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.async.beta.sessions + +import com.anthropic.TestServerExtension +import com.anthropic.client.okhttp.AnthropicOkHttpClientAsync +import com.anthropic.models.beta.AnthropicBeta +import com.anthropic.models.beta.sessions.threads.ThreadArchiveParams +import com.anthropic.models.beta.sessions.threads.ThreadRetrieveParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class ThreadServiceAsyncTest { + + @Test + fun retrieve() { + val client = + AnthropicOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("my-anthropic-api-key") + .build() + val threadServiceAsync = client.beta().sessions().threads() + + val betaManagedAgentsSessionThreadFuture = + threadServiceAsync.retrieve( + ThreadRetrieveParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + ) + + val betaManagedAgentsSessionThread = betaManagedAgentsSessionThreadFuture.get() + betaManagedAgentsSessionThread.validate() + } + + @Disabled("buildURL drops path-level query params (SDK-4349)") + @Test + fun list() { + val client = + AnthropicOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("my-anthropic-api-key") + .build() + val threadServiceAsync = client.beta().sessions().threads() + + val pageFuture = threadServiceAsync.list("sesn_011CZkZAtmR3yMPDzynEDxu7") + + val page = pageFuture.get() + page.response().validate() + } + + @Test + fun archive() { + val client = + AnthropicOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("my-anthropic-api-key") + .build() + val threadServiceAsync = client.beta().sessions().threads() + + val betaManagedAgentsSessionThreadFuture = + threadServiceAsync.archive( + ThreadArchiveParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + ) + + val betaManagedAgentsSessionThread = betaManagedAgentsSessionThreadFuture.get() + betaManagedAgentsSessionThread.validate() + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/sessions/threads/EventServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/sessions/threads/EventServiceAsyncTest.kt new file mode 100644 index 000000000..7782cf962 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/sessions/threads/EventServiceAsyncTest.kt @@ -0,0 +1,65 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.async.beta.sessions.threads + +import com.anthropic.TestServerExtension +import com.anthropic.client.okhttp.AnthropicOkHttpClientAsync +import com.anthropic.models.beta.AnthropicBeta +import com.anthropic.models.beta.sessions.threads.events.EventListParams +import com.anthropic.models.beta.sessions.threads.events.EventStreamParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class EventServiceAsyncTest { + + @Disabled("buildURL drops path-level query params (SDK-4349)") + @Test + fun list() { + val client = + AnthropicOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("my-anthropic-api-key") + .build() + val eventServiceAsync = client.beta().sessions().threads().events() + + val pageFuture = + eventServiceAsync.list( + EventListParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .build() + ) + + val page = pageFuture.get() + page.response().validate() + } + + @Test + fun streamStreaming() { + val client = + AnthropicOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("my-anthropic-api-key") + .build() + val eventServiceAsync = client.beta().sessions().threads().events() + + val betaManagedAgentsStreamSessionThreadEventsStreamResponse = + eventServiceAsync.streamStreaming( + EventStreamParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + ) + + val onCompleteFuture = + betaManagedAgentsStreamSessionThreadEventsStreamResponse + .subscribe { betaManagedAgentsStreamSessionThreadEvents -> + betaManagedAgentsStreamSessionThreadEvents.validate() + } + .onCompleteFuture() + onCompleteFuture.get() + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/vaults/CredentialServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/vaults/CredentialServiceAsyncTest.kt index 549b7a12b..3138eb245 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/vaults/CredentialServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/vaults/CredentialServiceAsyncTest.kt @@ -13,6 +13,7 @@ import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsTokenEndpoi import com.anthropic.models.beta.vaults.credentials.CredentialArchiveParams import com.anthropic.models.beta.vaults.credentials.CredentialCreateParams import com.anthropic.models.beta.vaults.credentials.CredentialDeleteParams +import com.anthropic.models.beta.vaults.credentials.CredentialMcpOAuthValidateParams import com.anthropic.models.beta.vaults.credentials.CredentialRetrieveParams import com.anthropic.models.beta.vaults.credentials.CredentialUpdateParams import java.time.OffsetDateTime @@ -189,4 +190,28 @@ internal class CredentialServiceAsyncTest { val betaManagedAgentsCredential = betaManagedAgentsCredentialFuture.get() betaManagedAgentsCredential.validate() } + + @Disabled("prism can't find endpoint with beta only tag") + @Test + fun mcpOAuthValidate() { + val client = + AnthropicOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("my-anthropic-api-key") + .build() + val credentialServiceAsync = client.beta().vaults().credentials() + + val betaManagedAgentsCredentialValidationFuture = + credentialServiceAsync.mcpOAuthValidate( + CredentialMcpOAuthValidateParams.builder() + .vaultId("vlt_011CZkZDLs7fYzm1hXNPeRjv") + .credentialId("vcrd_011CZkZEMt8gZan2iYOQfSkw") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + ) + + val betaManagedAgentsCredentialValidation = + betaManagedAgentsCredentialValidationFuture.get() + betaManagedAgentsCredentialValidation.validate() + } } diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/AgentServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/AgentServiceTest.kt index c8dcd05a1..62562a31c 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/AgentServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/AgentServiceTest.kt @@ -17,7 +17,9 @@ import com.anthropic.models.beta.agents.BetaManagedAgentsAlwaysAllowPolicy import com.anthropic.models.beta.agents.BetaManagedAgentsAnthropicSkillParams import com.anthropic.models.beta.agents.BetaManagedAgentsModel import com.anthropic.models.beta.agents.BetaManagedAgentsModelConfigParams +import com.anthropic.models.beta.agents.BetaManagedAgentsMultiagentSelfParams import com.anthropic.models.beta.agents.BetaManagedAgentsUrlMcpServerParams +import com.anthropic.models.beta.sessions.BetaManagedAgentsMultiagentParams import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -53,6 +55,17 @@ internal class AgentServiceTest { .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) + .multiagent( + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + ) .addSkill( BetaManagedAgentsAnthropicSkillParams.builder() .skillId("xlsx") @@ -158,6 +171,17 @@ internal class AgentServiceTest { .speed(BetaManagedAgentsModelConfigParams.Speed.STANDARD) .build() ) + .multiagent( + BetaManagedAgentsMultiagentParams.builder() + .addAgent("agent_011CZkYqphY8vELVzwCUpqiQ") + .addAgent( + BetaManagedAgentsMultiagentSelfParams.builder() + .type(BetaManagedAgentsMultiagentSelfParams.Type.SELF) + .build() + ) + .type(BetaManagedAgentsMultiagentParams.Type.COORDINATOR) + .build() + ) .name("name") .addSkill( BetaManagedAgentsAnthropicSkillParams.builder() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/UserProfileServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/UserProfileServiceTest.kt index 0f7d2971e..2acd7442f 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/UserProfileServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/UserProfileServiceTest.kt @@ -31,6 +31,8 @@ internal class UserProfileServiceTest { .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) .externalId("user_12345") .metadata(UserProfileCreateParams.Metadata.builder().build()) + .name("x") + .relationship(UserProfileCreateParams.Relationship.EXTERNAL) .build() ) @@ -77,6 +79,8 @@ internal class UserProfileServiceTest { .putAdditionalProperty("foo", JsonValue.from("string")) .build() ) + .name("x") + .relationship(UserProfileUpdateParams.Relationship.EXTERNAL) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/WebhookServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/WebhookServiceTest.kt new file mode 100644 index 000000000..b8110614a --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/WebhookServiceTest.kt @@ -0,0 +1,159 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.blocking.beta + +import com.anthropic.TestServerExtension +import com.anthropic.client.okhttp.AnthropicOkHttpClient +import com.anthropic.core.UnwrapWebhookParams +import com.anthropic.core.http.Headers +import com.anthropic.errors.AnthropicWebhookException +import com.standardwebhooks.Webhook +import java.time.Instant +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class WebhookServiceTest { + + @Test + fun unwrap() { + val client = AnthropicOkHttpClient.builder().apiKey("my-anthropic-api-key").build() + val webhookService = client.beta().webhooks() + + val payload = + "{\"id\":\"wevt_011CZkZYZd9rLmz3ujAcsqEw\",\"created_at\":\"2026-03-15T10:00:00Z\",\"data\":{\"id\":\"sesn_011CZkZAtmR3yMPDzynEDxu7\",\"organization_id\":\"org_011CZkZZAe0sMna4vkBdtrfx\",\"type\":\"session.status_idled\",\"workspace_id\":\"wrkspc_011CZkZaBF1tNoB5wlCeusgy\"},\"type\":\"event\"}" + val webhookSecret = "whsec_c2VjcmV0Cg==" + val messageId = "1" + val timestampSeconds = Instant.now().epochSecond + val webhook = Webhook(webhookSecret) + val signature = webhook.sign(messageId, timestampSeconds, payload) + val headers = + Headers.builder() + .putAll( + mapOf( + "webhook-signature" to listOf(signature), + "webhook-id" to listOf(messageId), + "webhook-timestamp" to listOf(timestampSeconds.toString()), + ) + ) + .build() + + // Correct key should not throw + webhookService.unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(headers) + .secret(webhookSecret) + .build() + ) + webhookService + .withOptions { it.webhookKey(webhookSecret) } + .unwrap(UnwrapWebhookParams.builder().body(payload).headers(headers).build()) + + // Secret in method takes precedence to secret on client + val wrongKey = "whsec_aaaaaaaaaa" + webhookService + .withOptions { it.webhookKey(wrongKey) } + .unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(headers) + .secret(webhookSecret) + .build() + ) + + // Wrong key should throw + assertThrows { + val wrongKey = "whsec_aaaaaaaaaa" + webhookService.unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(headers) + .secret(wrongKey) + .build() + ) + } + assertThrows { + val wrongKey = "whsec_aaaaaaaaaa" + webhookService + .withOptions { it.webhookKey(wrongKey) } + .unwrap(UnwrapWebhookParams.builder().body(payload).headers(headers).build()) + } + + assertThrows { + val wrongKey = "whsec_aaaaaaaaaa" + webhookService.unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(headers) + .secret(wrongKey) + .build() + ) + } + assertThrows { + val wrongKey = "whsec_aaaaaaaaaa" + webhookService + .withOptions { it.webhookKey(wrongKey) } + .unwrap(UnwrapWebhookParams.builder().body(payload).headers(headers).build()) + } + + // Bad signature should throw + assertThrows { + val badSig = webhook.sign(messageId, timestampSeconds, "some other payload") + val badHeaders = + headers.toBuilder().replace("webhook-signature", listOf(badSig)).build() + webhookService.unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(badHeaders) + .secret(webhookSecret) + .build() + ) + } + assertThrows { + val badSig = webhook.sign(messageId, timestampSeconds, "some other payload") + val badHeaders = + headers.toBuilder().replace("webhook-signature", listOf(badSig)).build() + webhookService + .withOptions { it.webhookKey(webhookSecret) } + .unwrap(UnwrapWebhookParams.builder().body(payload).headers(badHeaders).build()) + } + + // Old timestamp should throw + assertThrows { + val oldHeaders = headers.toBuilder().replace("webhook-timestamp", listOf("5")).build() + webhookService.unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(oldHeaders) + .secret(webhookSecret) + .build() + ) + } + assertThrows { + val oldHeaders = headers.toBuilder().replace("webhook-timestamp", listOf("5")).build() + webhookService + .withOptions { it.webhookKey(webhookSecret) } + .unwrap(UnwrapWebhookParams.builder().body(payload).headers(oldHeaders).build()) + } + + // Wrong message ID should throw + assertThrows { + val wrongIdHeaders = headers.toBuilder().replace("webhook-id", listOf("wrong")).build() + webhookService.unwrap( + UnwrapWebhookParams.builder() + .body(payload) + .headers(wrongIdHeaders) + .secret(webhookSecret) + .build() + ) + } + assertThrows { + val wrongIdHeaders = headers.toBuilder().replace("webhook-id", listOf("wrong")).build() + webhookService + .withOptions { it.webhookKey(webhookSecret) } + .unwrap(UnwrapWebhookParams.builder().body(payload).headers(wrongIdHeaders).build()) + } + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/sessions/ThreadServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/sessions/ThreadServiceTest.kt new file mode 100644 index 000000000..b29118059 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/sessions/ThreadServiceTest.kt @@ -0,0 +1,73 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.blocking.beta.sessions + +import com.anthropic.TestServerExtension +import com.anthropic.client.okhttp.AnthropicOkHttpClient +import com.anthropic.models.beta.AnthropicBeta +import com.anthropic.models.beta.sessions.threads.ThreadArchiveParams +import com.anthropic.models.beta.sessions.threads.ThreadRetrieveParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class ThreadServiceTest { + + @Test + fun retrieve() { + val client = + AnthropicOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("my-anthropic-api-key") + .build() + val threadService = client.beta().sessions().threads() + + val betaManagedAgentsSessionThread = + threadService.retrieve( + ThreadRetrieveParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + ) + + betaManagedAgentsSessionThread.validate() + } + + @Disabled("buildURL drops path-level query params (SDK-4349)") + @Test + fun list() { + val client = + AnthropicOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("my-anthropic-api-key") + .build() + val threadService = client.beta().sessions().threads() + + val page = threadService.list("sesn_011CZkZAtmR3yMPDzynEDxu7") + + page.response().validate() + } + + @Test + fun archive() { + val client = + AnthropicOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("my-anthropic-api-key") + .build() + val threadService = client.beta().sessions().threads() + + val betaManagedAgentsSessionThread = + threadService.archive( + ThreadArchiveParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + ) + + betaManagedAgentsSessionThread.validate() + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/sessions/threads/EventServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/sessions/threads/EventServiceTest.kt new file mode 100644 index 000000000..5fc01e2ee --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/sessions/threads/EventServiceTest.kt @@ -0,0 +1,63 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.services.blocking.beta.sessions.threads + +import com.anthropic.TestServerExtension +import com.anthropic.client.okhttp.AnthropicOkHttpClient +import com.anthropic.models.beta.AnthropicBeta +import com.anthropic.models.beta.sessions.threads.events.EventListParams +import com.anthropic.models.beta.sessions.threads.events.EventStreamParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class EventServiceTest { + + @Disabled("buildURL drops path-level query params (SDK-4349)") + @Test + fun list() { + val client = + AnthropicOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("my-anthropic-api-key") + .build() + val eventService = client.beta().sessions().threads().events() + + val page = + eventService.list( + EventListParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .build() + ) + + page.response().validate() + } + + @Test + fun streamStreaming() { + val client = + AnthropicOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("my-anthropic-api-key") + .build() + val eventService = client.beta().sessions().threads().events() + + val betaManagedAgentsStreamSessionThreadEventsStreamResponse = + eventService.streamStreaming( + EventStreamParams.builder() + .sessionId("sesn_011CZkZAtmR3yMPDzynEDxu7") + .threadId("sthr_011CZkZVWa6oIjw0rgXZpnBt") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + ) + + betaManagedAgentsStreamSessionThreadEventsStreamResponse.use { + betaManagedAgentsStreamSessionThreadEventsStreamResponse.stream().forEach { + betaManagedAgentsStreamSessionThreadEvents -> + betaManagedAgentsStreamSessionThreadEvents.validate() + } + } + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/vaults/CredentialServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/vaults/CredentialServiceTest.kt index 64a686447..3da23b3aa 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/vaults/CredentialServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/vaults/CredentialServiceTest.kt @@ -13,6 +13,7 @@ import com.anthropic.models.beta.vaults.credentials.BetaManagedAgentsTokenEndpoi import com.anthropic.models.beta.vaults.credentials.CredentialArchiveParams import com.anthropic.models.beta.vaults.credentials.CredentialCreateParams import com.anthropic.models.beta.vaults.credentials.CredentialDeleteParams +import com.anthropic.models.beta.vaults.credentials.CredentialMcpOAuthValidateParams import com.anthropic.models.beta.vaults.credentials.CredentialRetrieveParams import com.anthropic.models.beta.vaults.credentials.CredentialUpdateParams import java.time.OffsetDateTime @@ -183,4 +184,26 @@ internal class CredentialServiceTest { betaManagedAgentsCredential.validate() } + + @Disabled("prism can't find endpoint with beta only tag") + @Test + fun mcpOAuthValidate() { + val client = + AnthropicOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("my-anthropic-api-key") + .build() + val credentialService = client.beta().vaults().credentials() + + val betaManagedAgentsCredentialValidation = + credentialService.mcpOAuthValidate( + CredentialMcpOAuthValidateParams.builder() + .vaultId("vlt_011CZkZDLs7fYzm1hXNPeRjv") + .credentialId("vcrd_011CZkZEMt8gZan2iYOQfSkw") + .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .build() + ) + + betaManagedAgentsCredentialValidation.validate() + } } diff --git a/scripts/mock b/scripts/mock index 2147c2f80..04d29019f 100755 --- a/scripts/mock +++ b/scripts/mock @@ -24,7 +24,7 @@ if [ "$1" == "--daemon" ]; then # Pre-install the package so the download doesn't eat into the startup timeout npm exec --package=@stdy/cli@0.22.1 -- steady --version - npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log & + npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=brackets --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log & # Wait for server to come online via health endpoint (max 30s) echo -n "Waiting for server" @@ -48,5 +48,5 @@ if [ "$1" == "--daemon" ]; then echo else - npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" + npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=brackets --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" fi diff --git a/scripts/test b/scripts/test index d7590fa25..e81baf829 100755 --- a/scripts/test +++ b/scripts/test @@ -43,7 +43,7 @@ elif ! steady_is_running ; then echo -e "To run the server, pass in the path or url of your OpenAPI" echo -e "spec to the steady command:" echo - echo -e " \$ ${YELLOW}npm exec --package=@stdy/cli@0.22.1 -- steady path/to/your.openapi.yml --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets${NC}" + echo -e " \$ ${YELLOW}npm exec --package=@stdy/cli@0.22.1 -- steady path/to/your.openapi.yml --host 127.0.0.1 -p 4010 --validator-query-array-format=brackets --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets${NC}" echo exit 1 From c390c200d0fb228caaebb7c14ae22fa72bec22b9 Mon Sep 17 00:00:00 2001 From: Cameron McAteer <246350779+cameron-mcateer@users.noreply.github.com> Date: Tue, 5 May 2026 15:30:21 -0400 Subject: [PATCH 3/6] chore: fix merge errors --- .../main/kotlin/com/anthropic/client/okhttp/OkHttpClient.kt | 5 ++--- anthropic-java-core/build.gradle.kts | 1 + .../src/main/kotlin/com/anthropic/core/ClientOptions.kt | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/OkHttpClient.kt b/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/OkHttpClient.kt index 08a39db0c..acef12bd4 100644 --- a/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/OkHttpClient.kt +++ b/anthropic-java-client-okhttp/src/main/kotlin/com/anthropic/client/okhttp/OkHttpClient.kt @@ -53,8 +53,7 @@ internal constructor( val call = newCall(preparedRequest, requestOptions) return try { - backend.prepareResponse( - call.execute().toHttpResponse()) + backend.prepareResponse(call.execute().toHttpResponse()) } catch (e: IOException) { throw AnthropicIoException("Request failed", e) } finally { @@ -353,7 +352,7 @@ private fun requiresBody(method: HttpMethod): Boolean = } private fun HttpRequest.toUrl(): String { - val builder = baseUrl.toHttpUrl().newBuilder() + val builder = baseUrl!!.toHttpUrl().newBuilder() pathSegments.forEach(builder::addPathSegment) queryParams.keys().forEach { key -> queryParams.values(key).forEach { builder.addQueryParameter(key, it) } diff --git a/anthropic-java-core/build.gradle.kts b/anthropic-java-core/build.gradle.kts index e1ec6018b..b8c9f6431 100644 --- a/anthropic-java-core/build.gradle.kts +++ b/anthropic-java-core/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { api("com.fasterxml.jackson.core:jackson-core:2.18.2") api("com.fasterxml.jackson.core:jackson-databind:2.18.2") api("com.google.errorprone:error_prone_annotations:2.33.0") + api("com.standardwebhooks:standardwebhooks:1.1.0") api("io.swagger.core.v3:swagger-annotations:2.2.31") implementation("com.fasterxml.jackson.core:jackson-annotations:2.18.2") diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/core/ClientOptions.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/core/ClientOptions.kt index 742fb5e1a..7a12aa5dc 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/core/ClientOptions.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/core/ClientOptions.kt @@ -112,6 +112,7 @@ private constructor( * Defaults to 2. */ @get:JvmName("maxRetries") val maxRetries: Int, + private val webhookKey: String?, private val credentialResult: CredentialResult?, ) { @@ -177,6 +178,7 @@ private constructor( responseValidation = clientOptions.responseValidation timeout = clientOptions.timeout maxRetries = clientOptions.maxRetries + webhookKey = clientOptions.webhookKey credentialResult = clientOptions.credentialResult } @@ -482,8 +484,8 @@ private constructor( responseValidation, timeout, maxRetries, - credentialResult, webhookKey, + credentialResult, ) } } From e641d5fef03fb832064d933326be8b0294e4ab0c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 6 May 2026 00:31:25 +0000 Subject: [PATCH 4/6] feat(api): add support for Managed Agents multiagents and outcomes, webhooks, vault validation --- .../kotlin/com/anthropic/core/ClientOptions.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/core/ClientOptions.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/core/ClientOptions.kt index 7a12aa5dc..46a00b877 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/core/ClientOptions.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/core/ClientOptions.kt @@ -395,8 +395,21 @@ private constructor( fun timeout(): Timeout = timeout - /** Updates configuration using environment variables. */ + /** + * Updates configuration using system properties and environment variables. + * + * See this table for the available options: + * + * |Setter |System property |Environment variable |Required|Default value| + * |------------|-----------------------------|-------------------------------|--------|-------------| + * |`webhookKey`|`anthropic.webhookSigningKey`|`ANTHROPIC_WEBHOOK_SIGNING_KEY`|false |- | + * + * System properties take precedence over environment variables. + */ fun fromEnv() = apply { + (System.getProperty("anthropic.webhookSigningKey") + ?: System.getenv("ANTHROPIC_WEBHOOK_SIGNING_KEY")) + ?.let { webhookKey(it) } System.getenv("ANTHROPIC_CUSTOM_HEADERS")?.let { customHeadersEnv -> for (line in customHeadersEnv.split("\n")) { val colon = line.indexOf(':') From 34ea5b41cb152df7abdc9d5e43949817c74d4375 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 6 May 2026 00:56:58 +0000 Subject: [PATCH 5/6] fix(api): Adjust webhook configuration --- .stats.yml | 6 +- .../models/beta/webhooks/BetaWebhookEvent.kt | 6 +- .../beta/webhooks/BetaWebhookEventData.kt | 56 +++++++++--------- ...bhookSessionStatusRescheduledEventData.kt} | 41 ++++++------- .../beta/webhooks/UnwrapWebhookEvent.kt | 6 +- .../beta/webhooks/BetaWebhookEventDataTest.kt | 59 ++++++++++--------- ...okSessionStatusRescheduledEventDataTest.kt | 47 +++++++++++++++ ...hookSessionStatusScheduledEventDataTest.kt | 47 --------------- 8 files changed, 135 insertions(+), 133 deletions(-) rename anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/{BetaWebhookSessionStatusScheduledEventData.kt => BetaWebhookSessionStatusRescheduledEventData.kt} (87%) create mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRescheduledEventDataTest.kt delete mode 100644 anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventDataTest.kt diff --git a/.stats.yml b/.stats.yml index 89ca80542..5a84c2e7b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 97 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic/anthropic-9f858907356014087c51d59846cd158425826fc558a1683e6ebf49483503cd5e.yml -openapi_spec_hash: 87cd38428be2fb157f6d79b50c00f573 -config_hash: 0ed9b1770bb175fa6bdc1e4d41afb180 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic/anthropic-0df2c793ea4c3ad955e8e488be39d7041a0a95e2fe144dd69ae4d9fb72835190.yml +openapi_spec_hash: b169b786bdf1f07d7f77f18f7b94abfa +config_hash: ed43b84afda7441f472a59dda6badb05 diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEvent.kt index f571169d7..c1184ff19 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEvent.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEvent.kt @@ -219,10 +219,10 @@ private constructor( /** * Alias for calling [data] with - * `BetaWebhookEventData.ofSessionStatusScheduled(sessionStatusScheduled)`. + * `BetaWebhookEventData.ofSessionStatusRescheduled(sessionStatusRescheduled)`. */ - fun data(sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData) = - data(BetaWebhookEventData.ofSessionStatusScheduled(sessionStatusScheduled)) + fun data(sessionStatusRescheduled: BetaWebhookSessionStatusRescheduledEventData) = + data(BetaWebhookEventData.ofSessionStatusRescheduled(sessionStatusRescheduled)) /** * Alias for calling [data] with diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventData.kt index 7afd99f26..4cc1e175b 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventData.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventData.kt @@ -29,7 +29,7 @@ private constructor( private val sessionRequiresAction: BetaWebhookSessionRequiresActionEventData? = null, private val sessionArchived: BetaWebhookSessionArchivedEventData? = null, private val sessionDeleted: BetaWebhookSessionDeletedEventData? = null, - private val sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData? = null, + private val sessionStatusRescheduled: BetaWebhookSessionStatusRescheduledEventData? = null, private val sessionStatusRunStarted: BetaWebhookSessionStatusRunStartedEventData? = null, private val sessionStatusIdled: BetaWebhookSessionStatusIdledEventData? = null, private val sessionStatusTerminated: BetaWebhookSessionStatusTerminatedEventData? = null, @@ -70,8 +70,8 @@ private constructor( fun sessionDeleted(): Optional = Optional.ofNullable(sessionDeleted) - fun sessionStatusScheduled(): Optional = - Optional.ofNullable(sessionStatusScheduled) + fun sessionStatusRescheduled(): Optional = + Optional.ofNullable(sessionStatusRescheduled) fun sessionStatusRunStarted(): Optional = Optional.ofNullable(sessionStatusRunStarted) @@ -130,7 +130,7 @@ private constructor( fun isSessionDeleted(): Boolean = sessionDeleted != null - fun isSessionStatusScheduled(): Boolean = sessionStatusScheduled != null + fun isSessionStatusRescheduled(): Boolean = sessionStatusRescheduled != null fun isSessionStatusRunStarted(): Boolean = sessionStatusRunStarted != null @@ -180,8 +180,8 @@ private constructor( fun asSessionDeleted(): BetaWebhookSessionDeletedEventData = sessionDeleted.getOrThrow("sessionDeleted") - fun asSessionStatusScheduled(): BetaWebhookSessionStatusScheduledEventData = - sessionStatusScheduled.getOrThrow("sessionStatusScheduled") + fun asSessionStatusRescheduled(): BetaWebhookSessionStatusRescheduledEventData = + sessionStatusRescheduled.getOrThrow("sessionStatusRescheduled") fun asSessionStatusRunStarted(): BetaWebhookSessionStatusRunStartedEventData = sessionStatusRunStarted.getOrThrow("sessionStatusRunStarted") @@ -264,8 +264,8 @@ private constructor( visitor.visitSessionRequiresAction(sessionRequiresAction) sessionArchived != null -> visitor.visitSessionArchived(sessionArchived) sessionDeleted != null -> visitor.visitSessionDeleted(sessionDeleted) - sessionStatusScheduled != null -> - visitor.visitSessionStatusScheduled(sessionStatusScheduled) + sessionStatusRescheduled != null -> + visitor.visitSessionStatusRescheduled(sessionStatusRescheduled) sessionStatusRunStarted != null -> visitor.visitSessionStatusRunStarted(sessionStatusRunStarted) sessionStatusIdled != null -> visitor.visitSessionStatusIdled(sessionStatusIdled) @@ -348,10 +348,10 @@ private constructor( sessionDeleted.validate() } - override fun visitSessionStatusScheduled( - sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData + override fun visitSessionStatusRescheduled( + sessionStatusRescheduled: BetaWebhookSessionStatusRescheduledEventData ) { - sessionStatusScheduled.validate() + sessionStatusRescheduled.validate() } override fun visitSessionStatusRunStarted( @@ -480,9 +480,9 @@ private constructor( sessionDeleted: BetaWebhookSessionDeletedEventData ) = sessionDeleted.validity() - override fun visitSessionStatusScheduled( - sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData - ) = sessionStatusScheduled.validity() + override fun visitSessionStatusRescheduled( + sessionStatusRescheduled: BetaWebhookSessionStatusRescheduledEventData + ) = sessionStatusRescheduled.validity() override fun visitSessionStatusRunStarted( sessionStatusRunStarted: BetaWebhookSessionStatusRunStartedEventData @@ -554,7 +554,7 @@ private constructor( sessionRequiresAction == other.sessionRequiresAction && sessionArchived == other.sessionArchived && sessionDeleted == other.sessionDeleted && - sessionStatusScheduled == other.sessionStatusScheduled && + sessionStatusRescheduled == other.sessionStatusRescheduled && sessionStatusRunStarted == other.sessionStatusRunStarted && sessionStatusIdled == other.sessionStatusIdled && sessionStatusTerminated == other.sessionStatusTerminated && @@ -580,7 +580,7 @@ private constructor( sessionRequiresAction, sessionArchived, sessionDeleted, - sessionStatusScheduled, + sessionStatusRescheduled, sessionStatusRunStarted, sessionStatusIdled, sessionStatusTerminated, @@ -607,8 +607,8 @@ private constructor( "BetaWebhookEventData{sessionRequiresAction=$sessionRequiresAction}" sessionArchived != null -> "BetaWebhookEventData{sessionArchived=$sessionArchived}" sessionDeleted != null -> "BetaWebhookEventData{sessionDeleted=$sessionDeleted}" - sessionStatusScheduled != null -> - "BetaWebhookEventData{sessionStatusScheduled=$sessionStatusScheduled}" + sessionStatusRescheduled != null -> + "BetaWebhookEventData{sessionStatusRescheduled=$sessionStatusRescheduled}" sessionStatusRunStarted != null -> "BetaWebhookEventData{sessionStatusRunStarted=$sessionStatusRunStarted}" sessionStatusIdled != null -> @@ -670,9 +670,9 @@ private constructor( BetaWebhookEventData(sessionDeleted = sessionDeleted) @JvmStatic - fun ofSessionStatusScheduled( - sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData - ) = BetaWebhookEventData(sessionStatusScheduled = sessionStatusScheduled) + fun ofSessionStatusRescheduled( + sessionStatusRescheduled: BetaWebhookSessionStatusRescheduledEventData + ) = BetaWebhookEventData(sessionStatusRescheduled = sessionStatusRescheduled) @JvmStatic fun ofSessionStatusRunStarted( @@ -761,8 +761,8 @@ private constructor( fun visitSessionDeleted(sessionDeleted: BetaWebhookSessionDeletedEventData): T - fun visitSessionStatusScheduled( - sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData + fun visitSessionStatusRescheduled( + sessionStatusRescheduled: BetaWebhookSessionStatusRescheduledEventData ): T fun visitSessionStatusRunStarted( @@ -887,12 +887,12 @@ private constructor( ?.let { BetaWebhookEventData(sessionDeleted = it, _json = json) } ?: BetaWebhookEventData(_json = json) } - "session.status_scheduled" -> { + "session.status_rescheduled" -> { return tryDeserialize( node, - jacksonTypeRef(), + jacksonTypeRef(), ) - ?.let { BetaWebhookEventData(sessionStatusScheduled = it, _json = json) } + ?.let { BetaWebhookEventData(sessionStatusRescheduled = it, _json = json) } ?: BetaWebhookEventData(_json = json) } "session.status_run_started" -> { @@ -1022,8 +1022,8 @@ private constructor( generator.writeObject(value.sessionRequiresAction) value.sessionArchived != null -> generator.writeObject(value.sessionArchived) value.sessionDeleted != null -> generator.writeObject(value.sessionDeleted) - value.sessionStatusScheduled != null -> - generator.writeObject(value.sessionStatusScheduled) + value.sessionStatusRescheduled != null -> + generator.writeObject(value.sessionStatusRescheduled) value.sessionStatusRunStarted != null -> generator.writeObject(value.sessionStatusRunStarted) value.sessionStatusIdled != null -> generator.writeObject(value.sessionStatusIdled) diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventData.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRescheduledEventData.kt similarity index 87% rename from anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventData.kt rename to anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRescheduledEventData.kt index 37e087ed6..3cfff65a4 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventData.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRescheduledEventData.kt @@ -15,7 +15,7 @@ import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects -class BetaWebhookSessionStatusScheduledEventData +class BetaWebhookSessionStatusRescheduledEventData @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, @@ -54,7 +54,7 @@ private constructor( /** * Expected to always return the following: * ```java - * JsonValue.from("session.status_scheduled") + * JsonValue.from("session.status_rescheduled") * ``` * * However, this method can be useful for debugging and logging (e.g. if the server responded @@ -109,7 +109,7 @@ private constructor( /** * Returns a mutable builder for constructing an instance of - * [BetaWebhookSessionStatusScheduledEventData]. + * [BetaWebhookSessionStatusRescheduledEventData]. * * The following fields are required: * ```java @@ -121,25 +121,26 @@ private constructor( @JvmStatic fun builder() = Builder() } - /** A builder for [BetaWebhookSessionStatusScheduledEventData]. */ + /** A builder for [BetaWebhookSessionStatusRescheduledEventData]. */ class Builder internal constructor() { private var id: JsonField? = null private var organizationId: JsonField? = null - private var type: JsonValue = JsonValue.from("session.status_scheduled") + private var type: JsonValue = JsonValue.from("session.status_rescheduled") private var workspaceId: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from( - betaWebhookSessionStatusScheduledEventData: BetaWebhookSessionStatusScheduledEventData + betaWebhookSessionStatusRescheduledEventData: + BetaWebhookSessionStatusRescheduledEventData ) = apply { - id = betaWebhookSessionStatusScheduledEventData.id - organizationId = betaWebhookSessionStatusScheduledEventData.organizationId - type = betaWebhookSessionStatusScheduledEventData.type - workspaceId = betaWebhookSessionStatusScheduledEventData.workspaceId + id = betaWebhookSessionStatusRescheduledEventData.id + organizationId = betaWebhookSessionStatusRescheduledEventData.organizationId + type = betaWebhookSessionStatusRescheduledEventData.type + workspaceId = betaWebhookSessionStatusRescheduledEventData.workspaceId additionalProperties = - betaWebhookSessionStatusScheduledEventData.additionalProperties.toMutableMap() + betaWebhookSessionStatusRescheduledEventData.additionalProperties.toMutableMap() } /** ID of the resource that triggered the event. */ @@ -172,7 +173,7 @@ private constructor( * It is usually unnecessary to call this method because the field defaults to the * following: * ```java - * JsonValue.from("session.status_scheduled") + * JsonValue.from("session.status_rescheduled") * ``` * * This method is primarily for setting the field to an undocumented or not yet supported @@ -211,7 +212,7 @@ private constructor( } /** - * Returns an immutable instance of [BetaWebhookSessionStatusScheduledEventData]. + * Returns an immutable instance of [BetaWebhookSessionStatusRescheduledEventData]. * * Further updates to this [Builder] will not mutate the returned instance. * @@ -224,8 +225,8 @@ private constructor( * * @throws IllegalStateException if any required field is unset. */ - fun build(): BetaWebhookSessionStatusScheduledEventData = - BetaWebhookSessionStatusScheduledEventData( + fun build(): BetaWebhookSessionStatusRescheduledEventData = + BetaWebhookSessionStatusRescheduledEventData( checkRequired("id", id), checkRequired("organizationId", organizationId), type, @@ -244,7 +245,7 @@ private constructor( * @throws AnthropicInvalidDataException if any value type in this object doesn't match its * expected type. */ - fun validate(): BetaWebhookSessionStatusScheduledEventData = apply { + fun validate(): BetaWebhookSessionStatusRescheduledEventData = apply { if (validated) { return@apply } @@ -252,7 +253,7 @@ private constructor( id() organizationId() _type().let { - if (it != JsonValue.from("session.status_scheduled")) { + if (it != JsonValue.from("session.status_rescheduled")) { throw AnthropicInvalidDataException("'type' is invalid, received $it") } } @@ -277,7 +278,7 @@ private constructor( internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) + (if (organizationId.asKnown().isPresent) 1 else 0) + - type.let { if (it == JsonValue.from("session.status_scheduled")) 1 else 0 } + + type.let { if (it == JsonValue.from("session.status_rescheduled")) 1 else 0 } + (if (workspaceId.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { @@ -285,7 +286,7 @@ private constructor( return true } - return other is BetaWebhookSessionStatusScheduledEventData && + return other is BetaWebhookSessionStatusRescheduledEventData && id == other.id && organizationId == other.organizationId && type == other.type && @@ -300,5 +301,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "BetaWebhookSessionStatusScheduledEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" + "BetaWebhookSessionStatusRescheduledEventData{id=$id, organizationId=$organizationId, type=$type, workspaceId=$workspaceId, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/UnwrapWebhookEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/UnwrapWebhookEvent.kt index 41c70dedb..a99a40644 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/UnwrapWebhookEvent.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/webhooks/UnwrapWebhookEvent.kt @@ -219,10 +219,10 @@ private constructor( /** * Alias for calling [data] with - * `BetaWebhookEventData.ofSessionStatusScheduled(sessionStatusScheduled)`. + * `BetaWebhookEventData.ofSessionStatusRescheduled(sessionStatusRescheduled)`. */ - fun data(sessionStatusScheduled: BetaWebhookSessionStatusScheduledEventData) = - data(BetaWebhookEventData.ofSessionStatusScheduled(sessionStatusScheduled)) + fun data(sessionStatusRescheduled: BetaWebhookSessionStatusRescheduledEventData) = + data(BetaWebhookEventData.ofSessionStatusRescheduled(sessionStatusRescheduled)) /** * Alias for calling [data] with diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventDataTest.kt index 18747fbad..5adfec5fd 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventDataTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookEventDataTest.kt @@ -32,7 +32,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -88,7 +88,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -144,7 +144,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -200,7 +200,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -257,7 +257,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).contains(sessionRequiresAction) assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -313,7 +313,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).contains(sessionArchived) assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -369,7 +369,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).contains(sessionDeleted) - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -408,16 +408,16 @@ internal class BetaWebhookEventDataTest { } @Test - fun ofSessionStatusScheduled() { - val sessionStatusScheduled = - BetaWebhookSessionStatusScheduledEventData.builder() + fun ofSessionStatusRescheduled() { + val sessionStatusRescheduled = + BetaWebhookSessionStatusRescheduledEventData.builder() .id("id") .organizationId("organization_id") .workspaceId("workspace_id") .build() val betaWebhookEventData = - BetaWebhookEventData.ofSessionStatusScheduled(sessionStatusScheduled) + BetaWebhookEventData.ofSessionStatusRescheduled(sessionStatusRescheduled) assertThat(betaWebhookEventData.sessionCreated()).isEmpty assertThat(betaWebhookEventData.sessionPending()).isEmpty @@ -426,7 +426,8 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).contains(sessionStatusScheduled) + assertThat(betaWebhookEventData.sessionStatusRescheduled()) + .contains(sessionStatusRescheduled) assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -444,11 +445,11 @@ internal class BetaWebhookEventDataTest { } @Test - fun ofSessionStatusScheduledRoundtrip() { + fun ofSessionStatusRescheduledRoundtrip() { val jsonMapper = jsonMapper() val betaWebhookEventData = - BetaWebhookEventData.ofSessionStatusScheduled( - BetaWebhookSessionStatusScheduledEventData.builder() + BetaWebhookEventData.ofSessionStatusRescheduled( + BetaWebhookSessionStatusRescheduledEventData.builder() .id("id") .organizationId("organization_id") .workspaceId("workspace_id") @@ -483,7 +484,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).contains(sessionStatusRunStarted) assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -539,7 +540,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).contains(sessionStatusIdled) assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -596,7 +597,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).contains(sessionStatusTerminated) @@ -652,7 +653,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -708,7 +709,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -765,7 +766,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -822,7 +823,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -879,7 +880,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -935,7 +936,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -991,7 +992,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -1049,7 +1050,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -1108,7 +1109,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -1167,7 +1168,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty @@ -1226,7 +1227,7 @@ internal class BetaWebhookEventDataTest { assertThat(betaWebhookEventData.sessionRequiresAction()).isEmpty assertThat(betaWebhookEventData.sessionArchived()).isEmpty assertThat(betaWebhookEventData.sessionDeleted()).isEmpty - assertThat(betaWebhookEventData.sessionStatusScheduled()).isEmpty + assertThat(betaWebhookEventData.sessionStatusRescheduled()).isEmpty assertThat(betaWebhookEventData.sessionStatusRunStarted()).isEmpty assertThat(betaWebhookEventData.sessionStatusIdled()).isEmpty assertThat(betaWebhookEventData.sessionStatusTerminated()).isEmpty diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRescheduledEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRescheduledEventDataTest.kt new file mode 100644 index 000000000..87f54ad7b --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusRescheduledEventDataTest.kt @@ -0,0 +1,47 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.webhooks + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaWebhookSessionStatusRescheduledEventDataTest { + + @Test + fun create() { + val betaWebhookSessionStatusRescheduledEventData = + BetaWebhookSessionStatusRescheduledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + assertThat(betaWebhookSessionStatusRescheduledEventData.id()).isEqualTo("id") + assertThat(betaWebhookSessionStatusRescheduledEventData.organizationId()) + .isEqualTo("organization_id") + assertThat(betaWebhookSessionStatusRescheduledEventData.workspaceId()) + .isEqualTo("workspace_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaWebhookSessionStatusRescheduledEventData = + BetaWebhookSessionStatusRescheduledEventData.builder() + .id("id") + .organizationId("organization_id") + .workspaceId("workspace_id") + .build() + + val roundtrippedBetaWebhookSessionStatusRescheduledEventData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaWebhookSessionStatusRescheduledEventData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaWebhookSessionStatusRescheduledEventData) + .isEqualTo(betaWebhookSessionStatusRescheduledEventData) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventDataTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventDataTest.kt deleted file mode 100644 index ccb353c25..000000000 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/webhooks/BetaWebhookSessionStatusScheduledEventDataTest.kt +++ /dev/null @@ -1,47 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.anthropic.models.beta.webhooks - -import com.anthropic.core.jsonMapper -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class BetaWebhookSessionStatusScheduledEventDataTest { - - @Test - fun create() { - val betaWebhookSessionStatusScheduledEventData = - BetaWebhookSessionStatusScheduledEventData.builder() - .id("id") - .organizationId("organization_id") - .workspaceId("workspace_id") - .build() - - assertThat(betaWebhookSessionStatusScheduledEventData.id()).isEqualTo("id") - assertThat(betaWebhookSessionStatusScheduledEventData.organizationId()) - .isEqualTo("organization_id") - assertThat(betaWebhookSessionStatusScheduledEventData.workspaceId()) - .isEqualTo("workspace_id") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val betaWebhookSessionStatusScheduledEventData = - BetaWebhookSessionStatusScheduledEventData.builder() - .id("id") - .organizationId("organization_id") - .workspaceId("workspace_id") - .build() - - val roundtrippedBetaWebhookSessionStatusScheduledEventData = - jsonMapper.readValue( - jsonMapper.writeValueAsString(betaWebhookSessionStatusScheduledEventData), - jacksonTypeRef(), - ) - - assertThat(roundtrippedBetaWebhookSessionStatusScheduledEventData) - .isEqualTo(betaWebhookSessionStatusScheduledEventData) - } -} From 99141d6ff90a52950ceb3bbac16750876b9beb19 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 6 May 2026 00:57:26 +0000 Subject: [PATCH 6/6] chore: release main --- .release-please-manifest.json | 2 +- CHANGELOG.md | 20 ++++++++++++++++++++ README.md | 4 ++-- build.gradle.kts | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index e294a783a..2a0dd335b 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,4 +1,4 @@ { - ".": "2.29.0", + ".": "2.30.0", "anthropic-java-aws": "0.2.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e38f62da9..785441317 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # Changelog +## 2.30.0 (2026-05-06) + +Full Changelog: [v2.29.0...v2.30.0](https://github.com/anthropics/anthropic-sdk-java/compare/v2.29.0...v2.30.0) + +### Features + +* **api:** add support for Managed Agents multiagents and outcomes, webhooks, vault validation ([e641d5f](https://github.com/anthropics/anthropic-sdk-java/commit/e641d5fef03fb832064d933326be8b0294e4ab0c)) +* **api:** add support for Managed Agents multiagents and outcomes, webhooks, vault validation ([6067599](https://github.com/anthropics/anthropic-sdk-java/commit/60675993a7c520e7fb74d02dc797d64e854d58e8)) +* **client:** support proxy authentication ([d91fea2](https://github.com/anthropics/anthropic-sdk-java/commit/d91fea2762368d5b52296dddd36e1b9b67ff1bf5)) + + +### Bug Fixes + +* **api:** Adjust webhook configuration ([34ea5b4](https://github.com/anthropics/anthropic-sdk-java/commit/34ea5b41cb152df7abdc9d5e43949817c74d4375)) + + +### Chores + +* fix merge errors ([c390c20](https://github.com/anthropics/anthropic-sdk-java/commit/c390c200d0fb228caaebb7c14ae22fa72bec22b9)) + ## 2.29.0 (2026-05-05) Full Changelog: [v2.28.0...v2.29.0](https://github.com/anthropics/anthropic-sdk-java/compare/v2.28.0...v2.29.0) diff --git a/README.md b/README.md index 7d505beb5..7fb8be0f2 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Full documentation is available at **[platform.claude.com/docs/en/api/sdks/java] ### Gradle ```kotlin -implementation("com.anthropic:anthropic-java:2.29.0") +implementation("com.anthropic:anthropic-java:2.30.0") ``` ### Maven @@ -24,7 +24,7 @@ implementation("com.anthropic:anthropic-java:2.29.0") com.anthropic anthropic-java - 2.29.0 + 2.30.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index bcda09b69..ca0aa4662 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.anthropic" - version = "2.29.0" // x-release-please-version + version = "2.30.0" // x-release-please-version } subprojects {